1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 #ifndef _IPDF_PNGHELPER_HXX
22 #define _IPDF_PNGHELPER_HXX
23 
24 #include "sal/types.h"
25 #include "pdfioutdev_gpl.hxx"
26 
27 
28 namespace pdfi
29 {
30     class PngHelper
31     {
32         static sal_uInt32 crc_table[ 256 ];
33         static bool bCRCTableInit;
34 
35         static void initCRCTable();
36         static void appendFileHeader( OutputBuffer& o_rOutputBuf );
37         static size_t startChunk( const char* pChunkName, OutputBuffer& o_rOut );
38         static void endChunk( size_t nStart, OutputBuffer& o_rOut );
39 
40         static void set( sal_uInt32 i_nValue, OutputBuffer& o_rOutputBuf, size_t i_nIndex );
append(sal_uInt32 i_nValue,OutputBuffer & o_rOutputBuf)41         static void append( sal_uInt32 i_nValue, OutputBuffer& o_rOutputBuf )
42         {
43             size_t nCur = o_rOutputBuf.size();
44             o_rOutputBuf.insert( o_rOutputBuf.end(), 4, (Output_t)0 );
45             set( i_nValue, o_rOutputBuf, nCur );
46         }
47 
48         static void appendIHDR( OutputBuffer& o_rOutputBuf, int width, int height, int depth, int colortype );
49         static void appendIEND( OutputBuffer& o_rOutputBuf );
50 
51     public:
52         static void updateCRC( sal_uInt32& io_rCRC, const sal_uInt8* i_pBuf, size_t i_nLen );
53         static sal_uInt32 getCRC( const sal_uInt8* i_pBuf, size_t i_nLen );
54 
55         // deflates the passed buff i_pBuf and appends it to the output vector
56         // returns the number of bytes added to the output
57         static sal_uInt32 deflateBuffer( const Output_t* i_pBuf, size_t i_nLen, OutputBuffer& o_rOut );
58 
59         static void createPng( OutputBuffer&     o_rOutputBuf,
60                                Stream*           str,
61                                int               width,
62                                int               height,
63                                GfxRGB&           zeroColor,
64                                GfxRGB&           oneColor,
65                                bool              bIsMask
66                                );
67         static void createPng( OutputBuffer& o_rOutputBuf,
68                                Stream* str,
69                                int width, int height, GfxImageColorMap* colorMap,
70                                Stream* maskStr,
71                                int maskWidth, int maskHeight, GfxImageColorMap* maskColorMap );
72 
73         // for one bit masks
74         static void createPng( OutputBuffer& o_rOutputBuf,
75                                Stream* str,
76                                int width, int height, GfxImageColorMap* colorMap,
77                                Stream* maskStr,
78                                int maskWidth, int maskHeight, bool maskInvert );
79 
80     };
81 }
82 
83 #endif
84