//------------------------------------------------------------------------ // 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; } }
//------------------------------------------------------------------------ // JpegEncoder::Compress //------------------------------------------------------------------------ void JpegEncoder::Compress(MemBufPtr ptrmbSrc, struct jpeg_compress_struct *pcinfo) { // Start compressor jpeg_start_compress(pcinfo, TRUE); JSAMPROW *row_pointer = new JSAMPROW[pcinfo->image_height]; for( uint ui = 0; ui < pcinfo->image_height; ui++ ) row_pointer[ui] = (unsigned char *)(ptrmbSrc->Buf() + ui * pcinfo->image_width); // Write all rows in one single pass jpeg_write_scanlines(pcinfo, row_pointer, pcinfo->image_height); // Terminate encoding process jpeg_finish_compress(pcinfo); jpeg_destroy_compress(pcinfo); }