File indexing completed on 2025-12-10 10:23:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #ifndef JPXSTREAM_H
0024 #define JPXSTREAM_H
0025
0026 #include "Object.h"
0027 #include "Stream.h"
0028
0029 class JArithmeticDecoder;
0030 class JArithmeticDecoderStats;
0031
0032
0033
0034 enum JPXColorSpaceType
0035 {
0036 jpxCSBiLevel = 0,
0037 jpxCSYCbCr1 = 1,
0038 jpxCSYCbCr2 = 3,
0039 jpxCSYCBCr3 = 4,
0040 jpxCSPhotoYCC = 9,
0041 jpxCSCMY = 11,
0042 jpxCSCMYK = 12,
0043 jpxCSYCCK = 13,
0044 jpxCSCIELab = 14,
0045 jpxCSsRGB = 16,
0046 jpxCSGrayscale = 17,
0047 jpxCSBiLevel2 = 18,
0048 jpxCSCIEJab = 19,
0049 jpxCSCISesRGB = 20,
0050 jpxCSROMMRGB = 21,
0051 jpxCSsRGBYCbCr = 22,
0052 jpxCSYPbPr1125 = 23,
0053 jpxCSYPbPr1250 = 24
0054 };
0055
0056 struct JPXColorSpecCIELab
0057 {
0058 unsigned int rl, ol, ra, oa, rb, ob, il;
0059 };
0060
0061 struct JPXColorSpecEnumerated
0062 {
0063 JPXColorSpaceType type;
0064 union {
0065 JPXColorSpecCIELab cieLab;
0066 };
0067 };
0068
0069 struct JPXColorSpec
0070 {
0071 unsigned int meth;
0072 int prec;
0073 union {
0074 JPXColorSpecEnumerated enumerated;
0075 };
0076 };
0077
0078
0079
0080 struct JPXPalette
0081 {
0082 unsigned int nEntries;
0083 unsigned int nComps;
0084 unsigned int *bpc;
0085 int *c;
0086
0087 };
0088
0089
0090
0091 struct JPXCompMap
0092 {
0093 unsigned int nChannels;
0094 unsigned int *comp;
0095 unsigned int *type;
0096 unsigned int *pComp;
0097 };
0098
0099
0100
0101 struct JPXChannelDefn
0102 {
0103 unsigned int nChannels;
0104 unsigned int *idx;
0105 unsigned int *type;
0106 unsigned int *assoc;
0107 };
0108
0109
0110
0111 struct JPXTagTreeNode
0112 {
0113 bool finished;
0114 unsigned int val;
0115 };
0116
0117
0118
0119 struct JPXCodeBlock
0120 {
0121
0122 unsigned int x0, y0, x1, y1;
0123
0124
0125 bool seen;
0126
0127 unsigned int lBlock;
0128 unsigned int nextPass;
0129
0130
0131 unsigned int nZeroBitPlanes;
0132
0133
0134 unsigned int included;
0135
0136 unsigned int nCodingPasses;
0137 unsigned int *dataLen;
0138 unsigned int dataLenSize;
0139
0140
0141 int *coeffs;
0142 char *touched;
0143 unsigned short len;
0144 JArithmeticDecoder
0145 *arithDecoder;
0146 JArithmeticDecoderStats
0147 *stats;
0148 };
0149
0150
0151
0152 struct JPXSubband
0153 {
0154
0155 unsigned int x0, y0, x1, y1;
0156 unsigned int nXCBs, nYCBs;
0157
0158
0159
0160 unsigned int maxTTLevel;
0161 JPXTagTreeNode *inclusion;
0162 JPXTagTreeNode *zeroBitPlane;
0163
0164
0165
0166 JPXCodeBlock *cbs;
0167 };
0168
0169
0170
0171 struct JPXPrecinct
0172 {
0173
0174 unsigned int x0, y0, x1, y1;
0175
0176
0177 JPXSubband *subbands;
0178 };
0179
0180
0181
0182 struct JPXResLevel
0183 {
0184
0185 unsigned int precinctWidth;
0186 unsigned int precinctHeight;
0187
0188
0189 unsigned int x0, y0, x1, y1;
0190 unsigned int bx0[3], by0[3],
0191 bx1[3], by1[3];
0192
0193
0194 JPXPrecinct *precincts;
0195 };
0196
0197
0198
0199 struct JPXTileComp
0200 {
0201
0202 bool sgned;
0203 unsigned int prec;
0204 unsigned int hSep;
0205 unsigned int vSep;
0206
0207
0208 unsigned int style;
0209 unsigned int nDecompLevels;
0210 unsigned int codeBlockW;
0211 unsigned int codeBlockH;
0212 unsigned int codeBlockStyle;
0213 unsigned int transform;
0214
0215
0216 unsigned int quantStyle;
0217 unsigned int *quantSteps;
0218 unsigned int nQuantSteps;
0219
0220
0221 unsigned int x0, y0, x1, y1;
0222 unsigned int w;
0223 unsigned int cbW;
0224 unsigned int cbH;
0225
0226
0227 int *data;
0228 int *buf;
0229
0230
0231
0232 JPXResLevel *resLevels;
0233
0234 };
0235
0236
0237
0238 struct JPXTile
0239 {
0240 bool init;
0241
0242
0243 unsigned int progOrder;
0244 unsigned int nLayers;
0245 unsigned int multiComp;
0246
0247
0248 unsigned int x0, y0, x1, y1;
0249 unsigned int maxNDecompLevels;
0250
0251
0252
0253 unsigned int comp;
0254 unsigned int res;
0255 unsigned int precinct;
0256 unsigned int layer;
0257
0258
0259 JPXTileComp *tileComps;
0260 };
0261
0262
0263
0264 struct JPXImage
0265 {
0266
0267 unsigned int xSize, ySize;
0268 unsigned int xOffset, yOffset;
0269 unsigned int xTileSize, yTileSize;
0270 unsigned int xTileOffset,
0271 yTileOffset;
0272 unsigned int nComps;
0273
0274
0275 unsigned int nXTiles;
0276 unsigned int nYTiles;
0277
0278
0279 JPXTile *tiles;
0280 };
0281
0282
0283
0284 class JPXStream : public FilterStream
0285 {
0286 public:
0287 JPXStream(Stream *strA);
0288 virtual ~JPXStream();
0289 StreamKind getKind() const override { return strJPX; }
0290 void reset() override;
0291 void close() override;
0292 int getChar() override;
0293 int lookChar() override;
0294 GooString *getPSFilter(int psLevel, const char *indent) override;
0295 bool isBinary(bool last = true) const override;
0296 void getImageParams(int *bitsPerComponent, StreamColorSpaceMode *csMode) override;
0297
0298 private:
0299 void fillReadBuf();
0300 void getImageParams2(int *bitsPerComponent, StreamColorSpaceMode *csMode);
0301 bool readBoxes();
0302 bool readColorSpecBox(unsigned int dataLen);
0303 bool readCodestream(unsigned int len);
0304 bool readTilePart();
0305 bool readTilePartData(unsigned int tileIdx, unsigned int tilePartLen, bool tilePartToEOC);
0306 bool readCodeBlockData(JPXTileComp *tileComp, JPXResLevel *resLevel, JPXPrecinct *precinct, JPXSubband *subband, unsigned int res, unsigned int sb, JPXCodeBlock *cb);
0307 void inverseTransform(JPXTileComp *tileComp);
0308 void inverseTransformLevel(JPXTileComp *tileComp, unsigned int r, JPXResLevel *resLevel);
0309 void inverseTransform1D(JPXTileComp *tileComp, int *data, unsigned int offset, unsigned int n);
0310 bool inverseMultiCompAndDC(JPXTile *tile);
0311 bool readBoxHdr(unsigned int *boxType, unsigned int *boxLen, unsigned int *dataLen);
0312 int readMarkerHdr(int *segType, unsigned int *segLen);
0313 bool readUByte(unsigned int *x);
0314 bool readByte(int *x);
0315 bool readUWord(unsigned int *x);
0316 bool readULong(unsigned int *x);
0317 bool readNBytes(int nBytes, bool signd, int *x);
0318 void startBitBuf(unsigned int byteCountA);
0319 bool readBits(int nBits, unsigned int *x);
0320 void skipSOP();
0321 void skipEPH();
0322 unsigned int finishBitBuf();
0323
0324 BufStream *bufStr;
0325
0326 unsigned int nComps;
0327 unsigned int *bpc;
0328 unsigned int width, height;
0329 bool haveImgHdr;
0330
0331 JPXColorSpec cs;
0332 bool haveCS;
0333 JPXPalette palette;
0334 bool havePalette;
0335 JPXCompMap compMap;
0336 bool haveCompMap;
0337 JPXChannelDefn channelDefn;
0338 bool haveChannelDefn;
0339
0340 JPXImage img;
0341 unsigned int bitBuf;
0342 int bitBufLen;
0343 bool bitBufSkip;
0344
0345 unsigned int byteCount;
0346
0347 unsigned int curX, curY, curComp;
0348 unsigned int readBuf;
0349 unsigned int readBufLen;
0350 };
0351
0352 #endif