Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

JPXStream.h

Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // JPXStream.h
00004 //
00005 // Copyright 2002-2003 Glyph & Cog, LLC
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;                   // method
00049   int prec;                     // precedence
00050   union {
00051     struct {
00052       JPXColorSpaceType type;   // color space 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;               // number of entries in the palette
00066   Guint nComps;                 // number of components in each entry
00067   Guint *bpc;                   // bits per component, for each component
00068   int *c;                       // color data:
00069                                 //   c[i*nComps+j] = entry i, component j
00070 };
00071 
00072 //------------------------------------------------------------------------
00073 
00074 struct JPXCompMap {
00075   Guint nChannels;              // number of channels
00076   Guint *comp;                  // codestream components mapped to each channel
00077   Guint *type;                  // 0 for direct use, 1 for palette mapping
00078   Guint *pComp;                 // palette components to use
00079 };
00080 
00081 //------------------------------------------------------------------------
00082 
00083 struct JPXChannelDefn {
00084   Guint nChannels;              // number of channels
00085   Guint *idx;                   // channel indexes
00086   Guint *type;                  // channel types
00087   Guint *assoc;                 // channel associations
00088 };
00089 
00090 //------------------------------------------------------------------------
00091 
00092 struct JPXTagTreeNode {
00093   GBool finished;               // true if this node is finished
00094   Guint val;                    // current value
00095 };
00096 
00097 //------------------------------------------------------------------------
00098 
00099 struct JPXCoeff {
00100   Gushort flags;                // flag bits
00101   Gushort len;                  // number of significant bits in mag
00102   Guint mag;                    // magnitude value
00103 };
00104 
00105 // coefficient flags
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   //----- size
00119   Guint x0, y0, x1, y1;         // bounds
00120 
00121   //----- persistent state
00122   GBool seen;                   // true if this code-block has already
00123                                 //   been seen
00124   Guint lBlock;                 // base number of bits used for pkt data length
00125   Guint nextPass;               // next coding pass
00126 
00127   //---- info from first packet
00128   Guint nZeroBitPlanes;         // number of zero bit planes
00129 
00130   //----- info for the current packet
00131   Guint included;               // code-block inclusion in this packet:
00132                                 //   0=not included, 1=included
00133   Guint nCodingPasses;          // number of coding passes in this pkt
00134   Guint dataLen;                // pkt data length
00135 
00136   //----- coefficient data
00137   JPXCoeff *coeffs;             // the coefficients
00138   JArithmeticDecoderStats       // arithmetic decoder stats
00139     *stats;
00140 };
00141 
00142 //------------------------------------------------------------------------
00143 
00144 struct JPXSubband {
00145   //----- computed
00146   Guint x0, y0, x1, y1;         // bounds
00147   Guint nXCBs, nYCBs;           // number of code-blocks in the x and y
00148                                 //   directions
00149 
00150   //----- tag trees
00151   Guint maxTTLevel;             // max tag tree level
00152   JPXTagTreeNode *inclusion;    // inclusion tag tree for each subband
00153   JPXTagTreeNode *zeroBitPlane; // zero-bit plane tag tree for each
00154                                 //   subband
00155 
00156   //----- children
00157   JPXCodeBlock *cbs;            // the code-blocks (len = nXCBs * nYCBs)
00158 };
00159 
00160 //------------------------------------------------------------------------
00161 
00162 struct JPXPrecinct {
00163   //----- computed
00164   Guint x0, y0, x1, y1;         // bounds of the precinct
00165 
00166   //----- children
00167   JPXSubband *subbands;         // the subbands
00168 };
00169 
00170 //------------------------------------------------------------------------
00171 
00172 struct JPXResLevel {
00173   //----- from the COD and COC segments (main and tile)
00174   Guint precinctWidth;          // log2(precinct width)
00175   Guint precinctHeight;         // log2(precinct height)
00176 
00177   //----- computed
00178   Guint x0, y0, x1, y1;         // bounds of the tile-comp (for this res level)
00179   Guint bx0[3], by0[3],         // subband bounds
00180         bx1[3], by1[3];
00181 
00182   //---- children
00183   JPXPrecinct *precincts;       // the precincts
00184 };
00185 
00186 //------------------------------------------------------------------------
00187 
00188 struct JPXTileComp {
00189   //----- from the SIZ segment
00190   GBool sgned;                  // 1 for signed, 0 for unsigned
00191   Guint prec;                   // precision, in bits
00192   Guint hSep;                   // horizontal separation of samples
00193   Guint vSep;                   // vertical separation of samples
00194 
00195   //----- from the COD and COC segments (main and tile)
00196   Guint style;                  // coding style parameter (Scod / Scoc)
00197   Guint nDecompLevels;          // number of decomposition levels
00198   Guint codeBlockW;             // log2(code-block width)
00199   Guint codeBlockH;             // log2(code-block height)
00200   Guint codeBlockStyle;         // code-block style
00201   Guint transform;              // wavelet transformation
00202 
00203   //----- from the QCD and QCC segments (main and tile)
00204   Guint quantStyle;             // quantization style
00205   Guint *quantSteps;            // quantization step size for each subband
00206   Guint nQuantSteps;            // number of entries in quantSteps
00207 
00208   //----- computed
00209   Guint x0, y0, x1, y1;         // bounds of the tile-comp, in ref coords
00210   Guint cbW;                    // code-block width
00211   Guint cbH;                    // code-block height
00212 
00213   //----- image data
00214   int *data;                    // the decoded image data
00215   int *buf;                     // intermediate buffer for the inverse
00216                                 //   transform
00217 
00218   //----- children
00219   JPXResLevel *resLevels;       // the resolution levels
00220                                 //   (len = nDecompLevels + 1)
00221 };
00222 
00223 //------------------------------------------------------------------------
00224 
00225 struct JPXTile {
00226   //----- from the COD segments (main and tile)
00227   Guint progOrder;              // progression order
00228   Guint nLayers;                // number of layers
00229   Guint multiComp;              // multiple component transformation
00230 
00231   //----- computed
00232   Guint x0, y0, x1, y1;         // bounds of the tile, in ref coords
00233   Guint maxNDecompLevels;       // max number of decomposition levels used
00234                                 //   in any component in this tile
00235 
00236   //----- progression order loop counters
00237   Guint comp;                   //   component
00238   Guint res;                    //   resolution level
00239   Guint precinct;               //   precinct
00240   Guint layer;                  //   layer
00241 
00242   //----- children
00243   JPXTileComp *tileComps;       // the tile-components (len = JPXImage.nComps)
00244 };
00245 
00246 //------------------------------------------------------------------------
00247 
00248 struct JPXImage {
00249   //----- from the SIZ segment
00250   Guint xSize, ySize;           // size of reference grid
00251   Guint xOffset, yOffset;       // image offset
00252   Guint xTileSize, yTileSize;   // size of tiles
00253   Guint xTileOffset,            // offset of first tile
00254         yTileOffset;
00255   Guint nComps;                 // number of components
00256 
00257   //----- computed
00258   Guint nXTiles;                // number of tiles in x direction
00259   Guint nYTiles;                // number of tiles in y direction
00260 
00261   //----- children
00262   JPXTile *tiles;               // the tiles (len = nXTiles * nYTiles)
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;                 // number of components
00314   Guint *bpc;                   // bits per component, for each component
00315   Guint width, height;          // image size
00316   GBool haveImgHdr;             // set if a JP2/JPX image header has been
00317                                 //   found
00318   JPXColorSpec cs;              // color specification
00319   GBool haveCS;                 // set if a color spec has been found
00320   JPXPalette palette;           // the palette
00321   GBool havePalette;            // set if a palette has been found
00322   JPXCompMap compMap;           // the component mapping
00323   GBool haveCompMap;            // set if a component mapping has been found
00324   JPXChannelDefn channelDefn;   // channel definition
00325   GBool haveChannelDefn;        // set if a channel defn has been found
00326 
00327   JPXImage img;                 // JPEG2000 decoder data
00328   Guint bitBuf;                 // buffer for bit reads
00329   int bitBufLen;                // number of bits in bitBuf
00330   GBool bitBufSkip;             // true if next bit should be skipped
00331                                 //   (for bit stuffing)
00332   Guint byteCount;              // number of bytes read since last call
00333                                 //   to clearBitBuf
00334 
00335   Guint curX, curY, curComp;    // current position for lookChar/getChar
00336   Guint readBuf;                // read buffer
00337   Guint readBufLen;             // number of valid bits in readBuf
00338 };
00339 
00340 #endif

Generated on Wed Nov 3 12:58:59 2004 for Lemur Toolkit by doxygen1.2.18