Changeset 1203


Ignore:
Timestamp:
06/10/11 08:42:50 (2 years ago)
Author:
msl
Message:

Edge overlay

  • some improvements for edge overlay function
  • author philmoz
  • http://chdk.setepontos.com/index.php?topic=650.msg67404#msg67404
  • reduced size of edgebuf memory allocation
  • fixed bug when using 'Filter Edges'
  • renamed some variables to clearer names
  • cleaned up code to remove all, but one "#if defined(CAM_USES_ASPECT_CORRECTION)" section - this one could probably also be removed, it will be required a test.
  • added code to restore Canon OSD when edge overlay is cleared to clean up any remnants of the overlay
  • restore any Canon OSD bits that were overwritten.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/edgeoverlay.c

    r1024 r1203  
    2525static unsigned char* smbuf = NULL; 
    2626 
    27 static int slice = 0;       // the current slice of the frame we are calculating/drawing 
    28 static int slice_height;    // the height of a single slice 
    29  
    30 static int viewport_size;   // whole viewport size in bytes ?? 
    31 static int viewport_width;      // screenwidth * 3, width in bytes of one viewport line ?? 
    32 static int viewport_height; 
     27static int slice = 0;           // the current slice of the frame we are calculating/drawing 
     28static int slice_height;        // the height of a single slice 
     29 
     30static int viewport_byte_width; // width in bytes of one viewport line ?? 
     31static int viewport_height;     // height of visible / used area of viewport 
     32static int viewport_width;      // width of visible / used area of viewport (in 3 byte units) 
    3333static int viewport_xoffset;    // used when image size != viewport size (e.g. wide screen image on 4:3 LCD) 
    3434static int viewport_yoffset;    // used when image size != viewport size (e.g. wide screen image on 4:3 LCD) 
    35 #if CAM_USES_ASPECT_CORRECTION 
    36 static int viewportw; //nandoide , width of viewport (not necessarily equal to width of screen) 
    37 #endif 
    3835 
    3936static void get_viewport_size() 
     
    4239    // here too to calculate the buffer we need... 
    4340 
    44 #if CAM_USES_ASPECT_CORRECTION//nandoide sept-2009 get the viewport dimensions, not the screen dimensions, on sx200is they aren't the same. 
     41#if defined(CAM_USES_ASPECT_CORRECTION) 
     42    //nandoide sept-2009 get the viewport dimensions, not the screen dimensions, on sx200is they aren't the same. 
    4543    viewport_height = vid_get_viewport_height()-EDGE_HMARGIN*2; //don't trace bottom lines 
    46     viewportw = vid_get_viewport_width(); 
    47     viewport_width = vid_get_viewport_buffer_width() * 3; 
     44    viewport_width = vid_get_viewport_width(); 
     45    viewport_byte_width = vid_get_viewport_buffer_width() * 3; 
    4846#else 
    4947    viewport_height = screen_height;//vid_get_viewport_height(); 
    50     viewport_width = screen_width * 3; 
     48    viewport_width = screen_width; 
     49    viewport_byte_width = screen_width * 3; 
    5150#endif 
    5251 
     
    5453        viewport_yoffset = vid_get_viewport_yoffset(); 
    5554 
    56     viewport_size = viewport_height * viewport_width; 
    5755    slice_height = viewport_height / EDGE_SLICES; 
    58  
    5956} 
    6057 
     
    6360    if(edgebuf == NULL) 
    6461    { 
    65         edgebuf = bv_create(viewport_size, 1); 
     62        edgebuf = bv_create(viewport_height * viewport_width, 1); 
    6663        if (edgebuf != NULL) 
    6764            memset(edgebuf->ptr, 0, edgebuf->ptrLen); 
     
    6966    if (conf.edge_overlay_filter && (smbuf == NULL)) 
    7067    { 
    71         smbuf = (unsigned char*)malloc(viewport_width*3); 
     68        smbuf = (unsigned char*)malloc(viewport_byte_width*3); 
    7269        if (smbuf != NULL) 
    73             memset(smbuf, 0, viewport_width*3); 
     70            memset(smbuf, 0, viewport_byte_width*3); 
    7471        else 
    7572        { 
     
    8885    } 
    8986 
    90     bv_free(edgebuf); 
    91     edgebuf = NULL; 
     87    if (edgebuf != NULL) 
     88    { 
     89        draw_restore();     // Refresh display to restore Canon OSD 
     90        bv_free(edgebuf); 
     91        edgebuf = NULL; 
     92    } 
     93 
    9294    fsm_state = EDGE_LIVE; 
    9395    slice = 0; 
     
    206208} 
    207209 
    208 static void average_filter_row(const unsigned char*  ptrh1,  // previous row 
    209                                const unsigned char*  ptrh2,  // current row 
    210                                const unsigned char*  ptrh3,  // next row 
    211                                unsigned char*  smptr )       // write results here 
    212 { 
    213     int x; 
    214 #if CAM_USES_ASPECT_CORRECTION 
    215     const int x_max = (viewportw + viewport_xoffset - 2) * 3; 
    216 #else 
    217     const int x_max = (screen_width + viewport_xoffset - 2) * 3; 
    218 #endif 
    219  
    220     for (x=viewport_xoffset*3+6; x<x_max; x+=6) 
     210static void average_filter_row(const unsigned char* ptrh1,  // previous row 
     211                               unsigned char* smptr,        // write results here 
     212                               int x, int x_max) 
     213{ 
     214    const unsigned char* ptrh2 = ptrh1 + viewport_byte_width;  // current row 
     215    const unsigned char* ptrh3 = ptrh2 + viewport_byte_width;  // next row 
     216 
     217    for (; x<x_max; x+=6) 
    221218    { 
    222219        *(smptr + x + 1) = (*(ptrh1 + x - 1) + 
     
    268265                            *(ptrh3 + x + 7)) / 9u; 
    269266    } 
     267 
     268    // copy 2nd last column to last column to prevent vertical stripe artifact. 
     269    smptr[x+1] = smptr[x-5]; 
     270    smptr[x+3] = smptr[x-3]; 
     271    smptr[x+4] = smptr[x-2]; 
     272    smptr[x+5] = smptr[x-1]; 
    270273} 
    271274 
     
    287290    const int y_max = viewport_yoffset + EDGE_HMARGIN+(slice+1)*slice_height; 
    288291    const int x_min = viewport_xoffset*3 + 6; 
    289 #if CAM_USES_ASPECT_CORRECTION 
    290     const int x_max = (viewportw + viewport_xoffset - 2) * 3; 
    291 #else 
    292     const int x_max = (screen_width + viewport_xoffset - 2) * 3; 
    293 #endif 
    294  
    295     const int vp_width = viewport_width; 
     292    const int x_max = (viewport_width + viewport_xoffset - 2) * 3; 
    296293 
    297294    xoffset = 0; 
     
    322319            shutter_fullpress |= kbd_is_key_pressed(KEY_SHOOT_FULL); 
    323320 
    324             ptrh1 = img + (y_min+y-1) * vp_width; 
    325             ptrh2 = img + (y_min+y  ) * vp_width; 
    326             ptrh3 = img + (y_min+y+1) * vp_width; 
    327             smptr = smbuf + (y+1) * vp_width; 
    328  
    329             average_filter_row(ptrh1, ptrh2, ptrh3, smptr); 
     321            ptrh1 = img + (y_min+y-1) * viewport_byte_width; 
     322            smptr = smbuf + (y+1) * viewport_byte_width; 
     323 
     324            average_filter_row(ptrh1, smptr, x_min, x_max); 
    330325        } 
    331326    } 
     
    344339 
    345340            // Shift 
    346             memcpy(smbuf+vp_width*0, smbuf+vp_width*1, vp_width); 
    347             memcpy(smbuf+vp_width*1, smbuf+vp_width*2, vp_width); 
     341            memcpy(smbuf, smbuf+viewport_byte_width, viewport_byte_width*2); 
    348342 
    349343            // Filter new line 
    350             ptrh1 = img +  y * vp_width; 
    351             ptrh2 = img + (y+1) * vp_width; 
    352             ptrh3 = img + (y+2) * vp_width; 
    353             smptr = smbuf + 2   * vp_width; 
    354             average_filter_row(ptrh1, ptrh2, ptrh3, smptr); 
    355  
    356             ptrh1 = smbuf + 0 * vp_width; 
    357             ptrh2 = smbuf + 1 * vp_width; 
    358             ptrh3 = smbuf + 2 * vp_width; 
     344            ptrh1 = img + y * viewport_byte_width; 
     345            smptr = smbuf + 2 * viewport_byte_width; 
     346            average_filter_row(ptrh1, smptr, x_min, x_max); 
     347 
     348            ptrh1 = smbuf; 
    359349        } 
    360350        else 
    361351        { 
    362             ptrh1 = img + (y-1) * vp_width; 
    363             ptrh2 = img +  y    * vp_width; 
    364             ptrh3 = img + (y+1) * vp_width; 
    365         } 
     352            ptrh1 = img + (y-1) * viewport_byte_width; 
     353        } 
     354        ptrh2 = ptrh1 + viewport_byte_width; 
     355        ptrh3 = ptrh2 + viewport_byte_width; 
    366356 
    367357        // Now we do sobel on the current line 
     
    394384            if (conv1 + conv2 > conf.edge_overlay_thresh) 
    395385            { 
    396                 bv_set(edgebuf, (y-viewport_yoffset-EDGE_HMARGIN)*vp_width + xdiv3, 1); 
     386                bv_set(edgebuf, (y-viewport_yoffset-EDGE_HMARGIN)*viewport_width + xdiv3, 1); 
    397387            } 
    398388 
     
    424414            if (conv1 + conv2 > conf.edge_overlay_thresh) 
    425415            { 
    426                 bv_set(edgebuf, (y-viewport_yoffset-EDGE_HMARGIN)*vp_width + xdiv3+1, 1); 
     416                bv_set(edgebuf, (y-viewport_yoffset-EDGE_HMARGIN)*viewport_width + xdiv3+1, 1); 
    427417            } 
    428418        }   // for x 
     
    452442//                shutter_fullpress |= kbd_is_key_pressed(KEY_SHOOT_FULL); 
    453443// 
    454 //#if CAM_USES_ASPECT_CORRECTION 
    455 //                for (x=12; x<(viewportw - 4); ++x) 
    456 //#else 
    457 //                for (x=12; x<(screen_width - 4); ++x) 
    458 //#endif 
     444//                for (x=12; x<(viewport_width - 4); ++x) 
    459445//                { 
    460446//                    int bEdge = bv_get(edgebuf, y*viewport_width + x); 
     
    509495    const int y_max = viewport_yoffset+EDGE_HMARGIN+viewport_height; 
    510496    const int x_min = viewport_xoffset+2; 
    511 #if CAM_USES_ASPECT_CORRECTION 
    512     const int x_max = (viewportw + viewport_xoffset - 2); 
    513 #else 
    514     const int x_max = (screen_width + viewport_xoffset - 2); 
    515 #endif 
     497    const int x_max = (viewport_width + viewport_xoffset - 2); 
    516498 
    517499    if( !is_buffer_ready() ) return 0; 
     
    595577{ 
    596578    const int y_max = viewport_height; 
    597 #if CAM_USES_ASPECT_CORRECTION 
    598     const int x_max = (viewportw - 2); 
    599 #else 
    600     const int x_max = (screen_width - 2); 
    601 #endif 
     579    const int x_max = (viewport_width - 2); 
    602580 
    603581    switch(conf.edge_overlay_pano) 
Note: See TracChangeset for help on using the changeset viewer.