diff options
Diffstat (limited to 'sdext/source/pdfimport/xpdfwrapper/pnghelper.cxx')
-rw-r--r-- | sdext/source/pdfimport/xpdfwrapper/pnghelper.cxx | 80 |
1 files changed, 40 insertions, 40 deletions
diff --git a/sdext/source/pdfimport/xpdfwrapper/pnghelper.cxx b/sdext/source/pdfimport/xpdfwrapper/pnghelper.cxx index a28a676bcf79..8bf3952eb8d0 100644 --- a/sdext/source/pdfimport/xpdfwrapper/pnghelper.cxx +++ b/sdext/source/pdfimport/xpdfwrapper/pnghelper.cxx @@ -16,12 +16,12 @@ * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public * License along with this program; if not, write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, @@ -44,10 +44,10 @@ using namespace pdfi; /* Table of CRCs of all 8-bit messages. */ sal_uInt32 PngHelper::crc_table[256]; - + /* Flag: has the table been computed? Initially false. */ bool PngHelper::bCRCTableInit = true; - + /* Make the table for a fast CRC. */ void PngHelper::initCRCTable() { @@ -65,7 +65,7 @@ void PngHelper::initCRCTable() } bCRCTableInit = false; } - + /* Update a running CRC with the bytes buf[0..len-1]--the CRC should be initialized to all 1's, and the transmitted value is the 1's complement of the final running CRC (see the @@ -75,7 +75,7 @@ void PngHelper::updateCRC( sal_uInt32& io_rCRC, const sal_uInt8* i_pBuf, size_t { if( bCRCTableInit ) initCRCTable(); - + sal_uInt32 nCRC = io_rCRC; for( size_t n = 0; n < i_nLen; n++ ) nCRC = crc_table[(nCRC ^ i_pBuf[n]) & 0xff] ^ (nCRC >> 8); @@ -92,7 +92,7 @@ sal_uInt32 PngHelper::getCRC( const sal_uInt8* i_pBuf, size_t i_nLen ) sal_uInt32 PngHelper::deflateBuffer( const Output_t* i_pBuf, size_t i_nLen, OutputBuffer& o_rOut ) { size_t nOrigSize = o_rOut.size(); - + // prepare z stream z_stream aStream; aStream.zalloc = Z_NULL; @@ -101,7 +101,7 @@ sal_uInt32 PngHelper::deflateBuffer( const Output_t* i_pBuf, size_t i_nLen, Outp deflateInit( &aStream, Z_BEST_COMPRESSION ); aStream.avail_in = uInt(i_nLen); aStream.next_in = (Bytef*)i_pBuf; - + sal_uInt8 aOutBuf[ 32768 ]; do { @@ -115,17 +115,17 @@ sal_uInt32 PngHelper::deflateBuffer( const Output_t* i_pBuf, size_t i_nLen, Outp o_rOut.resize( nOrigSize ); return 0; } - + // append compressed bytes sal_uInt32 nCompressedBytes = sizeof( aOutBuf ) - aStream.avail_out; if( nCompressedBytes ) o_rOut.insert( o_rOut.end(), aOutBuf, aOutBuf+nCompressedBytes ); } while( aStream.avail_out == 0 ); - + // cleanup deflateEnd( &aStream ); - + return sal_uInt32( o_rOut.size() - nOrigSize ); } @@ -159,12 +159,12 @@ void PngHelper::endChunk( size_t nStart, OutputBuffer& o_rOutputBuf ) { if( nStart+8 > o_rOutputBuf.size() ) return; // something broken is going on - + // update chunk length size_t nLen = o_rOutputBuf.size() - nStart; sal_uInt32 nDataLen = sal_uInt32(nLen)-8; set( nDataLen, o_rOutputBuf, nStart ); - + // append chunk crc sal_uInt32 nChunkCRC = getCRC( (sal_uInt8*)&o_rOutputBuf[nStart+4], nLen-4 ); append( nChunkCRC, o_rOutputBuf ); @@ -186,7 +186,7 @@ void PngHelper::appendIHDR( OutputBuffer& o_rOutputBuf, int width, int height, i void PngHelper::appendIEND( OutputBuffer& o_rOutputBuf ) { size_t nStart = startChunk( "IEND", o_rOutputBuf ); - endChunk( nStart, o_rOutputBuf ); + endChunk( nStart, o_rOutputBuf ); } void PngHelper::createPng( OutputBuffer& o_rOutputBuf, @@ -200,8 +200,8 @@ void PngHelper::createPng( OutputBuffer& o_rOutputBuf, { appendFileHeader( o_rOutputBuf ); appendIHDR( o_rOutputBuf, width, height, 1, 3 ); - - // write palette + + // write palette size_t nIdx = startChunk( "PLTE", o_rOutputBuf ); // write colors 0 and 1 o_rOutputBuf.push_back(colToByte(zeroColor.r)); @@ -212,7 +212,7 @@ void PngHelper::createPng( OutputBuffer& o_rOutputBuf, o_rOutputBuf.push_back(colToByte(oneColor.b)); // end PLTE chunk endChunk( nIdx, o_rOutputBuf ); - + if( bIsMask ) { // write tRNS chunk @@ -236,14 +236,14 @@ void PngHelper::createPng( OutputBuffer& o_rOutputBuf, for( int x = 0; x < nLineSize; x++ ) aScanlines.push_back( str->getChar() ); } - + // begin IDAT chunk for scanline data nIdx = startChunk( "IDAT", o_rOutputBuf ); // compress scanlines - deflateBuffer( &aScanlines[0], aScanlines.size(), o_rOutputBuf ); + deflateBuffer( &aScanlines[0], aScanlines.size(), o_rOutputBuf ); // end IDAT chunk endChunk( nIdx, o_rOutputBuf ); - + // output IEND appendIEND( o_rOutputBuf ); } @@ -256,14 +256,14 @@ void PngHelper::createPng( OutputBuffer& o_rOutputBuf, { appendFileHeader( o_rOutputBuf ); appendIHDR( o_rOutputBuf, width, height, 8, 6 ); // RGBA image - + // initialize stream Guchar *p, *pm; GfxRGB rgb; GfxGray alpha; ImageStream* imgStr = - new ImageStream(str, - width, + new ImageStream(str, + width, colorMap->getNumPixelComps(), colorMap->getBits()); imgStr->reset(); @@ -272,34 +272,34 @@ void PngHelper::createPng( OutputBuffer& o_rOutputBuf, OutputBuffer aScanlines; aScanlines.reserve( width*height*4 + height ); - for( int y=0; y<height; ++y) + for( int y=0; y<height; ++y) { aScanlines.push_back( 0 ); p = imgStr->getLine(); - for( int x=0; x<width; ++x) + for( int x=0; x<width; ++x) { colorMap->getRGB(p, &rgb); aScanlines.push_back(colToByte(rgb.r)); aScanlines.push_back(colToByte(rgb.g)); aScanlines.push_back(colToByte(rgb.b)); aScanlines.push_back( 0xff ); - + p +=colorMap->getNumPixelComps(); } } // now fill in the mask data - + // CAUTION: originally this was done in one single loop // it caused merry chaos; the reason is that maskStr and str are // not independent streams, it happens that reading one advances // the other, too. Hence the two passes are imperative ! - + // initialize mask stream ImageStream* imgStrMask = - new ImageStream(maskStr, - maskWidth, + new ImageStream(maskStr, + maskWidth, maskColorMap->getNumPixelComps(), maskColorMap->getBits()); @@ -320,7 +320,7 @@ void PngHelper::createPng( OutputBuffer& o_rOutputBuf, delete imgStr; delete imgStrMask; - + // begind IDAT chunk for scanline data size_t nIdx = startChunk( "IDAT", o_rOutputBuf ); // compress scanlines @@ -342,13 +342,13 @@ void PngHelper::createPng( OutputBuffer& o_rOutputBuf, { appendFileHeader( o_rOutputBuf ); appendIHDR( o_rOutputBuf, width, height, 8, 6 ); // RGBA image - + // initialize stream Guchar *p; GfxRGB rgb; ImageStream* imgStr = - new ImageStream(str, - width, + new ImageStream(str, + width, colorMap->getNumPixelComps(), colorMap->getBits()); imgStr->reset(); @@ -357,30 +357,30 @@ void PngHelper::createPng( OutputBuffer& o_rOutputBuf, OutputBuffer aScanlines; aScanlines.reserve( width*height*4 + height ); - for( int y=0; y<height; ++y) + for( int y=0; y<height; ++y) { aScanlines.push_back( 0 ); p = imgStr->getLine(); - for( int x=0; x<width; ++x) + for( int x=0; x<width; ++x) { colorMap->getRGB(p, &rgb); aScanlines.push_back(colToByte(rgb.r)); aScanlines.push_back(colToByte(rgb.g)); aScanlines.push_back(colToByte(rgb.b)); aScanlines.push_back( 0xff ); - + p +=colorMap->getNumPixelComps(); } } // now fill in the mask data - + // CAUTION: originally this was done in one single loop // it caused merry chaos; the reason is that maskStr and str are // not independent streams, it happens that reading one advances // the other, too. Hence the two passes are imperative ! - + // initialize mask stream ImageStream* imgStrMask = new ImageStream(maskStr, maskWidth, 1, 1); @@ -404,7 +404,7 @@ void PngHelper::createPng( OutputBuffer& o_rOutputBuf, delete imgStr; delete imgStrMask; - + // begind IDAT chunk for scanline data size_t nIdx = startChunk( "IDAT", o_rOutputBuf ); // compress scanlines |