1 /************************************************************************* 2 * 3 * OpenOffice.org - a multi-platform office productivity suite 4 * 5 * The Contents of this file are made available subject to 6 * the terms of GNU General Public License Version 2. 7 * 8 * 9 * GNU General Public License, version 2 10 * ============================================= 11 * Copyright 2005 by Sun Microsystems, Inc. 12 * 901 San Antonio Road, Palo Alto, CA 94303, USA 13 * 14 * This program is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU General Public License as 16 * published by the Free Software Foundation; either version 2 of 17 * the License, or (at your option) any later version. 18 * 19 * This program is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * GNU General Public License for more details. 23 * 24 * You should have received a copy of the GNU General Public 25 * License along with this program; if not, write to the Free 26 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 27 * Boston, MA 02110-1301, USA. 28 * 29 ************************************************************************/ 30 #ifndef _IPDF_PNGHELPER_HXX 31 #define _IPDF_PNGHELPER_HXX 32 33 #include "sal/types.h" 34 #include "pdfioutdev_gpl.hxx" 35 36 37 namespace pdfi 38 { 39 class PngHelper 40 { 41 static sal_uInt32 crc_table[ 256 ]; 42 static bool bCRCTableInit; 43 44 static void initCRCTable(); 45 static void appendFileHeader( OutputBuffer& o_rOutputBuf ); 46 static size_t startChunk( const char* pChunkName, OutputBuffer& o_rOut ); 47 static void endChunk( size_t nStart, OutputBuffer& o_rOut ); 48 49 static void set( sal_uInt32 i_nValue, OutputBuffer& o_rOutputBuf, size_t i_nIndex ); 50 static void append( sal_uInt32 i_nValue, OutputBuffer& o_rOutputBuf ) 51 { 52 size_t nCur = o_rOutputBuf.size(); 53 o_rOutputBuf.insert( o_rOutputBuf.end(), 4, (Output_t)0 ); 54 set( i_nValue, o_rOutputBuf, nCur ); 55 } 56 57 static void appendIHDR( OutputBuffer& o_rOutputBuf, int width, int height, int depth, int colortype ); 58 static void appendIEND( OutputBuffer& o_rOutputBuf ); 59 60 public: 61 static void updateCRC( sal_uInt32& io_rCRC, const sal_uInt8* i_pBuf, size_t i_nLen ); 62 static sal_uInt32 getCRC( const sal_uInt8* i_pBuf, size_t i_nLen ); 63 64 // deflates the passed buff i_pBuf and appends it to the output vector 65 // returns the number of bytes added to the output 66 static sal_uInt32 deflateBuffer( const Output_t* i_pBuf, size_t i_nLen, OutputBuffer& o_rOut ); 67 68 static void createPng( OutputBuffer& o_rOutputBuf, 69 Stream* str, 70 int width, 71 int height, 72 GfxRGB& zeroColor, 73 GfxRGB& oneColor, 74 bool bIsMask 75 ); 76 static void createPng( OutputBuffer& o_rOutputBuf, 77 Stream* str, 78 int width, int height, GfxImageColorMap* colorMap, 79 Stream* maskStr, 80 int maskWidth, int maskHeight, GfxImageColorMap* maskColorMap ); 81 82 // for one bit masks 83 static void createPng( OutputBuffer& o_rOutputBuf, 84 Stream* str, 85 int width, int height, GfxImageColorMap* colorMap, 86 Stream* maskStr, 87 int maskWidth, int maskHeight, bool maskInvert ); 88 89 }; 90 } 91 92 #endif 93