Logo Search packages:      
Sourcecode: camstream version File versions  Download package

int CVideoDevice::ReadImage (  ) 

Read image into Buffers.

Returns:
0 on success, -errno otherwise.
This function reads the raw data from the device and transforms it into RGB and/or YUV images, doing all necessary conversions.

Definition at line 1270 of file VideoDevice.cc.

References MCapture(), MSync(), and Notify().

Referenced by LoadImage().

{
   uchar *dst = 0, *src = 0;
   int i, n;

   if (CamFD < 0)
     return -ENODEV;
   if (vid_io_buffer == NULL)
     return -ENOMEM;
     
   src = vid_io_buffer + vid_io_offsets[CurBuffer];
   if (VMBuf.size > 0) { // mmap()ed.
     i = MSync();
     if (i < 0)
       return i;
     if (Buffers > 1) // we have space, start capture immediately in next buffer. Otherwise, see end of function
       MCapture((CurBuffer + 1) % Buffers); 
   }
   else {
     if (read(CamFD, src, vid_io_image_size) < 0)
       return -errno;
   }
   
   /* At this point we have our (raw) data in the buffer; it could be we
      are finished now because we have put the data into place with
      PalRGB && VIDEO_PALETTE_RGB32 or PalYUV && VIDEO_PALETTE_YUV420P.
      But in most other cases we will have to do some conversion...
    */
   n = image_w * image_h;

   switch (Palette) {
     case VIDEO_PALETTE_YUV420P:
       /* only RGB needs conversion :-) */
       if (PalRGB) {
         dst = RGB[CurBuffer]->bits();
         ccvt_420p_bgr32(image_w, image_h, src, dst);
       }
       break;

     case VIDEO_PALETTE_RGB24:
       /* "Broken" BGR palette */
       if (PalRGB) {
         dst = RGB[CurBuffer]->bits();
         ccvt_bgr24_bgr32(image_w, image_h, src, dst);
       }
/* Does not exist yet 
       if (PalYUV)
         ccvt_bgr24_420p(image_w, image_h, vid_buffer, dy, du, dv);
*/        
       break;

     case VIDEO_PALETTE_RGB32:
       /* Quick-n-dirty palette */
       if (PalRGB) {
         dst = RGB[CurBuffer]->bits();
         memcpy(dst, src, n * 4);
       }
       if (PalYUV) {
         // convert to YUV planes
       }
       break;

#if 0
       // Planar format... easy :)
       if (PalYUV) {
         if (dy != NULL)
           memcpy(dy, src, n);
         src += n;
         n /= 4; /* UV boxes are only a quarter size */
         if (du != NULL)
           memcpy(du, src, n);
         src += n;
         if (dv != NULL)
           memcpy(dv, src, n);
       }
       else {
         dy = src;
         du = src + n;
         dv = du + (n / 4);
       }
#if 0
       /* some code to determine max/min values */
       int miny, maxy, minu, maxu, minv, maxv;
       
       miny = 255; maxy = 0;
       src = dy;
       for (i = 0; i < n; i++) {
          if (*src < miny) miny = *src;
          if (*src > maxy) maxy = *src;
          src++;
       }
       n /= 4;
       minu = 255; maxu = 0;
       src = du;
       for (i = 0; i < n; i++) {
          if (*src < minu) minu = *src;
          if (*src > maxu) maxu = *src;
          src++;
       }
       minv = 255; maxv = 0;
       src = dv;
       for (i = 0; i < n; i++) {
          if (*src < minv) minv = *src;
          if (*src > maxv) maxv = *src;
          src++;
       }
       qDebug("Y: min = %3d, max = %3d | U: min = %3d, max = %3d  | V: min = %3d, max = %3d ", miny, maxy, minu, maxu, minv, maxv);
#endif       
#endif
      
     case VIDEO_PALETTE_YUV422:
     case VIDEO_PALETTE_YUYV:
       if (PalYUV) {
         ccvt_yuyv_420p(image_w, image_h, src, Y[CurBuffer]->bits(), U[CurBuffer]->bits(), V[CurBuffer]->bits());
       }
       if (PalRGB) {
         ccvt_yuyv_bgr32(image_w, image_h, src, dst);
       }
       break;
   }

   emit Notify();

   /* Go to next buffer (including capture). In case of 1 buffer CurBuffer
      will get stuck at 0, so we do this after we processed the buffer
      content.
    */
   CurBuffer = (CurBuffer + 1) % Buffers;
   if (Buffers == 1) {
     if (MCapture(CurBuffer) < 0)
       return -errno;
   }

   return 0;
}


Generated by  Doxygen 1.6.0   Back to index