Changeset 546
- Timestamp:
- 10/14/07 19:22:49 (1 year ago)
- Files:
-
- trunk/projects/camscripter/lualib.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/projects/camscripter/lualib.c
r543 r546 10 10 #include <lualib.h> 11 11 12 13 /* State information so that get_pixel() doesn't have to always grab 14 * This is cleared by take_picture() 15 */ 16 cc3_image_t g_img; 17 int g_img_prev_x, g_img_prev_y; 18 19 12 20 /* type-safety helper macros - checks that the object passed in is the correct type of pointer */ 13 21 #define checkimage(_l) (cc3_image_t*) luaL_checkudata(_l, 1, "scripter.image") … … 556 564 */ 557 565 int get_pixel(lua_State *_l) { 558 cc3_image_t img;559 566 cc3_pixel_t *pixel = checkpixel(_l, 1); 560 567 int x = luaL_checknumber(_l, 2); … … 566 573 luaL_argcheck(_l, y < cc3_g_pixbuf_frame.height, 3, 567 574 "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; 578 590 579 591 return 0; … … 1198 1210 int take_picture(lua_State *_l) { 1199 1211 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; 1200 1218 return 0; 1201 1219 }
