Changeset 392

Show
Ignore:
Timestamp:
02/11/07 17:45:48 (2 years ago)
Author:
goodea
Message:

pixbuf

Files:

Legend:

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

    r387 r392  
    3535// Globals used by CMUCam functions 
    3636cc3_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, stride 
     37cc3_frame_t cc3_g_pixbuf_frame;        // global that keeps clip, stride 
    3838 
    3939 
     
    6161static void _cc3_update_frame_bounds (cc3_frame_t *); 
    6262 
    63 static void _cc3_resize_pixbuf (void); 
     63static void _cc3_pixbuf_resize (void); 
    6464 
    6565void cc3_pixbuf_load () 
     
    6969  unsigned int i; 
    7070 
    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(); 
    7473  } 
    7574 
     
    10099 
    101100  cc3_pixbuf_rewind(); 
    102   cc3_g_current_frame.y_loc = 0; 
     101  cc3_g_pixbuf_frame.y_loc = 0; 
    103102 
    104103  //while (REG (GPIO_IOPIN) & _CC3_CAM_VSYNC); 
     
    129128void _cc3_seek_top () 
    130129{ 
    131   if (cc3_g_current_frame.y_loc < cc3_g_current_frame.y0) { 
    132     _cc3_pixbuf_skip_pixels (cc3_g_current_frame.raw_width / 2 
    133                              * 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; 
    136135  } 
    137136} 
     
    140139void _cc3_seek_left () 
    141140{ 
    142   _cc3_pixbuf_skip_pixels (cc3_g_current_frame.x0 / 2); 
     141  _cc3_pixbuf_skip_pixels (cc3_g_pixbuf_frame.x0 / 2); 
    143142} 
    144143 
     
    160159                             uint8_t off0, uint8_t off1, uint8_t off2) 
    161160{ 
    162   if (cc3_g_current_frame.x_step == 1) { 
     161  if (cc3_g_pixbuf_frame.x_step == 1) { 
    163162    if (_cc3_second_green_valid) { 
    164163      // use the second green 
     
    186185} 
    187186 
    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; 
     187void _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(); 
    192192} 
    193193 
     
    207207  REG (GPIO_IOSET) = _CC3_BUF_RRST; 
    208208  // 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); 
    211211  _cc3_second_green_valid = false; 
    212   cc3_g_current_frame.y_loc = 0; 
     212  cc3_g_pixbuf_frame.y_loc = 0; 
    213213} 
    214214 
     
    250250uint8_t *cc3_malloc_rows (uint32_t rows) 
    251251{ 
    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; 
    254254 
    255255  return (uint8_t *) malloc (width * channels * rows); 
     
    273273  uint8_t off0, off1, off2; 
    274274 
    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; 
    279279 
    280280  if (row_limit < rows) { 
     
    302302 
    303303  for (r = 0; r < rows; r++) { 
    304     int x = cc3_g_current_frame.x0; 
     304    int x = cc3_g_pixbuf_frame.x0; 
    305305 
    306306    // First read into line 
    307307    _cc3_seek_left (); 
    308308 
    309     switch (cc3_g_current_frame.coi) { 
     309    switch (cc3_g_pixbuf_frame.coi) { 
    310310    case CC3_ALL: 
    311311      _cc3_second_green_valid = false; 
     
    316316 
    317317        // 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); 
    320320      } 
    321321 
     
    326326        uint8_t *p = ((uint8_t *) mem) + (r * width + j); 
    327327 
    328         if ((j & 0x1) == 0 || cc3_g_current_frame.x_step > 1) { 
     328        if ((j & 0x1) == 0 || cc3_g_pixbuf_frame.x_step > 1) { 
    329329          // read 
    330330          _cc3_pixbuf_skip_subpixel (); 
     
    336336        } 
    337337 
    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); 
    340340      } 
    341341      break; 
     
    345345        uint8_t *p = ((uint8_t *) mem) + (r * width + j); 
    346346 
    347         if ((j & 0x1) == 0 || cc3_g_current_frame.x_step > 1) { 
     347        if ((j & 0x1) == 0 || cc3_g_pixbuf_frame.x_step > 1) { 
    348348          // read 
    349349          *p = _cc3_pixbuf_read_subpixel (); 
     
    355355        } 
    356356 
    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); 
    359359      } 
    360360      break; 
     
    364364        uint8_t *p = ((uint8_t *) mem) + (r * width + j); 
    365365 
    366         if ((j & 0x1) == 0 || cc3_g_current_frame.x_step > 1) { 
     366        if ((j & 0x1) == 0 || cc3_g_pixbuf_frame.x_step > 1) { 
    367367          // read 
    368368          _cc3_pixbuf_skip_subpixel (); 
     
    374374        } 
    375375 
    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); 
    378378      } 
    379379      break; 
    380380    } 
    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); 
    382382 
    383383 
    384384    // 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; 
    387387  } 
    388388  return rows; 
     
    419419int cc3_pixbuf_set_roi (int16_t x0, int16_t y0, int16_t x1, int16_t y1) 
    420420{ 
    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; 
    423423 
    424424  // constrain 
     
    458458 
    459459  // 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); 
    466466 
    467467  return 1; 
     
    493493  } 
    494494 
    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); 
    504504 
    505505  return result; 
     
    516516  if (chan > 4) 
    517517    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); 
    521521 
    522522  return 1; 
     
    553553  _cc3_set_register_state (); 
    554554 
    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 
     560void 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; 
    572571 
    573572  cc3_pixbuf_set_coi(CC3_ALL); 
    574573 
    575   _cc3_update_frame_bounds (&cc3_g_current_frame); 
     574  _cc3_update_frame_bounds (&cc3_g_pixbuf_frame); 
    576575} 
    577576 
     
    751750 
    752751/** 
    753  * Sets the resolution, cc3_g_current_frame width and height not updated 
     752 * Sets the resolution, cc3_g_pixbuf_frame width and height not updated 
    754753 * until next pixbuf load. 
    755754 * Takes enum CC3_LOW_RES and CC3_HIGH_RES. 
     
    759758  _cc3_g_current_camera_state.resolution = cam_res; 
    760759  _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; 
    762761 
    763762  return 1; 
  • trunk/hal/lpc2106-cmucam3/cc3_hal.c

    r387 r392  
    109109        // Set the right data bus mode 
    110110        cc3_set_raw_register (0x14, 0x20); 
    111         // Set the resolution and update the cc3_g_current_frame size flags 
     111        // Set the resolution and update the size flags 
    112112        if (_cc3_g_current_camera_state.resolution == CC3_LOW_RES) { 
    113113            _cc3_g_current_camera_state.raw_width = CC3_LO_RES_WIDTH; // 88 * 2; 
  • trunk/hal/virtual-cam/cc3.c

    r387 r392  
    3535// Globals used by CMUCam functions 
    3636cc3_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, stride 
     37cc3_frame_t cc3_g_pixbuf_frame;        // global that keeps clip, stride 
    3838 
    3939 
     
    7171  static int img_cnt=0; 
    7272 
    73   if (cc3_g_current_frame.reset_on_next_load) { 
     73  if (cc3_g_pixbuf_frame.reset_on_next_load) { 
    7474    _cc3_resize_pixbuf(); 
    75     cc3_frame_default(); 
    7675  } 
    7776   
     
    170169   printf( "Virtual FIFO Loaded %d bytes.\n", i); 
    171170   virtual_fifo_index=0; 
    172    cc3_g_current_frame.y_loc = 0; 
     171   cc3_g_pixbuf_frame.y_loc = 0; 
    173172 
    174173} 
     
    200199void _cc3_seek_top () 
    201200{ 
    202   if (cc3_g_current_frame.y_loc < cc3_g_current_frame.y0) { 
    203     _cc3_pixbuf_skip_pixels (cc3_g_current_frame.raw_width / 2 
    204                              * 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; 
    207206  } 
    208207} 
     
    211210void _cc3_seek_left () 
    212211{ 
    213   _cc3_pixbuf_skip_pixels (cc3_g_current_frame.x0 / 2); 
     212  _cc3_pixbuf_skip_pixels (cc3_g_pixbuf_frame.x0 / 2); 
    214213} 
    215214 
     
    232231                             uint8_t off0, uint8_t off1, uint8_t off2) 
    233232{ 
    234   if (cc3_g_current_frame.x_step == 1) { 
     233  if (cc3_g_pixbuf_frame.x_step == 1) { 
    235234    if (_cc3_second_green_valid) { 
    236235      // use the second green 
     
    270269  virtual_fifo_index=0; 
    271270  _cc3_second_green_valid = false; 
    272   cc3_g_current_frame.y_loc = 0; 
     271  cc3_g_pixbuf_frame.y_loc = 0; 
    273272} 
    274273 
     
    309308void _cc3_resize_pixbuf () 
    310309{ 
    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; 
    313312 
    314313} 
     
    316315uint8_t *cc3_malloc_rows (uint32_t rows) 
    317316{ 
    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; 
    320319 
    321320  return (uint8_t *) malloc (width * channels * rows); 
     
    339338  uint8_t off0, off1, off2; 
    340339 
    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; 
    345344 
    346345  if (row_limit < rows) { 
     
    368367 
    369368  for (r = 0; r < rows; r++) { 
    370     int x = cc3_g_current_frame.x0; 
     369    int x = cc3_g_pixbuf_frame.x0; 
    371370 
    372371    // First read into line 
    373372    _cc3_seek_left (); 
    374373 
    375     switch (cc3_g_current_frame.coi) { 
     374    switch (cc3_g_pixbuf_frame.coi) { 
    376375    case CC3_ALL: 
    377376      _cc3_second_green_valid = false; 
     
    382381 
    383382        // 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); 
    386385      } 
    387386 
     
    392391        uint8_t *p = ((uint8_t *) mem) + (r * width + j); 
    393392 
    394         if ((j & 0x1) == 0 || cc3_g_current_frame.x_step > 1) { 
     393        if ((j & 0x1) == 0 || cc3_g_pixbuf_frame.x_step > 1) { 
    395394          // read 
    396395          _cc3_pixbuf_skip_subpixel (); 
     
    402401        } 
    403402 
    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); 
    406405      } 
    407406      break; 
     
    411410        uint8_t *p = ((uint8_t *) mem) + (r * width + j); 
    412411 
    413         if ((j & 0x1) == 0 || cc3_g_current_frame.x_step > 1) { 
     412        if ((j & 0x1) == 0 || cc3_g_pixbuf_frame.x_step > 1) { 
    414413          // read 
    415414          *p = _cc3_pixbuf_read_subpixel (); 
     
    421420        } 
    422421 
    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); 
    425424      } 
    426425      break; 
     
    430429        uint8_t *p = ((uint8_t *) mem) + (r * width + j); 
    431430 
    432         if ((j & 0x1) == 0 || cc3_g_current_frame.x_step > 1) { 
     431        if ((j & 0x1) == 0 || cc3_g_pixbuf_frame.x_step > 1) { 
    433432          // read 
    434433          _cc3_pixbuf_skip_subpixel (); 
     
    440439        } 
    441440 
    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); 
    444443      } 
    445444      break; 
    446445    } 
    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); 
    448447 
    449448 
    450449    // 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; 
    453452  } 
    454453  return rows; 
     
    488487int cc3_pixbuf_set_roi (int16_t x0, int16_t y0, int16_t x1, int16_t y1) 
    489488{ 
    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; 
    492491 
    493492  // constrain 
     
    527526 
    528527  // 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); 
    535534 
    536535  return 1; 
     
    562561  } 
    563562 
    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); 
    573572 
    574573  return result; 
     
    585584  if (chan > 4) 
    586585    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); 
    590589 
    591590  return 1; 
     
    618617 
    619618  _cc3_resize_pixbuf (); 
    620   cc3_frame_default (); 
    621619  printf( "cc3_camera_init()\n" ); 
    622620  _cc3_virtual_cam_path_prefix = getenv("CC3_VCAM_PATH");  
     
    630628} 
    631629 
    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; 
     630void 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; 
    643641 
    644642  cc3_pixbuf_set_coi(CC3_ALL); 
    645643 
    646   _cc3_update_frame_bounds (&cc3_g_current_frame); 
     644  _cc3_update_frame_bounds (&cc3_g_pixbuf_frame); 
    647645} 
    648646 
     
    723721 
    724722/** 
    725  * Sets the resolution, also updates cc3_g_current_frame width and height 
     723 * Sets the resolution, also updates cc3_g_pixbuf_frame width and height 
    726724 * Takes enum CC3_LOW_RES and CC3_HIGH_RES. 
    727725 */ 
     
    730728  _cc3_g_current_camera_state.resolution = cam_res; 
    731729  _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; 
    733731 
    734732  return 1; 
  • trunk/include/cc3.h

    r388 r392  
    131131/** 
    132132 * 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. 
    134134 */ 
    135135typedef struct { 
     
    162162 * Current parameters for the internal pixbuf, should be 
    163163 * 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 */ 
     166extern cc3_frame_t cc3_g_pixbuf_frame; 
    167167 
    168168/** 
    169169 * Allocate a number of rows of the correct size based on the values in 
    170  * #cc3_g_current_frame. 
     170 * #cc3_g_pixbuf_frame. 
    171171 * 
    172172 * @param[in] rows The number of rows to allocate space for. 
     
    177177/** 
    178178 * 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. 
    181181 */ 
    182182void cc3_pixbuf_load (void); 
    183183 
    184184/** 
    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 */ 
     187void cc3_pixbuf_frame_reset (void); 
    188188 
    189189/** 
     
    230230void cc3_camera_kill (void); 
    231231/** 
    232  * Sets the resolution, also updates cc3_g_current_frame width and height 
     232 * Sets the resolution, also updates cc3_g_pixbuf_frame width and height 
    233233 */ 
    234234int cc3_set_resolution (cc3_camera_resolution_t); 
  • trunk/lib/cc3-ilp/cc3_color_info.c

    r302 r392  
    5555        cc3_get_pixel( img, x, 0, &cp );         
    5656        pkt->scratch_pix++; 
    57         if(cc3_g_current_frame.coi==CC3_ALL ) {        
     57        if(cc3_g_pixbuf_frame.coi==CC3_ALL ) {         
    5858                uint8_t i; 
    5959                for(i=0; i<3; i++ ) 
     
    6767        { 
    6868            uint8_t i; 
    69                 i=cc3_g_current_frame.coi; 
     69                i=cc3_g_pixbuf_frame.coi; 
    7070                pkt->scratch_mean[i]+=cp.channel[i]; 
    7171                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  
    6060  pixel = row = cc3_malloc_rows(1); 
    6161   
    62   for (y = 0; y < cc3_g_current_frame.height; y++) { 
     62  for (y = 0; y < cc3_g_pixbuf_frame.height; y++) { 
    6363    cc3_pixbuf_read_rows(row, 1); 
    6464 
    65     for (x = 0; x < cc3_g_current_frame.width; x++) { 
     65    for (x = 0; x < cc3_g_pixbuf_frame.width; x++) { 
    6666      bool pixel_good = 0; 
    6767 
    68       if (cc3_g_current_frame.coi == CC3_ALL) { 
     68      if (cc3_g_pixbuf_frame.coi == CC3_ALL) { 
    6969        if (pixel[0] >= pkt->lower_bound.channel[0] 
    7070            && pixel[0] <= pkt->upper_bound.channel[0] 
     
    7979      else { 
    8080        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]) 
    8484          pixel_good = 1; 
    8585           
     
    166166      //cc3_pixbuf_read(); 
    167167      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) { 
    169169        if (cp.channel[0] >= pkt->lower_bound.channel[0] && 
    170170            cp.channel[0] <= pkt->upper_bound.channel[0] && 
     
    176176      } 
    177177      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]) 
    182182          pixel_good = 1; 
    183183      } 
  • trunk/lib/cc3-ilp/cc3_ilp.c

    r331 r392  
    2525void cc3_send_image_direct (void) 
    2626{ 
     27  cc3_pixbuf_load (); 
     28 
    2729  uint32_t x, y; 
    2830  uint32_t size_x, size_y; 
    2931  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; 
    3133 
    3234 
    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; 
    3737 
    3838  putchar (1); 
  • trunk/lib/cc3-ilp/cc3_jpg.c

    r330 r392  
    3535 
    3636void 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) 
    3841  cc3_jpeg_t *cj = init_jpeg(); 
    3942 
     
    5861 
    5962  // 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; 
    6265 
    6366  //printf( "image width=%d image height=%d\n", cinfo.image_width, cinfo.image_height ); 
     
    8689  jpeg_stdio_dest(&cj->cinfo, f); 
    8790 
    88   // capture a frame to the FIFO 
    89   cc3_pixbuf_load(); 
    90  
    9191  // read and compress 
    9292  jpeg_start_compress(&cj->cinfo, TRUE); 
  • trunk/projects/cmucam2/cmucam2.c

    r352 r392  
    9191  cc3_set_resolution(CC3_LOW_RES); 
    9292 
     93  cc3_pixbuf_load(); 
     94 
    9395  printf ("%s\r", VERSION_BANNER); 
    9496 
     
    150152          print_ACK (); 
    151153        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(); 
    155160        break; 
    156161 
     
    190195 
    191196      case SEND_FRAME: 
    192         old_coi = cc3_g_current_frame.coi; 
     197        old_coi = cc3_g_pixbuf_frame.coi; 
    193198        if (n == 1) { 
    194199          if (arg_list[0] > 4) { 
     
    275280                polly_config_t p_config; 
    276281                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); 
    278283          
    279284                p_config.color_thresh=arg_list[0]; //20; 
     
    283288                p_config.vertical_edges=arg_list[4]; //1; 
    284289                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; 
    287292                do { 
    288293                        polly(p_config); 
    289                         cc3_linear_reg(x_axis, p_config.histogram, cc3_g_current_frame.width,&reg_line); 
     294                        cc3_linear_reg(x_axis, p_config.histogram, cc3_g_pixbuf_frame.width,&reg_line); 
    290295 
    291296                        // return linear regression offset value    
     
    296301                        printf( "%f ",reg_line.r_sqr );      
    297302                        // 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; 
    299304                        printf( " %f\r",distance );  
    300305     
     
    352357  cc3_image_t img; 
    353358  img.channels = 3; 
    354   img.width = cc3_g_current_frame.width; 
     359  img.width = cc3_g_pixbuf_frame.width; 
    355360  img.height = 1;               // image will hold just 1 row for scanline processing 
    356361  img.pix = malloc (3 * img.width); 
     
    379384 
    380385  img.channels = 3; 
    381   img.width = cc3_g_current_frame.width; 
     386  img.width = cc3_g_pixbuf_frame.width; 
    382387  img.height = 1;               // image will hold just 1 row for scanline processing 
    383388  img.pix = cc3_malloc_rows(1); 
     
    395400          lm_width++; 
    396401        putchar (0xAA); 
    397         if (cc3_g_current_frame.height > 255) 
     402        if (cc3_g_pixbuf_frame.height > 255) 
    398403          lm_height = 255; 
    399404        else 
    400           lm_height = cc3_g_current_frame.height; 
     405          lm_height = cc3_g_pixbuf_frame.height; 
    401406 
    402407        //putchar(lm_width); 
  • trunk/projects/cmucam2/polly.c

    r391 r392  
    4949  cc3_set_auto_exposure (true); 
    5050 
     51  cc3_pixbuf_load (); 
    5152 
    5253  cc3_pixbuf_set_subsample (CC3_NEAREST, 2, 2); 
     
    5758  //img.channels=CC3_GREEN; 
    5859  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 processing 
     60  img.width = cc3_g_pixbuf_frame.width; 
     61  img.height = cc3_g_pixbuf_frame.height;      // image will hold just 1 row for scanline processing 
    6162  //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); 
    6364  if (img.pix == NULL) { 
    6465    printf ("Not enough memory...\n"); 
     
    9192 
    9293 
    93   cc3_pixbuf_load (); 
    94  
    9594#ifdef MMC_DEBUG 
    9695  cc3_pixbuf_set_coi (CC3_ALL); 
     
    10099#endif 
    101100 
    102   cc3_pixbuf_read_rows (img.pix, cc3_g_current_frame.height); 
     101  cc3_pixbuf_read_rows (img.pix, cc3_g_pixbuf_frame.height); 
    103102  if (config.blur == 1) { 
    104103    blur.size = 3; 
     
    527526  } 
    528527 
    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; 
    531530 
    532531  fprintf (f, "P3\n%d %d\n255\n", size_x, size_y); 
  • trunk/projects/edge-follow/main.c

    r389 r392  
    5454  cc3_clr_led (2); 
    5555 
     56  // load into pixbuf to initialize cc3_g_pixbuf_frame 
     57  cc3_pixbuf_load(); 
     58 
    5659  // sample wait command in ms  
    5760  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); 
    6063 
    6164  p_config.color_thresh = 10; 
     
    6568  p_config.vertical_edges = 1; 
    6669  p_config.blur = 1; 
    67   p_config.histogram = malloc (cc3_g_current_frame.width); 
     70  p_config.histogram = malloc (cc3_g_pixbuf_frame.width); 
    6871 
    6972  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 processing 
     73  img.width = cc3_g_pixbuf_frame.width; 
     74  img.height = cc3_g_pixbuf_frame.height;      // image will hold just 1 row for scanline processing 
    7275  //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); 
    7477  if (img.pix == NULL) { 
    7578    printf ("Not enough memory...\n"); 
     
    7881 
    7982  tmp_img.channels = 3; 
    80   tmp_img.width = cc3_g_current_frame.width; 
     83  tmp_img.width = cc3_g_pixbuf_frame.width; 
    8184  tmp_img.height = 1; 
    8285  tmp_img.pix = cc3_malloc_rows (1); 
    8386 
    8487  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; 
    8790  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); 
    8992 
    9093  p_black.channel[0] = 0; 
     
    101104#endif 
    102105 
    103     for (i = 0; i < cc3_g_current_frame.height; i++) { 
     106    for (i = 0; i < cc3_g_pixbuf_frame.height; i++) { 
    104107      cc3_pixbuf_read_rows (tmp_img.pix, tmp_img.height); 
    105108      for (x = 0; x < tmp_img.width; x++) { 
     
    123126    // get added into the regression line. 
    124127    cnt = 0; 
    125     for (i = 0; i < cc3_g_current_frame.width; i++) { 
     128    for (i = 0; i < cc3_g_pixbuf_frame.width; i++) { 
    126129      if (p_config.histogram[i] > 0 && p_config.histogram[i] < 71) { 
    127130        h[cnt] = p_config.histogram[i]; 
     
    148151      total_error += error; 
    149152