home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 12 / MA_Cover_12.iso / source / xpdf-0.80 / xpdf / stream.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-20  |  21.1 KB  |  663 lines

  1. //========================================================================
  2. //
  3. // Stream.h
  4. //
  5. // Copyright 1996 Derek B. Noonburg
  6. //
  7. //========================================================================
  8.  
  9. #ifndef STREAM_H
  10. #define STREAM_H
  11.  
  12. #ifdef __GNUC__
  13. #pragma interface
  14. #endif
  15.  
  16. #include <stdio.h>
  17. #include "mystdio.h"
  18. #include "gtypes.h"
  19. #include "Object.h"
  20.  
  21. //------------------------------------------------------------------------
  22.  
  23. enum StreamKind {
  24.   strFile,
  25.   strASCIIHex,
  26.   strASCII85,
  27.   strLZW,
  28.   strRunLength,
  29.   strCCITTFax,
  30.   strDCT,
  31.   strFlate,
  32.   strWeird                      // internal-use stream types
  33. };
  34.  
  35. //------------------------------------------------------------------------
  36. // Stream (base class)
  37. //------------------------------------------------------------------------
  38.  
  39. class Stream {
  40. public:
  41.  
  42.   // Constructor.
  43.   Stream();
  44.  
  45.   // Destructor.
  46.   virtual ~Stream();
  47.  
  48.   // Reference counting.
  49.   int incRef() { return ++ref; }
  50.   int decRef() { return --ref; }
  51.  
  52.   // Get kind of stream.
  53.   virtual StreamKind getKind() = 0;
  54.  
  55.   // Reset stream to beginning.
  56.   virtual void reset() = 0;
  57.  
  58.   // Reset stream and allocate buffers for use by getPixel().
  59.   // The image has <width1> pixels per line, <nComps1> components per
  60.   // pixel, and <nBits1> bits per component.
  61.   virtual void resetImage(int width1, int nComps1, int nBits1);
  62.  
  63.   // Get next char from stream.
  64.   virtual int getChar() = 0;
  65.  
  66.   // Peek at next char in stream.
  67.   virtual int lookChar() = 0;
  68.  
  69.   // Get next line from stream.
  70.   virtual char *getLine(char *buf, int size);
  71.  
  72.   // Gets the next pixel from the stream.  (resetImage() must be called
  73.   // first.)  <pix> should be able to hold at least nComps elements.
  74.   // Returns false at end of file.
  75.   virtual GBool getImagePixel(Guchar *pix);
  76.  
  77.   // Skip an entire line from the image.
  78.   virtual void skipImageLine();
  79.  
  80.   // Get current position in file.
  81.   virtual int getPos() = 0;
  82.  
  83.   // Go to a position in the stream.
  84.   virtual void setPos(int pos1);
  85.  
  86.   // Get PostScript command for the filter(s).
  87.   virtual GString *getPSFilter(char *indent);
  88.  
  89.   // Does this stream type potentially contain non-printable chars?
  90.   virtual GBool isBinary(GBool last = gTrue) = 0;
  91.  
  92.   // Get the base FileStream or SubStream of this stream.
  93.   virtual Stream *getBaseStream() = 0;
  94.  
  95.   // Get the base file of this stream.
  96.   virtual myFILE *getFile() = 0;
  97.  
  98.   // Get the dictionary associated with this stream.
  99.   virtual Dict *getDict() = 0;
  100.  
  101.   // Is this an encoding filter?
  102.   virtual GBool isEncoder() { return gFalse; }
  103.  
  104.   // Add filters to this stream according to the parameters in <dict>.
  105.   // Returns the new stream.
  106.   Stream *addFilters(Object *dict);
  107.  
  108. private:
  109.  
  110.   Stream *makeFilter(char *name, Stream *str, Object *params);
  111.  
  112.   int ref;                      // reference count
  113.  
  114. protected:
  115.  
  116.   //----- image stuff
  117.   int predictor;                // predictor
  118.   int width;                    // pixels per line
  119.   int nComps;                   // components per pixel
  120.   int nBits;                    // bits per component
  121.   int nVals;                    // components per line
  122.   int pixBytes;                 // bytes per pixel
  123.   int rowBytes;                 // bytes per line
  124.   Guchar *rawLine;              // raw line buffer
  125.   Guchar *pixLine;              // pixel line buffer
  126.   int pixIdx;                   // current index in line buffer
  127. };
  128.  
  129. //------------------------------------------------------------------------
  130. // FileStream
  131. //------------------------------------------------------------------------
  132.  
  133. class FileStream: public Stream {
  134. public:
  135.  
  136.   FileStream(myFILE *f1, int start1, int length1, Object *dict1);
  137.   virtual ~FileStream();
  138.   virtual StreamKind getKind() { return strFile; }
  139.   virtual void reset();
  140.   virtual int getChar()
  141.     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
  142.   virtual int lookChar()
  143.     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
  144.   virtual int getPos() { return bufPos + (bufPtr - buf); }
  145.   virtual void setPos(int pos1);
  146.   virtual GBool isBinary(GBool last = gTrue) { return last; }
  147.   virtual Stream *getBaseStream() { return this; }
  148.   virtual myFILE *getFile() { return f; }
  149.   virtual Dict *getDict() { return dict.getDict(); }
  150.  
  151.   // Check for a PDF header on this stream.  Skip past some garbage
  152.   // if necessary.
  153.   GBool checkHeader();
  154.  
  155.   // Get position of first byte of stream within the file.
  156.   int getStart() { return start; }
  157.  
  158. private:
  159.  
  160.   GBool fillBuf();
  161.  
  162.   myFILE *f;
  163.   int start;
  164.   int length;
  165.   char buf[256];
  166.   char *bufPtr;
  167.   char *bufEnd;
  168.   int bufPos;
  169.   int savePos;
  170.   Object dict;
  171. };
  172.  
  173. //------------------------------------------------------------------------
  174. // SubStream
  175. //------------------------------------------------------------------------
  176.  
  177. class SubStream: public Stream {
  178. public:
  179.  
  180.   SubStream(Stream *str1, Object *dict1);
  181.   virtual ~SubStream();
  182.   virtual StreamKind getKind() { return str->getKind(); }
  183.   virtual void reset() {}
  184.   virtual int getChar() { return str->getChar(); }
  185.   virtual int lookChar() { return str->lookChar(); }
  186.   virtual int getPos() { return str->getPos(); }
  187.   virtual GBool isBinary(GBool last = gTrue) { return last; }
  188.   virtual Stream *getBaseStream() { return this; }
  189.   virtual myFILE *getFile() { return str->getFile(); }
  190.   virtual Dict *getDict() { return dict.getDict(); }
  191.  
  192. private:
  193.  
  194.   Stream *str;
  195.   Object dict;
  196. };
  197.  
  198. //------------------------------------------------------------------------
  199. // ASCIIHexStream
  200. //------------------------------------------------------------------------
  201.  
  202. class ASCIIHexStream: public Stream {
  203. public:
  204.  
  205.   ASCIIHexStream(Stream *str1);
  206.   virtual ~ASCIIHexStream();
  207.   virtual StreamKind getKind() { return strASCIIHex; }
  208.   virtual void reset();
  209.   virtual int getChar()
  210.     { int c = lookChar(); buf = EOF; return c; }
  211.   virtual int lookChar();
  212.   virtual int getPos() { return str->getPos(); }
  213.   virtual GString *getPSFilter(char *indent);
  214.   virtual GBool isBinary(GBool last = gTrue);
  215.   virtual Stream *getBaseStream() { return str->getBaseStream(); }
  216.   virtual myFILE *getFile() { return str->getFile(); }
  217.   virtual Dict *getDict() { return str->getDict(); }
  218.  
  219. private:
  220.  
  221.   Stream *str;
  222.   int buf;
  223.   GBool eof;
  224. };
  225.  
  226. //------------------------------------------------------------------------
  227. // ASCII85Stream
  228. //------------------------------------------------------------------------
  229.  
  230. class ASCII85Stream: public Stream {
  231. public:
  232.  
  233.   ASCII85Stream(Stream *str1);
  234.   virtual ~ASCII85Stream();
  235.   virtual StreamKind getKind() { return strASCII85; }
  236.   virtual void reset();
  237.   virtual int getChar()
  238.     { int ch = lookChar(); ++index; return ch; }
  239.   virtual int lookChar();
  240.   virtual int getPos() { return str->getPos(); }
  241.   virtual GString *getPSFilter(char *indent);
  242.   virtual GBool isBinary(GBool last = gTrue);
  243.   virtual Stream *getBaseStream() { return str->getBaseStream(); }
  244.   virtual myFILE *getFile() { return str->getFile(); }
  245.   virtual Dict *getDict() { return str->getDict(); }
  246.  
  247. private:
  248.  
  249.   Stream *str;
  250.   int c[5];
  251.   int b[4];
  252.   int index, n;
  253.   GBool eof;
  254. };
  255.  
  256. //------------------------------------------------------------------------
  257. // LZWStream
  258. //------------------------------------------------------------------------
  259.  
  260. class LZWStream: public Stream {
  261. public:
  262.  
  263.   LZWStream(Stream *str1, int predictor1, int columns1, int colors1,
  264.         int bits1, int early1);
  265.   virtual ~LZWStream();
  266.   virtual StreamKind getKind() { return strLZW; }
  267.   virtual void reset();
  268.   virtual int getChar();
  269.   virtual int lookChar();
  270.   virtual int getPos() { return str->getPos(); }
  271.   virtual GString *getPSFilter(char *indent);
  272.   virtual GBool isBinary(GBool last = gTrue);
  273.   virtual Stream *getBaseStream() { return str->getBaseStream(); }
  274.   virtual myFILE *getFile() { return str->getFile(); }
  275.   virtual Dict *getDict() { return str->getDict(); }
  276.  
  277. private:
  278.  
  279.   Stream *str;                  // stream
  280.   int early;                    // early parameter
  281.   char zCmd[256];               // uncompress command
  282.   myFILE *zPipe;                // uncompress pipe
  283.   char *zName;                  // .Z file name (in zCmd)
  284.   int inputBuf;                 // input buffer
  285.   int inputBits;                // number of bits in input buffer
  286.   int inCodeBits;               // size of input code
  287.   char buf[256];                // buffer
  288.   char *bufPtr;                 // next char to read
  289.   char *bufEnd;                 // end of buffer
  290.  
  291.   void dumpFile(FILE *f);
  292.   int getCode();
  293.   GBool fillBuf();
  294. };
  295.  
  296. //------------------------------------------------------------------------
  297. // RunLengthStream
  298. //------------------------------------------------------------------------
  299.  
  300. class RunLengthStream: public Stream {
  301. public:
  302.  
  303.   RunLengthStream(Stream *str1);
  304.   virtual ~RunLengthStream();
  305.   virtual StreamKind getKind() { return strRunLength; }
  306.   virtual void reset();
  307.   virtual int getChar()
  308.     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
  309.   virtual int lookChar()
  310.     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
  311.   virtual int getPos() { return str->getPos(); }
  312.   virtual GString *getPSFilter(char *indent);
  313.   virtual GBool isBinary(GBool last = gTrue);
  314.   virtual Stream *getBaseStream() { return str->getBaseStream(); }
  315.   virtual myFILE *getFile() { return str->getFile(); }
  316.   virtual Dict *getDict() { return str->getDict(); }
  317.  
  318. private:
  319.  
  320.   Stream *str;
  321.   char buf[128];                // buffer
  322.   char *bufPtr;                 // next char to read
  323.   char *bufEnd;                 // end of buffer
  324.   GBool eof;
  325.  
  326.   GBool fillBuf();
  327. };
  328.  
  329. //------------------------------------------------------------------------
  330. // CCITTFaxStream
  331. //------------------------------------------------------------------------
  332.  
  333. struct CCITTCodeTable;
  334.  
  335. class CCITTFaxStream: public Stream {
  336. public:
  337.  
  338.   CCITTFaxStream(Stream *str1, int encoding1, GBool byteAlign1,
  339.          int columns1, int rows1, GBool black1);
  340.   virtual ~CCITTFaxStream();
  341.   virtual StreamKind getKind() { return strCCITTFax; }
  342.   virtual void reset();
  343.   virtual int getChar()
  344.     { int c = lookChar(); buf = EOF; return c; }
  345.   virtual int lookChar();
  346.   virtual int getPos() { return str->getPos(); }
  347.   virtual GString *getPSFilter(char *indent);
  348.   virtual GBool isBinary(GBool last = gTrue);
  349.   virtual Stream *getBaseStream() { return str->getBaseStream(); }
  350.   virtual myFILE *getFile() { return str->getFile(); }
  351.   virtual Dict *getDict() { return str->getDict(); }
  352.  
  353. private:
  354.  
  355.   Stream *str;                  // stream
  356.   int encoding;                 // 'K' parameter
  357.   GBool byteAlign;              // 'EncodedByteAlign' parameter
  358.   int columns;                  // 'Columns' parameter
  359.   int rows;                     // 'Rows' parameter
  360.   GBool black;                  // 'BlackIs1' parameter
  361.   GBool eof;                    // true if at eof
  362.   GBool nextLine2D;             // true if next line uses 2D encoding
  363.   int inputBuf;                 // input buffer
  364.   int inputBits;                // number of bits in input buffer
  365.   short *refLine;               // reference line changing elements
  366.   int b1;                       // index into refLine
  367.   short *codingLine;            // coding line changing elements
  368.   int a0;                       // index into codingLine
  369.   int outputBits;               // remaining ouput bits
  370.   int buf;                      // character buffer
  371.  
  372.   short getTwoDimCode();
  373.   short getWhiteCode();
  374.   short getBlackCode();
  375.   short look13Bits();
  376.   void eatBits(int bits) { inputBits -= bits; }
  377. };
  378.  
  379. //------------------------------------------------------------------------
  380. // DCTStream
  381. //------------------------------------------------------------------------
  382.  
  383. // DCT component info
  384. struct DCTCompInfo {
  385.   int id;                       // component ID
  386.   GBool inScan;                 // is this component in the current scan?
  387.   int hSample, vSample;         // horiz/vert sampling resolutions
  388.   int quantTable;               // quantization table number
  389.   int dcHuffTable, acHuffTable; // Huffman table numbers
  390.   int prevDC;                   // DC coefficient accumulator
  391. };
  392.  
  393. // DCT Huffman decoding table
  394. struct DCTHuffTable {
  395.   Guchar firstSym[17];          // first symbol for this bit length
  396.   Gushort firstCode[17];        // first code for this bit length
  397.   Gushort numCodes[17];         // number of codes of this bit length
  398.   Guchar sym[256];              // symbols
  399. };
  400.  
  401. class DCTStream: public Stream {
  402. public:
  403.  
  404.   DCTStream(Stream *str1);
  405.   virtual ~DCTStream();
  406.   virtual StreamKind getKind() { return strDCT; }
  407.   virtual void reset();
  408.   virtual int getChar();
  409.   virtual int lookChar();
  410.   virtual int getPos() { return str->getPos(); }
  411.   virtual GString *getPSFilter(char *indent);
  412.   virtual GBool isBinary(GBool last = gTrue);
  413.   virtual Stream *getBaseStream() { return str->getBaseStream(); }
  414.   virtual myFILE *getFile() { return str->getFile(); }
  415.   virtual Dict *getDict() { return str->getDict(); }
  416.   Stream *getRawStream() { return str; }
  417.  
  418. private:
  419.  
  420.   Stream *str;                  // stream
  421.   int width, height;            // image size
  422.   int mcuWidth, mcuHeight;      // size of min coding unit, in data units
  423.   DCTCompInfo compInfo[4];      // info for each component
  424.   int numComps;                 // number of components in image
  425.   int colorXform;               // need YCbCr-to-RGB transform?
  426.   int restartInterval;          // restart interval, in MCUs
  427.   Guchar quantTables[4][64];    // quantization tables
  428.   int numQuantTables;           // number of quantization tables
  429.   DCTHuffTable dcHuffTables[4]; // DC Huffman tables
  430.   DCTHuffTable acHuffTables[4]; // AC Huffman tables
  431.   int numDCHuffTables;          // number of DC Huffman tables
  432.   int numACHuffTables;          // number of AC Huffman tables
  433.   Guchar *rowBuf[4][32];        // buffer for one MCU
  434.   int comp, x, y, dy;           // current position within image/MCU
  435.   int restartCtr;               // MCUs left until restart
  436.   int restartMarker;            // next restart marker
  437.   int inputBuf;                 // input buffer for variable length codes
  438.   int inputBits;                // number of valid bits in input buffer
  439.  
  440.   void restart();
  441.   GBool readMCURow();
  442.   GBool readDataUnit(DCTHuffTable *dcHuffTable, DCTHuffTable *acHuffTable,
  443.              Guchar quantTable[64], int *prevDC, Guchar data[64]);
  444.   int readHuffSym(DCTHuffTable *table);
  445.   int readAmp(int size);
  446.   int readBit();
  447.   GBool readHeader();
  448.   GBool readFrameInfo();
  449.   GBool readScanInfo();
  450.   GBool readQuantTables();
  451.   GBool readHuffmanTables();
  452.   GBool readRestartInterval();
  453.   GBool readAdobeMarker();
  454.   GBool readTrailer();
  455.   int readMarker();
  456.   int read16();
  457. };
  458.  
  459. //------------------------------------------------------------------------
  460. // FlateStream
  461. //------------------------------------------------------------------------
  462.  
  463. #define flateWindow          32768    // buffer size
  464. #define flateMask            (flateWindow-1)
  465. #define flateMaxHuffman         15    // max Huffman code length
  466. #define flateMaxCodeLenCodes    19    // max # code length codes
  467. #define flateMaxLitCodes       288    // max # literal codes
  468. #define flateMaxDistCodes       30    // max # distance codes
  469.  
  470. // Huffman code table entry
  471. struct FlateCode {
  472.   int len;                      // code length in bits
  473.   int code;                     // code word
  474.   int val;                      // value represented by this code
  475. };
  476.  
  477. // Huffman code table
  478. struct FlateHuffmanTab {
  479.   int start[flateMaxHuffman+2]; // indexes of first code of each length
  480.   FlateCode *codes;             // codes, sorted by length and code word
  481. };
  482.  
  483. // Decoding info for length and distance code words
  484. struct FlateDecode {
  485.   int bits;                     // # extra bits
  486.   int first;                    // first length/distance
  487. };
  488.  
  489. class FlateStream: public Stream {
  490. public:
  491.  
  492.   FlateStream(Stream *str1, int predictor1, int columns1,
  493.           int colors1, int bits1);
  494.   virtual ~FlateStream();
  495.   virtual StreamKind getKind() { return strFlate; }
  496.   virtual void reset();
  497.   virtual int getChar();
  498.   virtual int lookChar();
  499.   virtual int getPos() { return str->getPos(); }
  500.   virtual GString *getPSFilter(char *indent);
  501.   virtual GBool isBinary(GBool last = gTrue);
  502.   virtual Stream *getBaseStream() { return str->getBaseStream(); }
  503.   virtual myFILE *getFile() { return str->getFile(); }
  504.   virtual Dict *getDict() { return str->getDict(); }
  505.  
  506. private:
  507.  
  508.   Stream *str;                  // stream
  509.   Guchar buf[flateWindow];      // output data buffer
  510.   int index;                    // current index into output buffer
  511.   int remain;                   // number valid bytes in output buffer
  512.   int codeBuf;                  // input buffer
  513.   int codeSize;                 // number of bits in input buffer
  514.   FlateCode                     // literal and distance codes
  515.     allCodes[flateMaxLitCodes + flateMaxDistCodes];
  516.   FlateHuffmanTab litCodeTab;   // literal code table
  517.   FlateHuffmanTab distCodeTab;  // distance code table
  518.   GBool compressedBlock;        // set if reading a compressed block
  519.   int blockLen;                 // remaining length of uncompressed block
  520.   GBool endOfBlock;             // set when end of block is reached
  521.   GBool eof;                    // set when end of stream is reached
  522.  
  523.   static int                    // code length code reordering
  524.     codeLenCodeMap[flateMaxCodeLenCodes];
  525.   static FlateDecode            // length decoding info
  526.     lengthDecode[flateMaxLitCodes-257];
  527.   static FlateDecode            // distance decoding info
  528.     distDecode[flateMaxDistCodes];
  529.  
  530.   void readSome();
  531.   GBool startBlock();
  532.   void loadFixedCodes();
  533.   GBool readDynamicCodes();
  534.   void compHuffmanCodes(FlateHuffmanTab *tab, int n);
  535.   int getHuffmanCodeWord(FlateHuffmanTab *tab);
  536.   int getCodeWord(int bits);
  537. };
  538.  
  539. //------------------------------------------------------------------------
  540. // EOFStream
  541. //------------------------------------------------------------------------
  542.  
  543. class EOFStream: public Stream {
  544. public:
  545.  
  546.   EOFStream(Stream *str1);
  547.   virtual ~EOFStream();
  548.   virtual StreamKind getKind() { return strWeird; }
  549.   virtual void reset() {}
  550.   virtual int getChar() { return EOF; }
  551.   virtual int lookChar() { return EOF; }
  552.   virtual int getPos() { return str->getPos(); }
  553.   virtual GString *getPSFilter(char *indent)  { return NULL; }
  554.   virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
  555.   virtual Stream *getBaseStream() { return str->getBaseStream(); }
  556.   virtual myFILE *getFile() { return str->getFile(); }
  557.   virtual Dict *getDict() { return str->getDict(); }
  558.  
  559. private:
  560.  
  561.   Stream *str;
  562. };
  563.  
  564. //------------------------------------------------------------------------
  565. // FixedLengthEncoder
  566. //------------------------------------------------------------------------
  567.  
  568. class FixedLengthEncoder: public Stream {
  569. public:
  570.  
  571.   FixedLengthEncoder(Stream *str1, int length1);
  572.   ~FixedLengthEncoder();
  573.   virtual StreamKind getKind() { return strWeird; }
  574.   virtual void reset();
  575.   virtual int getChar();
  576.   virtual int lookChar();
  577.   virtual int getPos() { return str->getPos(); }
  578.   virtual GString *getPSFilter(char *indent) { return NULL; }
  579.   virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
  580.   virtual Stream *getBaseStream() { return str->getBaseStream(); }
  581.   virtual myFILE *getFile() { return str->getFile(); }
  582.   virtual Dict *getDict() { return str->getDict(); }
  583.   virtual GBool isEncoder() { return gTrue; }
  584.  
  585. private:
  586.  
  587.   Stream *str;
  588.   int length;
  589.   int count;
  590. };
  591.  
  592. //------------------------------------------------------------------------
  593. // ASCII85Encoder
  594. //------------------------------------------------------------------------
  595.  
  596. class ASCII85Encoder: public Stream {
  597. public:
  598.  
  599.   ASCII85Encoder(Stream *str1);
  600.   virtual ~ASCII85Encoder();
  601.   virtual StreamKind getKind() { return strWeird; }
  602.   virtual void reset();
  603.   virtual int getChar()
  604.     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
  605.   virtual int lookChar()
  606.     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
  607.   virtual int getPos() { return str->getPos(); }
  608.   virtual GString *getPSFilter(char *indent) { return NULL; }
  609.   virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
  610.   virtual Stream *getBaseStream() { return str->getBaseStream(); }
  611.   virtual myFILE *getFile() { return str->getFile(); }
  612.   virtual Dict *getDict() { return str->getDict(); }
  613.   virtual GBool isEncoder() { return gTrue; }
  614.  
  615. private:
  616.  
  617.   Stream *str;
  618.   char buf[8];
  619.   char *bufPtr;
  620.   char *bufEnd;
  621.   int lineLen;
  622.   GBool eof;
  623.  
  624.   GBool fillBuf();
  625. };
  626.  
  627. //------------------------------------------------------------------------
  628. // RunLengthEncoder
  629. //------------------------------------------------------------------------
  630.  
  631. class RunLengthEncoder: public Stream {
  632. public:
  633.  
  634.   RunLengthEncoder(Stream *str1);
  635.   virtual ~RunLengthEncoder();
  636.   virtual StreamKind getKind() { return strWeird; }
  637.   virtual void reset();
  638.   virtual int getChar()
  639.     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
  640.   virtual int lookChar()
  641.     { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
  642.   virtual int getPos() { return str->getPos(); }
  643.   virtual GString *getPSFilter(char *indent) { return NULL; }
  644.   virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
  645.   virtual Stream *getBaseStream() { return str->getBaseStream(); }
  646.   virtual myFILE *getFile() { return str->getFile(); }
  647.   virtual Dict *getDict() { return str->getDict(); }
  648.   virtual GBool isEncoder() { return gTrue; }
  649.  
  650. private:
  651.  
  652.   Stream *str;
  653.   char buf[131];
  654.   char *bufPtr;
  655.   char *bufEnd;
  656.   char *nextEnd;
  657.   GBool eof;
  658.  
  659.   GBool fillBuf();
  660. };
  661.  
  662. #endif
  663.