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