filters

Stream.h

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