Ejemplo n.º 1
0
//------------------------------------------------------------------------
// BmpEncoder::EncodeGrayScaleToMemBuf
//------------------------------------------------------------------------
void BmpEncoder::EncodeGrayScaleToMemBuf(MemBufPtr ptrmbSrc, MemBufPtr ptrmbDst)
{
  int iWidth, iHeight;
  try
  {
    ptrmbSrc->GetIntegerMetadata("width", &iWidth);
    ptrmbSrc->GetIntegerMetadata("height", &iHeight);
  }
  catch( NoDataException e )
  {
    // Transform exception into a jpeg exception
    throw BmpEncoder::Exception(PSZ(e.Error()), PSZ(e.Reason()), "BmpEncoder::EncodeGrayScaleToMemBuf");
  }

  if( iWidth < 1 || iWidth > BMP_MAX_DIMENSION )
    throw Exception("BAD_PARAMETER", "Wrongs image dimensions. Must be in [1, 65000]", "BmpEncoder::EncodeGrayScaleToMemBuf");

  int iBytePaddingPerRow = 0;
  EncodeHeader(ptrmbDst, 8, iWidth, iHeight, &iBytePaddingPerRow);

  // Image data
  for( int y = 0; y < iHeight; y++ )
  {
    ptrmbDst->PutBloc((uint8 *)(ptrmbSrc->Buf()) + (iHeight - y - 1) * iWidth, iWidth);
    for( int i = 0; i < iBytePaddingPerRow; i++ )
      (*ptrmbDst) << (uint8)0;
  }
}
Ejemplo n.º 2
0
//------------------------------------------------------------------------
// JpegEncoder::InitCompressor
//------------------------------------------------------------------------
void JpegEncoder::InitCompressor(MemBufPtr ptrmbSrc, struct jpeg_compress_struct *pcinfo)
{
  int iWidth, iHeight;
  try
  {
    ptrmbSrc->GetIntegerMetadata("width", &iWidth);
    ptrmbSrc->GetIntegerMetadata("height", &iHeight);
  }
  catch( NoDataException e )
  {
    // Transform exception into a jpeg exception
    throw JpegEncoder::Exception(PSZ(e.Error()), PSZ(e.Reason()), "JpegEncoder::InitCompressor");
  }

  if( iWidth < 1 ||iWidth > JPEG_MAX_DIMENSION )
    throw JpegEncoder::Exception("BAD_PARAMETER", "Wrongs image dimensions. Must be in [1, 65000]", "JpegEncoder::Encode");

  // create context
  jpeg_create_compress(pcinfo);

  // Put cinfo values
  pcinfo->image_width = iWidth;
  pcinfo->image_height = iHeight;
  pcinfo->input_components = 1; // grayscale image
  pcinfo->in_color_space = JCS_GRAYSCALE;

  // Set compression parameters to default values
  jpeg_set_defaults(pcinfo);

  // Set quality to max
  jpeg_set_quality(pcinfo, 100, TRUE);
}