beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / poppler / JPXStream.h
blob30855431fb4f3db02f57f7c6db5f36ac4df81a4d
1 //========================================================================
2 //
3 // JPXStream.h
4 //
5 // Copyright 2002-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 #ifndef JPXSTREAM_H
10 #define JPXSTREAM_H
12 #ifdef USE_GCC_PRAGMAS
13 #pragma interface
14 #endif
16 #include "goo/gtypes.h"
17 #include "Object.h"
18 #include "Stream.h"
20 class JArithmeticDecoder;
21 class JArithmeticDecoderStats;
23 //------------------------------------------------------------------------
25 enum JPXColorSpaceType {
26 jpxCSBiLevel = 0,
27 jpxCSYCbCr1 = 1,
28 jpxCSYCbCr2 = 3,
29 jpxCSYCBCr3 = 4,
30 jpxCSPhotoYCC = 9,
31 jpxCSCMY = 11,
32 jpxCSCMYK = 12,
33 jpxCSYCCK = 13,
34 jpxCSCIELab = 14,
35 jpxCSsRGB = 16,
36 jpxCSGrayscale = 17,
37 jpxCSBiLevel2 = 18,
38 jpxCSCIEJab = 19,
39 jpxCSCISesRGB = 20,
40 jpxCSROMMRGB = 21,
41 jpxCSsRGBYCbCr = 22,
42 jpxCSYPbPr1125 = 23,
43 jpxCSYPbPr1250 = 24
46 struct JPXColorSpecCIELab {
47 Guint rl, ol, ra, oa, rb, ob, il;
50 struct JPXColorSpecEnumerated {
51 JPXColorSpaceType type; // color space type
52 union {
53 JPXColorSpecCIELab cieLab;
57 struct JPXColorSpec {
58 Guint meth; // method
59 int prec; // precedence
60 union {
61 JPXColorSpecEnumerated enumerated;
65 //------------------------------------------------------------------------
67 struct JPXPalette {
68 Guint nEntries; // number of entries in the palette
69 Guint nComps; // number of components in each entry
70 Guint *bpc; // bits per component, for each component
71 int *c; // color data:
72 // c[i*nComps+j] = entry i, component j
75 //------------------------------------------------------------------------
77 struct JPXCompMap {
78 Guint nChannels; // number of channels
79 Guint *comp; // codestream components mapped to each channel
80 Guint *type; // 0 for direct use, 1 for palette mapping
81 Guint *pComp; // palette components to use
84 //------------------------------------------------------------------------
86 struct JPXChannelDefn {
87 Guint nChannels; // number of channels
88 Guint *idx; // channel indexes
89 Guint *type; // channel types
90 Guint *assoc; // channel associations
93 //------------------------------------------------------------------------
95 struct JPXTagTreeNode {
96 GBool finished; // true if this node is finished
97 Guint val; // current value
100 //------------------------------------------------------------------------
102 struct JPXCodeBlock {
103 //----- size
104 Guint x0, y0, x1, y1; // bounds
106 //----- persistent state
107 GBool seen; // true if this code-block has already
108 // been seen
109 Guint lBlock; // base number of bits used for pkt data length
110 Guint nextPass; // next coding pass
112 //---- info from first packet
113 Guint nZeroBitPlanes; // number of zero bit planes
115 //----- info for the current packet
116 Guint included; // code-block inclusion in this packet:
117 // 0=not included, 1=included
118 Guint nCodingPasses; // number of coding passes in this pkt
119 Guint *dataLen; // data lengths (one per codeword segment)
120 Guint dataLenSize; // size of the dataLen array
122 //----- coefficient data
123 int *coeffs;
124 char *touched; // coefficient 'touched' flags
125 Gushort len; // coefficient length
126 JArithmeticDecoder // arithmetic decoder
127 *arithDecoder;
128 JArithmeticDecoderStats // arithmetic decoder stats
129 *stats;
132 //------------------------------------------------------------------------
134 struct JPXSubband {
135 //----- computed
136 Guint x0, y0, x1, y1; // bounds
137 Guint nXCBs, nYCBs; // number of code-blocks in the x and y
138 // directions
140 //----- tag trees
141 Guint maxTTLevel; // max tag tree level
142 JPXTagTreeNode *inclusion; // inclusion tag tree for each subband
143 JPXTagTreeNode *zeroBitPlane; // zero-bit plane tag tree for each
144 // subband
146 //----- children
147 JPXCodeBlock *cbs; // the code-blocks (len = nXCBs * nYCBs)
150 //------------------------------------------------------------------------
152 struct JPXPrecinct {
153 //----- computed
154 Guint x0, y0, x1, y1; // bounds of the precinct
156 //----- children
157 JPXSubband *subbands; // the subbands
160 //------------------------------------------------------------------------
162 struct JPXResLevel {
163 //----- from the COD and COC segments (main and tile)
164 Guint precinctWidth; // log2(precinct width)
165 Guint precinctHeight; // log2(precinct height)
167 //----- computed
168 Guint x0, y0, x1, y1; // bounds of the tile-comp (for this res level)
169 Guint bx0[3], by0[3], // subband bounds
170 bx1[3], by1[3];
172 //---- children
173 JPXPrecinct *precincts; // the precincts
176 //------------------------------------------------------------------------
178 struct JPXTileComp {
179 //----- from the SIZ segment
180 GBool sgned; // 1 for signed, 0 for unsigned
181 Guint prec; // precision, in bits
182 Guint hSep; // horizontal separation of samples
183 Guint vSep; // vertical separation of samples
185 //----- from the COD and COC segments (main and tile)
186 Guint style; // coding style parameter (Scod / Scoc)
187 Guint nDecompLevels; // number of decomposition levels
188 Guint codeBlockW; // log2(code-block width)
189 Guint codeBlockH; // log2(code-block height)
190 Guint codeBlockStyle; // code-block style
191 Guint transform; // wavelet transformation
193 //----- from the QCD and QCC segments (main and tile)
194 Guint quantStyle; // quantization style
195 Guint *quantSteps; // quantization step size for each subband
196 Guint nQuantSteps; // number of entries in quantSteps
198 //----- computed
199 Guint x0, y0, x1, y1; // bounds of the tile-comp, in ref coords
200 Guint w; // x1 - x0
201 Guint cbW; // code-block width
202 Guint cbH; // code-block height
204 //----- image data
205 int *data; // the decoded image data
206 int *buf; // intermediate buffer for the inverse
207 // transform
209 //----- children
210 JPXResLevel *resLevels; // the resolution levels
211 // (len = nDecompLevels + 1)
214 //------------------------------------------------------------------------
216 struct JPXTile {
217 GBool init;
219 //----- from the COD segments (main and tile)
220 Guint progOrder; // progression order
221 Guint nLayers; // number of layers
222 Guint multiComp; // multiple component transformation
224 //----- computed
225 Guint x0, y0, x1, y1; // bounds of the tile, in ref coords
226 Guint maxNDecompLevels; // max number of decomposition levels used
227 // in any component in this tile
229 //----- progression order loop counters
230 Guint comp; // component
231 Guint res; // resolution level
232 Guint precinct; // precinct
233 Guint layer; // layer
235 //----- children
236 JPXTileComp *tileComps; // the tile-components (len = JPXImage.nComps)
239 //------------------------------------------------------------------------
241 struct JPXImage {
242 //----- from the SIZ segment
243 Guint xSize, ySize; // size of reference grid
244 Guint xOffset, yOffset; // image offset
245 Guint xTileSize, yTileSize; // size of tiles
246 Guint xTileOffset, // offset of first tile
247 yTileOffset;
248 Guint nComps; // number of components
250 //----- computed
251 Guint nXTiles; // number of tiles in x direction
252 Guint nYTiles; // number of tiles in y direction
254 //----- children
255 JPXTile *tiles; // the tiles (len = nXTiles * nYTiles)
258 //------------------------------------------------------------------------
260 class JPXStream: public FilterStream {
261 public:
263 JPXStream(Stream *strA);
264 virtual ~JPXStream();
265 virtual StreamKind getKind() { return strJPX; }
266 virtual void reset();
267 virtual void close();
268 virtual int getChar();
269 virtual int lookChar();
270 virtual GooString *getPSFilter(int psLevel, const char *indent);
271 virtual GBool isBinary(GBool last = gTrue);
272 virtual void getImageParams(int *bitsPerComponent,
273 StreamColorSpaceMode *csMode);
275 private:
277 void fillReadBuf();
278 void getImageParams2(int *bitsPerComponent, StreamColorSpaceMode *csMode);
279 GBool readBoxes();
280 GBool readColorSpecBox(Guint dataLen);
281 GBool readCodestream(Guint len);
282 GBool readTilePart();
283 GBool readTilePartData(Guint tileIdx,
284 Guint tilePartLen, GBool tilePartToEOC);
285 GBool readCodeBlockData(JPXTileComp *tileComp,
286 JPXResLevel *resLevel,
287 JPXPrecinct *precinct,
288 JPXSubband *subband,
289 Guint res, Guint sb,
290 JPXCodeBlock *cb);
291 void inverseTransform(JPXTileComp *tileComp);
292 void inverseTransformLevel(JPXTileComp *tileComp,
293 Guint r, JPXResLevel *resLevel);
294 void inverseTransform1D(JPXTileComp *tileComp, int *data,
295 Guint offset, Guint n);
296 GBool inverseMultiCompAndDC(JPXTile *tile);
297 GBool readBoxHdr(Guint *boxType, Guint *boxLen, Guint *dataLen);
298 int readMarkerHdr(int *segType, Guint *segLen);
299 GBool readUByte(Guint *x);
300 GBool readByte(int *x);
301 GBool readUWord(Guint *x);
302 GBool readULong(Guint *x);
303 GBool readNBytes(int nBytes, GBool signd, int *x);
304 void startBitBuf(Guint byteCountA);
305 GBool readBits(int nBits, Guint *x);
306 void skipSOP();
307 void skipEPH();
308 Guint finishBitBuf();
310 BufStream *bufStr; // buffered stream (for lookahead)
312 Guint nComps; // number of components
313 Guint *bpc; // bits per component, for each component
314 Guint width, height; // image size
315 GBool haveImgHdr; // set if a JP2/JPX image header has been
316 // found
317 JPXColorSpec cs; // color specification
318 GBool haveCS; // set if a color spec has been found
319 JPXPalette palette; // the palette
320 GBool havePalette; // set if a palette has been found
321 JPXCompMap compMap; // the component mapping
322 GBool haveCompMap; // set if a component mapping has been found
323 JPXChannelDefn channelDefn; // channel definition
324 GBool haveChannelDefn; // set if a channel defn has been found
326 JPXImage img; // JPEG2000 decoder data
327 Guint bitBuf; // buffer for bit reads
328 int bitBufLen; // number of bits in bitBuf
329 GBool bitBufSkip; // true if next bit should be skipped
330 // (for bit stuffing)
331 Guint byteCount; // number of available bytes left
333 Guint curX, curY, curComp; // current position for lookChar/getChar
334 Guint readBuf; // read buffer
335 Guint readBufLen; // number of valid bits in readBuf
338 #endif