1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pngread.hxx,v $
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 ************************************************************************/
35 #include <tools/gen.hxx>
38 #include <vcl/graph.h>
47 class BitmapWriteAccess
;
52 // ------------------------------------------------------------------------
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
;
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 ];
86 BitmapWriteAccess
* mpAcc
;
88 AlphaMask
* mpAlphaMask
;
89 BitmapWriteAccess
* mpMaskAcc
;
93 BYTE
* mpInflateInBuf
; // as big as the size of a scanline + alphachannel + 1
94 BYTE
* mpScanprior
; // pointer to the latest scanline
101 ULONG mnChunkType
; // Chunk which is currently open
103 long mnChunkDatSizeOrg
;
108 sal_uInt32 mnPrefWidth
; // preferred width in meter
109 sal_uInt32 mnPrefHeight
; // preferred Height in meter
110 BYTE mnBitDepth
; // sample depth
112 BYTE mnCompressionType
;
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
122 BOOL mbPalette
; // FALSE if we need a Palette
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
; //
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
);
140 void ImplResizeScanline();
141 void ImplGetFilter( ULONG nXStart
=0, ULONG nXAdd
=1 );
142 void ImplReadTransparent();
144 void ImplGetBackground();
145 BYTE
ImplScaleColor();
146 BOOL
ImplReadHeader();
147 BOOL
ImplReadPalette();
148 void ImplGetGrayPalette( ULONG
);
149 void ImplOpenChunk();
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
);
159 ReadState
ReadPNG( Graphic
& rGraphic
);
161 PNGReader( SvStream
& rStm
, void* pCallData
);
162 virtual ~PNGReader();
170 BOOL
ImportPNG( SvStream
& rStream
, Graphic
& rGraphic
, void* pCallerData
);
174 #endif // _PNGREAD_HXX