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

Stream.h

Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // Stream.h
00004 //
00005 // Copyright 1996-2003 Glyph & Cog, LLC
00006 //
00007 //========================================================================
00008 
00009 #ifndef STREAM_H
00010 #define STREAM_H
00011 
00012 #include <aconf.h>
00013 
00014 #ifdef USE_GCC_PRAGMAS
00015 #pragma interface
00016 #endif
00017 
00018 #include <stdio.h>
00019 #include "gtypes.h"
00020 #include "Object.h"
00021 
00022 #ifndef NO_DECRYPTION
00023 class Decrypt;
00024 #endif
00025 class BaseStream;
00026 
00027 //------------------------------------------------------------------------
00028 
00029 enum StreamKind {
00030   strFile,
00031   strASCIIHex,
00032   strASCII85,
00033   strLZW,
00034   strRunLength,
00035   strCCITTFax,
00036   strDCT,
00037   strFlate,
00038   strJBIG2,
00039   strJPX,
00040   strWeird                      // internal-use stream types
00041 };
00042 
00043 //------------------------------------------------------------------------
00044 // Stream (base class)
00045 //------------------------------------------------------------------------
00046 
00047 class Stream {
00048 public:
00049 
00050   // Constructor.
00051   Stream();
00052 
00053   // Destructor.
00054   virtual ~Stream();
00055 
00056   // Reference counting.
00057   int incRef() { return ++ref; }
00058   int decRef() { return --ref; }
00059 
00060   // Get kind of stream.
00061   virtual StreamKind getKind() = 0;
00062 
00063   // Reset stream to beginning.
00064   virtual void reset() = 0;
00065 
00066   // Close down the stream.
00067   virtual void close();
00068 
00069   // Get next char from stream.
00070   virtual int getChar() = 0;
00071 
00072   // Peek at next char in stream.
00073   virtual int lookChar() = 0;
00074 
00075   // Get next char from stream without using the predictor.
00076   // This is only used by StreamPredictor.
00077   virtual int getRawChar();
00078 
00079   // Get next line from stream.
00080   virtual char *getLine(char *buf, int size);
00081 
00082   // Get current position in file.
00083   virtual int getPos() = 0;
00084 
00085   // Go to a position in the stream.  If <dir> is negative, the
00086   // position is from the end of the file; otherwise the position is
00087   // from the start of the file.
00088   virtual void setPos(Guint pos, int dir = 0) = 0;
00089 
00090   // Get PostScript command for the filter(s).
00091   virtual GString *getPSFilter(int psLevel, char *indent);
00092 
00093   // Does this stream type potentially contain non-printable chars?
00094   virtual GBool isBinary(GBool last = gTrue) = 0;
00095 
00096   // Get the BaseStream of this stream.
00097   virtual BaseStream *getBaseStream() = 0;
00098 
00099   // Get the dictionary associated with this stream.
00100   virtual Dict *getDict() = 0;
00101 
00102   // Is this an encoding filter?
00103   virtual GBool isEncoder() { return gFalse; }
00104 
00105   // Add filters to this stream according to the parameters in <dict>.
00106   // Returns the new stream.
00107   Stream *addFilters(Object *dict);
00108 
00109   // Tell this stream to ignore any length limitation -- this only
00110   // applies to BaseStream subclasses, and is used as a hack to work
00111   // around broken PDF files with incorrect stream lengths.
00112   virtual void ignoreLength() {}
00113 
00114 private:
00115 
00116   Stream *makeFilter(char *name, Stream *str, Object *params);
00117 
00118   int ref;                      // reference count
00119 };
00120 
00121 //------------------------------------------------------------------------
00122 // BaseStream
00123 //
00124 // This is the base class for all streams that read directly from a file.
00125 //------------------------------------------------------------------------
00126 
00127 class BaseStream: public Stream {
00128 public:
00129 
00130   BaseStream(Object *dictA);
00131   virtual ~BaseStream();
00132   virtual Stream *makeSubStream(Guint start, GBool limited,
00133                                 Guint length, Object *dict) = 0;
00134   virtual void setPos(Guint pos, int dir = 0) = 0;
00135   virtual GBool isBinary(GBool last = gTrue) { return last; }
00136   virtual BaseStream *getBaseStream() { return this; }
00137   virtual Dict *getDict() { return dict.getDict(); }
00138 
00139   // Get/set position of first byte of stream within the file.
00140   virtual Guint getStart() = 0;
00141   virtual void moveStart(int delta) = 0;
00142 
00143 #ifndef NO_DECRYPTION
00144   // Set decryption for this stream.
00145   virtual void doDecryption(Guchar *fileKey, int keyLength,
00146                             int objNum, int objGen);
00147 #endif
00148 
00149 #ifndef NO_DECRYPTION
00150 protected:
00151 
00152   Decrypt *decrypt;
00153 #endif
00154 
00155 private:
00156 
00157   Object dict;
00158 };
00159 
00160 //------------------------------------------------------------------------
00161 // FilterStream
00162 //
00163 // This is the base class for all streams that filter another stream.
00164 //------------------------------------------------------------------------
00165 
00166 class FilterStream: public Stream {
00167 public:
00168 
00169   FilterStream(Stream *strA);
00170   virtual ~FilterStream();
00171   virtual void close();
00172   virtual int getPos() { return str->getPos(); }
00173   virtual void setPos(Guint pos, int dir = 0);
00174   virtual BaseStream *getBaseStream() { return str->getBaseStream(); }
00175   virtual Dict *getDict() { return str->getDict(); }
00176   virtual void ignoreLength() { str->ignoreLength(); }
00177 
00178 protected:
00179 
00180   Stream *str;
00181 };
00182 
00183 //------------------------------------------------------------------------
00184 // ImageStream
00185 //------------------------------------------------------------------------
00186 
00187 class ImageStream {
00188 public:
00189 
00190   // Create an image stream object for an image with the specified
00191   // parameters.  Note that these are the actual image parameters,
00192   // which may be different from the predictor parameters.
00193   ImageStream(Stream *strA, int widthA, int nCompsA, int nBitsA);
00194 
00195   ~ImageStream();
00196 
00197   // Reset the stream.
00198   void reset();
00199 
00200   // Gets the next pixel from the stream.  <pix> should be able to hold
00201   // at least nComps elements.  Returns false at end of file.
00202   GBool getPixel(Guchar *pix);
00203 
00204   // Returns a pointer to the next line of pixels.  Returns NULL at
00205   // end of file.
00206   Guchar *getLine();
00207 
00208   // Skip an entire line from the image.
00209   void skipLine();
00210 
00211 private:
00212 
00213   Stream *str;                  // base stream
00214   int width;                    // pixels per line
00215   int nComps;                   // components per pixel
00216   int nBits;                    // bits per component
00217   int nVals;                    // components per line
00218   Guchar *imgLine;              // line buffer
00219   int imgIdx;                   // current index in imgLine
00220 };
00221 
00222 //------------------------------------------------------------------------
00223 // StreamPredictor
00224 //------------------------------------------------------------------------
00225 
00226 class StreamPredictor {
00227 public:
00228 
00229   // Create a predictor object.  Note that the parameters are for the
00230   // predictor, and may not match the actual image parameters.
00231   StreamPredictor(Stream *strA, int predictorA,
00232                   int widthA, int nCompsA, int nBitsA);
00233 
00234   ~StreamPredictor();
00235 
00236   int lookChar();
00237   int getChar();
00238 
00239 private:
00240 
00241   GBool getNextLine();
00242 
00243   Stream *str;                  // base stream
00244   int predictor;                // predictor
00245   int width;                    // pixels per line
00246   int nComps;                   // components per pixel
00247   int nBits;                    // bits per component
00248   int nVals;                    // components per line
00249   int pixBytes;                 // bytes per pixel
00250   int rowBytes;                 // bytes per line
00251   Guchar *predLine;             // line buffer
00252   int predIdx;                  // current index in predLine
00253 };
00254 
00255 //------------------------------------------------------------------------
00256 // FileStream
00257 //------------------------------------------------------------------------
00258 
00259 #define fileStreamBufSize 256
00260 
00261 class FileStream: public BaseStream {
00262 public:
00263 
00264   FileStream(FILE *fA, Guint startA, GBool limitedA,
00265              Guint lengthA, Object *dictA);
00266   virtual ~FileStream();
00267   virtual Stream *makeSubStream(Guint startA, GBool limitedA,
00268                                 Guint lengthA, Object *dictA);
00269   virtual StreamKind getKind() { return strFile; }
00270   virtual void reset();
00271   virtual void close();
00272   virtual int getChar()
00273     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
00274   virtual int lookChar()
00275     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
00276   virtual int getPos() { return bufPos + (bufPtr - buf); }
00277   virtual void setPos(Guint pos, int dir = 0);
00278   virtual void ignoreLength() { limited = gFalse; }
00279   virtual Guint getStart() { return start; }
00280   virtual void moveStart(int delta);
00281 
00282 private:
00283 
00284   GBool fillBuf();
00285 
00286   FILE *f;
00287   Guint start;
00288   GBool limited;
00289   Guint length;
00290   char buf[fileStreamBufSize];
00291   char *bufPtr;
00292   char *bufEnd;
00293   Guint bufPos;
00294   int savePos;
00295   GBool saved;
00296 };
00297 
00298 //------------------------------------------------------------------------
00299 // MemStream
00300 //------------------------------------------------------------------------
00301 
00302 class MemStream: public BaseStream {
00303 public:
00304 
00305   MemStream(char *bufA, Guint startA, Guint lengthA, Object *dictA);
00306   virtual ~MemStream();
00307   virtual Stream *makeSubStream(Guint start, GBool limited,
00308                                 Guint lengthA, Object *dictA);
00309   virtual StreamKind getKind() { return strWeird; }
00310   virtual void reset();
00311   virtual void close();
00312   virtual int getChar()
00313     { return (bufPtr < bufEnd) ? (*bufPtr++ & 0xff) : EOF; }
00314   virtual int lookChar()
00315     { return (bufPtr < bufEnd) ? (*bufPtr & 0xff) : EOF; }
00316   virtual int getPos() { return (int)(bufPtr - buf); }
00317   virtual void setPos(Guint pos, int dir = 0);
00318   virtual Guint getStart() { return start; }
00319   virtual void moveStart(int delta);
00320 #ifndef NO_DECRYPTION
00321   virtual void doDecryption(Guchar *fileKey, int keyLength,
00322                             int objNum, int objGen);
00323 #endif
00324 
00325 private:
00326 
00327   char *buf;
00328   Guint start;
00329   Guint length;
00330   char *bufEnd;
00331   char *bufPtr;
00332   GBool needFree;
00333 };
00334 
00335 //------------------------------------------------------------------------
00336 // EmbedStream
00337 //
00338 // This is a special stream type used for embedded streams (inline
00339 // images).  It reads directly from the base stream -- after the
00340 // EmbedStream is deleted, reads from the base stream will proceed where
00341 // the BaseStream left off.  Note that this is very different behavior
00342 // that creating a new FileStream (using makeSubStream).
00343 //------------------------------------------------------------------------
00344 
00345 class EmbedStream: public BaseStream {
00346 public:
00347 
00348   EmbedStream(Stream *strA, Object *dictA, GBool limitedA, Guint lengthA);
00349   virtual ~EmbedStream();
00350   virtual Stream *makeSubStream(Guint start, GBool limitedA,
00351                                 Guint lengthA, Object *dictA);
00352   virtual StreamKind getKind() { return str->getKind(); }
00353   virtual void reset() {}
00354   virtual int getChar();
00355   virtual int lookChar();
00356   virtual int getPos() { return str->getPos(); }
00357   virtual void setPos(Guint pos, int dir = 0);
00358   virtual Guint getStart();
00359   virtual void moveStart(int delta);
00360 
00361 private:
00362 
00363   Stream *str;
00364   GBool limited;
00365   Guint length;
00366 };
00367 
00368 //------------------------------------------------------------------------
00369 // ASCIIHexStream
00370 //------------------------------------------------------------------------
00371 
00372 class ASCIIHexStream: public FilterStream {
00373 public:
00374 
00375   ASCIIHexStream(Stream *strA);
00376   virtual ~ASCIIHexStream();
00377   virtual StreamKind getKind() { return strASCIIHex; }
00378   virtual void reset();
00379   virtual int getChar()
00380     { int c = lookChar(); buf = EOF; return c; }
00381   virtual int lookChar();
00382   virtual GString *getPSFilter(int psLevel, char *indent);
00383   virtual GBool isBinary(GBool last = gTrue);
00384 
00385 private:
00386 
00387   int buf;
00388   GBool eof;
00389 };
00390 
00391 //------------------------------------------------------------------------
00392 // ASCII85Stream
00393 //------------------------------------------------------------------------
00394 
00395 class ASCII85Stream: public FilterStream {
00396 public:
00397 
00398   ASCII85Stream(Stream *strA);
00399   virtual ~ASCII85Stream();
00400   virtual StreamKind getKind() { return strASCII85; }
00401   virtual void reset();
00402   virtual int getChar()
00403     { int ch = lookChar(); ++index; return ch; }
00404   virtual int lookChar();
00405   virtual GString *getPSFilter(int psLevel, char *indent);
00406   virtual GBool isBinary(GBool last = gTrue);
00407 
00408 private:
00409 
00410   int c[5];
00411   int b[4];
00412   int index, n;
00413   GBool eof;
00414 };
00415 
00416 //------------------------------------------------------------------------
00417 // LZWStream
00418 //------------------------------------------------------------------------
00419 
00420 class LZWStream: public FilterStream {
00421 public:
00422 
00423   LZWStream(Stream *strA, int predictor, int columns, int colors,
00424             int bits, int earlyA);
00425   virtual ~LZWStream();
00426   virtual StreamKind getKind() { return strLZW; }
00427   virtual void reset();
00428   virtual int getChar();
00429   virtual int lookChar();
00430   virtual int getRawChar();
00431   virtual GString *getPSFilter(int psLevel, char *indent);
00432   virtual GBool isBinary(GBool last = gTrue);
00433 
00434 private:
00435 
00436   StreamPredictor *pred;        // predictor
00437   int early;                    // early parameter
00438   GBool eof;                    // true if at eof
00439   int inputBuf;                 // input buffer
00440   int inputBits;                // number of bits in input buffer
00441   struct {                      // decoding table
00442     int length;
00443     int head;
00444     Guchar tail;
00445   } table[4097];
00446   int nextCode;                 // next code to be used
00447   int nextBits;                 // number of bits in next code word
00448   int prevCode;                 // previous code used in stream
00449   int newChar;                  // next char to be added to table
00450   Guchar seqBuf[4097];          // buffer for current sequence
00451   int seqLength;                // length of current sequence
00452   int seqIndex;                 // index into current sequence
00453   GBool first;                  // first code after a table clear
00454 
00455   GBool processNextCode();
00456   void clearTable();
00457   int getCode();
00458 };
00459 
00460 //------------------------------------------------------------------------
00461 // RunLengthStream
00462 //------------------------------------------------------------------------
00463 
00464 class RunLengthStream: public FilterStream {
00465 public:
00466 
00467   RunLengthStream(Stream *strA);
00468   virtual ~RunLengthStream();
00469   virtual StreamKind getKind() { return strRunLength; }
00470   virtual void reset();
00471   virtual int getChar()
00472     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
00473   virtual int lookChar()
00474     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
00475   virtual GString *getPSFilter(int psLevel, char *indent);
00476   virtual GBool isBinary(GBool last = gTrue);
00477 
00478 private:
00479 
00480   char buf[128];                // buffer
00481   char *bufPtr;                 // next char to read
00482   char *bufEnd;                 // end of buffer
00483   GBool eof;
00484 
00485   GBool fillBuf();
00486 };
00487 
00488 //------------------------------------------------------------------------
00489 // CCITTFaxStream
00490 //------------------------------------------------------------------------
00491 
00492 struct CCITTCodeTable;
00493 
00494 class CCITTFaxStream: public FilterStream {
00495 public:
00496 
00497   CCITTFaxStream(Stream *strA, int encodingA, GBool endOfLineA,
00498                  GBool byteAlignA, int columnsA, int rowsA,
00499                  GBool endOfBlockA, GBool blackA);
00500   virtual ~CCITTFaxStream();
00501   virtual StreamKind getKind() { return strCCITTFax; }
00502   virtual void reset();
00503   virtual int getChar()
00504     { int c = lookChar(); buf = EOF; return c; }
00505   virtual int lookChar();
00506   virtual GString *getPSFilter(int psLevel, char *indent);
00507   virtual GBool isBinary(GBool last = gTrue);
00508 
00509 private:
00510 
00511   int encoding;                 // 'K' parameter
00512   GBool endOfLine;              // 'EndOfLine' parameter
00513   GBool byteAlign;              // 'EncodedByteAlign' parameter
00514   int columns;                  // 'Columns' parameter
00515   int rows;                     // 'Rows' parameter
00516   GBool endOfBlock;             // 'EndOfBlock' parameter
00517   GBool black;                  // 'BlackIs1' parameter
00518   GBool eof;                    // true if at eof
00519   GBool nextLine2D;             // true if next line uses 2D encoding
00520   int row;                      // current row
00521   int inputBuf;                 // input buffer
00522   int inputBits;                // number of bits in input buffer
00523   short *refLine;               // reference line changing elements
00524   int b1;                       // index into refLine
00525   short *codingLine;            // coding line changing elements
00526   int a0;                       // index into codingLine
00527   int outputBits;               // remaining ouput bits
00528   int buf;                      // character buffer
00529 
00530   short getTwoDimCode();
00531   short getWhiteCode();
00532   short getBlackCode();
00533   short lookBits(int n);
00534   void eatBits(int n) { inputBits -= n; }
00535 };
00536 
00537 //------------------------------------------------------------------------
00538 // DCTStream
00539 //------------------------------------------------------------------------
00540 
00541 // DCT component info
00542 struct DCTCompInfo {
00543   int id;                       // component ID
00544   int hSample, vSample;         // horiz/vert sampling resolutions
00545   int quantTable;               // quantization table number
00546   int prevDC;                   // DC coefficient accumulator
00547 };
00548 
00549 struct DCTScanInfo {
00550   GBool comp[4];                // comp[i] is set if component i is
00551                                 //   included in this scan
00552   int numComps;                 // number of components in the scan
00553   int dcHuffTable[4];           // DC Huffman table numbers
00554   int acHuffTable[4];           // AC Huffman table numbers
00555   int firstCoeff, lastCoeff;    // first and last DCT coefficient
00556   int ah, al;                   // successive approximation parameters
00557 };
00558 
00559 // DCT Huffman decoding table
00560 struct DCTHuffTable {
00561   Guchar firstSym[17];          // first symbol for this bit length
00562   Gushort firstCode[17];        // first code for this bit length
00563   Gushort numCodes[17];         // number of codes of this bit length
00564   Guchar sym[256];              // symbols
00565 };
00566 
00567 class DCTStream: public FilterStream {
00568 public:
00569 
00570   DCTStream(Stream *strA);
00571   virtual ~DCTStream();
00572   virtual StreamKind getKind() { return strDCT; }
00573   virtual void reset();
00574   virtual int getChar();
00575   virtual int lookChar();
00576   virtual GString *getPSFilter(int psLevel, char *indent);
00577   virtual GBool isBinary(GBool last = gTrue);
00578   Stream *getRawStream() { return str; }
00579 
00580 private:
00581 
00582   GBool progressive;            // set if in progressive mode
00583   GBool interleaved;            // set if in interleaved mode
00584   int width, height;            // image size
00585   int mcuWidth, mcuHeight;      // size of min coding unit, in data units
00586   int bufWidth, bufHeight;      // frameBuf size
00587   DCTCompInfo compInfo[4];      // info for each component
00588   DCTScanInfo scanInfo;         // info for the current scan
00589   int numComps;                 // number of components in image
00590   int colorXform;               // need YCbCr-to-RGB transform?
00591   GBool gotJFIFMarker;          // set if APP0 JFIF marker was present
00592   GBool gotAdobeMarker;         // set if APP14 Adobe marker was present
00593   int restartInterval;          // restart interval, in MCUs
00594   Guchar quantTables[4][64];    // quantization tables
00595   int numQuantTables;           // number of quantization tables
00596   DCTHuffTable dcHuffTables[4]; // DC Huffman tables
00597   DCTHuffTable acHuffTables[4]; // AC Huffman tables
00598   int numDCHuffTables;          // number of DC Huffman tables
00599   int numACHuffTables;          // number of AC Huffman tables
00600   Guchar *rowBuf[4][32];        // buffer for one MCU (non-progressive mode)
00601   int *frameBuf[4];             // buffer for frame (progressive mode)
00602   int comp, x, y, dy;           // current position within image/MCU
00603   int restartCtr;               // MCUs left until restart
00604   int restartMarker;            // next restart marker
00605   int eobRun;                   // number of EOBs left in the current run
00606   int inputBuf;                 // input buffer for variable length codes
00607   int inputBits;                // number of valid bits in input buffer
00608 
00609   void restart();
00610   GBool readMCURow();
00611   void readScan();
00612   GBool readDataUnit(DCTHuffTable *dcHuffTable,
00613                      DCTHuffTable *acHuffTable,
00614                      int *prevDC, int data[64]);
00615   GBool readProgressiveDataUnit(DCTHuffTable *dcHuffTable,
00616                                 DCTHuffTable *acHuffTable,
00617                                 int *prevDC, int data[64]);
00618   void decodeImage();
00619   void transformDataUnit(Guchar *quantTable,
00620                          int dataIn[64], Guchar dataOut[64]);
00621   int readHuffSym(DCTHuffTable *table);
00622   int readAmp(int size);
00623   int readBit();
00624   GBool readHeader();
00625   GBool readBaselineSOF();
00626   GBool readProgressiveSOF();
00627   GBool readScanInfo();
00628   GBool readQuantTables();
00629   GBool readHuffmanTables();
00630   GBool readRestartInterval();
00631   GBool readJFIFMarker();
00632   GBool readAdobeMarker();
00633   GBool readTrailer();
00634   int readMarker();
00635   int read16();
00636 };
00637 
00638 //------------------------------------------------------------------------
00639 // FlateStream
00640 //------------------------------------------------------------------------
00641 
00642 #define flateWindow          32768    // buffer size
00643 #define flateMask            (flateWindow-1)
00644 #define flateMaxHuffman         15    // max Huffman code length
00645 #define flateMaxCodeLenCodes    19    // max # code length codes
00646 #define flateMaxLitCodes       288    // max # literal codes
00647 #define flateMaxDistCodes       30    // max # distance codes
00648 
00649 // Huffman code table entry
00650 struct FlateCode {
00651   Gushort len;                  // code length, in bits
00652   Gushort val;                  // value represented by this code
00653 };
00654 
00655 struct FlateHuffmanTab {
00656   FlateCode *codes;
00657   int maxLen;
00658 };
00659 
00660 // Decoding info for length and distance code words
00661 struct FlateDecode {
00662   int bits;                     // # extra bits
00663   int first;                    // first length/distance
00664 };
00665 
00666 class FlateStream: public FilterStream {
00667 public:
00668 
00669   FlateStream(Stream *strA, int predictor, int columns,
00670               int colors, int bits);
00671   virtual ~FlateStream();
00672   virtual StreamKind getKind() { return strFlate; }
00673   virtual void reset();
00674   virtual int getChar();
00675   virtual int lookChar();
00676   virtual int getRawChar();
00677   virtual GString *getPSFilter(int psLevel, char *indent);
00678   virtual GBool isBinary(GBool last = gTrue);
00679 
00680 private:
00681 
00682   StreamPredictor *pred;        // predictor
00683   Guchar buf[flateWindow];      // output data buffer
00684   int index;                    // current index into output buffer
00685   int remain;                   // number valid bytes in output buffer
00686   int codeBuf;                  // input buffer
00687   int codeSize;                 // number of bits in input buffer
00688   int                           // literal and distance code lengths
00689     codeLengths[flateMaxLitCodes + flateMaxDistCodes];
00690   FlateHuffmanTab litCodeTab;   // literal code table
00691   FlateHuffmanTab distCodeTab;  // distance code table
00692   GBool compressedBlock;        // set if reading a compressed block
00693   int blockLen;                 // remaining length of uncompressed block
00694   GBool endOfBlock;             // set when end of block is reached
00695   GBool eof;                    // set when end of stream is reached
00696 
00697   static int                    // code length code reordering
00698     codeLenCodeMap[flateMaxCodeLenCodes];
00699   static FlateDecode            // length decoding info
00700     lengthDecode[flateMaxLitCodes-257];
00701   static FlateDecode            // distance decoding info
00702     distDecode[flateMaxDistCodes];
00703 
00704   void readSome();
00705   GBool startBlock();
00706   void loadFixedCodes();
00707   GBool readDynamicCodes();
00708   void compHuffmanCodes(int *lengths, int n, FlateHuffmanTab *tab);
00709   int getHuffmanCodeWord(FlateHuffmanTab *tab);
00710   int getCodeWord(int bits);
00711 };
00712 
00713 //------------------------------------------------------------------------
00714 // EOFStream
00715 //------------------------------------------------------------------------
00716 
00717 class EOFStream: public FilterStream {
00718 public:
00719 
00720   EOFStream(Stream *strA);
00721   virtual ~EOFStream();
00722   virtual StreamKind getKind() { return strWeird; }
00723   virtual void reset() {}
00724   virtual int getChar() { return EOF; }
00725   virtual int lookChar() { return EOF; }
00726   virtual GString *getPSFilter(int psLevel, char *indent)  { return NULL; }
00727   virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
00728 };
00729 
00730 //------------------------------------------------------------------------
00731 // FixedLengthEncoder
00732 //------------------------------------------------------------------------
00733 
00734 class FixedLengthEncoder: public FilterStream {
00735 public:
00736 
00737   FixedLengthEncoder(Stream *strA, int lengthA);
00738   ~FixedLengthEncoder();
00739   virtual StreamKind getKind() { return strWeird; }
00740   virtual void reset();
00741   virtual int getChar();
00742   virtual int lookChar();
00743   virtual GString *getPSFilter(int psLevel, char *indent) { return NULL; }
00744   virtual GBool isBinary(GBool last = gTrue);
00745   virtual GBool isEncoder() { return gTrue; }
00746 
00747 private:
00748 
00749   int length;
00750   int count;
00751 };
00752 
00753 //------------------------------------------------------------------------
00754 // ASCIIHexEncoder
00755 //------------------------------------------------------------------------
00756 
00757 class ASCIIHexEncoder: public FilterStream {
00758 public:
00759 
00760   ASCIIHexEncoder(Stream *strA);
00761   virtual ~ASCIIHexEncoder();
00762   virtual StreamKind getKind() { return strWeird; }
00763   virtual void reset();
00764   virtual int getChar()
00765     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
00766   virtual int lookChar()
00767     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
00768   virtual GString *getPSFilter(int psLevel, char *indent) { return NULL; }
00769   virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
00770   virtual GBool isEncoder() { return gTrue; }
00771 
00772 private:
00773 
00774   char buf[4];
00775   char *bufPtr;
00776   char *bufEnd;
00777   int lineLen;
00778   GBool eof;
00779 
00780   GBool fillBuf();
00781 };
00782 
00783 //------------------------------------------------------------------------
00784 // ASCII85Encoder
00785 //------------------------------------------------------------------------
00786 
00787 class ASCII85Encoder: public FilterStream {
00788 public:
00789 
00790   ASCII85Encoder(Stream *strA);
00791   virtual ~ASCII85Encoder();
00792   virtual StreamKind getKind() { return strWeird; }
00793   virtual void reset();
00794   virtual int getChar()
00795     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
00796   virtual int lookChar()
00797     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
00798   virtual GString *getPSFilter(int psLevel, char *indent) { return NULL; }
00799   virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
00800   virtual GBool isEncoder() { return gTrue; }
00801 
00802 private:
00803 
00804   char buf[8];
00805   char *bufPtr;
00806   char *bufEnd;
00807   int lineLen;
00808   GBool eof;
00809 
00810   GBool fillBuf();
00811 };
00812 
00813 //------------------------------------------------------------------------
00814 // RunLengthEncoder
00815 //------------------------------------------------------------------------
00816 
00817 class RunLengthEncoder: public FilterStream {
00818 public:
00819 
00820   RunLengthEncoder(Stream *strA);
00821   virtual ~RunLengthEncoder();
00822   virtual StreamKind getKind() { return strWeird; }
00823   virtual void reset();
00824   virtual int getChar()
00825     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
00826   virtual int lookChar()
00827     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
00828   virtual GString *getPSFilter(int psLevel, char *indent) { return NULL; }
00829   virtual GBool isBinary(GBool last = gTrue) { return gTrue; }
00830   virtual GBool isEncoder() { return gTrue; }
00831 
00832 private:
00833 
00834   char buf[131];
00835   char *bufPtr;
00836   char *bufEnd;
00837   char *nextEnd;
00838   GBool eof;
00839 
00840   GBool fillBuf();
00841 };
00842 
00843 #endif

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