Changeset 209
- Timestamp:
- 03/22/06 00:12:35 (3 years ago)
- Files:
-
- trunk/hal/lpc2106-cmucam3/cc3.c (modified) (18 diffs)
- trunk/include/cc3.h (modified) (1 diff)
- trunk/lib/cc3_ilp/cc3_color_track.c (modified) (2 diffs)
- trunk/lib/cc3_ilp/cc3_ilp.c (modified) (1 diff)
- trunk/projects/benchmark/bench.c (modified) (1 diff)
- trunk/projects/cmucam2/cmucam2.c (modified) (4 diffs)
- trunk/projects/hello_world/main.c (modified) (4 diffs)
- trunk/projects/jpeg-6b/main.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/hal/lpc2106-cmucam3/cc3.c
r205 r209 21 21 22 22 static inline void _cc3_seek_left (void); 23 static inline void _cc3_seek_right_down (void);24 23 static inline void _cc3_seek_top (void); 25 static inline void _cc3_advance_x_loc (void);26 24 27 25 static inline void _cc3_pixbuf_skip_pixels (uint32_t size); … … 45 43 void cc3_pixbuf_load () 46 44 { 45 // uint32_t start_time; 46 47 47 unsigned int i; 48 48 //REG(GPIO_IOCLR)=CAM_IE; … … 50 50 cc3_pixbuf_rewind (); 51 51 _cc3_pixbuf_write_rewind (); 52 53 // start_time = cc3_timer(); 52 54 while (!(REG (GPIO_IOPIN) & _CC3_CAM_VSYNC)); //while(CAM_VSYNC); 53 55 while (REG (GPIO_IOPIN) & _CC3_CAM_VSYNC); //while(!CAM_VSYNC); 54 56 57 55 58 REG (GPIO_IOSET) = _CC3_BUF_WEE; 59 // printf("vsync wait: %3d ms\r", cc3_timer() - start_time); 60 56 61 57 62 // wait for vsync to finish … … 63 68 while (REG (GPIO_IOPIN) & _CC3_CAM_HREF); 64 69 } 65 cc3_g_current_frame.x_loc = 0; 70 66 71 cc3_g_current_frame.y_loc = 0; 72 67 73 //while (REG (GPIO_IOPIN) & _CC3_CAM_VSYNC); 68 74 //REG (GPIO_IOCLR) = _CC3_BUF_WEE; … … 80 86 { 81 87 uint32_t i; 82 for (i = 0; i < size * 4; i++) { 83 _cc3_fifo_read_inc (); 84 } 85 } 86 87 /** 88 * cc3_pixbuf_read(): 89 * loads cc3_g_current_pixel from fifo 90 * Returns 1 upon success and 0 upon a bounds failure 91 * This is slow, but takes care of channel of interest, downsampling, and virtual bounding boxes 92 */ 88 89 for (i = 0; i < size; i++) { 90 _cc3_pixbuf_skip_subpixel (); 91 _cc3_pixbuf_skip_subpixel (); 92 _cc3_pixbuf_skip_subpixel (); 93 _cc3_pixbuf_skip_subpixel (); 94 } 95 } 96 93 97 94 98 void _cc3_seek_top () 95 99 { 96 int8_t i; 97 98 // Skip top 99 for (cc3_g_current_frame.y_loc = 0; 100 cc3_g_current_frame.y_loc < cc3_g_current_frame.y0; 101 cc3_g_current_frame.y_loc++) 102 for (i = 0; i < cc3_g_current_frame.y_step; i++) 103 _cc3_pixbuf_skip_pixels (cc3_g_current_frame.raw_width); 104 cc3_g_current_frame.x_loc = 0; 100 if (cc3_g_current_frame.y_loc < cc3_g_current_frame.y0) { 101 _cc3_pixbuf_skip_pixels (cc3_g_current_frame.raw_width / 2 102 * cc3_g_current_frame.y0); 103 104 cc3_g_current_frame.y_loc = cc3_g_current_frame.y0; 105 } 105 106 } 106 107 … … 108 109 void _cc3_seek_left () 109 110 { 110 // Skip left 111 if (cc3_g_current_frame.x_loc < cc3_g_current_frame.x0) { 112 _cc3_pixbuf_skip_pixels (cc3_g_current_frame.x0 113 * cc3_g_current_frame.x_step); 114 cc3_g_current_frame.x_loc = cc3_g_current_frame.x0; 115 } 116 } 117 118 void _cc3_seek_right_down () 119 { 120 int16_t j; 121 if (cc3_g_current_frame.x_loc < cc3_g_current_frame.x1) { 122 // no need for seeking 123 return; 124 } 125 126 // Skip right and down 127 _cc3_pixbuf_skip_pixels (cc3_g_current_frame.raw_width - 128 (cc3_g_current_frame.x_loc * 129 cc3_g_current_frame.x_step)); 130 cc3_g_current_frame.x_loc = 0; 131 cc3_g_current_frame.y_loc++; 132 if (cc3_g_current_frame.y_step > 1) { 133 // skip horizontally down the image 134 for (j = 0; j < cc3_g_current_frame.y_step - 1; j++) 135 _cc3_pixbuf_skip_pixels (cc3_g_current_frame.raw_width); 136 } 137 } 138 139 void _cc3_advance_x_loc () 140 { 141 cc3_g_current_frame.x_loc++; 142 // skip horizontally for next read 143 if (cc3_g_current_frame.x_step > 1) { 144 if (cc3_g_current_frame.raw_width > 145 (cc3_g_current_frame.x_loc + cc3_g_current_frame.x_step)) { 146 // skip pixel 147 _cc3_pixbuf_skip_pixels (cc3_g_current_frame.x_step - 1); 148 } 149 } 111 _cc3_pixbuf_skip_pixels (cc3_g_current_frame.x0 / 2); 150 112 } 151 113 … … 167 129 uint8_t off0, uint8_t off1, uint8_t off2) 168 130 { 169 if (_cc3_second_green_valid) { 170 // use the second green 171 _cc3_second_green_valid = false; 172 *(pixel + off0) = *(saved + off0); 173 *(pixel + off1) = _cc3_second_green; 174 *(pixel + off2) = *(saved + off2); 175 176 return; 177 } 178 179 // otherwise, load a new thing 180 _cc3_second_green = _cc3_pixbuf_read_subpixel (); 181 *(pixel + off0) = _cc3_pixbuf_read_subpixel (); 182 *(pixel + off1) = _cc3_pixbuf_read_subpixel (); 183 *(pixel + off2) = _cc3_pixbuf_read_subpixel (); 184 185 _cc3_second_green_valid = true; 131 if (cc3_g_current_frame.x_step == 1) { 132 if (_cc3_second_green_valid) { 133 // use the second green 134 _cc3_second_green_valid = false; 135 *(pixel + off0) = *(saved + off0); 136 *(pixel + off1) = _cc3_second_green; 137 *(pixel + off2) = *(saved + off2); 138 139 return; 140 } 141 142 // otherwise, load a new thing 143 *(pixel + off1) = _cc3_pixbuf_read_subpixel (); // G 144 *(pixel + off0) = _cc3_pixbuf_read_subpixel (); // R 145 _cc3_second_green = _cc3_pixbuf_read_subpixel (); // G 146 *(pixel + off2) = _cc3_pixbuf_read_subpixel (); // B 147 148 _cc3_second_green_valid = true; 149 } else { 150 _cc3_pixbuf_skip_subpixel (); 151 *(pixel + off0) = _cc3_pixbuf_read_subpixel (); 152 *(pixel + off1) = _cc3_pixbuf_read_subpixel (); 153 *(pixel + off2) = _cc3_pixbuf_read_subpixel (); 154 } 186 155 } 187 156 … … 202 171 203 172 _cc3_second_green_valid = false; 173 cc3_g_current_frame.y_loc = 0; 204 174 } 205 175 … … 242 212 { 243 213 int channels; 214 int width = (cc3_g_current_frame.x1 - cc3_g_current_frame.x0) 215 / cc3_g_current_frame.x_step; 216 244 217 if (cc3_g_current_frame.coi == CC3_ALL) { 245 218 channels = 3; … … 249 222 } 250 223 251 return (uint8_t *) malloc ( cc3_g_current_frame.width * channels * rows);224 return (uint8_t *) malloc (width * channels * rows); 252 225 } 253 226 … … 259 232 * of cc3_pixel_t memory. 260 233 * This should be the lowest level call that the user directly interacts with. 261 * Returns 1 upon success 262 * Returns -1 if requesting too many rows 234 * Returns number of rows read. (May be zero if error.) 263 235 */ 264 236 int cc3_pixbuf_read_rows (void * mem, uint32_t rows) … … 270 242 uint8_t off0, off1, off2; 271 243 272 if ((cc3_g_current_frame.y0 + rows) > cc3_g_current_frame.y1) 273 return -1; 244 int width = (cc3_g_current_frame.x1 - cc3_g_current_frame.x0) 245 / cc3_g_current_frame.x_step; 246 247 int row_limit = (cc3_g_current_frame.y1 - cc3_g_current_frame.y_loc) 248 / cc3_g_current_frame.y_step; 249 250 if (row_limit < rows) { 251 rows = row_limit; 252 } 274 253 275 254 if (_cc3_g_current_camera_state.colorspace == CC3_RGB) { … … 293 272 294 273 for (r = 0; r < rows; r++) { 295 // First read after line 296 _cc3_seek_right_down (); 274 int x = cc3_g_current_frame.x0; 297 275 298 276 // First read into line … … 300 278 301 279 if (cc3_g_current_frame.coi == CC3_ALL) { 302 for (j = 0; j < cc3_g_current_frame.width; j++) {280 for (j = 0; j < width; j++) { 303 281 uint8_t *p = ((uint8_t *) mem) + 304 (r * cc3_g_current_frame.width + j * 3);282 (r * width + j * 3); 305 283 _cc3_pixbuf_read_pixel (p, p - 3, off0, off1, off2); 306 _cc3_advance_x_loc (); 284 285 // advance by x_step, but don't go over the edge 286 if (cc3_g_current_frame.x_step == 1) { 287 x++; 288 } else if (cc3_g_current_frame.x_step + x 289 >= cc3_g_current_frame.raw_width) { 290 _cc3_pixbuf_skip_pixels ((cc3_g_current_frame.raw_width - x) / 2); 291 // and we're done with this row 292 } else { 293 _cc3_pixbuf_skip_pixels (cc3_g_current_frame.x_step / 2); 294 x += cc3_g_current_frame.x_step; 295 } 307 296 } 308 297 } … … 310 299 // ... 311 300 } 312 } 313 return 1; 301 302 cc3_g_current_frame.y_loc++; 303 } 304 return rows; 314 305 } 315 306 … … 358 349 cc3_g_current_frame.x1 = x1; 359 350 cc3_g_current_frame.y1 = y1; 360 cc3_g_current_frame.width = x1 - x0;361 cc3_g_current_frame.height = y1 - y0;362 351 return 1; 363 352 } … … 381 370 cc3_g_current_frame.x_step = x_step; 382 371 cc3_g_current_frame.y_step = y_step; 383 cc3_g_current_frame.width = cc3_g_current_frame.raw_width / x_step;384 cc3_g_current_frame.height = cc3_g_current_frame.raw_height / y_step;385 372 cc3_g_current_frame.x0 = 0; 386 373 cc3_g_current_frame.y0 = 0; 387 cc3_g_current_frame.x1 = cc3_g_current_frame. width;388 cc3_g_current_frame.y1 = cc3_g_current_frame. height;374 cc3_g_current_frame.x1 = cc3_g_current_frame.raw_width; 375 cc3_g_current_frame.y1 = cc3_g_current_frame.raw_height; 389 376 cc3_g_current_frame.subsample_mode = mode; 390 377 return 1; … … 447 434 cc3_g_current_frame.x0 = 0; 448 435 cc3_g_current_frame.y0 = 0; 449 cc3_g_current_frame.width = cc3_g_current_frame.raw_width;450 cc3_g_current_frame.height = cc3_g_current_frame.raw_height;451 436 cc3_g_current_frame.x1 = cc3_g_current_frame.raw_width; 452 437 cc3_g_current_frame.y1 = cc3_g_current_frame.raw_height; 453 cc3_g_current_frame.x_loc = 0;454 438 cc3_g_current_frame.y_loc = 0; 455 439 cc3_g_current_frame.subsample_mode = CC3_NEAREST; trunk/include/cc3.h
r207 r209 78 78 typedef struct { 79 79 uint16_t raw_width, raw_height; // raw image width and height 80 uint16_t width, height; // subsampled and bound width and height81 80 uint16_t x0, y0, x1, y1; // bounding box in frame 82 uint16_t x_loc, y_loc;// current position in frame81 uint16_t y_loc; // current position in frame 83 82 uint8_t x_step, y_step; // subsampling step 84 83 cc3_channel_t coi; trunk/lib/cc3_ilp/cc3_color_track.c
r204 r209 21 21 { 22 22 uint16_t y, x; 23 int height, width; 23 24 24 25 uint8_t *row, *pixel; … … 42 43 pixel = row = cc3_malloc_rows(1); 43 44 44 for (y = 0; y < cc3_g_current_frame.height; y++) { 45 height = (cc3_g_current_frame.y1 - cc3_g_current_frame.y0) 46 / cc3_g_current_frame.y_step; 47 width = (cc3_g_current_frame.x1 - cc3_g_current_frame.x0) 48 / cc3_g_current_frame.x_step; 49 50 for (y = 0; y < height; y++) { 45 51 cc3_pixbuf_read_rows(row, 1); 46 52 47 for (x = 0; x < cc3_g_current_frame.width; x++) {53 for (x = 0; x < width; x++) { 48 54 bool pixel_good = 0; 49 55 trunk/lib/cc3_ilp/cc3_ilp.c
r205 r209 12 12 13 13 cc3_set_led (1); 14 size_x = cc3_g_current_frame.width; 15 size_y = cc3_g_current_frame.height; 14 size_x = (cc3_g_current_frame.x1 - cc3_g_current_frame.x0) 15 / cc3_g_current_frame.x_step; 16 size_y = (cc3_g_current_frame.y1 - cc3_g_current_frame.y0) 17 / cc3_g_current_frame.y_step; 16 18 17 19 putchar (1); trunk/projects/benchmark/bench.c
r208 r209 45 45 46 46 while(true) { 47 int y = 0;48 49 47 cc3_pixbuf_load(); 50 48 51 for (y = 0; y < cc3_g_current_frame.height; y++) { 52 cc3_pixbuf_read_rows(buf, 1); 53 } 49 while(cc3_pixbuf_read_rows(buf, 1)); 54 50 55 51 i++; trunk/projects/cmucam2/cmucam2.c
r206 r209 240 240 uint16_t i; 241 241 img.channels = 3; 242 img.width = cc3_g_current_frame.width; 242 img.width = (cc3_g_current_frame.x1 - cc3_g_current_frame.x0) 243 / cc3_g_current_frame.x_step; 243 244 img.height = 1; // image will hold just 1 row for scanline processing 244 245 img.pix = malloc (3 * img.width); … … 246 247 cc3_pixbuf_load (); 247 248 if (cc3_color_info_scanline_start (s_pkt) != 0) { 248 for (i = 0; i < cc3_g_current_frame.height; i++) { 249 cc3_pixbuf_read_rows (img.pix, 1); 249 while (cc3_pixbuf_read_rows (img.pix, 1)) { 250 250 cc3_color_info_scanline (&img, s_pkt); 251 251 } … … 265 265 cc3_image_t img; 266 266 uint16_t i; 267 int height = (cc3_g_current_frame.y1 - cc3_g_current_frame.y0) / cc3_g_current_frame.y_step; 268 267 269 img.channels = 3; 268 img.width = cc3_g_current_frame.width;270 img.width = (cc3_g_current_frame.x1 - cc3_g_current_frame.x0) / cc3_g_current_frame.x_step; 269 271 img.height = 1; // image will hold just 1 row for scanline processing 270 img.pix = malloc (3 * img.width);272 img.pix = cc3_malloc_rows(1); 271 273 do { 272 274 cc3_pixbuf_load (); … … 278 280 if (line_mode == 1) { 279 281 lm = &t_pkt->binary_scanline; 280 lm_width = cc3_g_current_frame.width / 8;281 if ( cc3_g_current_frame.width % 8 != 0)282 lm_width = img.width / 8; 283 if (img.width % 8 != 0) 282 284 lm_width++; 283 285 putchar (0xAA); 284 if ( cc3_g_current_frame.height > 255)286 if (height > 255) 285 287 lm_height = 255; 286 288 else 287 lm_height = cc3_g_current_frame.height;289 lm_height = height; 288 290 289 291 //putchar(lm_width); 290 putchar ( cc3_g_current_frame.width);292 putchar (img.width); 291 293 putchar (lm_height); 292 294 293 295 } 294 for (i = 0; i < cc3_g_current_frame.height; i++) { 295 cc3_pixbuf_read_rows (img.pix, 1); 296 while (cc3_pixbuf_read_rows (img.pix, 1)) { 296 297 cc3_track_color_scanline (&img, t_pkt); 297 298 if (line_mode == 1) { trunk/projects/hello_world/main.c
r200 r209 69 69 // setup an image structure 70 70 img.channels=3; 71 img.width= cc3_g_current_frame.width;71 img.width=(cc3_g_current_frame.x1 - cc3_g_current_frame.x0) / cc3_g_current_frame.x_step; 72 72 img.height=1; // image will hold just 1 row for scanline processing 73 img.pix = malloc(3 * img.width); // malloc!73 img.pix = cc3_malloc_rows(1); 74 74 75 75 printf( "Now we will use image data...\n" ); … … 80 80 while(1) 81 81 { 82 int y; 82 83 uint16_t my_x, my_y; 83 84 uint8_t max_red; … … 96 97 // any internal location information. 97 98 cc3_pixbuf_load(); 98 for(uint16_t y=0; y<cc3_g_current_frame.height; y++ ) 99 { 99 100 y = 0; 101 while(cc3_pixbuf_read_rows(img.pix, 1)) { 100 102 // FIXME: add cc3_pixbug img read rows 101 103 // read a row into the image picture memory from the camera 102 cc3_pixbuf_read_rows(img.pix, 1);103 104 for(uint16_t x=0; x<img.width; x++ ) 104 105 { … … 113 114 } 114 115 116 y++; 115 117 } 116 118 trunk/projects/jpeg-6b/main.c
r200 r209 81 81 82 82 // parameters for jpeg image 83 cinfo.image_width = cc3_g_current_frame.width;84 cinfo.image_height = cc3_g_current_frame.height;85 printf( "image width=%d image height=%d\n", cc3_g_current_frame.width, cc3_g_current_frame.height );83 cinfo.image_width = (cc3_g_current_frame.x1 - cc3_g_current_frame.x0) / cc3_g_current_frame.x_step; 84 cinfo.image_height = (cc3_g_current_frame.y1 - cc3_g_current_frame.y0) / cc3_g_current_frame.y_step; 85 printf( "image width=%d image height=%d\n", cinfo.image_width, cinfo.image_height ); 86 86 cinfo.input_components = 3; 87 87 // cinfo.in_color_space = JCS_YCbCr; … … 93 93 94 94 // allocate memory for 1 row 95 row = malloc(3 * cc3_g_current_frame.width);95 row = cc3_malloc_rows(1); 96 96 if(row==NULL) printf( "FUCK, out of memory!\n" ); 97 97 }
