Changeset 1580


Ignore:
Timestamp:
01/19/12 08:29:14 (17 months ago)
Author:
philmoz
Message:

Rework of zebra module to make the module platform independent, also re-organised the code and added some comments. ZEBRA_HMARGIN0 is no longer needed so removed from platform_camera.h files.

Location:
trunk
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/gui_osd.h

    r1569 r1580  
    4747//ARM End 
    4848 
    49 extern int  gui_osd_draw_zebra(int show); 
    5049extern void gui_osd_draw_movie_time_left(); 
    5150 
  • trunk/core/main.c

    r1569 r1580  
    6161    CAM_BITMAP_WIDTH, CAM_BITMAP_HEIGHT, CAM_BITMAP_WIDTH * CAM_BITMAP_HEIGHT, 
    6262    EDGE_HMARGIN, CAM_TS_BUTTON_BORDER, 
     63#if defined(CAM_ZEBRA_NOBUF) 
     64    1, 
     65#else 
     66    0, 
     67#endif 
     68#if defined(CAM_ZEBRA_ASPECT_ADJUST) 
     69    1, 
     70#else 
     71    0, 
     72#endif 
     73#if defined(CAM_HAS_VARIABLE_ASPECT) 
     74    1, 
     75#else 
     76    0, 
     77#endif 
    6378}; 
    6479 
     
    85100    PROPCASE_FLASH_MODE, PROPCASE_FLASH_FIRE,  
    86101    PROPCASE_METERING_MODE, PROPCASE_WB_ADJ, 
     102#if defined(PROPCASE_ASPECT_RATIO) 
     103    PROPCASE_ASPECT_RATIO, 
     104#else 
     105    0, 
     106#endif 
     107    PROPCASE_SHOOTING, 
    87108    }, 
    88109    ROMBASEADDR, MAXRAMADDR, 
  • trunk/core/zebra.c

    r1569 r1580  
    1616//------------------------------------------------------------------- 
    1717 
     18// Notes on Zebra implementation. 
     19 
     20// The zebra code examines the Y (luminance) values of the camera 
     21// viewport to look for overexposed or underexposed pixels. The 
     22// range of low and high values that determine over and under 
     23// exposure is set with the 'zebra_over' and 'zebra_under' settings. 
     24 
     25// There is an RGB mode controlled by zebra_multichannel that 
     26// converts the viewport data from YUV to RGB and looks for exposure 
     27// problems in each channel. 
     28 
     29// Over and underexposed pixels are displayed on the bitmap screen 
     30// using the zebra_color setting - foregound color is used of over 
     31// exposure and background for under exposure. 
     32 
     33// The code tries to allocate a memory buffer that is the same dimensions 
     34// as the bitmap screen. The zebra display is written to this buffer 
     35// and when done the buffer is copied into the camera bitmap screen memory. 
     36// If the code can't allocate a memory buffer it writes the zebra data 
     37// directly to the camera bitmap screen memory. Allocation of the memory 
     38// buffer can also be overridden by setting CAM_ZEBRA_NOBUF in 
     39// platform_camera.h. The code here uses the equivalent setting from 
     40// camera_screen.zebra_nobuf for module platform indepedance. 
     41 
     42// There are two variations of the basic zebra code to cater for 
     43// different camera generations. Older cameras have a 360 byte wide 
     44// bitmap screen (or 480 for wide screen cameras). This matches the 
     45// CHDK virtual screen size so over and under exposed pixels are set 
     46// in the bitmap image buffer directly. 
     47// Newer cameras have a 720 (or 960) byte wide bitmap screen and the 
     48// zebra code write two bytes (pixels) into the buffer for every 
     49// over or underexposed pixel. Again the buffer is copied to the 
     50// camera bitmap memory when done. 
     51 
     52// Determining which code path is done with the CAM_ZEBRA_ASPECT_ADJUST 
     53// value in platform_camera.h (accessed via camera_screen.zebra_aspect_adjust). 
     54// If CAM_ZEBRA_ASPECT_ADJUST is not defined (or 0) the older code 
     55// is used that assumes the bitmap screen is 360 bytes wide. 
     56// Defining CAM_ZEBRA_ASPECT_ADJUST as 1 will use the newer code. 
     57 
     58// Another difference is that the old code path saves the top and bottom 
     59// of the Canon OSD from the bitmap screen memory and overlays this on 
     60// top of the zebra buffer. The new code version does not do this. The 
     61// size of the strips saved is defined by ZFIX_TOP and ZFIX_BOTTOM. 
     62 
     63// The final element comes from cameras that can capture images in 
     64// different aspect ratios. Canon cameras all have a 4:3 ratio sensor 
     65// but many can capture an image in different sizes - e.g. 1:1, 3:2 and 16:9. 
     66// When these alternate ratios are selected the camera displays black 
     67// bars at the top and bottom or left and right edges of the image in 
     68// the viewport. The zebra code attempts to cater for this and not 
     69// display underexposure indicators in these unused areas. The size 
     70// and position of the black bars is also dependant on the aspect ratio 
     71// of the camera LCD. Cameras with 4:3 LCD screens will show a 16:9 image 
     72// with bars above and below. Cameras with 16:9 LCD screens will show 
     73// a 4:3 image with bars to the left and right. 
     74 
     75// For older cameras (that do not define CAM_ZEBRA_ASPECT_ADJUST) the  
     76// aspect ratio is controlled by the CAM_HAS_VARIABLE_ASPECT value 
     77// in platform_camera.h (camera_screen.has_variable_aspect). Defining 
     78// this value tells the code that the camera has a 16:9 LCD but can 
     79// also display a 4:3 image with black bars on the left and right. 
     80// The value of the PROPCASE_ASPECT_RATIO property determines which 
     81// image size if displayed. The code cannot handle other combinations 
     82// of LCD size and image ratio. 
     83 
     84// For newer cameras the code can handle any combination of LCD size 
     85// and image aspect ratio provided the vid_get_viewport_height(),  
     86// vid_get_viewport_width(), vid_get_viewport_image_offset(), 
     87// vid_get_viewport_row_offset(), vid_get_viewport_xoffset(), 
     88// and vid_get_viewport_yoffset() functions have been correctly 
     89// implemented for the camera. 
     90 
     91// philmoz. Jan 2012. 
     92 
     93//------------------------------------------------------------------- 
     94// Zebra config settings 
     95 
    1896typedef struct 
    1997{ 
    20     color zebra_color;    // under/over 
     98    color zebra_color;          // under/over colors 
    2199    int zebra_mode; 
    22100    int zebra_restore_screen; 
     
    43121//------------------------------------------------------------------- 
    44122 
    45 #if defined (CAM_ZEBRA_NOBUF) && !defined(CAM_ZEBRA_ASPECT_ADJUST) 
    46 // old sx20 #ifdefs were roughly equivalent of both 
    47         #error "defined (CAM_ZEBRA_NOBUF) && !defined(CAM_ZEBRA_ASPECT_ADJUST). Remove this if you've verified it will work!" 
    48 #endif 
    49  
    50 #ifdef CAM_ZEBRA_ASPECT_ADJUST 
    51 // TODO should just not save anything at all instead of 1 px. Also, this shouldn't be tied to aspect correct 
    52   #define ZEBRA_CANONOSD_BORDER_RESTORE   1 
    53   #define ZFIX_TOP    1 
    54   #define ZFIX_BOTTOM 1 
    55 #else 
    56 // Width (in pixels) of half-shoot Canon OSD area of the screen buffer, for restore during  
     123// Height (in pixels) of half-shoot Canon OSD area of the screen buffer, for restore during  
    57124// Zebra draw, to limit RAM usage of zebra. Only these border areas are stored in RAM. 
    58 // Only top and bottom are restored, not left&right. 
    59   #define ZEBRA_CANONOSD_BORDER_RESTORE   1 
    60   #define ZFIX_TOP    29 
    61   #define ZFIX_BOTTOM 30 
    62 #endif 
     125// Only top and bottom are restored, not left & right. 
     126#define ZFIX_TOP    29 
     127#define ZFIX_BOTTOM 30 
    63128 
    64129static unsigned char *img_buf, *scr_buf; 
    65 #if ZEBRA_CANONOSD_BORDER_RESTORE 
    66130static unsigned char *cur_buf_top, *cur_buf_bot; 
    67 #else 
    68 static unsigned char *cur_buf; 
    69 #endif 
    70 static int cur_buf_size; 
    71131static int timer = 0; 
    72132static unsigned char *buf = NULL; 
    73  
    74 #ifdef CAM_ZEBRA_ASPECT_ADJUST 
    75133static int buffer_size; 
    76 #endif 
     134static color cl_under, cl_over; 
    77135 
    78136unsigned char clip8(signed short x){ if (x<0) x=0; else if (x>255) x=255; return x; } 
     
    80138//------------------------------------------------------------------- 
    81139// free and NULL zebra buffers. free(NULL) is always OK. 
    82 static void gui_osd_zebra_free() { 
    83 #if !defined (CAM_ZEBRA_NOBUF) 
    84         free(buf); 
    85 #endif 
    86         buf=NULL; 
    87 #if ZEBRA_CANONOSD_BORDER_RESTORE 
    88         free(cur_buf_top); 
    89         cur_buf_top=NULL; 
    90         free(cur_buf_bot); 
    91         cur_buf_bot=NULL; 
    92 #else 
    93         free(cur_buf); 
    94         cur_buf=NULL; 
    95 #endif       
    96 } 
     140static void gui_osd_zebra_free() 
     141{ 
     142    if (buf != scr_buf) free(buf); 
     143    buf = NULL; 
     144 
     145    free(cur_buf_top); 
     146    cur_buf_top = NULL; 
     147 
     148    free(cur_buf_bot); 
     149    cur_buf_bot = NULL; 
     150} 
     151 
    97152// prepare zebra resources, or free them 
    98153// returns 1 if zebra should be drawn 
    99 static int gui_osd_zebra_init(int show) { 
    100         unsigned i; 
    101  
    102   if(show) 
    103   { 
    104     if (!buf) 
     154static int gui_osd_zebra_init(int show) 
     155{ 
     156    cl_under = BG_COLOR(zconf.zebra_color); 
     157    cl_over = FG_COLOR(zconf.zebra_color); 
     158 
     159    if (show) 
    105160    { 
    106       timer = 0; 
    107           #if defined (CAM_ZEBRA_NOBUF) 
    108         buffer_size=camera_screen.buffer_size-ZEBRA_HMARGIN0*camera_screen.buffer_width; 
    109         buf=vid_get_bitmap_fb(); 
    110           #elif defined (CAM_ZEBRA_ASPECT_ADJUST) 
    111         buffer_size=camera_screen.buffer_size-ZEBRA_HMARGIN0*camera_screen.buffer_width; 
    112         buf = malloc(buffer_size); 
    113         //~ if (!buf) draw_txt_string(0, 14, "Warn: No space to allocate zebra buffer: restart camera", MAKE_COLOR(COLOR_ALT_BG, COLOR_FG)); 
    114161        if (!buf) 
    115           buf=vid_get_bitmap_fb(); //without new buffer: directly into screen buffer: we got some flickering in OSD and histogram but it's usable 
    116         //~ msleep(50); 
    117       #else 
    118         buf = malloc(camera_screen.buffer_size); 
    119       #endif 
     162        { 
     163            timer = 0; 
     164            // Determine bitmap buffer size. If physical buffer is taller than displayed height then ignore bottom strip - (used to be ZEBRA_HMARGIN0). 
     165            buffer_size = camera_screen.buffer_size - (camera_screen.buffer_height - camera_screen.height) * camera_screen.buffer_width; 
    120166            scr_buf = vid_get_bitmap_fb(); 
    121 #if ZEBRA_CANONOSD_BORDER_RESTORE 
    122             cur_buf_top = malloc(camera_screen.buffer_width * ZFIX_TOP);  
    123             cur_buf_bot = malloc(camera_screen.buffer_width * ZFIX_BOTTOM);  
    124 #if defined (CAM_ZEBRA_ASPECT_ADJUST) 
    125             if (cur_buf_top) memset(cur_buf_top,0,camera_screen.buffer_width * ZFIX_TOP); 
    126             if (cur_buf_bot) memset(cur_buf_bot,0,camera_screen.buffer_width * ZFIX_BOTTOM); 
    127 #endif 
    128 #else 
    129             cur_buf = malloc(camera_screen.buffer_size); 
    130 #endif       
    131                         // cleanup and disable zebra if any mallocs failed 
    132                         if(!buf ||  
    133 #if ZEBRA_CANONOSD_BORDER_RESTORE 
    134                                 !cur_buf_top || 
    135                                 !cur_buf_bot  
    136 #else 
    137                                 !cur_buf 
    138 #endif 
    139                                 ) { 
    140                                 gui_osd_zebra_free(); 
    141                         } 
    142 #if CAM_HAS_VARIABLE_ASPECT 
    143                         else // in variable aspect, the borders would never be cleared 
    144                                 memset(buf,0,camera_screen.buffer_size); 
    145 #endif 
     167            if (camera_screen.zebra_nobuf == 0) 
     168            { 
     169                buf = malloc(buffer_size); 
     170                //if (!buf) draw_txt_string(0, 14, "Warn: No space to allocate zebra buffer: restart camera", MAKE_COLOR(COLOR_ALT_BG, COLOR_FG)); 
     171            } 
     172            if (!buf) 
     173            { 
     174                buf = scr_buf;  //without new buffer: directly into screen buffer: we got some flickering in OSD and histogram but it's usable 
     175            } 
     176            if (camera_screen.zebra_aspect_adjust) 
     177            { 
     178                cur_buf_top = cur_buf_bot = 0; 
     179            } 
     180            else 
     181            { 
     182                cur_buf_top = malloc(camera_screen.buffer_width * ZFIX_TOP);  
     183                cur_buf_bot = malloc(camera_screen.buffer_width * ZFIX_BOTTOM);  
     184                // cleanup and disable zebra if any mallocs failed 
     185                if (!cur_buf_top || !cur_buf_bot) 
     186                    gui_osd_zebra_free(); 
     187                if (cur_buf_top) memset(cur_buf_top,0,camera_screen.buffer_width * ZFIX_TOP); 
     188                if (cur_buf_bot) memset(cur_buf_bot,0,camera_screen.buffer_width * ZFIX_BOTTOM); 
     189            } 
     190            // in variable aspect, the borders would never be cleared 
     191            if (camera_screen.has_variable_aspect) 
     192                memset(buf,0,buffer_size); 
    146193        } 
    147194    } 
    148195    else { 
    149                 if(buf) // if zebra was previously on, restore 
    150                         draw_restore(); 
    151  
    152                 gui_osd_zebra_free(); 
    153     } 
    154         return (buf != NULL); 
    155 } 
    156  
    157 //------------------------------------------------------------------- 
    158 #if ZEBRA_CANONOSD_BORDER_RESTORE 
    159 unsigned char get_cur_buf(unsigned int idx) { 
    160     unsigned int a; 
    161      
    162     a=camera_screen.buffer_size - camera_screen.buffer_width * ZFIX_BOTTOM; 
    163      
    164     if (idx < camera_screen.buffer_width * ZFIX_TOP) return(cur_buf_top[idx]); 
    165     if (idx >= a && idx < camera_screen.buffer_size) return(cur_buf_bot[idx - a]); 
    166     return (COLOR_TRANSPARENT); 
    167 } 
    168 #endif 
    169  
    170 //------------------------------------------------------------------- 
    171 static void draw_pixel_buffered(unsigned int offset, color cl) { 
    172 // shouldn't this be checked on all cams ? 
    173    #if defined CAM_ZEBRA_ASPECT_ADJUST 
    174       if (offset < buffer_size) 
    175          buf[offset] = cl; 
    176    #else 
    177       buf[offset] = cl; 
    178    #endif 
     196        if (buf) // if zebra was previously on, restore 
     197            draw_restore(); 
     198 
     199        gui_osd_zebra_free(); 
     200    } 
     201    return (buf != NULL); 
     202} 
     203 
     204//------------------------------------------------------------------- 
     205// Override for standard drawing function to draw OSD elements 
     206// into the zebra memory buffer instead of the camera screen. 
     207static void draw_pixel_buffered(unsigned int offset, color cl) 
     208{ 
     209    buf[offset] = cl; 
    179210} 
    180211 
     
    239270} 
    240271 
    241 // reyalp - TODO this should be rewritten so there is one generic zebra func for all cameras 
    242 #if defined(CAM_ZEBRA_ASPECT_ADJUST) 
    243 //nandoide sept-2009  
    244 // viewport is 360x240 and screen buffer 960x270, we need to expand the x coordinate 
    245 //reyalp - applies to other cameras where the real bitmap width is is different from what lib.c reports. Also used on some other cameras ... 
    246 int gui_osd_draw_zebra(int show) { 
    247     unsigned int v, s, x, y, f, over; 
    248     color cl_under = BG_COLOR(zconf.zebra_color), cl_over = FG_COLOR(zconf.zebra_color); 
     272//------------------------------------------------------------------- 
     273static void disp_zebra() 
     274{ 
     275    // draw CHDK osd and histogram to buf[] (if enabled in config) 
     276    gui_osd_draw_zebra_osd(); 
     277 
     278    // copy buf[] to both display buffers 
     279    if (buf != scr_buf) 
     280        memcpy(scr_buf, buf, buffer_size); 
     281    memcpy(scr_buf+camera_screen.buffer_size, buf, buffer_size); 
     282} 
     283 
     284//------------------------------------------------------------------- 
     285// CHDK uses a virtual screen size of 360 x 240 pixels (480x240 for wide screen models) 
     286// This function calculates the Zebra overlay for cameras where the screen buffer width 
     287// is not equivalent to the CHDK virtual screen width. Newer cameras have a 720 
     288// pixel wide screen (960 for wide screen models). 
     289static int draw_zebra_aspect_adjust(int mrec, unsigned int f, color *cls) 
     290{ 
     291    unsigned int v, s, x, y, over; 
    249292    static int need_restore=0; 
    250293    int viewport_height; 
     
    252295    int viewport_image_offset;  // for when viewport memory buffer is wider than viewport 
    253296    int viewport_row_offset;    // for when viewport memory buffer is wider than viewport 
    254     int viewport_xoffset;       // used when image size != viewport size 
    255     int viewport_yoffset;       // used when image size != viewport size 
     297    int viewport_xoffset;           // used when image size != viewport size 
     298    int viewport_yoffset;           // used when image size != viewport size 
     299    int zebra_drawn=0; 
     300 
     301    viewport_height = vid_get_viewport_height(); 
     302    viewport_width = vid_get_viewport_width();  
     303    viewport_image_offset = vid_get_viewport_image_offset();  
     304    viewport_row_offset = vid_get_viewport_row_offset();  
     305    viewport_xoffset = vid_get_viewport_xoffset(); 
     306    viewport_yoffset = vid_get_viewport_yoffset(); 
     307 
     308    // if not in no-zebra phase of blink mode zebra, draw zebra to buf[] 
     309    if (f) { 
     310        if (viewport_yoffset > 0) { // clear top & bottom areas of buffer if image height if smaller than viewport 
     311            memset(buf, COLOR_TRANSPARENT, viewport_yoffset*camera_screen.buffer_width); 
     312            memset(buf+(viewport_yoffset+viewport_height)*camera_screen.buffer_width, COLOR_TRANSPARENT, viewport_yoffset*camera_screen.buffer_width); 
     313        } 
     314        int step_x, step_v, sy, sx; 
     315        over = 255-zconf.zebra_over; 
     316        if (zconf.zebra_multichannel) {step_x=2; step_v=6;} else {step_x=1; step_v=3;} 
     317        for (y=viewport_yoffset, v=viewport_image_offset; y<viewport_yoffset+viewport_height; ++y) { 
     318            sy = y*camera_screen.buffer_width; 
     319            sx = viewport_xoffset; 
     320            if (viewport_xoffset > 0) { // clear left & right areas of buffer if image width if smaller than viewport 
     321                memset(buf+sy, COLOR_TRANSPARENT, sx*2); 
     322                memset(buf+sy+(sx+viewport_width)*2, COLOR_TRANSPARENT, sx*2); 
     323            } 
     324            for (x=viewport_xoffset; x<viewport_xoffset+viewport_width; x+=step_x, sx+=step_x, v+=step_v) { 
     325                register int yy; 
     326                yy = img_buf[v+1]; 
     327                s = sy + sx*2; 
     328 
     329                if (zconf.zebra_multichannel) { 
     330                    register int uu, vv; 
     331                    int sel; 
     332                    uu = (signed char)img_buf[v]; 
     333                    vv = (signed char)img_buf[v+2]; 
     334                    sel=0; 
     335                    if (!((zconf.zebra_mode == ZEBRA_MODE_ZEBRA_1 || zconf.zebra_mode == ZEBRA_MODE_ZEBRA_2) && (y-x-timer)&f)) { 
     336                        if (clip8(((yy<<12) +           vv*5743 + 2048)>>12)>over) sel  = 4; // R 
     337                        if (clip8(((yy<<12) - uu*1411 - vv*2925 + 2048)>>12)>over) sel |= 2; // G 
     338                        if (clip8(((yy<<12) + uu*7258           + 2048)>>12)>over) sel |= 1; // B 
     339                    } 
     340                    buf[s] = buf[s+1] = cls[sel]; 
     341                    buf[s+2] = buf[s+3] = cls[sel]; 
     342                } 
     343                else if (((zconf.zebra_mode == ZEBRA_MODE_ZEBRA_1 || zconf.zebra_mode == ZEBRA_MODE_ZEBRA_2) && (y-x-timer)&f)) 
     344                    buf[s] = buf[s+1] = COLOR_TRANSPARENT; 
     345                else  
     346                    buf[s] = buf[s+1] = (yy>over)?cl_over:(yy<zconf.zebra_under)?cl_under:COLOR_TRANSPARENT; 
     347 
     348                if (buf[s] != COLOR_TRANSPARENT && !zebra_drawn)  
     349                    zebra_drawn = 1; 
     350            } 
     351            // adjust for cases where buffer is wider than viewport (e.g. on G12) 
     352            v += viewport_row_offset; 
     353        } 
     354        if (!zebra_drawn) f=0; 
     355    } 
     356    // if blink mode is in no-zebra phase OR if there was no over/underexposed pixels to draw zebra on 
     357    if (!f) { 
     358        // if zebra was drawn during previous call of this function 
     359        if (need_restore) { 
     360            if (zconf.zebra_restore_screen || zconf.zebra_restore_osd) { 
     361                draw_restore(); 
     362            } else {  // clear buf[] of zebra, only leave Canon OSD 
     363                if (!mrec) { // Not REC mode 
     364                    // No Canon OSD restore, fill buf[] with transparent color: 
     365                    memset(buf, COLOR_TRANSPARENT, buffer_size); 
     366                } 
     367                disp_zebra(); 
     368            } 
     369            need_restore=0; 
     370        } 
     371        return !(zconf.zebra_restore_screen && zconf.zebra_restore_osd); 
     372        // if zebra was drawn 
     373    } else { 
     374        disp_zebra(); 
     375 
     376        need_restore=1; 
     377        return 1; 
     378    } 
     379    return 0; 
     380} 
     381 
     382//------------------------------------------------------------------- 
     383// Get the current Canon OSD pixel value for the top or bottom strip 
     384static unsigned char get_cur_buf(unsigned int idx) { 
     385    unsigned int a; 
     386 
     387    a=camera_screen.buffer_size - camera_screen.buffer_width * ZFIX_BOTTOM; 
     388 
     389    if (idx < camera_screen.buffer_width * ZFIX_TOP) return(cur_buf_top[idx]); 
     390    if (idx >= a && idx < camera_screen.buffer_size) return(cur_buf_bot[idx - a]); 
     391    return (COLOR_TRANSPARENT); 
     392} 
     393 
     394//------------------------------------------------------------------- 
     395// This function calculates the Zebra overlay for cameras where the screen buffer width 
     396// is equivalent to the CHDK virtual screen width. For older cameras where the screen 
     397// width is 360 pixels (or 480 for wide screen). 
     398static int draw_zebra_no_aspect_adjust(int mrec, unsigned int f, color *cls) { 
     399    unsigned int v, s, x, y, over; 
     400    static int need_restore=0; 
     401    int viewport_height; 
     402    int zebra_drawn=0; 
     403 
     404    unsigned bWide = 1; // if wide (16:9) or standard (4:3) aspect ratio (but 1 in cameras that only have 4:3) 
     405    unsigned aspOffset = 0; // offset to add to x-coord (or buffer address) when drawing zebra 
     406 
     407    if (camera_screen.has_variable_aspect && camera_info.props.aspect_ratio) 
     408    { 
     409        if (shooting_get_prop(camera_info.props.aspect_ratio) == 0) // standard requires x-shift to overlay drawing 
     410        { 
     411            bWide = 0; 
     412            //aspOffset = (camera_screen.width - (camera_screen.width * 12 / 16)) / 2; // = actual calculation, simplified below 
     413            aspOffset = camera_screen.width / 8; // half of the difference in width between equal height 16:9 and 4:3 screens, = black bar width 
     414        } 
     415    } 
     416 
     417    viewport_height = vid_get_viewport_height(); 
     418 
     419    // if not in no-zebra phase of blink mode zebra, draw zebra to buf[] 
     420    if (f) { 
     421        int step_x, step_v; 
     422        over = 255-zconf.zebra_over; 
     423        if (zconf.zebra_multichannel) {step_x=2; step_v=6;} else {step_x=1; step_v=3;} 
     424        s = aspOffset; 
     425        for (y=1, v=0; y<=viewport_height; ++y) { 
     426            for (x=0; x<camera_screen.width; x+=step_x, s+=step_x, v+=step_v) { 
     427                register int yy, uu, vv; 
     428                int sel; 
     429 
     430                if (!bWide && (x + aspOffset >= camera_screen.width - aspOffset)) continue; // do not draw "outside screen"  
     431 
     432                yy = img_buf[v+1]; 
     433                if (zconf.zebra_multichannel) { 
     434                    uu = (signed char)img_buf[v]; 
     435                    vv = (signed char)img_buf[v+2]; 
     436                    sel=0; 
     437                    if (!((zconf.zebra_mode == ZEBRA_MODE_ZEBRA_1 || zconf.zebra_mode == ZEBRA_MODE_ZEBRA_2) && (y-x-timer)&f)) { 
     438                        if (clip8(((yy<<12) +           vv*5743 + 2048)>>12)>over) sel  = 4; // R 
     439                        if (clip8(((yy<<12) - uu*1411 - vv*2925 + 2048)>>12)>over) sel |= 2; // G 
     440                        if (clip8(((yy<<12) + uu*7258           + 2048)>>12)>over) sel |= 1; // B 
     441                    } 
     442                    buf[s]=buf[s+1]=cls[sel]; 
     443                } 
     444                else if (((zconf.zebra_mode == ZEBRA_MODE_ZEBRA_1 || zconf.zebra_mode == ZEBRA_MODE_ZEBRA_2) && (y-x-timer)&f)) buf[s]=COLOR_TRANSPARENT; 
     445                else buf[s]=(yy>over)?cl_over:(yy<zconf.zebra_under)?cl_under:COLOR_TRANSPARENT; 
     446                if (buf[s] != COLOR_TRANSPARENT && !zebra_drawn) zebra_drawn = 1; 
     447                if (mrec) { 
     448                    // draw Canon OSD to buf[] if in REC mode 
     449                    if(get_cur_buf(s)!=COLOR_TRANSPARENT) buf[s]=get_cur_buf(s);  
     450                    if(zconf.zebra_multichannel && get_cur_buf(s+1)!=COLOR_TRANSPARENT) buf[s+1]=get_cur_buf(s+1);  
     451                } 
     452            } 
     453            s+=camera_screen.buffer_width-camera_screen.width; 
     454            if (y*camera_screen.height/viewport_height == (s+camera_screen.buffer_width)/camera_screen.buffer_width) { 
     455                memcpy(buf+s, buf+s-camera_screen.buffer_width, camera_screen.buffer_width); 
     456                s+=camera_screen.buffer_width; 
     457            } 
     458        } 
     459        if (!zebra_drawn) f=0; 
     460    } 
     461    // if blink mode is in no-zebra phase OR if there was no over/underexposed pixels to draw zebra on 
     462    if (!f) { 
     463        // if zebra was drawn during previous call of this function 
     464        if (need_restore) { 
     465            if (zconf.zebra_restore_screen || zconf.zebra_restore_osd) { 
     466                draw_restore(); 
     467            } else {  // clear buf[] of zebra, only leave Canon OSD 
     468                if (mrec) { // REC mode 
     469                    // copy rescued Canon OSD to buf[] top/bottom parts and fill center with transparent color: 
     470                    memcpy(buf, cur_buf_top, camera_screen.buffer_width * ZFIX_TOP); 
     471                    memcpy(buf + buffer_size - camera_screen.buffer_width * ZFIX_BOTTOM, cur_buf_bot, camera_screen.buffer_width * ZFIX_BOTTOM); 
     472                    for (s = camera_screen.buffer_width*ZFIX_TOP; s < buffer_size-camera_screen.buffer_width*ZFIX_BOTTOM; s++) { 
     473                        buf[s]=COLOR_TRANSPARENT; 
     474                    } 
     475                } else { // Not REC mode 
     476                    // No Canon OSD restore, fill buf[] with transparent color: 
     477                    memset(buf, COLOR_TRANSPARENT, buffer_size); 
     478                } 
     479                disp_zebra(); 
     480            } 
     481            need_restore=0; 
     482        } 
     483        return !(zconf.zebra_restore_screen && zconf.zebra_restore_osd); 
     484        // if zebra was drawn 
     485    } else { 
     486        disp_zebra(); 
     487 
     488        need_restore=1; 
     489        return 1; 
     490    } 
     491    return 0; 
     492} 
     493 
     494//------------------------------------------------------------------- 
     495int gui_osd_draw_zebra(int show) 
     496{ 
     497    unsigned int f; 
     498 
     499    if (!gui_osd_zebra_init(show)) 
     500        return 0; 
     501 
    256502    int mrec = ((mode_get()&MODE_MASK) == MODE_REC); 
    257     int zebra_drawn=0; 
     503 
    258504    color cls[] = { 
    259505        COLOR_TRANSPARENT, 
     
    266512        COLOR_BLACK 
    267513    }; 
    268          
    269     if (!gui_osd_zebra_init(show)) 
     514 
     515    // Try to get the best viewport buffer. In playmode its the _d one, in 
     516    // record mode we try to get the fast live one first 
     517    if (!mrec) 
     518    { 
     519        img_buf = vid_get_viewport_fb_d(); 
     520    } 
     521    else 
     522    { 
     523        img_buf = vid_get_viewport_live_fb(); 
     524        if ( !img_buf ) 
     525            img_buf = vid_get_viewport_fb(); 
     526    } 
     527 
     528    if (timer==0) 
     529    { 
     530        draw_guard_pixel(); 
     531        timer = 1; 
    270532        return 0; 
    271  
    272     if(timer==0) { 
    273         draw_guard_pixel(); 
    274         timer=1; 
    275         return 0; 
    276     } 
    277     if(timer==1) { 
     533    } 
     534 
     535    if (timer==1) 
     536    { 
    278537        int ready; 
    279538        static int n=0; 
    280539        if (!mrec) ready=1; 
    281         else get_property_case(PROPCASE_SHOOTING, &ready, 4); 
     540        else get_property_case(camera_info.props.shooting, &ready, 4); 
    282541        n=draw_guard_pixel(); // will be 0 in PLAY mode, should be 1 or 2 in REC mode. 
    283542        if(!ready) return 0; 
     543        if (cur_buf_top) 
     544        { 
     545            // rescue Canon OSD from scr_buf to cur_buf_top and _bot: 
     546            if (n==1) { 
     547                memcpy(cur_buf_top, scr_buf, camera_screen.buffer_width*ZFIX_TOP); 
     548                memcpy(cur_buf_bot, scr_buf + camera_screen.buffer_size - camera_screen.buffer_width*ZFIX_BOTTOM, camera_screen.buffer_width*ZFIX_BOTTOM); 
     549            } 
     550            else { 
     551                memcpy(cur_buf_top, scr_buf + camera_screen.buffer_size, camera_screen.buffer_width*ZFIX_TOP); 
     552                memcpy(cur_buf_bot, scr_buf + 2*camera_screen.buffer_size - camera_screen.buffer_width*ZFIX_BOTTOM, camera_screen.buffer_width*ZFIX_BOTTOM); 
     553            } 
     554        } 
    284555    } 
    285556    ++timer; 
    286     // Try to get the best viewport buffer. In playmode its the _d one, in 
    287     // record mode we try to get the fast live one first 
    288     if (!mrec) { 
    289         img_buf = vid_get_viewport_fb_d(); 
    290     } 
    291     else { 
    292         img_buf = vid_get_viewport_live_fb(); 
    293         if( !img_buf ) { 
    294             img_buf = vid_get_viewport_fb(); 
    295         } 
    296     } 
    297     viewport_height = vid_get_viewport_height(); 
    298     viewport_width = vid_get_viewport_width();  
    299     viewport_image_offset = vid_get_viewport_image_offset();  
    300     viewport_row_offset = vid_get_viewport_row_offset();  
    301         viewport_xoffset = vid_get_viewport_xoffset(); 
    302         viewport_yoffset = vid_get_viewport_yoffset(); 
    303     switch (zconf.zebra_mode) { 
    304         case ZEBRA_MODE_ZEBRA_1: 
    305             f = 4; 
    306             break; 
    307         case ZEBRA_MODE_ZEBRA_2: 
    308             f = 8; 
    309             break; 
    310         case ZEBRA_MODE_SOLID: 
    311             f = 1;  
    312             break; 
    313         case ZEBRA_MODE_BLINKED_1: 
    314             f = timer&1;  
    315             break; 
    316         case ZEBRA_MODE_BLINKED_3: 
    317             f = timer&4;  
    318             break; 
    319         case ZEBRA_MODE_BLINKED_2: 
    320         default: 
    321             f = timer&2;  
    322             break; 
    323     } 
    324     // if not in no-zebra phase of blink mode zebra, draw zebra to buf[] 
    325     if (f) { 
    326                 if (viewport_yoffset > 0) { // clear top & bottom areas of buffer if image height if smaller than viewport 
    327                         memset(buf, COLOR_TRANSPARENT, viewport_yoffset*camera_screen.buffer_width); 
    328                         memset(buf+(viewport_yoffset+viewport_height)*camera_screen.buffer_width, COLOR_TRANSPARENT, viewport_yoffset*camera_screen.buffer_width); 
    329                 } 
    330         int step_x, step_v, sy, sx; 
    331         over = 255-zconf.zebra_over; 
    332             if (zconf.zebra_multichannel) {step_x=2; step_v=6;} else {step_x=1; step_v=3;} 
    333             for (y=viewport_yoffset, v=viewport_image_offset; y<viewport_yoffset+viewport_height; ++y) { 
    334                 sy=y*camera_screen.buffer_width; 
    335                 sx=viewport_xoffset; 
    336                                 if (viewport_xoffset > 0) { // clear left & right areas of buffer if image width if smaller than viewport 
    337                                         memset(buf+sy, COLOR_TRANSPARENT, sx*2); 
    338                                         memset(buf+sy+(sx+viewport_width)*2, COLOR_TRANSPARENT, sx*2); 
    339                                 } 
    340                 for (x=viewport_xoffset; x<viewport_xoffset+viewport_width; x+=step_x, sx+=step_x, v+=step_v) { 
    341                     register int yy, uu, vv; 
    342                     int sel; 
    343                     yy = img_buf[v+1]; 
    344                     s=sy+sx*2; 
    345                     if (zconf.zebra_multichannel) { 
    346                         uu = (signed char)img_buf[v]; 
    347                         vv = (signed char)img_buf[v+2]; 
    348                         sel=0; 
    349                         if (!((zconf.zebra_mode == ZEBRA_MODE_ZEBRA_1 || zconf.zebra_mode == ZEBRA_MODE_ZEBRA_2) && (y-x-timer)&f)) { 
    350                             if (clip8(((yy<<12) +           vv*5743 + 2048)>>12)>over) sel  = 4; // R 
    351                             if (clip8(((yy<<12) - uu*1411 - vv*2925 + 2048)>>12)>over) sel |= 2; // G 
    352                             if (clip8(((yy<<12) + uu*7258           + 2048)>>12)>over) sel |= 1; // B 
    353                         } 
    354                         buf[s]=buf[s+1]=cls[sel]; 
    355                         buf[s+2]=buf[s+3]=cls[sel]; 
    356                     } 
    357                     else if (((zconf.zebra_mode == ZEBRA_MODE_ZEBRA_1 || zconf.zebra_mode == ZEBRA_MODE_ZEBRA_2) && (y-x-timer)&f)) buf[s]=buf[s+1]=COLOR_TRANSPARENT; 
    358                     else buf[s]=buf[s+1]=(yy>over)?cl_over:(yy<zconf.zebra_under)?cl_under:COLOR_TRANSPARENT; 
    359                     if (buf[s] != COLOR_TRANSPARENT && !zebra_drawn) zebra_drawn = 1; 
    360 #if ZEBRA_CANONOSD_BORDER_RESTORE                         
    361                         if(get_cur_buf(s)!=COLOR_TRANSPARENT) buf[s]=get_cur_buf(s);  
    362                         if(zconf.zebra_multichannel && get_cur_buf(s+1)!=COLOR_TRANSPARENT) buf[s+1]=get_cur_buf(s+1);  
    363 #else 
    364                         if(cur_buf[s]!=COLOR_TRANSPARENT) buf[s]=cur_buf[s]; 
    365                         if(zconf.zebra_multichannel && cur_buf[s+1]!=COLOR_TRANSPARENT) buf[s+1]=cur_buf[s+1]; 
    366 #endif 
    367  
    368                     if (mrec) { 
    369                     } 
    370                                 } 
    371                                 // adjust for cases where buffer is wider than viewport (e.g. on G12) 
    372                                 v += viewport_row_offset; 
    373             } 
    374         if (!zebra_drawn) f=0; 
    375     } 
    376     // if blink mode is in no-zebra phase OR if there was no over/underexposed pixels to draw zebra on 
    377     if (!f) { 
    378         // if zebra was drawn during previous call of this function 
    379         if (need_restore) { 
    380             if (zconf.zebra_restore_screen || zconf.zebra_restore_osd) { 
    381                 draw_restore(); 
    382             } else {  // clear buf[] of zebra, only leave Canon OSD 
    383                 if (mrec) { // REC mode 
    384 //~ #if ZEBRA_CANONOSD_BORDER_RESTORE 
    385                     //~ // copy rescued Canon OSD to buf[] top/bottom parts and fill center with transparent color: 
    386                     //~ memcpy(buf, cur_buf_top, camera_screen.buffer_width * ZFIX_TOP); 
    387                     //~ memcpy(buf + camera_screen.buffer_size - camera_screen.buffer_width * ZFIX_BOTTOM, cur_buf_bot, camera_screen.buffer_width * ZFIX_BOTTOM); 
    388                     //~ for (s = camera_screen.buffer_width*ZFIX_TOP; s < camera_screen.buffer_size-camera_screen.buffer_width*ZFIX_BOTTOM; s++) { 
    389                         //~ buf[s]=COLOR_TRANSPARENT; 
    390                     //~ } 
    391 //~ #else 
    392                     //~ // copy from a complete Canon OSD rescue screen dump 
    393                     //~ memcpy(buf, cur_buf, camera_screen.buffer_size);  
    394 //~ #endif 
    395                 } else { // Not REC mode 
    396                     // No Canon OSD restore, fill buf[] with transparent color: 
    397                     memset(buf, COLOR_TRANSPARENT, buffer_size); 
    398                 } 
    399                 // draw CHDK osd and histogram to buf[] (if enabled in config) 
    400                 gui_osd_draw_zebra_osd(); 
    401                 // copy buf[] to both display buffers 
    402                  
    403                 if (buf!=scr_buf) 
    404                   memcpy(scr_buf, buf, buffer_size); 
    405                   memcpy(scr_buf+camera_screen.buffer_size, buf, buffer_size); 
    406             } 
    407             need_restore=0; 
    408         } 
    409         return !(zconf.zebra_restore_screen && zconf.zebra_restore_osd); 
    410     // if zebra was drawn 
    411     } else { 
    412         // draw CHDK osd and histogram to buf[] over zebra (if enabled in config)             
    413         gui_osd_draw_zebra_osd(); 
    414         // copy buf[] to both display buffers    
    415         if (buf!=scr_buf) 
    416             memcpy(scr_buf, buf, buffer_size); 
    417             memcpy(scr_buf+camera_screen.buffer_size, buf, buffer_size); 
    418  
    419         need_restore=1; 
    420         return 1; 
    421     } 
    422     return 0; 
    423 } 
    424 #else 
    425 //------------------------------------------------------------------- 
    426 int gui_osd_draw_zebra(int show) { 
    427     unsigned int v, s, x, y, f, over; 
    428     color cl_under = BG_COLOR(zconf.zebra_color), cl_over = FG_COLOR(zconf.zebra_color); 
    429     static int need_restore=0; 
    430     int viewport_height; 
    431     int mrec = ((mode_get()&MODE_MASK) == MODE_REC); 
    432     int zebra_drawn=0; 
    433     color cls[] = { 
    434         COLOR_TRANSPARENT, 
    435         (mrec)?COLOR_HISTO_B:COLOR_HISTO_B_PLAY, 
    436         (mrec)?COLOR_HISTO_G:COLOR_HISTO_G_PLAY, 
    437         (mrec)?COLOR_HISTO_BG:COLOR_HISTO_BG_PLAY, 
    438         (mrec)?COLOR_HISTO_R:COLOR_HISTO_R_PLAY, 
    439         (mrec)?COLOR_HISTO_RB:COLOR_HISTO_RB_PLAY, 
    440         (mrec)?COLOR_HISTO_RG:COLOR_HISTO_RG_PLAY, 
    441         COLOR_BLACK 
    442     }; 
    443          
    444     unsigned bWide = 1; // if wide (16:9) or standard (4:3) aspect ratio (but 1 in cameras that only have 4:3) 
    445     unsigned aspOffset = 0; // offset to add to x-coord (or buffer address) when drawing zebra 
    446  
    447 #if CAM_HAS_VARIABLE_ASPECT 
    448     if (shooting_get_prop(PROPCASE_ASPECT_RATIO) == 0) // standard requires x-shift to overlay drawing 
     557 
     558    switch (zconf.zebra_mode) 
    449559    { 
    450         bWide = 0; 
    451         //aspOffset = (camera_screen.width - (camera_screen.width * 12 / 16)) / 2; // = actual calculation, simplified below 
    452         aspOffset = camera_screen.width / 8; // half of the difference in width between equal height 16:9 and 4:3 screens, = black bar width 
    453     } 
    454 #endif 
    455          
    456     if (!gui_osd_zebra_init(show)) 
    457         return 0; 
    458  
    459     if(timer==0) { 
    460         draw_guard_pixel(); 
    461         timer=1; 
    462         return 0; 
    463     } 
    464     if(timer==1) { 
    465         int ready; 
    466         static int n=0; 
    467         if (!mrec) ready=1; 
    468         else get_property_case(PROPCASE_SHOOTING, &ready, 4); 
    469         n=draw_guard_pixel(); // will be 0 in PLAY mode, should be 1 or 2 in REC mode. 
    470         if(!ready) return 0; 
    471 #if ZEBRA_CANONOSD_BORDER_RESTORE 
    472         // rescue Canon OSD from scr_buf to cur_buf_top and _bot: 
    473         if (n==1) { 
    474             memcpy(cur_buf_top, scr_buf, camera_screen.buffer_width*ZFIX_TOP); 
    475             memcpy(cur_buf_bot, scr_buf + camera_screen.buffer_size - camera_screen.buffer_width*ZFIX_BOTTOM, camera_screen.buffer_width*ZFIX_BOTTOM); 
    476         } 
    477         else { 
    478             memcpy(cur_buf_top, scr_buf + camera_screen.buffer_size, camera_screen.buffer_width*ZFIX_TOP); 
    479             memcpy(cur_buf_bot, scr_buf + 2*camera_screen.buffer_size - camera_screen.buffer_width*ZFIX_BOTTOM, camera_screen.buffer_width*ZFIX_BOTTOM); 
    480         } 
    481 #else 
    482         // rescue Canon OSD from cur_buf 
    483         if(n==1) memcpy(cur_buf, scr_buf, camera_screen.buffer_size); 
    484         else memcpy(cur_buf, scr_buf+camera_screen.buffer_size, camera_screen.buffer_size); 
    485 #endif 
    486     } 
    487     ++timer; 
    488     // Try to get the best viewport buffer. In playmode its the _d one, in 
    489     // record mode we try to get the fast live one first 
    490     if (!mrec) { 
    491         img_buf = vid_get_viewport_fb_d(); 
    492     } 
    493     else { 
    494         img_buf = vid_get_viewport_live_fb(); 
    495         if( !img_buf ) { 
    496             img_buf = vid_get_viewport_fb(); 
    497         } 
    498     } 
    499     viewport_height = vid_get_viewport_height(); 
    500     switch (zconf.zebra_mode) { 
    501         case ZEBRA_MODE_ZEBRA_1: 
    502             f = 4; 
    503             break; 
    504         case ZEBRA_MODE_ZEBRA_2: 
    505             f = 8; 
    506             break; 
    507         case ZEBRA_MODE_SOLID: 
    508             f = 1;  
    509             break; 
    510         case ZEBRA_MODE_BLINKED_1: 
    511             f = timer&1;  
    512             break; 
    513         case ZEBRA_MODE_BLINKED_3: 
    514             f = timer&4;  
    515             break; 
    516         case ZEBRA_MODE_BLINKED_2: 
    517         default: 
    518             f = timer&2;  
    519             break; 
    520     } 
    521     // if not in no-zebra phase of blink mode zebra, draw zebra to buf[] 
    522     if (f) { 
    523         int step_x, step_v; 
    524         over = 255-zconf.zebra_over; 
    525             if (zconf.zebra_multichannel) {step_x=2; step_v=6;} else {step_x=1; step_v=3;} 
    526             s = aspOffset; 
    527             for (y=1, v=0; y<=viewport_height; ++y) { 
    528                 for (x=0; x<camera_screen.width; x+=step_x, s+=step_x, v+=step_v) { 
    529                     register int yy, uu, vv; 
    530                     int sel; 
    531                                                                                  
    532                     if (!bWide && (x + aspOffset >= camera_screen.width - aspOffset)) continue; // do not draw "outside screen"  
    533                                                                                  
    534                     yy = img_buf[v+1]; 
    535                     if (zconf.zebra_multichannel) { 
    536                         uu = (signed char)img_buf[v]; 
    537                         vv = (signed char)img_buf[v+2]; 
    538                         sel=0; 
    539                         if (!((zconf.zebra_mode == ZEBRA_MODE_ZEBRA_1 || zconf.zebra_mode == ZEBRA_MODE_ZEBRA_2) && (y-x-timer)&f)) { 
    540                             if (clip8(((yy<<12) +           vv*5743 + 2048)>>12)>over) sel  = 4; // R 
    541                             if (clip8(((yy<<12) - uu*1411 - vv*2925 + 2048)>>12)>over) sel |= 2; // G 
    542                             if (clip8(((yy<<12) + uu*7258           + 2048)>>12)>over) sel |= 1; // B 
    543                         } 
    544                         buf[s]=buf[s+1]=cls[sel]; 
    545                     } 
    546                     else if (((zconf.zebra_mode == ZEBRA_MODE_ZEBRA_1 || zconf.zebra_mode == ZEBRA_MODE_ZEBRA_2) && (y-x-timer)&f)) buf[s]=COLOR_TRANSPARENT; 
    547                     else buf[s]=(yy>over)?cl_over:(yy<zconf.zebra_under)?cl_under:COLOR_TRANSPARENT; 
    548                     if (buf[s] != COLOR_TRANSPARENT && !zebra_drawn) zebra_drawn = 1; 
    549                     if (mrec) { 
    550                         // draw Canon OSD to buf[] if in REC mode 
    551 #if ZEBRA_CANONOSD_BORDER_RESTORE                         
    552                         if(get_cur_buf(s)!=COLOR_TRANSPARENT) buf[s]=get_cur_buf(s);  
    553                         if(zconf.zebra_multichannel && get_cur_buf(s+1)!=COLOR_TRANSPARENT) buf[s+1]=get_cur_buf(s+1);  
    554 #else 
    555                         if(cur_buf[s]!=COLOR_TRANSPARENT) buf[s]=cur_buf[s]; 
    556                         if(zconf.zebra_multichannel && cur_buf[s+1]!=COLOR_TRANSPARENT) buf[s+1]=cur_buf[s+1]; 
    557 #endif 
    558                     } 
    559                 } 
    560                 s+=camera_screen.buffer_width-camera_screen.width; 
    561                 if (y*camera_screen.height/viewport_height == (s+camera_screen.buffer_width)/camera_screen.buffer_width) { 
    562                     memcpy(buf+s, buf+s-camera_screen.buffer_width, camera_screen.buffer_width); 
    563                     s+=camera_screen.buffer_width; 
    564                 } 
    565             } 
    566         if (!zebra_drawn) f=0; 
    567     } 
    568     // if blink mode is in no-zebra phase OR if there was no over/underexposed pixels to draw zebra on 
    569     if (!f) { 
    570         // if zebra was drawn during previous call of this function 
    571         if (need_restore) { 
    572             if (zconf.zebra_restore_screen || zconf.zebra_restore_osd) { 
    573                 draw_restore(); 
    574             } else {  // clear buf[] of zebra, only leave Canon OSD 
    575                 if (mrec) { // REC mode 
    576 #if ZEBRA_CANONOSD_BORDER_RESTORE 
    577                     // copy rescued Canon OSD to buf[] top/bottom parts and fill center with transparent color: 
    578                     memcpy(buf, cur_buf_top, camera_screen.buffer_width * ZFIX_TOP); 
    579                     memcpy(buf + camera_screen.buffer_size - camera_screen.buffer_width * ZFIX_BOTTOM, cur_buf_bot, camera_screen.buffer_width * ZFIX_BOTTOM); 
    580                     for (s = camera_screen.buffer_width*ZFIX_TOP; s < camera_screen.buffer_size-camera_screen.buffer_width*ZFIX_BOTTOM; s++) { 
    581                         buf[s]=COLOR_TRANSPARENT; 
    582                     } 
    583 #else 
    584                     // copy from a complete Canon OSD rescue screen dump 
    585                     memcpy(buf, cur_buf, camera_screen.buffer_size);  
    586 #endif 
    587                 } else { // Not REC mode 
    588                     // No Canon OSD restore, fill buf[] with transparent color: 
    589                     memset(buf, COLOR_TRANSPARENT, camera_screen.buffer_size); 
    590                 } 
    591                 // draw CHDK osd and histogram to buf[] (if enabled in config) 
    592                 gui_osd_draw_zebra_osd(); 
    593                 // copy buf[] to both display buffers 
    594                 memcpy(scr_buf, buf, camera_screen.buffer_size); 
    595                 memcpy(scr_buf+camera_screen.buffer_size, buf, camera_screen.buffer_size); 
    596             } 
    597             need_restore=0; 
    598         } 
    599         return !(zconf.zebra_restore_screen && zconf.zebra_restore_osd); 
    600     // if zebra was drawn 
    601     } else { 
    602         // draw CHDK osd and histogram to buf[] over zebra (if enabled in config)             
    603         gui_osd_draw_zebra_osd(); 
    604         // copy buf[] to both display buffers           
    605         memcpy(scr_buf, buf, camera_screen.buffer_size); 
    606         memcpy(scr_buf+camera_screen.buffer_size, buf, camera_screen.buffer_size); 
    607  
    608         need_restore=1; 
    609         return 1; 
    610     } 
    611     return 0; 
    612 } 
    613 #endif 
     560        case ZEBRA_MODE_ZEBRA_1:    f = 4;          break; 
     561        case ZEBRA_MODE_ZEBRA_2:    f = 8;          break; 
     562        case ZEBRA_MODE_SOLID:      f = 1;          break; 
     563        case ZEBRA_MODE_BLINKED_1:  f = timer&1;    break; 
     564        case ZEBRA_MODE_BLINKED_3:  f = timer&4;    break; 
     565        case ZEBRA_MODE_BLINKED_2:   
     566        default:                    f = timer&2;    break; 
     567    } 
     568 
     569    if (camera_screen.zebra_aspect_adjust) 
     570        return draw_zebra_aspect_adjust(mrec,f,cls);    // For newer cameras with 720/960 pixel wide screen 
     571    else 
     572        return draw_zebra_no_aspect_adjust(mrec,f,cls); // For older cameras with 360/480 pixel wide screen 
     573} 
    614574 
    615575//------------------------------------------------------------------- 
     
    681641  if ( !API_VERSION_MATCH_REQUIREMENT( conf.api_version, 2, 0 ) ) 
    682642         return 1; 
     643  if ( !API_VERSION_MATCH_REQUIREMENT( camera_info.api_version, 1, 0 ) ) 
     644         return 1; 
    683645 
    684646  conf_info[0].cl = MAKE_COLOR(COLOR_RED, COLOR_RED); 
  • trunk/include/camera.h

    r1570 r1580  
    9191#define CAM_BITMAP_PALETTE          1           // which color set is used for this camera 
    9292 
    93 #undef CAM_HAS_VARIABLE_ASPECT                  // can switch between 16:9 and 4:3 
    94  
    95 // by nandoide sept-2009 
    96 // zebra adjust buffer height: show use at sx200is: needed for save memory space 
    97 #define ZEBRA_HMARGIN0              0 
    98  
    9993// Older cameras had a screen/bitmap buffer that was 360 pixels wide (or 480 for wide screen models) 
    10094// CHDK was built around this 360 pixel wide display model 
     
    118112#undef CAM_ZEBRA_ASPECT_ADJUST                  // zebra needs to account for real bitmap size being different from what lib.c reports 
    119113                                                // also used by some cameras with normal bitmap layouts for memory saving ? 
    120 #undef CAM_ZEBRA_NOBUF                          // zebra draws directly on bitmap buffer. Requires above as well 
     114#undef CAM_ZEBRA_NOBUF                          // zebra draws directly on bitmap buffer. 
     115#undef CAM_HAS_VARIABLE_ASPECT                  // can switch between 16:9 and 4:3 (only used by zebra code) 
    121116 
    122117#undef CAM_DATE_FOLDER_NAMING                   // set if camera uses date based folder naming (Option "Create Folder" in Canon Menu) and get_target_dir_name is implemented 
     
    269264    unsigned int    buffer_width, buffer_height, buffer_size;   // Physical size of bitmap screen 
    270265    int             edge_hmargin, ts_button_border;             // margin and touch-screen adjustment values 
     266    int             zebra_nobuf, zebra_aspect_adjust;           // zebra feature settings 
     267    int             has_variable_aspect;                        // zebra feature settings 
    271268} _cam_screen; 
    272269 
     
    293290        int metering_mode; 
    294291        int wb_adj; 
     292        int aspect_ratio; 
     293        int shooting; 
    295294    } props; 
    296295    int rombaseaddr, maxramaddr; 
  • trunk/platform/g10/platform_camera.h

    r1555 r1580  
    9797        #define CAM_ZEBRA_ASPECT_ADJUST 1 
    9898        #define CAM_ZEBRA_NOBUF 1 
    99         #undef ZEBRA_HMARGIN0 
    100         #define ZEBRA_HMARGIN0                                  30              //this 30 rows are not used by the display buffer is 720x240 effective, no 960x270, i.e. (270-240) reduction in widht possible but not done (more difficult to manage it and slower). 
    10199         
    102100        #undef  CAM_DATE_FOLDER_NAMING                                  // not needed for G10 
  • trunk/platform/g12/platform_camera.h

    r1570 r1580  
    9999 
    100100    #define CAM_ZEBRA_ASPECT_ADJUST         1 
    101  
    102     //zebra letterbox for saving memory 
    103     #undef ZEBRA_HMARGIN0 
    104     #define ZEBRA_HMARGIN0                  30  //this 30 rows are not used by the display buffer is 720x240 effective, no 960x270, i.e. (270-240) reduction in widht possible but not done (more difficult to manage it and slower). 
    105101     
    106102    #define CAM_DATE_FOLDER_NAMING          1 
  • trunk/platform/ixus1000_sd4500/platform_camera.h

    r1555 r1580  
    113113   #define CAM_ZEBRA_NOBUF 1 
    114114//#endif 
    115    #undef ZEBRA_HMARGIN0 
    116    #define ZEBRA_HMARGIN0  30 //this 30 rows are not used by the display buffer is 720x240 effective, no 960x270, i.e. (270-240) reduction in widht possible but not done (more difficult to manage it and slower). 
    117115 
    118116   #define CAM_QUALITY_OVERRIDE 1 
  • trunk/platform/ixus100_sd780/platform_camera.h

    r1555 r1580  
    6262    #define CAM_BITMAP_PALETTE          5 
    6363 
    64     #undef ZEBRA_HMARGIN0 
    65     #define ZEBRA_HMARGIN0              150                     //zebra adjust buffer height: show use at sx200is: needed for save memory space 
    66  
    6764    #define CAM_QUALITY_OVERRIDE 1 
    6865    #undef CAM_SENSOR_BITS_PER_PIXEL 
  • trunk/platform/ixus120_sd940/platform_camera.h

    r1555 r1580  
    9595    #define EDGE_HMARGIN 20 
    9696 
    97    //zebra letterbox for saving memory 
    98    #undef ZEBRA_HMARGIN0 
    99    #define ZEBRA_HMARGIN0  30 //this 30 rows are not used by the display buffer is 720x240 effective, no 960x270, i.e. (270-240) reduction in widht possible but not done (more difficult to manage it and slower). 
    100  
    10197   #define CAM_ZEBRA_ASPECT_ADJUST 1 
    10298   #define CAM_ZEBRA_NOBUF 1 
  • trunk/platform/ixus200_sd980/platform_camera.h

    r1555 r1580  
    8484    #undef EDGE_HMARGIN 
    8585    #define EDGE_HMARGIN 20 
    86  
    87     //zebra letterbox for saving memory 
    88     #undef ZEBRA_HMARGIN0 
    89     #define ZEBRA_HMARGIN0  30 //this 30 rows are not used by the display buffer is 720x240 effective, no 960x270, i.e. (270-240) reduction in widht possible but not done (more difficult to manage it and slower). 
    9086         
    9187        #define CAM_ZEBRA_ASPECT_ADJUST 1 
  • trunk/platform/ixus220_elph300hs/platform_camera.h

    r1555 r1580  
    8484    #define EDGE_HMARGIN 10 
    8585 
    86     #undef ZEBRA_HMARGIN0 
    87     #define ZEBRA_HMARGIN0  30 
    88  
    8986    #define CAM_ZEBRA_ASPECT_ADJUST 1 
    9087    #define CAM_ZEBRA_NOBUF 1 
  • trunk/platform/ixus230_elph310hs/platform_camera.h

    r1573 r1580  
    7979#define EDGE_HMARGIN                10 // Look into 
    8080 
    81 #undef ZEBRA_HMARGIN0 
    82 #define ZEBRA_HMARGIN0              30 // Look into 
    83  
    8481#define CAM_ZEBRA_ASPECT_ADJUST 1 
    8582#define CAM_ZEBRA_NOBUF 1 
  • trunk/platform/ixus310_elph500hs/platform_camera.h

    r1570 r1580  
    102102     
    103103    #define CAM_ZEBRA_ASPECT_ADJUST         1 
    104  
    105     //zebra letterbox for saving memory 
    106     #undef ZEBRA_HMARGIN0 
    107     #define ZEBRA_HMARGIN0                  30 //this 30 rows are not used by the display buffer is 720x240 effective, no 960x270, i.e. (270-240) reduction in widht possible but not done (more difficult to manage it and slower). 
    108104     
    109105    #define CAM_DATE_FOLDER_NAMING          1 
  • trunk/platform/sx130is/platform_camera.h

    r1555 r1580  
    7777     #define CAM_BITMAP_PALETTE                          7 
    7878  
    79      //zebra letterbox for saving memory 
    80      #undef ZEBRA_HMARGIN0 
    81      #define ZEBRA_HMARGIN0                              30 //this 30 rows are not used by the display buffer is 720x240 effective, no 960x270, i.e. (270-240) reduction in widht possible but not done (more difficult to manage it and slower). 
    82   
    8379     //#undef EDGE_HMARGIN 
    8480     //#define EDGE_HMARGIN                                28 
  • trunk/platform/sx150is/platform_camera.h

    r1555 r1580  
    7878     #define CAM_BITMAP_PALETTE                          7 
    7979  
    80      //zebra letterbox for saving memory 
    81      #undef ZEBRA_HMARGIN0 
    82      #define ZEBRA_HMARGIN0                              30 //this 30 rows are not used by the display buffer is 720x240 effective, no 960x270, i.e. (270-240) reduction in widht possible but not done (more difficult to manage it and slower). 
    83   
    8480     //#undef EDGE_HMARGIN 
    8581     //#define EDGE_HMARGIN                                28 
  • trunk/platform/sx20/platform_camera.h

    r1555 r1580  
    8585        #undef CAM_BITMAP_PALETTE 
    8686        #define CAM_BITMAP_PALETTE              6 
    87  
    88    //zebra letterbox for saving memory 
    89    #undef ZEBRA_HMARGIN0 
    90    #define ZEBRA_HMARGIN0  30 //this 30 rows are not used by the display buffer is 720x240 effective, no 960x270, i.e. (270-240) reduction in widht possible but not done (more difficult to manage it and slower). 
    9187   
    9288   #undef EDGE_HMARGIN 
  • trunk/platform/sx200is/platform_camera.h

    r1555 r1580  
    8080    #define EDGE_HMARGIN 28 
    8181 
    82     //zebra letterbox for saving memory 
    83     #undef ZEBRA_HMARGIN0 
    84     #define ZEBRA_HMARGIN0  30 //this 30 rows are not used by the display buffer is 720x240 effective, no 960x270, i.e. (270-240) reduction in widht possible but not done (more difficult to manage it and slower). 
    85  
    8682    #define CAM_QUALITY_OVERRIDE 1 
    8783    #define CAM_AF_SCAN_DURING_VIDEO_RECORD 1 
  • trunk/platform/sx220hs/platform_camera.h

    r1556 r1580  
    8585    #define EDGE_HMARGIN                    10 
    8686 
    87     #undef  ZEBRA_HMARGIN0 
    88     #define ZEBRA_HMARGIN0                  30 
    89  
    9087    #define CAM_ZEBRA_ASPECT_ADJUST         1 
    9188    #define CAM_ZEBRA_NOBUF                 1 
  • trunk/platform/sx230hs/platform_camera.h

    r1556 r1580  
    9696    #define EDGE_HMARGIN                    10 
    9797 
    98     #undef ZEBRA_HMARGIN0 
    99     #define ZEBRA_HMARGIN0                  30  
    100  
    10198    #define CAM_ZEBRA_ASPECT_ADJUST         1 
    10299    #define CAM_ZEBRA_NOBUF                 1 
  • trunk/platform/sx30/platform_camera.h

    r1570 r1580  
    9090 
    9191    #define CAM_ZEBRA_ASPECT_ADJUST 1 
    92     #define CAM_ZEBRA_NOBUF 1 
    9392 
    9493    #undef CAM_BITMAP_PALETTE 
    9594    #define CAM_BITMAP_PALETTE              12 
    96  
    97     //zebra letterbox for saving memory 
    98     #undef ZEBRA_HMARGIN0 
    99     #define ZEBRA_HMARGIN0                  30 //this 30 rows are not used by the display buffer is 720x240 effective, no 960x270, i.e. (270-240) reduction in widht possible but not done (more difficult to manage it and slower). 
    10095   
    10196    #undef EDGE_HMARGIN 
  • trunk/platform/sx40hs/platform_camera.h

    r1570 r1580  
    9494 
    9595    #define CAM_ZEBRA_ASPECT_ADJUST         1 
    96     #define CAM_ZEBRA_NOBUF 1 
    9796 
    9897    #undef CAM_BITMAP_PALETTE 
    9998    #define CAM_BITMAP_PALETTE              12 
    100  
    101     //zebra letterbox for saving memory 
    102     #undef ZEBRA_HMARGIN0 
    103     #define ZEBRA_HMARGIN0                  30 //this 30 rows are not used by the display buffer is 720x240 effective, no 960x270, i.e. (270-240) reduction in widht possible but not done (more difficult to manage it and slower). 
    10499   
    105100    #undef EDGE_HMARGIN 
Note: See TracChangeset for help on using the changeset viewer.