Changeset 2059


Ignore:
Timestamp:
08/07/12 06:48:41 (11 months ago)
Author:
reyalp
Message:

rework live_histogram_process_quick to support script histogram

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/histogram.c

    r2058 r2059  
    415415static int histogram_stored_stage = -1;         // Stored value of histogram_stage (-1 = not stored yet) 
    416416 
     417/* 
     418build histogram of viewport Y values (downsampled by HISTO_STEP_SIZE) in buf, return total number of pixel 
     419*/ 
     420int live_histogram_read_y(int *buf) 
     421{ 
     422    int i; 
     423    int total=0; 
     424    int x=0; 
     425    int vp_width=vid_get_viewport_width(); 
     426    int vp_offset=vid_get_viewport_row_offset(); 
     427    int viewport_size=vid_get_viewport_height() * vid_get_viewport_byte_width() * vid_get_viewport_yscale(); 
     428    unsigned char *img=vid_get_viewport_active_buffer(); 
     429    // can be NULL in playback mode (if a movie is selected) 
     430    // _fb will give us an address, although it may not contain the data we want! 
     431    // TODO should probably just return all zeros, but need to make sure auto-iso stuff will handle it 
     432    if (img==NULL){ 
     433       img = vid_get_viewport_fb(); 
     434    } 
     435 
     436    img += vid_get_viewport_image_offset(); 
     437 
     438    memset( buf, 0, sizeof(int)*256); 
     439 
     440    x = 0;      // count how many blocks we have done on the current row (to skip unused buffer space at end of each row) 
     441 
     442    for (i=1; i<viewport_size; i+=HISTO_STEP_SIZE*6) { 
     443       ++buf[img[i]]; 
     444       ++total; // TODO - would be better to just calculate this from dimensions and step 
     445 
     446       // Handle case where viewport memory buffer is wider than the actual buffer. 
     447       x += HISTO_STEP_SIZE * 2;        // viewport width is measured in blocks of three bytes each even though the data is stored in six byte chunks ! 
     448       if (x == vp_width) { 
     449           i += vp_offset; 
     450           x = 0; 
     451       } 
     452    } 
     453    return total; 
     454} 
     455 
    417456void live_histogram_process_quick() 
    418457{ 
    419     static unsigned char *img; 
    420     int i, y, x, stage,viewport_size; 
    421  
    422458    // Small hack: save space reuse common histogram buffer 
    423459    // It should be big enough for int[256]. Currently it is int [5*128] 
     
    430466    histogram_stage=HISTOGRAM_IDLE_STAGE; 
    431467 
    432     img=vid_get_viewport_active_buffer(); 
    433     if (img==NULL){ 
    434        img = vid_get_viewport_fb(); 
    435     } 
    436  
    437     img += vid_get_viewport_image_offset();             // offset into viewport for when image size != viewport size (e.g. 16:9 image on 4:3 LCD) 
    438     viewport_size = vid_get_viewport_height() * vid_get_viewport_byte_width() * vid_get_viewport_yscale(); 
    439  
    440     memset( live_histogram_proc, 0, sizeof(int)*256); 
    441  
    442     x = 0;      // count how many blocks we have done on the current row (to skip unused buffer space at end of each row) 
    443  
    444     for (i=1; i<viewport_size; i+=HISTO_STEP_SIZE*6) { 
    445        y = img[i]; 
    446        ++live_histogram_proc[y]; 
    447  
    448        // Handle case where viewport memory buffer is wider than the actual buffer. 
    449        x += HISTO_STEP_SIZE * 2;        // viewport width is measured in blocks of three bytes each even though the data is stored in six byte chunks ! 
    450        if (x == vid_get_viewport_width()) { 
    451            i += vid_get_viewport_row_offset(); 
    452            x = 0; 
    453        } 
    454     } 
    455  
    456     live_histogram_overall=0; 
    457     for (i=0; i<256; ++i)  
    458        live_histogram_overall += live_histogram_proc[i]; 
     468    live_histogram_overall = live_histogram_read_y(live_histogram_proc); 
    459469    live_histogram_overall /= 100; 
    460470} 
Note: See TracChangeset for help on using the changeset viewer.