00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef JPXSTREAM_H
00010 #define JPXSTREAM_H
00011
00012 #include <aconf.h>
00013
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017
00018 #include "gtypes.h"
00019 #include "Object.h"
00020 #include "Stream.h"
00021
00022 class JArithmeticDecoderStats;
00023
00024
00025
00026 enum JPXColorSpaceType {
00027 jpxCSBiLevel = 0,
00028 jpxCSYCbCr1 = 1,
00029 jpxCSYCbCr2 = 3,
00030 jpxCSYCBCr3 = 4,
00031 jpxCSPhotoYCC = 9,
00032 jpxCSCMY = 11,
00033 jpxCSCMYK = 12,
00034 jpxCSYCCK = 13,
00035 jpxCSCIELab = 14,
00036 jpxCSsRGB = 16,
00037 jpxCSGrayscale = 17,
00038 jpxCSBiLevel2 = 18,
00039 jpxCSCIEJab = 19,
00040 jpxCSCISesRGB = 20,
00041 jpxCSROMMRGB = 21,
00042 jpxCSsRGBYCbCr = 22,
00043 jpxCSYPbPr1125 = 23,
00044 jpxCSYPbPr1250 = 24
00045 };
00046
00047 struct JPXColorSpec {
00048 Guint meth;
00049 int prec;
00050 union {
00051 struct {
00052 JPXColorSpaceType type;
00053 union {
00054 struct {
00055 Guint rl, ol, ra, oa, rb, ob, il;
00056 } cieLab;
00057 };
00058 } enumerated;
00059 };
00060 };
00061
00062
00063
00064 struct JPXPalette {
00065 Guint nEntries;
00066 Guint nComps;
00067 Guint *bpc;
00068 int *c;
00069
00070 };
00071
00072
00073
00074 struct JPXCompMap {
00075 Guint nChannels;
00076 Guint *comp;
00077 Guint *type;
00078 Guint *pComp;
00079 };
00080
00081
00082
00083 struct JPXChannelDefn {
00084 Guint nChannels;
00085 Guint *idx;
00086 Guint *type;
00087 Guint *assoc;
00088 };
00089
00090
00091
00092 struct JPXTagTreeNode {
00093 GBool finished;
00094 Guint val;
00095 };
00096
00097
00098
00099 struct JPXCoeff {
00100 Gushort flags;
00101 Gushort len;
00102 Guint mag;
00103 };
00104
00105
00106 #define jpxCoeffSignificantB 0
00107 #define jpxCoeffTouchedB 1
00108 #define jpxCoeffFirstMagRefB 2
00109 #define jpxCoeffSignB 7
00110 #define jpxCoeffSignificant (1 << jpxCoeffSignificantB)
00111 #define jpxCoeffTouched (1 << jpxCoeffTouchedB)
00112 #define jpxCoeffFirstMagRef (1 << jpxCoeffFirstMagRefB)
00113 #define jpxCoeffSign (1 << jpxCoeffSignB)
00114
00115
00116
00117 struct JPXCodeBlock {
00118
00119 Guint x0, y0, x1, y1;
00120
00121
00122 GBool seen;
00123
00124 Guint lBlock;
00125 Guint nextPass;
00126
00127
00128 Guint nZeroBitPlanes;
00129
00130
00131 Guint included;
00132
00133 Guint nCodingPasses;
00134 Guint dataLen;
00135
00136
00137 JPXCoeff *coeffs;
00138 JArithmeticDecoderStats
00139 *stats;
00140 };
00141
00142
00143
00144 struct JPXSubband {
00145
00146 Guint x0, y0, x1, y1;
00147 Guint nXCBs, nYCBs;
00148
00149
00150
00151 Guint maxTTLevel;
00152 JPXTagTreeNode *inclusion;
00153 JPXTagTreeNode *zeroBitPlane;
00154
00155
00156
00157 JPXCodeBlock *cbs;
00158 };
00159
00160
00161
00162 struct JPXPrecinct {
00163
00164 Guint x0, y0, x1, y1;
00165
00166
00167 JPXSubband *subbands;
00168 };
00169
00170
00171
00172 struct JPXResLevel {
00173
00174 Guint precinctWidth;
00175 Guint precinctHeight;
00176
00177
00178 Guint x0, y0, x1, y1;
00179 Guint bx0[3], by0[3],
00180 bx1[3], by1[3];
00181
00182
00183 JPXPrecinct *precincts;
00184 };
00185
00186
00187
00188 struct JPXTileComp {
00189
00190 GBool sgned;
00191 Guint prec;
00192 Guint hSep;
00193 Guint vSep;
00194
00195
00196 Guint style;
00197 Guint nDecompLevels;
00198 Guint codeBlockW;
00199 Guint codeBlockH;
00200 Guint codeBlockStyle;
00201 Guint transform;
00202
00203
00204 Guint quantStyle;
00205 Guint *quantSteps;
00206 Guint nQuantSteps;
00207
00208
00209 Guint x0, y0, x1, y1;
00210 Guint cbW;
00211 Guint cbH;
00212
00213
00214 int *data;
00215 int *buf;
00216
00217
00218
00219 JPXResLevel *resLevels;
00220
00221 };
00222
00223
00224
00225 struct JPXTile {
00226
00227 Guint progOrder;
00228 Guint nLayers;
00229 Guint multiComp;
00230
00231
00232 Guint x0, y0, x1, y1;
00233 Guint maxNDecompLevels;
00234
00235
00236
00237 Guint comp;
00238 Guint res;
00239 Guint precinct;
00240 Guint layer;
00241
00242
00243 JPXTileComp *tileComps;
00244 };
00245
00246
00247
00248 struct JPXImage {
00249
00250 Guint xSize, ySize;
00251 Guint xOffset, yOffset;
00252 Guint xTileSize, yTileSize;
00253 Guint xTileOffset,
00254 yTileOffset;
00255 Guint nComps;
00256
00257
00258 Guint nXTiles;
00259 Guint nYTiles;
00260
00261
00262 JPXTile *tiles;
00263 };
00264
00265
00266
00267 class JPXStream: public FilterStream {
00268 public:
00269
00270 JPXStream(Stream *strA);
00271 virtual ~JPXStream();
00272 virtual StreamKind getKind() { return strJPX; }
00273 virtual void reset();
00274 virtual int getChar();
00275 virtual int lookChar();
00276 virtual GString *getPSFilter(int psLevel, char *indent);
00277 virtual GBool isBinary(GBool last = gTrue);
00278
00279 private:
00280
00281 void fillReadBuf();
00282 GBool readBoxes();
00283 GBool readColorSpecBox(Guint dataLen);
00284 GBool readCodestream(Guint len);
00285 GBool readTilePart();
00286 GBool readTilePartData(Guint tileIdx,
00287 Guint tilePartLen, GBool tilePartToEOC);
00288 GBool readCodeBlockData(JPXTileComp *tileComp,
00289 JPXResLevel *resLevel,
00290 JPXPrecinct *precinct,
00291 JPXSubband *subband,
00292 Guint res, Guint sb,
00293 JPXCodeBlock *cb);
00294 void inverseTransform(JPXTileComp *tileComp);
00295 void inverseTransformLevel(JPXTileComp *tileComp,
00296 Guint r, JPXResLevel *resLevel,
00297 Guint nx0, Guint ny0,
00298 Guint nx1, Guint ny1);
00299 void inverseTransform1D(JPXTileComp *tileComp,
00300 int *data, Guint stride,
00301 Guint i0, Guint i1);
00302 GBool inverseMultiCompAndDC(JPXTile *tile);
00303 GBool readBoxHdr(Guint *boxType, Guint *boxLen, Guint *dataLen);
00304 int readMarkerHdr(int *segType, Guint *segLen);
00305 GBool readUByte(Guint *x);
00306 GBool readByte(int *x);
00307 GBool readUWord(Guint *x);
00308 GBool readULong(Guint *x);
00309 GBool readNBytes(int nBytes, GBool signd, int *x);
00310 GBool readBits(int nBits, Guint *x);
00311 void clearBitBuf();
00312
00313 Guint nComps;
00314 Guint *bpc;
00315 Guint width, height;
00316 GBool haveImgHdr;
00317
00318 JPXColorSpec cs;
00319 GBool haveCS;
00320 JPXPalette palette;
00321 GBool havePalette;
00322 JPXCompMap compMap;
00323 GBool haveCompMap;
00324 JPXChannelDefn channelDefn;
00325 GBool haveChannelDefn;
00326
00327 JPXImage img;
00328 Guint bitBuf;
00329 int bitBufLen;
00330 GBool bitBufSkip;
00331
00332 Guint byteCount;
00333
00334
00335 Guint curX, curY, curComp;
00336 Guint readBuf;
00337 Guint readBufLen;
00338 };
00339
00340 #endif