Update of /cvsroot/playerstage/code/player/server/drivers/camera/1394
In directory 
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5752/server/drivers/camera/1394

Modified Files:
        camera1394.cc 
Log Message:
applied
[ 1894981 ] CVS: Big camera1394 patch



Index: camera1394.cc
===================================================================
RCS file: 
/cvsroot/playerstage/code/player/server/drivers/camera/1394/camera1394.cc,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** camera1394.cc       15 Feb 2008 08:16:48 -0000      1.40
--- camera1394.cc       18 Feb 2008 03:34:43 -0000      1.41
***************
*** 169,172 ****
--- 169,173 ----
  #include <stddef.h>       // for NULL
  #include <unistd.h>
+ #include <assert.h>
  
  #ifdef HAVE_LIBRAW1394
***************
*** 301,306 ****
    private: int GrabFrame();
  
-   private: uint8_t * resized;//[1280 * 960 * 3];
- 
    // Save a frame to disk
    private: int SaveFrame( const char *filename );
--- 302,305 ----
***************
*** 352,367 ****
    private: int save;
  
-   // Frame capture size
-   private: size_t frameSize;
- 
    // Capture timestamp
    private: double frameTime;
    
    // Data to send to server
!   private: player_camera_data_t *data;
  
    // Bayer Colour Conversion
    private: bool DoBayerConversion;
!   private: int BayerPattern;
    private: int BayerMethod;
  
--- 351,363 ----
    private: int save;
  
    // Capture timestamp
    private: double frameTime;
    
    // Data to send to server
!   private: player_camera_data_t * data;
  
    // Bayer Colour Conversion
    private: bool DoBayerConversion;
!   private: bayer_pattern_t BayerPattern;
    private: int BayerMethod;
  
***************
*** 399,403 ****
    float fps;
  
!   resized=NULL;
  
  #ifdef HAVE_LIBRAW1394
--- 395,399 ----
    float fps;
  
!   this->data = NULL;
  
  #ifdef HAVE_LIBRAW1394
***************
*** 439,443 ****
    {
      this->mode = MODE_160x120_YUV444;
-     this->frameSize = 160 * 120 * 2; // Is this correct?
    }
    */
