Update ooo320-m1
[ooovba.git] / binfilter / inc / bf_svtools / pngread.hxx
blob49b59002192957f204af924d51930545c4b57f98
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pngread.hxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _PNGREAD_HXX
32 #define _PNGREAD_HXX
34 #ifndef _GEN_HXX
35 #include <tools/gen.hxx>
36 #endif
37 #ifndef _SV_GRAPH_H
38 #include <vcl/graph.h>
39 #endif
41 class SvStream;
42 class Graphic;
43 class ZCodec;
44 class Bitmap;
45 class BitmapColor;
46 class AlphaMask;
47 class BitmapWriteAccess;
49 namespace binfilter
52 // ------------------------------------------------------------------------
54 enum ReadState
56 PNGREAD_OK,
57 PNGREAD_ERROR,
58 PNGREAD_NEED_MORE
61 // -------------
62 // - PNGReader -
63 // -------------
65 #define CHUNK_IS_OPEN 1
66 #define CHUNK_IS_CLOSED 2
67 #define CHUNK_IS_IN_USE 4
69 class PNGReader : public GraphicReader
71 ReadState meReadState;
72 SvStream* mpIStm;
73 void* mpCallerData;
74 USHORT mnIStmOldMode;
75 BOOL mbStatus;
76 BOOL mbFinished;
77 BOOL mbFirstEntry;
78 UINT32 mnChunkStatus;
79 UINT32 mnChunkStartPosition;
80 UINT32 mnIDATCRCCount;
81 UINT32 mnLatestStreamPos;
82 static const BYTE mnBlockHeight[ 8 ];
83 static const BYTE mnBlockWidth[ 8 ];
84 static const BYTE mpDefaultColorTable[ 256 ];
85 Bitmap* mpBmp;
86 BitmapWriteAccess* mpAcc;
87 Bitmap* mpMaskBmp;
88 AlphaMask* mpAlphaMask;
89 BitmapWriteAccess* mpMaskAcc;
92 ZCodec* mpZCodec;
93 BYTE* mpInflateInBuf; // as big as the size of a scanline + alphachannel + 1
94 BYTE* mpScanprior; // pointer to the latest scanline
95 BYTE* mpTransTab; //
96 BYTE mnTransRed;
97 BYTE mnTransGreen;
98 BYTE mnTransBlue;
99 BYTE mnDummy;
101 ULONG mnChunkType; // Chunk which is currently open
102 ULONG mnCRC;
103 long mnChunkDatSizeOrg;
104 long mnChunkDatSize;
106 ULONG mnWidth;
107 ULONG mnHeight;
108 sal_uInt32 mnPrefWidth; // preferred width in meter
109 sal_uInt32 mnPrefHeight; // preferred Height in meter
110 BYTE mnBitDepth; // sample depth
111 BYTE mnColorType;
112 BYTE mnCompressionType;
113 BYTE mnFilterType;
114 BYTE mnInterlaceType;
116 USHORT mnDepth; // pixel depth
117 ULONG mnBBP; // number of bytes per pixel
118 ULONG mnScansize; // max size of scanline
119 BOOL mbTransparent; // graphic includes an tRNS Chunk or an alpha Channel
120 BOOL mbAlphaChannel;
121 BOOL mbRGBTriple;
122 BOOL mbPalette; // FALSE if we need a Palette
123 BOOL mbGrayScale;
124 BOOL mbzCodecInUse;
125 BOOL mbIDAT; // TRUE if finished with the complete IDAT...
126 BOOL mbGamma; // TRUE if Gamma Correction available
127 BOOL mbpHYs; // TRUE if pysical size of pixel available
128 BYTE mnPass; // if interlaced the latest pass ( 1..7 ) else 7
129 ULONG mnYpos; // latest y position;
130 BYTE* mpScan; // pointer in the current scanline
131 BYTE* mpColorTable; //
132 BYTE cTransIndex1;
133 BYTE cNonTransIndex1;
136 void ImplSetPixel( ULONG y, ULONG x, const BitmapColor &, BOOL bTrans );
137 void ImplSetPixel( ULONG y, ULONG x, BYTE nPalIndex, BOOL bTrans );
138 void ImplSetAlphaPixel( ULONG y, ULONG x, const BitmapColor&, BYTE nAlpha );
139 void ImplReadIDAT();
140 void ImplResizeScanline();
141 void ImplGetFilter( ULONG nXStart=0, ULONG nXAdd=1 );
142 void ImplReadTransparent();
143 void ImplGetGamma();
144 void ImplGetBackground();
145 BYTE ImplScaleColor();
146 BOOL ImplReadHeader();
147 BOOL ImplReadPalette();
148 void ImplGetGrayPalette( ULONG );
149 void ImplOpenChunk();
150 BYTE ImplReadBYTE();
151 ULONG ImplReadULONG();
152 void ImplReadDAT( unsigned char* pSource, long nDatSize );
153 BOOL ImplCloseChunk();
154 void ImplSkipChunk();
155 sal_Bool ImplIsPending( sal_uInt32 nPos, sal_uInt32 nSize );
157 public:
159 ReadState ReadPNG( Graphic& rGraphic );
161 PNGReader( SvStream& rStm, void* pCallData );
162 virtual ~PNGReader();
166 // -------------
167 // - ImportPNG -
168 // -------------
170 BOOL ImportPNG( SvStream& rStream, Graphic& rGraphic, void* pCallerData );
174 #endif // _PNGREAD_HXX