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

Last change on this file since 257 was 250, checked in by Eugene Romanenko, 13 years ago

PDF plugin: poppler library updated to version 0.8.3

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