--- 435,438 ----
***************
*** 445,449 ****
    {
      this->mode = MODE_320x240_YUV422;
-     this->frameSize = 320 * 240 * 3;
    }
    /*
--- 440,443 ----
***************
*** 461,475 ****
    {
      this->mode = MODE_640x480_MONO;
-     this->frameSize = 640 * 480 * 1;
    }
    else if (0==strcmp(str,"640x480_yuv422"))
    {
      this->mode = MODE_640x480_YUV422;
-     this->frameSize = 640 * 480 * 3;
    }
    else if (0==strcmp(str,"640x480_rgb"))
    {
      this->mode = MODE_640x480_RGB;
-     this->frameSize = 640 * 480 * 3;
    }
    else if (0==strcmp(str,"800x600_mono"))
--- 455,466 ----
***************
*** 477,481 ****
      this->mode = MODE_800x600_MONO;
      this->format = FORMAT_SVGA_NONCOMPRESSED_1;
-     this->frameSize = 800 * 600 * 1;
    }
    else if (0==strcmp(str,"800x600_yuv422"))
--- 468,471 ----
***************
*** 483,487 ****
      this->mode = MODE_800x600_YUV422;
      this->format = FORMAT_SVGA_NONCOMPRESSED_1;
-     this->frameSize = 600 * 450 * 3;
    }
    else if (0==strcmp(str,"1024x768_mono"))
--- 473,476 ----
***************
*** 489,493 ****
      this->mode = MODE_1024x768_MONO;
      this->format = FORMAT_SVGA_NONCOMPRESSED_1;
-     this->frameSize = 1024 * 768 * 1;
    }
    else if (0==strcmp(str,"1024x768_yuv422"))
--- 478,481 ----
***************
*** 495,499 ****
      this->mode = MODE_1024x768_YUV422;
      this->format = FORMAT_SVGA_NONCOMPRESSED_1;
-     this->frameSize = 512 * 384 * 3;
    }
    else if (0==strcmp(str,"1280x960_mono"))
--- 483,486 ----
***************
*** 501,505 ****
      this->mode = MODE_1280x960_MONO;
      this->format = FORMAT_SVGA_NONCOMPRESSED_2;
-     this->frameSize = 1280 * 960 * 1;
    }
    else if (0==strcmp(str,"1280x960_yuv422"))
--- 488,491 ----
***************
*** 507,511 ****
      this->mode = MODE_1280x960_YUV422;
      this->format = FORMAT_SVGA_NONCOMPRESSED_2;
-     this->frameSize = 640 * 480 * 3;
    }
  #if LIBDC1394_VERSION == 0200
--- 493,496 ----
***************
*** 514,518 ****
      this->mode = MODE_FORMAT7_0;
      this->format = FORMAT_7;
-     this->frameSize = 0;
    }
  #endif
--- 499,502 ----
***************
*** 687,691 ****
        break;
    }
!   
    return;
  }
--- 671,675 ----
        break;
    }
! 
    return;
  }
***************
*** 695,700 ****
  void Camera1394::SafeCleanup()
  {
-   delete resized;
-   resized = NULL;
  
  #if LIBDC1394_VERSION == 0200
--- 679,682 ----
***************
*** 736,739 ****
--- 718,728 ----
    this->handle = NULL;
  #endif
+   if (this->data)
+   {
+     if (this->data->image) delete[](this->data->image);
+     this->data->image = NULL;
+     delete (this->data);
+   }
+   this->data = NULL;
  }
  
***************
*** 742,746 ****
  int Camera1394::Setup()
  {
!   this->data = 0;
  
  #if LIBDC1394_VERSION == 0200
--- 731,735 ----
  int Camera1394::Setup()
  {
!   
  
  #if LIBDC1394_VERSION == 0200
***************
*** 1161,1167 ****
  int Camera1394::GrabFrame()
  {
-   uint32_t f, c;
-   int  i, j;
-   unsigned char * ptr1, * ptr2, * dst;
  #if LIBDC1394_VERSION == 0200
    dc1394video_frame_t * frame = NULL;
--- 1150,1153 ----
***************
*** 1197,1201 ****
    }
  
-   this->data = (player_camera_data_t *)malloc(sizeof(*this->data));
    unsigned int frame_width;
    unsigned int frame_height;
--- 1183,1186 ----
***************
*** 1205,1291 ****
    frame_width = frame->size[0];
    frame_height = frame->size[1];
!   capture_buffer = (uint8_t *) frame->image;
  #else
    frame_width = this->camera.frame_width;
    frame_height = this->camera.frame_height;
!   capture_buffer = (uint8_t *) this->camera.capture_buffer;
  #endif
! 
!   if (frameSize == 0)
!     frameSize = frame_width * frame_height;
!   
    switch (this->mode)
    {
    case MODE_320x240_YUV422:
    case MODE_640x480_YUV422:
!     this->data->bpp = 24;
!     this->data->format = PLAYER_CAMERA_FORMAT_RGB888;
!     this->data->image_count = this->frameSize;
!     this->data->image = (uint8_t*) malloc(this->data->image_count);
!     this->data->width = frame_width;
!     this->data->height = frame_height;
!     uyvy2rgb(capture_buffer, this->data->image, (frame_width) * 
(frame_height));
!     break;
    case MODE_1024x768_YUV422:
    case MODE_1280x960_YUV422:
-     if (resized == NULL)
-       resized = new uint8_t [1280 * 960 * 3];
      this->data->bpp = 24;
      this->data->format = PLAYER_CAMERA_FORMAT_RGB888;
!     this->data->image_count = this->frameSize;
!     this->data->image = (uint8_t *) malloc(this->data->image_count);
!     this->data->width = frame_width / 2;
!     this->data->height = frame_height / 2;
!     assert(this->data->image_count <= sizeof(this->data->image));
!     uyvy2rgb(capture_buffer, this->resized, (frame_width) * (frame_height));
!     ptr1 = this->resized;
!     ptr2 = this->data->image;
!     for (f = 0; f < (this->data->height); f++)
!     {
!       for (c = 0; c < (this->data->width); c++)
!       {
!       ptr2[0] = ptr1[0];
!       ptr2[1] = ptr1[1];
!       ptr2[2] = ptr1[2];
!       ptr1 += (3 * 2);
!       ptr2 += 3;
!       }
!       ptr1 += ((frame_width) * 3);
!     }
      break;
-   case MODE_800x600_YUV422:
-     if (resized == NULL)
-       resized = new uint8_t [1280 * 960 * 3];
-     this->data->bpp = 24;
-     this->data->format = PLAYER_CAMERA_FORMAT_RGB888;
-     this->data->image_count = this->frameSize;
-     this->data->image = (uint8_t *) malloc(this->data->image_count);
-     this->data->width = 600;
-     this->data->height = 450;
-     uyvy2rgb(capture_buffer, this->resized, (frame_width) * (frame_height));
-     ptr1 = this->resized;
-     ptr2 = this->data->image;
-     i = 3; j = 3;
-     for (f = 0; f < (this->data->height); f++)
-     {
-       for (c = 0; c < (this->data->width); c++)
-       {
-       ptr2[0] = ptr1[0];
-       ptr2[1] = ptr1[1];
-       ptr2[2] = ptr1[2];
-       j--;
-       if (!j) ptr1 += (3 * 2), j = 3;
-       else ptr1 += 3;
-       ptr2 += 3;
-       }
-       i--;
-       if (!i) ptr1 += ((frame_width) * 3), i = 3;
-     }
-     break;  
    case MODE_640x480_RGB:
      this->data->bpp = 24;
      this->data->format = PLAYER_CAMERA_FORMAT_RGB888;
!     this->data->image_count = this->frameSize;
!     this->data->image = (uint8_t *)malloc(this->data->image_count);
      this->data->width = frame_width;
      this->data->height = frame_height;
--- 1190,1226 ----
    frame_width = frame->size[0];
    frame_height = frame->size[1];
!   capture_buffer = reinterpret_cast<uint8_t *>(frame->image);
  #else
    frame_width = this->camera.frame_width;
    frame_height = this->camera.frame_height;
!   capture_buffer = reinterpret_cast<uint8_t *>(this->camera.capture_buffer);
  #endif
!   assert(capture_buffer);
!   assert(!(this->data));
!   this->data = reinterpret_cast<player_camera_data_t 
*>(malloc(sizeof(player_camera_data_t)));
!   assert(this->data);
!   // memset(this->data, 0, sizeof(player_camera_data_t)); I assume everything 
is set properly later!
    switch (this->mode)
    {
    case MODE_320x240_YUV422:
    case MODE_640x480_YUV422:
!   case MODE_800x600_YUV422:
    case MODE_1024x768_YUV422:
    case MODE_1280x960_YUV422:
      this->data->bpp = 24;
      this->data->format = PLAYER_CAMERA_FORMAT_RGB888;
!     this->data->image_count = frame_width * frame_height * 3;
!     this->data->image = reinterpret_cast<uint8_t 
*>(malloc(this->data->image_count));
!     assert(this->data->image);
!     this->data->width = frame_width;
!     this->data->height = frame_height;
!     uyvy2rgb(reinterpret_cast<unsigned char *>(capture_buffer), 
reinterpret_cast<unsigned char *>(this->data->image), frame_width * 
frame_height);
      break;
    case MODE_640x480_RGB:
      this->data->bpp = 24;
      this->data->format = PLAYER_CAMERA_FORMAT_RGB888;
!     this->data->image_count = frame_width * frame_height * 3;
!     this->data->image = reinterpret_cast<uint8_t 
*>(malloc(this->data->image_count));
!     assert(this->data->image);
      this->data->width = frame_width;
      this->data->height = frame_height;
***************
*** 1301,1306 ****
        this->data->bpp = 8;
        this->data->format = PLAYER_CAMERA_FORMAT_MONO8;
!       this->data->image_count = this->frameSize;
!       this->data->image = (uint8_t*) malloc(this->data->image_count);
        this->data->width = frame_width;
        this->data->height = frame_height;
--- 1236,1242 ----
        this->data->bpp = 8;
        this->data->format = PLAYER_CAMERA_FORMAT_MONO8;
!       this->data->image_count = frame_width * frame_height;
!       this->data->image = reinterpret_cast<uint8_t 
*>(malloc(this->data->image_count));
!       assert(this->data->image);
        this->data->width = frame_width;
        this->data->height = frame_height;
***************
*** 1311,1339 ****
        this->data->bpp = 24;
        this->data->format = PLAYER_CAMERA_FORMAT_RGB888;
-       dst = this->data->image;
        switch (this->BayerMethod)
        {
        case BAYER_DECODING_DOWNSAMPLE:
          // quarter of the image but 3 bytes per pixel
!       this->data->image_count = this->frameSize/4*3;
!     this->data->image = (uint8_t *) malloc(this->data->image_count);
!       BayerDownsample(capture_buffer, this->data->image,
!                                       frame_width/2, frame_height/2,
!                                       (bayer_pattern_t)this->BayerPattern);
        break;
        case BAYER_DECODING_NEAREST:
!         this->data->image_count = this->frameSize * 3;
!         this->data->image = (uint8_t *) malloc(this->data->image_count);
!         BayerNearestNeighbor(capture_buffer, dst,
!                                       frame_width, frame_height,
!                                       (bayer_pattern_t)this->BayerPattern);
        break;
        case BAYER_DECODING_EDGE_SENSE:
!         this->data->image_count = this->frameSize * 3;
!         this->data->image = (uint8_t *) malloc(this->data->image_count);
!         
!       BayerEdgeSense(capture_buffer, dst,
!                                       frame_width, frame_height,
!                                       (bayer_pattern_t)this->BayerPattern);
        break;
        default:
--- 1247,1279 ----
        this->data->bpp = 24;
        this->data->format = PLAYER_CAMERA_FORMAT_RGB888;
        switch (this->BayerMethod)
        {
        case BAYER_DECODING_DOWNSAMPLE:
          // quarter of the image but 3 bytes per pixel
!       this->data->image_count = (frame_width / 2) * (frame_height / 2) * 3;
!         this->data->image = reinterpret_cast<uint8_t 
*>(malloc(this->data->image_count));
!       assert(this->data->image);
!       BayerDownsample(reinterpret_cast<unsigned char *>(capture_buffer), 
!                       reinterpret_cast<unsigned char *>(this->data->image),
!                       frame_width / 2, frame_height / 2,
!                       this->BayerPattern);
        break;
        case BAYER_DECODING_NEAREST:
!         this->data->image_count = frame_width * frame_height * 3;
!         this->data->image = reinterpret_cast<uint8_t 
*>(malloc(this->data->image_count));
!       assert(this->data->image);
!         BayerNearestNeighbor(reinterpret_cast<unsigned char 
*>(capture_buffer),
!                            reinterpret_cast<unsigned char 
*>(this->data->image),
!                            frame_width, frame_height,
!                            this->BayerPattern);
        break;
        case BAYER_DECODING_EDGE_SENSE:
!         this->data->image_count = frame_width * frame_height * 3;
!         this->data->image = reinterpret_cast<uint8_t 
*>(malloc(this->data->image_count));
!         assert(this->data->image);
!       BayerEdgeSense(reinterpret_cast<unsigned char *>(capture_buffer),
!                      reinterpret_cast<unsigned char *>(this->data->image),
!                      frame_width, frame_height,
!                      this->BayerPattern);
        break;
        default:
***************
*** 1348,1353 ****
        else
        {    //image is half the size of grabbed frame
!         this->data->width = frame_width/2;
!         this->data->height = frame_height/2;
        }
      }
--- 1288,1293 ----
        else
        {    //image is half the size of grabbed frame
!         this->data->width = frame_width / 2;
!         this->data->height = frame_height / 2;
        }
      }
***************
*** 1362,1366 ****
    if (this->method == methodVideo) dc1394_dma_done_with_buffer(&this->camera);
  #endif
- 
    this->data->compression = PLAYER_CAMERA_COMPRESS_RAW;
    return 0;
--- 1302,1305 ----
***************
*** 1371,1382 ****
  void Camera1394::RefreshData()
  {
    Publish(this->device_addr, 
            PLAYER_MSGTYPE_DATA, PLAYER_CAMERA_DATA_STATE,
!           reinterpret_cast<void*>(this->data),
  #if LIBDC1394_VERSION == 0200
!           0, &this->frameTime, false);  
  #else
!           0, 0, false);
! #endif  
    return;
  }
--- 1310,1330 ----
  void Camera1394::RefreshData()
  {
+   assert(this->data);
+   if (!(this->data->image_count))
+   {
+     PLAYER_ERROR("No image data to publish");
+     return;
+   }
+   assert(this->data->image);
    Publish(this->device_addr, 
            PLAYER_MSGTYPE_DATA, PLAYER_CAMERA_DATA_STATE,
!           reinterpret_cast<void *>(this->data),
  #if LIBDC1394_VERSION == 0200
!           0, &this->frameTime, false);
  #else
!           0, NULL, false);
! #endif
!   // I assume that Publish() freed this data!
!   this->data = NULL;
    return;
  }
***************
*** 1387,1393 ****
  int Camera1394::SaveFrame(const char *filename)
  {
!   FILE *fp = fopen(filename, "wb");
  
!   if (fp == NULL)
    {
      PLAYER_ERROR("Couldn't create image file");
--- 1335,1350 ----
  int Camera1394::SaveFrame(const char *filename)
  {
!   FILE * fp;
!   
!   assert(this->data);
!   if (!(this->data->image_count))
!   {
!     PLAYER_ERROR("No image data to write");
!     return -1;
!   }
!   assert(this->data->image);
  
!   fp = fopen(filename, "wb");
!   if (!fp)
    {
      PLAYER_ERROR("Couldn't create image file");


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit

Reply via email to