source: trunk/poppler/mypoppler/poppler/JPXStream.h @ 2

Last change on this file since 2 was 2, checked in by Eugene Romanenko, 16 years ago

First import

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