home *** CD-ROM | disk | FTP | other *** search
/ PSION CD 2 / PsionCDVol2.iso / Programs / 720 / PDF090B4-SorceCode / pdf / Stream.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-30  |  23.5 KB  |  794 lines

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