Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Stream.h

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

Generated on Sat Nov 5 16:18:17 2005 for OPIE by  doxygen 1.4.2