Changeset 392
- Timestamp:
- 02/11/07 17:45:48 (2 years ago)
- Files:
-
- trunk/hal/lpc2106-cmucam3/cc3.c (modified) (26 diffs)
- trunk/hal/lpc2106-cmucam3/cc3_hal.c (modified) (1 diff)
- trunk/hal/virtual-cam/cc3.c (modified) (26 diffs)
- trunk/include/cc3.h (modified) (4 diffs)
- trunk/lib/cc3-ilp/cc3_color_info.c (modified) (2 diffs)
- trunk/lib/cc3-ilp/cc3_color_track.c (modified) (4 diffs)
- trunk/lib/cc3-ilp/cc3_ilp.c (modified) (1 diff)
- trunk/lib/cc3-ilp/cc3_jpg.c (modified) (3 diffs)
- trunk/projects/cmucam2/cmucam2.c (modified) (9 diffs)
- trunk/projects/cmucam2/polly.c (modified) (5 diffs)
- trunk/projects/edge-follow/main.c (modified) (7 diffs)
- trunk/projects/edge-follow/polly.c (modified) (2 diffs)
- trunk/projects/hello-world/main.c (modified) (1 diff)
- trunk/projects/jpeg-cam/main.c (modified) (2 diffs)
- trunk/projects/png-grab/main.c (modified) (1 diff)
- trunk/projects/polly/main.c (modified) (5 diffs)
- trunk/projects/polly/polly.c (modified) (5 diffs)
- trunk/projects/ppm-grab/main.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/hal/lpc2106-cmucam3/cc3.c
r387 r392 35 35 // Globals used by CMUCam functions 36 36 cc3_pixel_t cc3_g_current_pixel; // global that gets updated with pixbuf calls 37 cc3_frame_t cc3_g_ current_frame; // global that keeps clip, stride37 cc3_frame_t cc3_g_pixbuf_frame; // global that keeps clip, stride 38 38 39 39 … … 61 61 static void _cc3_update_frame_bounds (cc3_frame_t *); 62 62 63 static void _cc3_ resize_pixbuf(void);63 static void _cc3_pixbuf_resize (void); 64 64 65 65 void cc3_pixbuf_load () … … 69 69 unsigned int i; 70 70 71 if (cc3_g_current_frame.reset_on_next_load) { 72 _cc3_resize_pixbuf(); 73 cc3_frame_default(); 71 if (cc3_g_pixbuf_frame.reset_on_next_load) { 72 _cc3_pixbuf_resize(); 74 73 } 75 74 … … 100 99 101 100 cc3_pixbuf_rewind(); 102 cc3_g_ current_frame.y_loc = 0;101 cc3_g_pixbuf_frame.y_loc = 0; 103 102 104 103 //while (REG (GPIO_IOPIN) & _CC3_CAM_VSYNC); … … 129 128 void _cc3_seek_top () 130 129 { 131 if (cc3_g_ current_frame.y_loc < cc3_g_current_frame.y0) {132 _cc3_pixbuf_skip_pixels (cc3_g_ current_frame.raw_width / 2133 * cc3_g_ current_frame.y0);134 135 cc3_g_ current_frame.y_loc = cc3_g_current_frame.y0;130 if (cc3_g_pixbuf_frame.y_loc < cc3_g_pixbuf_frame.y0) { 131 _cc3_pixbuf_skip_pixels (cc3_g_pixbuf_frame.raw_width / 2 132 * cc3_g_pixbuf_frame.y0); 133 134 cc3_g_pixbuf_frame.y_loc = cc3_g_pixbuf_frame.y0; 136 135 } 137 136 } … … 140 139 void _cc3_seek_left () 141 140 { 142 _cc3_pixbuf_skip_pixels (cc3_g_ current_frame.x0 / 2);141 _cc3_pixbuf_skip_pixels (cc3_g_pixbuf_frame.x0 / 2); 143 142 } 144 143 … … 160 159 uint8_t off0, uint8_t off1, uint8_t off2) 161 160 { 162 if (cc3_g_ current_frame.x_step == 1) {161 if (cc3_g_pixbuf_frame.x_step == 1) { 163 162 if (_cc3_second_green_valid) { 164 163 // use the second green … … 186 185 } 187 186 188 void _cc3_resize_pixbuf () 189 { 190 cc3_g_current_frame.raw_width = _cc3_g_current_camera_state.raw_width; 191 cc3_g_current_frame.raw_height = _cc3_g_current_camera_state.raw_height; 187 void _cc3_pixbuf_resize () 188 { 189 cc3_g_pixbuf_frame.raw_width = _cc3_g_current_camera_state.raw_width; 190 cc3_g_pixbuf_frame.raw_height = _cc3_g_current_camera_state.raw_height; 191 cc3_pixbuf_frame_reset(); 192 192 } 193 193 … … 207 207 REG (GPIO_IOSET) = _CC3_BUF_RRST; 208 208 // skip first line because it is blue 209 _cc3_pixbuf_skip_pixels (cc3_g_ current_frame.raw_width / 2);210 //_cc3_pixbuf_skip_pixels (cc3_g_ current_frame.raw_width / 2);209 _cc3_pixbuf_skip_pixels (cc3_g_pixbuf_frame.raw_width / 2); 210 //_cc3_pixbuf_skip_pixels (cc3_g_pixbuf_frame.raw_width / 2); 211 211 _cc3_second_green_valid = false; 212 cc3_g_ current_frame.y_loc = 0;212 cc3_g_pixbuf_frame.y_loc = 0; 213 213 } 214 214 … … 250 250 uint8_t *cc3_malloc_rows (uint32_t rows) 251 251 { 252 int channels = cc3_g_ current_frame.channels;253 int width = cc3_g_ current_frame.width;252 int channels = cc3_g_pixbuf_frame.channels; 253 int width = cc3_g_pixbuf_frame.width; 254 254 255 255 return (uint8_t *) malloc (width * channels * rows); … … 273 273 uint8_t off0, off1, off2; 274 274 275 int width = cc3_g_ current_frame.width;276 277 unsigned int row_limit = (cc3_g_ current_frame.y1 - cc3_g_current_frame.y_loc)278 / cc3_g_ current_frame.y_step;275 int width = cc3_g_pixbuf_frame.width; 276 277 unsigned int row_limit = (cc3_g_pixbuf_frame.y1 - cc3_g_pixbuf_frame.y_loc) 278 / cc3_g_pixbuf_frame.y_step; 279 279 280 280 if (row_limit < rows) { … … 302 302 303 303 for (r = 0; r < rows; r++) { 304 int x = cc3_g_ current_frame.x0;304 int x = cc3_g_pixbuf_frame.x0; 305 305 306 306 // First read into line 307 307 _cc3_seek_left (); 308 308 309 switch (cc3_g_ current_frame.coi) {309 switch (cc3_g_pixbuf_frame.coi) { 310 310 case CC3_ALL: 311 311 _cc3_second_green_valid = false; … … 316 316 317 317 // advance by x_step 318 x += cc3_g_ current_frame.x_step;319 _cc3_pixbuf_skip_pixels ((cc3_g_ current_frame.x_step - 1) / 2);318 x += cc3_g_pixbuf_frame.x_step; 319 _cc3_pixbuf_skip_pixels ((cc3_g_pixbuf_frame.x_step - 1) / 2); 320 320 } 321 321 … … 326 326 uint8_t *p = ((uint8_t *) mem) + (r * width + j); 327 327 328 if ((j & 0x1) == 0 || cc3_g_ current_frame.x_step > 1) {328 if ((j & 0x1) == 0 || cc3_g_pixbuf_frame.x_step > 1) { 329 329 // read 330 330 _cc3_pixbuf_skip_subpixel (); … … 336 336 } 337 337 338 x += cc3_g_ current_frame.x_step;339 _cc3_pixbuf_skip_pixels ((cc3_g_ current_frame.x_step - 1) / 2);338 x += cc3_g_pixbuf_frame.x_step; 339 _cc3_pixbuf_skip_pixels ((cc3_g_pixbuf_frame.x_step - 1) / 2); 340 340 } 341 341 break; … … 345 345 uint8_t *p = ((uint8_t *) mem) + (r * width + j); 346 346 347 if ((j & 0x1) == 0 || cc3_g_ current_frame.x_step > 1) {347 if ((j & 0x1) == 0 || cc3_g_pixbuf_frame.x_step > 1) { 348 348 // read 349 349 *p = _cc3_pixbuf_read_subpixel (); … … 355 355 } 356 356 357 x += cc3_g_ current_frame.x_step;358 _cc3_pixbuf_skip_pixels ((cc3_g_ current_frame.x_step - 1) / 2);357 x += cc3_g_pixbuf_frame.x_step; 358 _cc3_pixbuf_skip_pixels ((cc3_g_pixbuf_frame.x_step - 1) / 2); 359 359 } 360 360 break; … … 364 364 uint8_t *p = ((uint8_t *) mem) + (r * width + j); 365 365 366 if ((j & 0x1) == 0 || cc3_g_ current_frame.x_step > 1) {366 if ((j & 0x1) == 0 || cc3_g_pixbuf_frame.x_step > 1) { 367 367 // read 368 368 _cc3_pixbuf_skip_subpixel (); … … 374 374 } 375 375 376 x += cc3_g_ current_frame.x_step;377 _cc3_pixbuf_skip_pixels ((cc3_g_ current_frame.x_step - 1) / 2);376 x += cc3_g_pixbuf_frame.x_step; 377 _cc3_pixbuf_skip_pixels ((cc3_g_pixbuf_frame.x_step - 1) / 2); 378 378 } 379 379 break; 380 380 } 381 _cc3_pixbuf_skip_pixels ((cc3_g_ current_frame.raw_width - x) / 2);381 _cc3_pixbuf_skip_pixels ((cc3_g_pixbuf_frame.raw_width - x) / 2); 382 382 383 383 384 384 // advance by y_step 385 _cc3_pixbuf_skip_pixels ((cc3_g_ current_frame.y_step - 1) * cc3_g_current_frame.raw_width / 2);386 cc3_g_ current_frame.y_loc += cc3_g_current_frame.y_step;385 _cc3_pixbuf_skip_pixels ((cc3_g_pixbuf_frame.y_step - 1) * cc3_g_pixbuf_frame.raw_width / 2); 386 cc3_g_pixbuf_frame.y_loc += cc3_g_pixbuf_frame.y_step; 387 387 } 388 388 return rows; … … 419 419 int cc3_pixbuf_set_roi (int16_t x0, int16_t y0, int16_t x1, int16_t y1) 420 420 { 421 int w = cc3_g_ current_frame.raw_width;422 int h = cc3_g_ current_frame.raw_height;421 int w = cc3_g_pixbuf_frame.raw_width; 422 int h = cc3_g_pixbuf_frame.raw_height; 423 423 424 424 // constrain … … 458 458 459 459 // set if ok 460 cc3_g_ current_frame.x0 = x0;461 cc3_g_ current_frame.y0 = y0;462 cc3_g_ current_frame.x1 = x1;463 cc3_g_ current_frame.y1 = y1;464 465 _cc3_update_frame_bounds (&cc3_g_ current_frame);460 cc3_g_pixbuf_frame.x0 = x0; 461 cc3_g_pixbuf_frame.y0 = y0; 462 cc3_g_pixbuf_frame.x1 = x1; 463 cc3_g_pixbuf_frame.y1 = y1; 464 465 _cc3_update_frame_bounds (&cc3_g_pixbuf_frame); 466 466 467 467 return 1; … … 493 493 } 494 494 495 cc3_g_ current_frame.x_step = x_step;496 cc3_g_ current_frame.y_step = y_step;497 //cc3_g_ current_frame.x0 = 0;498 //cc3_g_ current_frame.y0 = 0;499 //cc3_g_ current_frame.x1 = cc3_g_current_frame.raw_width;500 //cc3_g_ current_frame.y1 = cc3_g_current_frame.raw_height;501 cc3_g_ current_frame.subsample_mode = mode;502 503 _cc3_update_frame_bounds (&cc3_g_ current_frame);495 cc3_g_pixbuf_frame.x_step = x_step; 496 cc3_g_pixbuf_frame.y_step = y_step; 497 //cc3_g_pixbuf_frame.x0 = 0; 498 //cc3_g_pixbuf_frame.y0 = 0; 499 //cc3_g_pixbuf_frame.x1 = cc3_g_pixbuf_frame.raw_width; 500 //cc3_g_pixbuf_frame.y1 = cc3_g_pixbuf_frame.raw_height; 501 cc3_g_pixbuf_frame.subsample_mode = mode; 502 503 _cc3_update_frame_bounds (&cc3_g_pixbuf_frame); 504 504 505 505 return result; … … 516 516 if (chan > 4) 517 517 return 0; // Sanity check on bounds 518 cc3_g_ current_frame.coi = chan;519 520 cc3_g_ current_frame.channels = (chan == CC3_ALL ? 3 : 1);518 cc3_g_pixbuf_frame.coi = chan; 519 520 cc3_g_pixbuf_frame.channels = (chan == CC3_ALL ? 3 : 1); 521 521 522 522 return 1; … … 553 553 _cc3_set_register_state (); 554 554 555 _cc3_resize_pixbuf(); 556 cc3_frame_default (); 557 558 return 1; 559 } 560 561 void cc3_frame_default () 562 { 563 cc3_g_current_frame.x_step = 1; 564 cc3_g_current_frame.y_step = 1; 565 cc3_g_current_frame.x0 = 0; 566 cc3_g_current_frame.y0 = 0; 567 cc3_g_current_frame.x1 = cc3_g_current_frame.raw_width; 568 cc3_g_current_frame.y1 = cc3_g_current_frame.raw_height; 569 cc3_g_current_frame.y_loc = 0; 570 cc3_g_current_frame.subsample_mode = CC3_NEAREST; 571 cc3_g_current_frame.reset_on_next_load = false; 555 _cc3_pixbuf_resize(); 556 557 return 1; 558 } 559 560 void cc3_pixbuf_frame_reset () 561 { 562 cc3_g_pixbuf_frame.x_step = 1; 563 cc3_g_pixbuf_frame.y_step = 1; 564 cc3_g_pixbuf_frame.x0 = 0; 565 cc3_g_pixbuf_frame.y0 = 0; 566 cc3_g_pixbuf_frame.x1 = cc3_g_pixbuf_frame.raw_width; 567 cc3_g_pixbuf_frame.y1 = cc3_g_pixbuf_frame.raw_height; 568 cc3_g_pixbuf_frame.y_loc = 0; 569 cc3_g_pixbuf_frame.subsample_mode = CC3_NEAREST; 570 cc3_g_pixbuf_frame.reset_on_next_load = false; 572 571 573 572 cc3_pixbuf_set_coi(CC3_ALL); 574 573 575 _cc3_update_frame_bounds (&cc3_g_ current_frame);574 _cc3_update_frame_bounds (&cc3_g_pixbuf_frame); 576 575 } 577 576 … … 751 750 752 751 /** 753 * Sets the resolution, cc3_g_ current_frame width and height not updated752 * Sets the resolution, cc3_g_pixbuf_frame width and height not updated 754 753 * until next pixbuf load. 755 754 * Takes enum CC3_LOW_RES and CC3_HIGH_RES. … … 759 758 _cc3_g_current_camera_state.resolution = cam_res; 760 759 _cc3_set_register_state (); // XXX Don't reset all of them, this is just quick and dirty... 761 cc3_g_ current_frame.reset_on_next_load = true;760 cc3_g_pixbuf_frame.reset_on_next_load = true; 762 761 763 762 return 1; trunk/hal/lpc2106-cmucam3/cc3_hal.c
r387 r392 109 109 // Set the right data bus mode 110 110 cc3_set_raw_register (0x14, 0x20); 111 // Set the resolution and update the cc3_g_current_framesize flags111 // Set the resolution and update the size flags 112 112 if (_cc3_g_current_camera_state.resolution == CC3_LOW_RES) { 113 113 _cc3_g_current_camera_state.raw_width = CC3_LO_RES_WIDTH; // 88 * 2; trunk/hal/virtual-cam/cc3.c
r387 r392 35 35 // Globals used by CMUCam functions 36 36 cc3_pixel_t cc3_g_current_pixel; // global that gets updated with pixbuf calls 37 cc3_frame_t cc3_g_ current_frame; // global that keeps clip, stride37 cc3_frame_t cc3_g_pixbuf_frame; // global that keeps clip, stride 38 38 39 39 … … 71 71 static int img_cnt=0; 72 72 73 if (cc3_g_ current_frame.reset_on_next_load) {73 if (cc3_g_pixbuf_frame.reset_on_next_load) { 74 74 _cc3_resize_pixbuf(); 75 cc3_frame_default();76 75 } 77 76 … … 170 169 printf( "Virtual FIFO Loaded %d bytes.\n", i); 171 170 virtual_fifo_index=0; 172 cc3_g_ current_frame.y_loc = 0;171 cc3_g_pixbuf_frame.y_loc = 0; 173 172 174 173 } … … 200 199 void _cc3_seek_top () 201 200 { 202 if (cc3_g_ current_frame.y_loc < cc3_g_current_frame.y0) {203 _cc3_pixbuf_skip_pixels (cc3_g_ current_frame.raw_width / 2204 * cc3_g_ current_frame.y0);205 206 cc3_g_ current_frame.y_loc = cc3_g_current_frame.y0;201 if (cc3_g_pixbuf_frame.y_loc < cc3_g_pixbuf_frame.y0) { 202 _cc3_pixbuf_skip_pixels (cc3_g_pixbuf_frame.raw_width / 2 203 * cc3_g_pixbuf_frame.y0); 204 205 cc3_g_pixbuf_frame.y_loc = cc3_g_pixbuf_frame.y0; 207 206 } 208 207 } … … 211 210 void _cc3_seek_left () 212 211 { 213 _cc3_pixbuf_skip_pixels (cc3_g_ current_frame.x0 / 2);212 _cc3_pixbuf_skip_pixels (cc3_g_pixbuf_frame.x0 / 2); 214 213 } 215 214 … … 232 231 uint8_t off0, uint8_t off1, uint8_t off2) 233 232 { 234 if (cc3_g_ current_frame.x_step == 1) {233 if (cc3_g_pixbuf_frame.x_step == 1) { 235 234 if (_cc3_second_green_valid) { 236 235 // use the second green … … 270 269 virtual_fifo_index=0; 271 270 _cc3_second_green_valid = false; 272 cc3_g_ current_frame.y_loc = 0;271 cc3_g_pixbuf_frame.y_loc = 0; 273 272 } 274 273 … … 309 308 void _cc3_resize_pixbuf () 310 309 { 311 cc3_g_ current_frame.raw_width = _cc3_g_current_camera_state.raw_width;312 cc3_g_ current_frame.raw_height = _cc3_g_current_camera_state.raw_height;310 cc3_g_pixbuf_frame.raw_width = _cc3_g_current_camera_state.raw_width; 311 cc3_g_pixbuf_frame.raw_height = _cc3_g_current_camera_state.raw_height; 313 312 314 313 } … … 316 315 uint8_t *cc3_malloc_rows (uint32_t rows) 317 316 { 318 int channels = cc3_g_ current_frame.channels;319 int width = cc3_g_ current_frame.width;317 int channels = cc3_g_pixbuf_frame.channels; 318 int width = cc3_g_pixbuf_frame.width; 320 319 321 320 return (uint8_t *) malloc (width * channels * rows); … … 339 338 uint8_t off0, off1, off2; 340 339 341 int width = cc3_g_ current_frame.width;342 343 unsigned int row_limit = (cc3_g_ current_frame.y1 - cc3_g_current_frame.y_loc)344 / cc3_g_ current_frame.y_step;340 int width = cc3_g_pixbuf_frame.width; 341 342 unsigned int row_limit = (cc3_g_pixbuf_frame.y1 - cc3_g_pixbuf_frame.y_loc) 343 / cc3_g_pixbuf_frame.y_step; 345 344 346 345 if (row_limit < rows) { … … 368 367 369 368 for (r = 0; r < rows; r++) { 370 int x = cc3_g_ current_frame.x0;369 int x = cc3_g_pixbuf_frame.x0; 371 370 372 371 // First read into line 373 372 _cc3_seek_left (); 374 373 375 switch (cc3_g_ current_frame.coi) {374 switch (cc3_g_pixbuf_frame.coi) { 376 375 case CC3_ALL: 377 376 _cc3_second_green_valid = false; … … 382 381 383 382 // advance by x_step 384 x += cc3_g_ current_frame.x_step;385 _cc3_pixbuf_skip_pixels ((cc3_g_ current_frame.x_step - 1) / 2);383 x += cc3_g_pixbuf_frame.x_step; 384 _cc3_pixbuf_skip_pixels ((cc3_g_pixbuf_frame.x_step - 1) / 2); 386 385 } 387 386 … … 392 391 uint8_t *p = ((uint8_t *) mem) + (r * width + j); 393 392 394 if ((j & 0x1) == 0 || cc3_g_ current_frame.x_step > 1) {393 if ((j & 0x1) == 0 || cc3_g_pixbuf_frame.x_step > 1) { 395 394 // read 396 395 _cc3_pixbuf_skip_subpixel (); … … 402 401 } 403 402 404 x += cc3_g_ current_frame.x_step;405 _cc3_pixbuf_skip_pixels ((cc3_g_ current_frame.x_step - 1) / 2);403 x += cc3_g_pixbuf_frame.x_step; 404 _cc3_pixbuf_skip_pixels ((cc3_g_pixbuf_frame.x_step - 1) / 2); 406 405 } 407 406 break; … … 411 410 uint8_t *p = ((uint8_t *) mem) + (r * width + j); 412 411 413 if ((j & 0x1) == 0 || cc3_g_ current_frame.x_step > 1) {412 if ((j & 0x1) == 0 || cc3_g_pixbuf_frame.x_step > 1) { 414 413 // read 415 414 *p = _cc3_pixbuf_read_subpixel (); … … 421 420 } 422 421 423 x += cc3_g_ current_frame.x_step;424 _cc3_pixbuf_skip_pixels ((cc3_g_ current_frame.x_step - 1) / 2);422 x += cc3_g_pixbuf_frame.x_step; 423 _cc3_pixbuf_skip_pixels ((cc3_g_pixbuf_frame.x_step - 1) / 2); 425 424 } 426 425 break; … … 430 429 uint8_t *p = ((uint8_t *) mem) + (r * width + j); 431 430 432 if ((j & 0x1) == 0 || cc3_g_ current_frame.x_step > 1) {431 if ((j & 0x1) == 0 || cc3_g_pixbuf_frame.x_step > 1) { 433 432 // read 434 433 _cc3_pixbuf_skip_subpixel (); … … 440 439 } 441 440 442 x += cc3_g_ current_frame.x_step;443 _cc3_pixbuf_skip_pixels ((cc3_g_ current_frame.x_step - 1) / 2);441 x += cc3_g_pixbuf_frame.x_step; 442 _cc3_pixbuf_skip_pixels ((cc3_g_pixbuf_frame.x_step - 1) / 2); 444 443 } 445 444 break; 446 445 } 447 _cc3_pixbuf_skip_pixels ((cc3_g_ current_frame.raw_width - x) / 2);446 _cc3_pixbuf_skip_pixels ((cc3_g_pixbuf_frame.raw_width - x) / 2); 448 447 449 448 450 449 // advance by y_step 451 _cc3_pixbuf_skip_pixels ((cc3_g_ current_frame.y_step - 1) * cc3_g_current_frame.raw_width / 2);452 cc3_g_ current_frame.y_loc += cc3_g_current_frame.y_step;450 _cc3_pixbuf_skip_pixels ((cc3_g_pixbuf_frame.y_step - 1) * cc3_g_pixbuf_frame.raw_width / 2); 451 cc3_g_pixbuf_frame.y_loc += cc3_g_pixbuf_frame.y_step; 453 452 } 454 453 return rows; … … 488 487 int cc3_pixbuf_set_roi (int16_t x0, int16_t y0, int16_t x1, int16_t y1) 489 488 { 490 int w = cc3_g_ current_frame.raw_width;491 int h = cc3_g_ current_frame.raw_height;489 int w = cc3_g_pixbuf_frame.raw_width; 490 int h = cc3_g_pixbuf_frame.raw_height; 492 491 493 492 // constrain … … 527 526 528 527 // set if ok 529 cc3_g_ current_frame.x0 = x0;530 cc3_g_ current_frame.y0 = y0;531 cc3_g_ current_frame.x1 = x1;532 cc3_g_ current_frame.y1 = y1;533 534 _cc3_update_frame_bounds (&cc3_g_ current_frame);528 cc3_g_pixbuf_frame.x0 = x0; 529 cc3_g_pixbuf_frame.y0 = y0; 530 cc3_g_pixbuf_frame.x1 = x1; 531 cc3_g_pixbuf_frame.y1 = y1; 532 533 _cc3_update_frame_bounds (&cc3_g_pixbuf_frame); 535 534 536 535 return 1; … … 562 561 } 563 562 564 cc3_g_ current_frame.x_step = x_step;565 cc3_g_ current_frame.y_step = y_step;566 //cc3_g_ current_frame.x0 = 0;567 //cc3_g_ current_frame.y0 = 0;568 //cc3_g_ current_frame.x1 = cc3_g_current_frame.raw_width;569 //cc3_g_ current_frame.y1 = cc3_g_current_frame.raw_height;570 cc3_g_ current_frame.subsample_mode = mode;571 572 _cc3_update_frame_bounds (&cc3_g_ current_frame);563 cc3_g_pixbuf_frame.x_step = x_step; 564 cc3_g_pixbuf_frame.y_step = y_step; 565 //cc3_g_pixbuf_frame.x0 = 0; 566 //cc3_g_pixbuf_frame.y0 = 0; 567 //cc3_g_pixbuf_frame.x1 = cc3_g_pixbuf_frame.raw_width; 568 //cc3_g_pixbuf_frame.y1 = cc3_g_pixbuf_frame.raw_height; 569 cc3_g_pixbuf_frame.subsample_mode = mode; 570 571 _cc3_update_frame_bounds (&cc3_g_pixbuf_frame); 573 572 574 573 return result; … … 585 584 if (chan > 4) 586 585 return 0; // Sanity check on bounds 587 cc3_g_ current_frame.coi = chan;588 589 cc3_g_ current_frame.channels = (chan == CC3_ALL ? 3 : 1);586 cc3_g_pixbuf_frame.coi = chan; 587 588 cc3_g_pixbuf_frame.channels = (chan == CC3_ALL ? 3 : 1); 590 589 591 590 return 1; … … 618 617 619 618 _cc3_resize_pixbuf (); 620 cc3_frame_default ();621 619 printf( "cc3_camera_init()\n" ); 622 620 _cc3_virtual_cam_path_prefix = getenv("CC3_VCAM_PATH"); … … 630 628 } 631 629 632 void cc3_ frame_default ()633 { 634 cc3_g_ current_frame.x_step = 1;635 cc3_g_ current_frame.y_step = 1;636 cc3_g_ current_frame.x0 = 0;637 cc3_g_ current_frame.y0 = 0;638 cc3_g_ current_frame.x1 = cc3_g_current_frame.raw_width;639 cc3_g_ current_frame.y1 = cc3_g_current_frame.raw_height;640 cc3_g_ current_frame.y_loc = 0;641 cc3_g_ current_frame.subsample_mode = CC3_NEAREST;642 cc3_g_ current_frame.reset_on_next_load = false;630 void cc3_pixbuf_frame_reset () 631 { 632 cc3_g_pixbuf_frame.x_step = 1; 633 cc3_g_pixbuf_frame.y_step = 1; 634 cc3_g_pixbuf_frame.x0 = 0; 635 cc3_g_pixbuf_frame.y0 = 0; 636 cc3_g_pixbuf_frame.x1 = cc3_g_pixbuf_frame.raw_width; 637 cc3_g_pixbuf_frame.y1 = cc3_g_pixbuf_frame.raw_height; 638 cc3_g_pixbuf_frame.y_loc = 0; 639 cc3_g_pixbuf_frame.subsample_mode = CC3_NEAREST; 640 cc3_g_pixbuf_frame.reset_on_next_load = false; 643 641 644 642 cc3_pixbuf_set_coi(CC3_ALL); 645 643 646 _cc3_update_frame_bounds (&cc3_g_ current_frame);644 _cc3_update_frame_bounds (&cc3_g_pixbuf_frame); 647 645 } 648 646 … … 723 721 724 722 /** 725 * Sets the resolution, also updates cc3_g_ current_frame width and height723 * Sets the resolution, also updates cc3_g_pixbuf_frame width and height 726 724 * Takes enum CC3_LOW_RES and CC3_HIGH_RES. 727 725 */ … … 730 728 _cc3_g_current_camera_state.resolution = cam_res; 731 729 _cc3_set_register_state (); // XXX Don't reset all of them, this is just quick and dirty... 732 cc3_g_ current_frame.reset_on_next_load = true;730 cc3_g_pixbuf_frame.reset_on_next_load = true; 733 731 734 732 return 1; trunk/include/cc3.h
r388 r392 131 131 /** 132 132 * Framebuffer definition. 133 * @sa #cc3_g_ current_frame for the main use of this definition.133 * @sa #cc3_g_pixbuf_frame for the main use of this definition. 134 134 */ 135 135 typedef struct { … … 162 162 * Current parameters for the internal pixbuf, should be 163 163 * considered read only. 164 * @sa cc3_ frame_default()165 */ 166 extern cc3_frame_t cc3_g_ current_frame;164 * @sa cc3_pixbuf_frame_reset() 165 */ 166 extern cc3_frame_t cc3_g_pixbuf_frame; 167 167 168 168 /** 169 169 * Allocate a number of rows of the correct size based on the values in 170 * #cc3_g_ current_frame.170 * #cc3_g_pixbuf_frame. 171 171 * 172 172 * @param[in] rows The number of rows to allocate space for. … … 177 177 /** 178 178 * Take a picture with the camera and load it into the internal pixbuf. 179 * If #cc3_g_ current_frame has cc3_frame_t.reset_on_next_load set,180 * then cc3_g_ current_frame is also reset with new values.179 * If #cc3_g_pixbuf_frame has cc3_frame_t.reset_on_next_load set, 180 * then cc3_g_pixbuf_frame is also reset with new values. 181 181 */ 182 182 void cc3_pixbuf_load (void); 183 183 184 184 /** 185 * Reset the cc3_g_ current_frame to default values.186 */ 187 void cc3_ frame_default (void);185 * Reset the cc3_g_pixbuf_frame to default values. 186 */ 187 void cc3_pixbuf_frame_reset (void); 188 188 189 189 /** … … 230 230 void cc3_camera_kill (void); 231 231 /** 232 * Sets the resolution, also updates cc3_g_ current_frame width and height232 * Sets the resolution, also updates cc3_g_pixbuf_frame width and height 233 233 */ 234 234 int cc3_set_resolution (cc3_camera_resolution_t); trunk/lib/cc3-ilp/cc3_color_info.c
r302 r392 55 55 cc3_get_pixel( img, x, 0, &cp ); 56 56 pkt->scratch_pix++; 57 if(cc3_g_ current_frame.coi==CC3_ALL ) {57 if(cc3_g_pixbuf_frame.coi==CC3_ALL ) { 58 58 uint8_t i; 59 59 for(i=0; i<3; i++ ) … … 67 67 { 68 68 uint8_t i; 69 i=cc3_g_ current_frame.coi;69 i=cc3_g_pixbuf_frame.coi; 70 70 pkt->scratch_mean[i]+=cp.channel[i]; 71 71 if(cp.channel[i]<pkt->min.channel[i]) pkt->min.channel[i]=cp.channel[i]; trunk/lib/cc3-ilp/cc3_color_track.c
r302 r392 60 60 pixel = row = cc3_malloc_rows(1); 61 61 62 for (y = 0; y < cc3_g_ current_frame.height; y++) {62 for (y = 0; y < cc3_g_pixbuf_frame.height; y++) { 63 63 cc3_pixbuf_read_rows(row, 1); 64 64 65 for (x = 0; x < cc3_g_ current_frame.width; x++) {65 for (x = 0; x < cc3_g_pixbuf_frame.width; x++) { 66 66 bool pixel_good = 0; 67 67 68 if (cc3_g_ current_frame.coi == CC3_ALL) {68 if (cc3_g_pixbuf_frame.coi == CC3_ALL) { 69 69 if (pixel[0] >= pkt->lower_bound.channel[0] 70 70 && pixel[0] <= pkt->upper_bound.channel[0] … … 79 79 else { 80 80 if (*pixel >= 81 pkt->lower_bound.channel[cc3_g_ current_frame.coi]82 && pixel [cc3_g_ current_frame.coi] <=83 pkt->upper_bound.channel[cc3_g_ current_frame.coi])81 pkt->lower_bound.channel[cc3_g_pixbuf_frame.coi] 82 && pixel [cc3_g_pixbuf_frame.coi] <= 83 pkt->upper_bound.channel[cc3_g_pixbuf_frame.coi]) 84 84 pixel_good = 1; 85 85 … … 166 166 //cc3_pixbuf_read(); 167 167 cc3_get_pixel (img, x, 0, &cp); 168 if (cc3_g_ current_frame.coi == CC3_ALL) {168 if (cc3_g_pixbuf_frame.coi == CC3_ALL) { 169 169 if (cp.channel[0] >= pkt->lower_bound.channel[0] && 170 170 cp.channel[0] <= pkt->upper_bound.channel[0] && … … 176 176 } 177 177 else { 178 if (cp.channel[cc3_g_ current_frame.coi] >=179 pkt->lower_bound.channel[cc3_g_ current_frame.coi]180 && cp.channel[cc3_g_ current_frame.coi] <=181 pkt->upper_bound.channel[cc3_g_ current_frame.coi])178 if (cp.channel[cc3_g_pixbuf_frame.coi] >= 179 pkt->lower_bound.channel[cc3_g_pixbuf_frame.coi] 180 && cp.channel[cc3_g_pixbuf_frame.coi] <= 181 pkt->upper_bound.channel[cc3_g_pixbuf_frame.coi]) 182 182 pixel_good = 1; 183 183 } trunk/lib/cc3-ilp/cc3_ilp.c
r331 r392 25 25 void cc3_send_image_direct (void) 26 26 { 27 cc3_pixbuf_load (); 28 27 29 uint32_t x, y; 28 30 uint32_t size_x, size_y; 29 31 uint8_t *row = cc3_malloc_rows(1); 30 uint8_t num_channels = cc3_g_ current_frame.coi == CC3_ALL ? 3 : 1;32 uint8_t num_channels = cc3_g_pixbuf_frame.coi == CC3_ALL ? 3 : 1; 31 33 32 34 33 size_x = cc3_g_current_frame.width; 34 size_y = cc3_g_current_frame.height; 35 36 cc3_pixbuf_load (); 35 size_x = cc3_g_pixbuf_frame.width; 36 size_y = cc3_g_pixbuf_frame.height; 37 37 38 38 putchar (1); trunk/lib/cc3-ilp/cc3_jpg.c
r330 r392 35 35 36 36 void cc3_jpeg_send_simple(void) { 37 // init jpeg 37 // capture a frame to the FIFO 38 cc3_pixbuf_load(); 39 40 // init jpeg (allocates memory based on FIFO contents) 38 41 cc3_jpeg_t *cj = init_jpeg(); 39 42 … … 58 61 59 62 // parameters for jpeg image 60 cj->cinfo.image_width = cc3_g_ current_frame.width;61 cj->cinfo.image_height = cc3_g_ current_frame.height;63 cj->cinfo.image_width = cc3_g_pixbuf_frame.width; 64 cj->cinfo.image_height = cc3_g_pixbuf_frame.height; 62 65 63 66 //printf( "image width=%d image height=%d\n", cinfo.image_width, cinfo.image_height ); … … 86 89 jpeg_stdio_dest(&cj->cinfo, f); 87 90 88 // capture a frame to the FIFO89 cc3_pixbuf_load();90 91 91 // read and compress 92 92 jpeg_start_compress(&cj->cinfo, TRUE); trunk/projects/cmucam2/cmucam2.c
r352 r392 91 91 cc3_set_resolution(CC3_LOW_RES); 92 92 93 cc3_pixbuf_load(); 94 93 95 printf ("%s\r", VERSION_BANNER); 94 96 … … 150 152 print_ACK (); 151 153 if (arg_list[0] == 1) 152 cc3_set_resolution(CC3_HIGH_RES); 153 else 154 cc3_set_resolution(CC3_LOW_RES); 154 cc3_set_resolution(CC3_HIGH_RES); 155 else 156 cc3_set_resolution(CC3_LOW_RES); 157 158 // re-init fifo 159 cc3_pixbuf_load(); 155 160 break; 156 161 … … 190 195 191 196 case SEND_FRAME: 192 old_coi = cc3_g_ current_frame.coi;197 old_coi = cc3_g_pixbuf_frame.coi; 193 198 if (n == 1) { 194 199 if (arg_list[0] > 4) { … … 275 280 polly_config_t p_config; 276 281 cc3_linear_reg_data_t reg_line; 277 x_axis = malloc(cc3_g_ current_frame.width);282 x_axis = malloc(cc3_g_pixbuf_frame.width); 278 283 279 284 p_config.color_thresh=arg_list[0]; //20; … … 283 288 p_config.vertical_edges=arg_list[4]; //1; 284 289 p_config.blur=arg_list[5]; //1; 285 p_config.histogram=malloc(cc3_g_ current_frame.width);286 for(uint32_t i=0; i<cc3_g_ current_frame.width; i++ ) x_axis[i]=i;290 p_config.histogram=malloc(cc3_g_pixbuf_frame.width); 291 for(uint32_t i=0; i<cc3_g_pixbuf_frame.width; i++ ) x_axis[i]=i; 287 292 do { 288 293 polly(p_config); 289 cc3_linear_reg(x_axis, p_config.histogram, cc3_g_ current_frame.width,®_line);294 cc3_linear_reg(x_axis, p_config.histogram, cc3_g_pixbuf_frame.width,®_line); 290 295 291 296 // return linear regression offset value … … 296 301 printf( "%f ",reg_line.r_sqr ); 297 302 // return distance to line at middle of image 298 double distance=reg_line.m*(cc3_g_ current_frame.width/2)+reg_line.b;303 double distance=reg_line.m*(cc3_g_pixbuf_frame.width/2)+reg_line.b; 299 304 printf( " %f\r",distance ); 300 305 … … 352 357 cc3_image_t img; 353 358 img.channels = 3; 354 img.width = cc3_g_ current_frame.width;359 img.width = cc3_g_pixbuf_frame.width; 355 360 img.height = 1; // image will hold just 1 row for scanline processing 356 361 img.pix = malloc (3 * img.width); … … 379 384 380 385 img.channels = 3; 381 img.width = cc3_g_ current_frame.width;386 img.width = cc3_g_pixbuf_frame.width; 382 387 img.height = 1; // image will hold just 1 row for scanline processing 383 388 img.pix = cc3_malloc_rows(1); … … 395 400 lm_width++; 396 401 putchar (0xAA); 397 if (cc3_g_ current_frame.height > 255)402 if (cc3_g_pixbuf_frame.height > 255) 398 403 lm_height = 255; 399 404 else 400 lm_height = cc3_g_ current_frame.height;405 lm_height = cc3_g_pixbuf_frame.height; 401 406 402 407 //putchar(lm_width); trunk/projects/cmucam2/polly.c
r391 r392 49 49 cc3_set_auto_exposure (true); 50 50 51 cc3_pixbuf_load (); 51 52 52 53 cc3_pixbuf_set_subsample (CC3_NEAREST, 2, 2); … … 57 58 //img.channels=CC3_GREEN; 58 59 img.channels = 1; 59 img.width = cc3_g_ current_frame.width;60 img.height = cc3_g_ current_frame.height; // image will hold just 1 row for scanline processing60 img.width = cc3_g_pixbuf_frame.width; 61 img.height = cc3_g_pixbuf_frame.height; // image will hold just 1 row for scanline processing 61 62 //img.pix = cc3_malloc_rows(1); 62 img.pix = cc3_malloc_rows (cc3_g_ current_frame.height);63 img.pix = cc3_malloc_rows (cc3_g_pixbuf_frame.height); 63 64 if (img.pix == NULL) { 64 65 printf ("Not enough memory...\n"); … … 91 92 92 93 93 cc3_pixbuf_load ();94 95 94 #ifdef MMC_DEBUG 96 95 cc3_pixbuf_set_coi (CC3_ALL); … … 100 99 #endif 101 100 102 cc3_pixbuf_read_rows (img.pix, cc3_g_ current_frame.height);101 cc3_pixbuf_read_rows (img.pix, cc3_g_pixbuf_frame.height); 103 102 if (config.blur == 1) { 104 103 blur.size = 3; … … 527 526 } 528 527 529 size_x = cc3_g_ current_frame.width;530 size_y = cc3_g_ current_frame.height;528 size_x = cc3_g_pixbuf_frame.width; 529 size_y = cc3_g_pixbuf_frame.height; 531 530 532 531 fprintf (f, "P3\n%d %d\n255\n", size_x, size_y); trunk/projects/edge-follow/main.c
r389 r392 54 54 cc3_clr_led (2); 55 55 56 // load into pixbuf to initialize cc3_g_pixbuf_frame 57 cc3_pixbuf_load(); 58 56 59 // sample wait command in ms 57 60 cc3_wait_ms (1000); 58 x_axis = malloc (cc3_g_ current_frame.width);59 h = malloc (cc3_g_ current_frame.width);61 x_axis = malloc (cc3_g_pixbuf_frame.width); 62 h = malloc (cc3_g_pixbuf_frame.width); 60 63 61 64 p_config.color_thresh = 10; … … 65 68 p_config.vertical_edges = 1; 66 69 p_config.blur = 1; 67 p_config.histogram = malloc (cc3_g_ current_frame.width);70 p_config.histogram = malloc (cc3_g_pixbuf_frame.width); 68 71 69 72 img.channels = 1; 70 img.width = cc3_g_ current_frame.width;71 img.height = cc3_g_ current_frame.height; // image will hold just 1 row for scanline processing73 img.width = cc3_g_pixbuf_frame.width; 74 img.height = cc3_g_pixbuf_frame.height; // image will hold just 1 row for scanline processing 72 75 //img.pix = cc3_malloc_rows(1); 73 img.pix = malloc (cc3_g_ current_frame.height * cc3_g_current_frame.width);76 img.pix = malloc (cc3_g_pixbuf_frame.height * cc3_g_pixbuf_frame.width); 74 77 if (img.pix == NULL) { 75 78 printf ("Not enough memory...\n"); … … 78 81 79 82 tmp_img.channels = 3; 80 tmp_img.width = cc3_g_ current_frame.width;83 tmp_img.width = cc3_g_pixbuf_frame.width; 81 84 tmp_img.height = 1; 82 85 tmp_img.pix = cc3_malloc_rows (1); 83 86 84 87 mask_img.channels = 1; 85 mask_img.width = cc3_g_ current_frame.width;86 mask_img.height = cc3_g_ current_frame.height;88 mask_img.width = cc3_g_pixbuf_frame.width; 89 mask_img.height = cc3_g_pixbuf_frame.height; 87 90 mask_img.pix = 88 malloc (cc3_g_ current_frame.width * cc3_g_current_frame.height);91 malloc (cc3_g_pixbuf_frame.width * cc3_g_pixbuf_frame.height); 89 92 90 93 p_black.channel[0] = 0; … … 101 104 #endif 102 105 103 for (i = 0; i < cc3_g_ current_frame.height; i++) {106 for (i = 0; i < cc3_g_pixbuf_frame.height; i++) { 104 107 cc3_pixbuf_read_rows (tmp_img.pix, tmp_img.height); 105 108 for (x = 0; x < tmp_img.width; x++) { … … 123 126 // get added into the regression line. 124 127 cnt = 0; 125 for (i = 0; i < cc3_g_ current_frame.width; i++) {128 for (i = 0; i < cc3_g_pixbuf_frame.width; i++) { 126 129 if (p_config.histogram[i] > 0 && p_config.histogram[i] < 71) { 127 130 h[cnt] = p_config.histogram[i]; … … 148 151 total_error += error; 149 152
