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;
  }
}