Changeset 209

Show
Ignore:
Timestamp:
03/22/06 00:12:35 (3 years ago)
Author:
goodea
Message:

take away a bunch of junk

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/hal/lpc2106-cmucam3/cc3.c

    r205 r209  
    2121 
    2222static inline void _cc3_seek_left (void); 
    23 static inline void _cc3_seek_right_down (void); 
    2423static inline void _cc3_seek_top (void); 
    25 static inline void _cc3_advance_x_loc (void); 
    2624 
    2725static inline void _cc3_pixbuf_skip_pixels (uint32_t size); 
     
    4543void cc3_pixbuf_load () 
    4644{ 
     45  //  uint32_t start_time; 
     46 
    4747  unsigned int i; 
    4848  //REG(GPIO_IOCLR)=CAM_IE;   
     
    5050  cc3_pixbuf_rewind (); 
    5151  _cc3_pixbuf_write_rewind (); 
     52 
     53  //  start_time = cc3_timer(); 
    5254  while (!(REG (GPIO_IOPIN) & _CC3_CAM_VSYNC)); //while(CAM_VSYNC); 
    5355  while (REG (GPIO_IOPIN) & _CC3_CAM_VSYNC);    //while(!CAM_VSYNC); 
    5456 
     57 
    5558  REG (GPIO_IOSET) = _CC3_BUF_WEE; 
     59  //  printf("vsync wait: %3d ms\r", cc3_timer() - start_time); 
     60 
    5661 
    5762  // wait for vsync to finish 
     
    6368    while (REG (GPIO_IOPIN) & _CC3_CAM_HREF); 
    6469  } 
    65   cc3_g_current_frame.x_loc = 0; 
     70 
    6671  cc3_g_current_frame.y_loc = 0; 
     72 
    6773  //while (REG (GPIO_IOPIN) & _CC3_CAM_VSYNC); 
    6874  //REG (GPIO_IOCLR) = _CC3_BUF_WEE; 
     
    8086{ 
    8187  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 
    9397 
    9498void _cc3_seek_top () 
    9599{ 
    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  } 
    105106} 
    106107 
     
    108109void _cc3_seek_left () 
    109110{ 
    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); 
    150112} 
    151113 
     
    167129                             uint8_t off0, uint8_t off1, uint8_t off2) 
    168130{ 
    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  } 
    186155} 
    187156 
     
    202171 
    203172  _cc3_second_green_valid = false; 
     173  cc3_g_current_frame.y_loc = 0; 
    204174} 
    205175 
     
    242212{ 
    243213  int channels; 
     214  int width = (cc3_g_current_frame.x1 - cc3_g_current_frame.x0) 
     215    / cc3_g_current_frame.x_step; 
     216 
    244217  if (cc3_g_current_frame.coi == CC3_ALL) { 
    245218    channels = 3; 
     
    249222  } 
    250223 
    251   return (uint8_t *) malloc (cc3_g_current_frame.width * channels * rows); 
     224  return (uint8_t *) malloc (width * channels * rows); 
    252225} 
    253226 
     
    259232 * of cc3_pixel_t memory. 
    260233 * 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.) 
    263235 */ 
    264236int cc3_pixbuf_read_rows (void * mem, uint32_t rows) 
     
    270242  uint8_t off0, off1, off2; 
    271243 
    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  } 
    274253 
    275254  if (_cc3_g_current_camera_state.colorspace == CC3_RGB) { 
     
    293272 
    294273  for (r = 0; r < rows; r++) { 
    295     // First read after line 
    296     _cc3_seek_right_down (); 
     274    int x = cc3_g_current_frame.x0; 
    297275 
    298276    // First read into line 
     
    300278 
    301279    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++) { 
    303281        uint8_t *p = ((uint8_t *) mem) + 
    304           (r * cc3_g_current_frame.width + j * 3); 
     282          (r * width + j * 3); 
    305283        _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        } 
    307296      } 
    308297    } 
     
    310299      // ... 
    311300    } 
    312   } 
    313   return 1; 
     301 
     302    cc3_g_current_frame.y_loc++; 
     303  } 
     304  return rows; 
    314305} 
    315306 
     
    358349    cc3_g_current_frame.x1 = x1; 
    359350    cc3_g_current_frame.y1 = y1; 
    360     cc3_g_current_frame.width = x1 - x0; 
    361     cc3_g_current_frame.height = y1 - y0; 
    362351    return 1; 
    363352  } 
     
    381370  cc3_g_current_frame.x_step = x_step; 
    382371  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; 
    385372  cc3_g_current_frame.x0 = 0; 
    386373  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; 
    389376  cc3_g_current_frame.subsample_mode = mode; 
    390377  return 1; 
     
    447434  cc3_g_current_frame.x0 = 0; 
    448435  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; 
    451436  cc3_g_current_frame.x1 = cc3_g_current_frame.raw_width; 
    452437  cc3_g_current_frame.y1 = cc3_g_current_frame.raw_height; 
    453   cc3_g_current_frame.x_loc = 0; 
    454438  cc3_g_current_frame.y_loc = 0; 
    455439  cc3_g_current_frame.subsample_mode = CC3_NEAREST; 
  • trunk/include/cc3.h

    r207 r209  
    7878typedef struct { 
    7979  uint16_t raw_width, raw_height;       // raw image width and height 
    80   uint16_t width, height;       // subsampled and bound width and height 
    8180  uint16_t x0, y0, x1, y1;      // bounding box in frame 
    82   uint16_t x_loc, y_loc;        // current position in frame 
     81  uint16_t y_loc;               // current position in frame 
    8382  uint8_t x_step, y_step;       // subsampling step 
    8483  cc3_channel_t coi; 
  • trunk/lib/cc3_ilp/cc3_color_track.c

    r204 r209  
    2121{ 
    2222  uint16_t y, x; 
     23  int height, width; 
    2324 
    2425  uint8_t *row, *pixel; 
     
    4243  pixel = row = cc3_malloc_rows(1); 
    4344   
    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++) { 
    4551    cc3_pixbuf_read_rows(row, 1); 
    4652 
    47     for (x = 0; x < cc3_g_current_frame.width; x++) { 
     53    for (x = 0; x < width; x++) { 
    4854      bool pixel_good = 0; 
    4955 
  • trunk/lib/cc3_ilp/cc3_ilp.c

    r205 r209  
    1212 
    1313  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; 
    1618 
    1719  putchar (1); 
  • trunk/projects/benchmark/bench.c

    r208 r209  
    4545 
    4646  while(true) { 
    47     int y = 0; 
    48  
    4947    cc3_pixbuf_load(); 
    5048 
    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)); 
    5450     
    5551    i++; 
  • trunk/projects/cmucam2/cmucam2.c

    r206 r209  
    240240  uint16_t i; 
    241241  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; 
    243244  img.height = 1;               // image will hold just 1 row for scanline processing 
    244245  img.pix = malloc (3 * img.width); 
     
    246247    cc3_pixbuf_load (); 
    247248    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)) { 
    250250        cc3_color_info_scanline (&img, s_pkt); 
    251251      } 
     
    265265  cc3_image_t img; 
    266266  uint16_t i; 
     267  int height = (cc3_g_current_frame.y1 - cc3_g_current_frame.y0) / cc3_g_current_frame.y_step; 
     268 
    267269  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
    269271  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); 
    271273  do { 
    272274    cc3_pixbuf_load (); 
     
    278280      if (line_mode == 1) { 
    279281        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) 
    282284          lm_width++; 
    283285        putchar (0xAA); 
    284         if (cc3_g_current_frame.height > 255) 
     286        if (height > 255) 
    285287          lm_height = 255; 
    286288        else 
    287           lm_height = cc3_g_current_frame.height; 
     289          lm_height = height; 
    288290 
    289291        //putchar(lm_width); 
    290         putchar (cc3_g_current_frame.width); 
     292        putchar (img.width); 
    291293        putchar (lm_height); 
    292294 
    293295      } 
    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)) { 
    296297        cc3_track_color_scanline (&img, t_pkt); 
    297298        if (line_mode == 1) { 
  • trunk/projects/hello_world/main.c

    r200 r209  
    6969    // setup an image structure 
    7070    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
    7272    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); 
    7474   
    7575    printf( "Now we will use image data...\n" );  
     
    8080    while(1) 
    8181    { 
     82    int y; 
    8283    uint16_t my_x, my_y; 
    8384    uint8_t max_red; 
     
    9697    // any internal location information. 
    9798    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)) { 
    100102                // FIXME: add cc3_pixbug img read rows 
    101103                // read a row into the image picture memory from the camera  
    102                 cc3_pixbuf_read_rows(img.pix, 1);        
    103104                for(uint16_t x=0; x<img.width; x++ ) 
    104105                { 
     
    113114                }        
    114115         
     116                y++; 
    115117        } 
    116118 
  • trunk/projects/jpeg-6b/main.c

    r200 r209  
    8181 
    8282  // 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 ); 
    8686  cinfo.input_components = 3; 
    8787 // cinfo.in_color_space = JCS_YCbCr; 
     
    9393 
    9494  // allocate memory for 1 row 
    95   row = malloc(3 * cc3_g_current_frame.width); 
     95  row = cc3_malloc_rows(1); 
    9696  if(row==NULL) printf( "FUCK, out of memory!\n" ); 
    9797}