Ejemplo n.º 1
0
Archivo: level.c Proyecto: callaa/luola
/* geometry changes. */
void reinit_stars(void) {
    SDL_Rect size = get_viewport_size();
    int r;
    for (r = 0; r < sizeof(lev_stars)/sizeof(Star); r++) {
        lev_stars[r].x = rand () % size.w;
        lev_stars[r].y = rand () % size.h;
    }
}
Ejemplo n.º 2
0
// saves the actual active overlay data to a file.
void save_edge_overlay(void)
{

    char fn[64];
    char msg[64];
    FILE *fd;
    DIR* d;
    int fnum = 0;
    int fr = 0;
    int zoom = 0;
    struct dirent* de;
    static struct utimbuf t;
    // nothing to save? then dont save

    if( !is_buffer_ready() )
    {
        draw_string(0, 0, "No overlay to save.", user_color(conf.osd_color));
        return;
    }

    zoom = shooting_get_zoom();

    // first figure out the most appropriate filename to use
    d = opendir(EDGE_SAVE_DIR);
    if( ! d )
    {
        return;
    }

    while( (de = readdir(d)) )
    {
        fr = get_edge_file_num(de->d_name);
        if( fr > fnum )
        {
            fnum = fr;
        }
    }
    ++fnum; // the highest is set, we use the next one
    get_viewport_size();
    // open the right file
    sprintf(fn, EDGE_SAVE_DIR "/" EDGE_FILE_FORMAT, fnum );
    fd = fopen(fn, "wb");
    if(fd !=NULL)
    {
        // write the data
        fwrite(edgebuf->ptr,edgebuf->ptrLen,1,fd);
        fwrite(&zoom,sizeof(zoom),1,fd);
        fclose(fd);
        t.actime = t.modtime = time(NULL);
        utime(fn, &t);
        sprintf(msg, "Saved as %s",fn);
        draw_string(0, 0, msg, user_color(conf.osd_color));
    }
    closedir(d);
}
Ejemplo n.º 3
0
// load the edge overlay from a file
void load_edge_overlay(const char* fn)
{
    FILE *fd;
    int zoom;

    get_viewport_size();
    ensure_allocate_imagebuffer( );
    fd = fopen(fn,"rb");
    if( fd != NULL )
    {
        int ret = fread(edgebuf->ptr,edgebuf->ptrLen,1,fd);
        int ret2 = fread (&zoom,sizeof(zoom),1,fd);
        fclose(fd);
        if( (ret == 1) && (ret2 == 1) )
        {
            fsm_state = EDGE_FROZEN;    // switch to "edge overlay frozen"-mode
            if (conf.edge_overlay_zoom)
            {
                shooting_set_zoom(zoom);
            }
        }
    }
}
Ejemplo n.º 4
0
// Main edge overlay function.
// It works by detecting edges using the Sobel operator
// (calc_edgeoverlay()), the detected edges are then stored into an
// array of 1-bit elements. A set bit indicates that there is an
// edge and that it should be drawn onto the overlay.
// When needed, the 1-bit edge buffer is drawn onto the screen
// (dynamically decompressing it) using draw_edge_overlay().
void edge_overlay()
{
    // Was the shutter fully pressed the last time we ran?
    // We use this to make sure that the user has released
    // the button before processing the next FullPress event.
    // This prevents switching FSM states more than once
    // per press.
    static int bFullPress_prev = 0;

    // Have we already started taking pictures in panorama mode?
    // We use this variable to be able to detect if panorama
    // mode has been turned off.
    static int bPanoInProgress = 0;

    // Precalculate some values to make the rest of the
    // code easier to read.
    int bFullPress = kbd_is_key_pressed(KEY_SHOOT_FULL);
    const int bHalfPress = camera_info.state.is_shutter_half_press;
    const int bPlayMode = camera_info.state.mode_play;
    const int bPanoramaMode = (conf.edge_overlay_pano != 0);
    const int bNeedHalfPress = (conf.edge_overlay_show != 1);
    const int bDisplayInPlay = (conf.edge_overlay_play == 1);
    const int bCanDisplay = (
                                (!bPlayMode && (bHalfPress || !bNeedHalfPress)) ||   // we have a HalfPress in rec-mode
                                ( bPlayMode && bDisplayInPlay)  // or we are in play-mode with the right settings
                            );

    if (bPanoInProgress && !bPanoramaMode)
    {
        // This means panorama mode has been recently
        // turned off in the menu. So let's release
        // Frozen mode for the user.
        reset_edge_overlay();
        bPanoInProgress = 0;
    }

    get_viewport_size();

    // For just two states a state machine is not actually needed.
    // But it is scalable in the future in case anybody
    // wants to extend the functionality of edge overlay.
    switch (fsm_state)
    {
    case EDGE_LIVE:
    {
        camera_info.state.edge_state_draw=0;
        // In this state we assume no edge overlay in memory,
        // but we are ready to create one if the user presses wishes so.

        int bRealtimeUpdate = bCanDisplay && (camera_info.state.gui_mode_alt || camera_info.state.gui_mode_none);
        if (bRealtimeUpdate)
        {
            // We try to detect button presses during the lengthy
            // calculations.
            bFullPress |= calc_edge_overlay();
            bFullPress |= draw_edge_overlay();
        }

        int bSwitch2Frozen = bFullPress && !bFullPress_prev && camera_info.state.gui_mode_none;
        if (bSwitch2Frozen)
        {
            // Switch to Frozen mode

            // Make sure we have one whole consistent frame
            for (slice = 0; slice < EDGE_SLICES; ++slice)
                calc_edge_overlay();

            set_offset_from_overlap();
            fsm_state = EDGE_FROZEN;
            bPanoInProgress = bPanoramaMode;
        }

        if (!bRealtimeUpdate && !bSwitch2Frozen)
        {
            // Nothing happens. So do nothing.
            // Or rather, we could clean up if we are that bored.
            reset_edge_overlay();
        }
        break;
    }
    case EDGE_FROZEN:
    {
        camera_info.state.edge_state_draw=1;
        // We have a stored edge overlay in memory and we display
        // it on screen in 'frozen' mode.

        // Move edge overlay around.
        if (camera_info.state.gui_mode_alt)
        {
            if (kbd_is_key_pressed(KEY_RIGHT))
                xoffset +=XINC;
            if (kbd_is_key_pressed(KEY_LEFT))
                xoffset -=XINC;
            if (kbd_is_key_pressed(KEY_DOWN))
                yoffset +=YINC;
            if (kbd_is_key_pressed(KEY_UP))
                yoffset -=YINC;
        }

        if (bCanDisplay && (camera_info.state.gui_mode_alt || camera_info.state.gui_mode_none))
        {
            // We try to detect button presses during the lengthy
            // calculations.
            bFullPress |= draw_edge_overlay();
            //draw_string(0, 0, "Frozen", user_color(conf.osd_color));
        }

        // In event of a FullPress, we either capture a new
        // overlay and stay frozen, OR we go back to live mode.
        if (bFullPress && !bFullPress_prev && camera_info.state.gui_mode_none)
        {
            // Possible mode switch
            if (bPanoramaMode)
            {
                // Make sure we have one whole consistent frame
                for (slice = 0; slice < EDGE_SLICES; ++slice)
                    calc_edge_overlay();

                set_offset_from_overlap();
                bPanoInProgress = 1;
            }
            else
                fsm_state = EDGE_LIVE;
        }

        break;
    }   // case
    }   // switch


    bFullPress_prev = bFullPress;

    if (++slice >= EDGE_SLICES)
        slice = 0;

}   // function
Ejemplo n.º 5
0
real_t CameraMatrix::get_aspect() const {

	real_t w, h;
	get_viewport_size(w, h);
	return w / h;
}