Changeset 546

Show
Ignore:
Timestamp:
10/14/07 19:22:49 (1 year ago)
Author:
anthony_rowe
Message:

update get_pixel() that is slightly faster, but still needs work

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/projects/camscripter/lualib.c

    r543 r546  
    1010#include <lualib.h> 
    1111 
     12 
     13/* State information so that get_pixel() doesn't have to always grab  
     14 * This is cleared by take_picture() 
     15 */ 
     16cc3_image_t g_img; 
     17int g_img_prev_x, g_img_prev_y; 
     18 
     19     
    1220/* type-safety helper macros - checks that the object passed in is the correct type of pointer */ 
    1321#define checkimage(_l) (cc3_image_t*) luaL_checkudata(_l, 1, "scripter.image") 
     
    556564 */ 
    557565int get_pixel(lua_State *_l) { 
    558     cc3_image_t img; 
    559566    cc3_pixel_t *pixel = checkpixel(_l, 1); 
    560567    int x = luaL_checknumber(_l, 2); 
     
    566573    luaL_argcheck(_l, y < cc3_g_pixbuf_frame.height, 3,  
    567574                  "y is outside the bounds of the image"); 
    568     cc3_pixbuf_rewind(); 
    569     img.pix = cc3_malloc_rows(1); 
    570     img.channels = cc3_g_pixbuf_frame.channels; 
    571     int idx = 0; 
    572     do { 
    573         cc3_pixbuf_read_rows(img.pix, 1); 
    574         idx++; 
    575     } while (idx <= y); 
    576     cc3_get_pixel(&img, x, 0, pixel); // only one row 
    577     free(img.pix); 
     575 
     576    // Only rewind the frame if we are accessing data behind current point in FIFO  
     577    if(g_img_prev_y<y || g_img_prev_y==-1) { cc3_pixbuf_rewind();   g_img_prev_y=-1; } 
     578    
     579    // only load a new row if we need to  
     580    int idy = g_img_prev_y; 
     581    while( idy<y) { 
     582        cc3_pixbuf_read_rows(g_img.pix, 1); 
     583        idy++; 
     584    }  
     585 
     586    cc3_get_pixel(&g_img, x, 0, pixel);  
     587    // update position in global image 
     588    g_img_prev_y=idy; 
     589    g_img_prev_x=x; 
    578590 
    579591    return 0; 
     
    11981210int take_picture(lua_State *_l) { 
    11991211    cc3_pixbuf_load(); 
     1212    // reset line buffer in case image properties changed 
     1213    g_img_prev_y=-1;  
     1214    g_img_prev_x=-1;  
     1215    if(g_img.pix!=NULL) free(g_img.pix); 
     1216    g_img.pix = cc3_malloc_rows(1); 
     1217    g_img.channels = cc3_g_pixbuf_frame.channels; 
    12001218    return 0; 
    12011219}