Esempio n. 1
0
bool CaptureFromFile::copyAndConvertFrame(const RawImage & src, RawImage & target)
{
#ifndef VDATA_NO_QT
  mutex.lock();
#endif
  ColorFormat output_fmt = Colors::stringToColorFormat(v_colorout->getSelection().c_str());
  ColorFormat src_fmt=src.getColorFormat();
    
  if (target.getData()==0)
    target.allocate(output_fmt, src.getWidth(), src.getHeight());
  else
    target.ensure_allocation(output_fmt, src.getWidth(), src.getHeight());
     
  target.setTime(src.getTime());
     
  if (output_fmt == src_fmt)
  {
    if (src.getData() != 0)
      memcpy(target.getData(),src.getData(),src.getNumBytes());
  }
  else if (src_fmt == COLOR_RGB8 && output_fmt == COLOR_YUV422_UYVY)
  {
    if (src.getData() != 0)
      dc1394_convert_to_YUV422(src.getData(), target.getData(), src.getWidth(), src.getHeight(), 
                               DC1394_BYTE_ORDER_UYVY, DC1394_COLOR_CODING_RGB8, 8);
  }
  else if (src_fmt == COLOR_YUV422_UYVY && output_fmt == COLOR_RGB8)
  {
    if (src.getData() != 0)
      dc1394_convert_to_RGB8(src.getData(),target.getData(), src.getWidth(), src.getHeight(), 
                             DC1394_BYTE_ORDER_UYVY, DC1394_COLOR_CODING_YUV422, 8);
  } 
  else 
  {
    fprintf(stderr,"Cannot copy and convert frame...unknown conversion selected from: %s to %s\n",
            Colors::colorFormatToString(src_fmt).c_str(),
            Colors::colorFormatToString(output_fmt).c_str());
#ifndef VDATA_NO_QT
    mutex.unlock();
#endif
    return false;
  } 
#ifndef VDATA_NO_QT
  mutex.unlock();
#endif
  return true;
}
Esempio n. 2
0
void GLLUTWidget::sampleImage(const RawImage & img) {
  //compute slice it sits on:
  ColorFormat source_format=img.getColorFormat();
  
  int n=img.getNumPixels();
  
  yuv color;
  int i=0;
  
  if (img.getWidth() > 1 && img.getHeight() > 1) {
    if (source_format==COLOR_RGB8) {
      rgbImage rgb_img(img);
      rgb * color_rgb=rgb_img.getPixelData();
      for (int j=0;j<n;j++) {
        color=Conversions::rgb2yuv(*color_rgb);
        i=_lut->norm2lutX(color.y);
        if (i >= 0 && i < (int)slices.size()) {
          drawSample(i,_lut->norm2lutY(color.u),_lut->norm2lutZ(color.v));
          //slices[i]->sampler->surface.setPixel(_lut->norm2lutY(color.u),_lut->norm2lutZ(color.v),rgba(255,255,255,255));
          slices[i]->sampler_update_pending=true;
        }
        color_rgb++;
      }
    } else if (source_format==COLOR_YUV444) {    
      yuvImage yuv_img(img);
      yuv * color_yuv=yuv_img.getPixelData();
      for (int j=0;j<n;j++) {
        color=(*color_yuv);
        i=_lut->norm2lutX(color.y);
        if (i >= 0 && i < (int)slices.size()) {
          //slices[i]->sampler->surface.setPixel(_lut->norm2lutY(color.u),_lut->norm2lutZ(color.v),rgba(255,255,255,255));
          drawSample(i,_lut->norm2lutY(color.u),_lut->norm2lutZ(color.v));
          slices[i]->sampler_update_pending=true;
        }
        color_yuv++;
      }
    } else if (source_format==COLOR_YUV422_UYVY) {
        uyvy * color_uyvy = (uyvy*)img.getData();
        uyvy color_uyvy_tmp;
        for (int j=0;j<n;j+=2) {
          color_uyvy_tmp=(*color_uyvy);
          color.u=color_uyvy_tmp.u;
          color.v=color_uyvy_tmp.v;
  
          color.y=color_uyvy_tmp.y1;
          i=_lut->norm2lutX(color.y);
          if (i >= 0 && i < (int)slices.size()) {
            //slices[i]->sampler->surface.setPixel(_lut->norm2lutY(color.u),_lut->norm2lutZ(color.v),rgba(255,255,255,255));
            drawSample(i,_lut->norm2lutY(color.u),_lut->norm2lutZ(color.v));
            slices[i]->sampler_update_pending=true;
          }
  
          color.y=color_uyvy_tmp.y2;
          i=_lut->norm2lutX(color.y);
          if (i >= 0 && i < (int)slices.size()) {
            //slices[i]->sampler->surface.setPixel(_lut->norm2lutY(color.u),_lut->norm2lutZ(color.v),rgba(255,255,255,255));
            drawSample(i,_lut->norm2lutY(color.u),_lut->norm2lutZ(color.v));
            slices[i]->sampler_update_pending=true;
          }
          color_uyvy++;
        }
    } else {
      fprintf(stderr,"Unable to sample colors from frame of format: %s\n",Colors::colorFormatToString(source_format).c_str());
      fprintf(stderr,"Currently supported are rgb8, yuv444, and yuv422 (UYVY).\n");
      fprintf(stderr,"(Feel free to add more conversions to glLUTwidget.cpp).\n");
    }
   }
  redraw();

}
Esempio n. 3
0
bool CaptureFlycap::convertFrame(const RawImage & src,
                           RawImage & target,
                           ColorFormat output_fmt,
                           bool debayer,
                           dc1394color_filter_t bayer_format,
                           dc1394bayer_method_t bayer_method,
                           int y16bits) {
  mutex.lock();

  int width = v_width->getInt();
  int height = v_height->getInt();

  ColorFormat src_fmt=src.getColorFormat();
  if (target.getData()==0) {
    //allocate target, if it does not exist yet
    target.allocate(output_fmt,src.getWidth(),src.getHeight());
  } else {
    target.ensure_allocation(output_fmt,src.getWidth(),src.getHeight());
  }
  target.setTime(src.getTime());
  if (output_fmt==src_fmt) {
    //just do a memcpy
    memcpy(target.getData(),src.getData(),src.getNumBytes());
  } else {
    //do some more fancy conversion
    if ((src_fmt==COLOR_MONO8 || src_fmt==COLOR_RAW8) && output_fmt==COLOR_RGB8) {
      //check whether to debayer or simply average to a grey rgb image
      if (debayer) {
        //de-bayer
        if ( dc1394_bayer_decoding_8bit( src.getData(), target.getData(), src.getWidth(), src.getHeight(), bayer_format, bayer_method) != DC1394_SUCCESS ) {
            mutex.unlock();
          return false;
        }
      } else {
        dc1394_convert_to_RGB8(src.getData(),target.getData(), width, height, 0,
                       DC1394_COLOR_CODING_MONO8, 8);
        //Conversions::y2rgb (src.getData(), target.getData(), src.getNumPixels());
      }
    } else if ((src_fmt==COLOR_MONO16 || src_fmt==COLOR_RAW16)) {
      //check whether to debayer or simply average to a grey rgb image
      if (debayer && output_fmt==COLOR_RGB16) {
        //de-bayer
        if ( dc1394_bayer_decoding_16bit( (uint16_t *)src.getData(), (uint16_t *)target.getData(), src.getWidth(), src.getHeight(), bayer_format, bayer_method, y16bits) != DC1394_SUCCESS ) {
          fprintf(stderr,"Error in 16bit Bayer Conversion");

            mutex.unlock();
          return false;
        }
      } else if (debayer==false && output_fmt==COLOR_RGB8) {

       dc1394_convert_to_RGB8(src.getData(),target.getData(), width, height, 0,
                       ((src_fmt==COLOR_MONO16) ? DC1394_COLOR_CODING_MONO16 : DC1394_COLOR_CODING_RAW16), y16bits);
        //Conversions::y162rgb (src.getData(), target.getData(), src.getNumPixels(), y16bits);
      } else {
      fprintf(stderr,"Cannot copy and convert frame...unknown conversion selected from: %s to %s\n",Colors::colorFormatToString(src_fmt).c_str(),Colors::colorFormatToString(output_fmt).c_str());
      mutex.unlock();
      return false;
      }
    } else if (src_fmt==COLOR_YUV411 && output_fmt==COLOR_RGB8) {
      dc1394_convert_to_RGB8(src.getData(),target.getData(), width, height, 0,
                       DC1394_COLOR_CODING_YUV411, 8);
      //Conversions::uyyvyy2rgb (src.getData(), target.getData(), src.getNumPixels());
    } else if (src_fmt==COLOR_YUV422_UYVY && output_fmt==COLOR_RGB8) {
        dc1394_convert_to_RGB8(src.getData(),target.getData(), width, height, DC1394_BYTE_ORDER_UYVY,
                       DC1394_COLOR_CODING_YUV422, 8);
    } else if (src_fmt==COLOR_YUV422_YUYV && output_fmt==COLOR_RGB8) {
        dc1394_convert_to_RGB8(src.getData(),target.getData(), width, height, DC1394_BYTE_ORDER_YUYV,
                       DC1394_COLOR_CODING_YUV422, 8);
    } else if (src_fmt==COLOR_YUV444 && output_fmt==COLOR_RGB8) {
      dc1394_convert_to_RGB8(src.getData(),target.getData(), width, height, 0,
                       DC1394_COLOR_CODING_YUV444, 8);
    } else {
      fprintf(stderr,"Cannot copy and convert frame...unknown conversion selected from: %s to %s\n",Colors::colorFormatToString(src_fmt).c_str(),Colors::colorFormatToString(output_fmt).c_str());
      mutex.unlock();
      return false;
    }
  }

  mutex.unlock();
  return true;
}
Esempio n. 4
0
bool CaptureFlycap::copyFrame(const RawImage & src, RawImage & target) {
    return convertFrame(src,target,src.getColorFormat());
}