Bringing apdf from vendor into main branch.
[AROS-Contrib.git] / apdf / xpdf / Stream.h
blob35da384b41e6459779aa1b7dc12d906540fad1ba
1 //========================================================================
2 //
3 // Stream.h
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 #ifndef STREAM_H
10 #define STREAM_H
12 #include <aconf.h>
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
18 #include <stdio.h>
19 #include "../server/mystdio.h"
20 #include "gtypes.h"
21 #include "Object.h"
22 #include "Error.h"
24 class Decrypt;
25 class BaseStream;
27 //------------------------------------------------------------------------
29 enum StreamKind {
30 strFile,
31 strASCIIHex,
32 strASCII85,
33 strLZW,
34 strRunLength,
35 strCCITTFax,
36 strDCT,
37 strFlate,
38 strJBIG2,
39 strJPX,
40 strString,
41 strWeird // internal-use stream types
44 enum StreamColorSpaceMode {
45 streamCSNone,
46 streamCSDeviceGray,
47 streamCSDeviceRGB,
48 streamCSDeviceCMYK
51 //------------------------------------------------------------------------
52 // Stream (base class)
53 //------------------------------------------------------------------------
55 class Stream {
56 public:
58 // Constructor.
59 Stream();
61 // Destructor.
62 virtual ~Stream();
64 // Reference counting.
65 int incRef() { return ++ref; }
66 int decRef() { return --ref; }
68 // Get kind of stream.
69 virtual StreamKind getKind() = 0;
71 // Reset stream to beginning.
72 virtual void reset() = 0;
74 // Close down the stream.
75 virtual void close();
77 // Get next char from stream.
78 virtual int getChar() = 0;
80 // Peek at next char in stream.
81 virtual int lookChar() = 0;
83 // Get next char from stream without using the predictor.
84 // This is only used by StreamPredictor.
85 virtual int getRawChar();
87 // Get next line from stream.
88 virtual char *getLine(char *buf, int size);
90 // Get current position in file.
91 virtual int getPos() = 0;
93 // Go to a position in the stream. If <dir> is negative, the
94 // position is from the end of the file; otherwise the position is
95 // from the start of the file.
96 virtual void setPos(Guint pos, int dir = 0) = 0;
98 // Get PostScript command for the filter(s).
99 virtual GString *getPSFilter(int psLevel, char *indent);
101 // Does this stream type potentially contain non-printable chars?
102 virtual GBool isBinary(GBool last = gTrue) = 0;
104 // Get the BaseStream of this stream.
105 virtual BaseStream *getBaseStream() = 0;
107 // Get the dictionary associated with this stream.
108 virtual Dict *getDict() = 0;
110 // Is this an encoding filter?
111 virtual GBool isEncoder() { return gFalse; }
113 virtual void preRead(int pos, int length) {}
114 virtual void removeParts() {}
116 // Get image parameters which are defined by the stream contents.
117 virtual void getImageParams(int *bitsPerComponent,
118 StreamColorSpaceMode *csMode) {}
120 // Add filters to this stream according to the parameters in <dict>.
121 // Returns the new stream.
122 Stream *addFilters(Object *dict);
124 private:
126 Stream *makeFilter(char *name, Stream *str, Object *params);
128 int ref; // reference count
131 //------------------------------------------------------------------------
132 // BaseStream
134 // This is the base class for all streams that read directly from a file.
135 //------------------------------------------------------------------------
137 class BaseStream: public Stream {
138 public:
140 BaseStream(Object *dictA);
141 virtual ~BaseStream();
142 virtual Stream *makeSubStream(Guint start, GBool limited,
143 Guint length, Object *dict) = 0;
144 virtual void setPos(Guint pos, int dir = 0) = 0;
145 virtual GBool isBinary(GBool last = gTrue) { return last; }
146 virtual BaseStream *getBaseStream() { return this; }
147 virtual Dict *getDict() { return dict.getDict(); }
149 // Get/set position of first byte of stream within the file.
150 virtual Guint getStart() = 0;
151 virtual void moveStart(int delta) = 0;
153 // Set decryption for this stream.
154 virtual void doDecryption(Guchar *fileKey, int keyLength,
155 int objNum, int objGen);
157 protected:
159 Decrypt *decrypt;
161 private:
163 Object dict;
166 //------------------------------------------------------------------------
167 // FilterStream
169 // This is the base class for all streams that filter another stream.
170 //------------------------------------------------------------------------
172 class FilterStream: public Stream {
173 public:
175 FilterStream(Stream *strA);
176 virtual ~FilterStream();
177 virtual void close();
178 virtual int getPos() { return str->getPos(); }
179 virtual void setPos(Guint pos, int dir = 0);
180 virtual BaseStream *getBaseStream() { return str->getBaseStream(); }
181 virtual Dict *getDict() { return str->getDict(); }
183 protected:
185 Stream *str;
188 //------------------------------------------------------------------------
189 // ImageStream
190 //------------------------------------------------------------------------
192 class ImageStream {
193 public:
195 // Create an image stream object for an image with the specified
196 // parameters. Note that these are the actual image parameters,
197 // which may be different from the predictor parameters.
198 ImageStream(Stream *strA, int widthA, int nCompsA, int nBitsA);
200 ~ImageStream();
202 // Reset the stream.
203 void reset();
205 // Gets the next pixel from the stream. <pix> should be able to hold
206 // at least nComps elements. Returns false at end of file.
207 GBool getPixel(Guchar *pix);
209 // Returns a pointer to the next line of pixels. Returns NULL at
210 // end of file.
211 Guchar *getLine();
213 // Skip an entire line from the image.
214 void skipLine();
216 private:
218 Stream *str; // base stream
219 int width; // pixels per line
220 int nComps; // components per pixel
221 int nBits; // bits per component
222 int nVals; // components per line
223 Guchar *imgLine; // line buffer
224 int imgIdx; // current index in imgLine
227 //------------------------------------------------------------------------
228 // StreamPredictor
229 //------------------------------------------------------------------------
231 class StreamPredictor {
232 public:
234 // Create a predictor object. Note that the parameters are for the
235 // predictor, and may not match the actual image parameters.
236 StreamPredictor(Stream *strA, int predictorA,
237 int widthA, int nCompsA, int nBitsA);
239 ~StreamPredictor();
241 GBool isOk() { return ok; }
243 int lookChar();
244 int getChar();
246 private:
248 GBool getNextLine();
250 Stream *str; // base stream
251 int predictor; // predictor
252 int width; // pixels per line
253 int nComps; // components per pixel
254 int nBits; // bits per component
255 int nVals; // components per line
256 int pixBytes; // bytes per pixel
257 int rowBytes; // bytes per line
258 Guchar *predLine; // line buffer
259 int predIdx; // current index in predLine
260 GBool ok;
263 //------------------------------------------------------------------------
264 // FileStream
265 //------------------------------------------------------------------------
267 #define fileStreamBufSize 256
269 class FileStream: public BaseStream {
270 public:
272 FileStream(myFILE *fA, Guint startA, GBool limitedA,
273 Guint lengthA, Object *dictA);
274 virtual ~FileStream();
275 virtual Stream *makeSubStream(Guint startA, GBool limitedA,
276 Guint lengthA, Object *dictA);
277 virtual StreamKind getKind() { return strFile; }
278 virtual void reset();
279 virtual void close();
280 virtual int getChar()
281 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
282 virtual int lookChar()
283 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
284 virtual int getPos() { return bufPos + (bufPtr - buf); }
285 virtual void setPos(Guint pos, int dir = 0);
286 virtual Guint getStart() { return start; }
287 virtual void moveStart(int delta);
288 virtual void preRead(int pos, int length);
289 virtual void removeParts();
291 private:
293 GBool fillBuf();
295 myFILE *f;
296 Guint start;
297 GBool limited;
298 Guint length;
299 char buf[fileStreamBufSize];
300 char *bufPtr;
301 char *bufEnd;
302 Guint bufPos;
303 int savePos;
304 GBool saved;
307 //------------------------------------------------------------------------
308 // MemStream
309 //------------------------------------------------------------------------
311 class MemStream: public BaseStream {
312 public:
314 MemStream(char *bufA, Guint startA, Guint lengthA, Object *dictA);
315 virtual ~MemStream();
316 virtual Stream *makeSubStream(Guint start, GBool limited,
317 Guint lengthA, Object *dictA);
318 virtual StreamKind getKind() { return strWeird; }
319 virtual void reset();
320 virtual void close();
321 virtual int getChar()
322 { return (bufPtr < bufEnd) ? (*bufPtr++ & 0xff) : EOF; }
323 virtual int lookChar()
324 { return (bufPtr < bufEnd) ? (*bufPtr & 0xff) : EOF; }
325 virtual int getPos() { return (int)(bufPtr - buf); }
326 virtual void setPos(Guint pos, int dir = 0);
327 virtual Guint getStart() { return start; }
328 virtual void moveStart(int delta);
329 virtual void doDecryption(Guchar *fileKey, int keyLength,
330 int objNum, int objGen);
332 private:
334 char *buf;
335 Guint start;
336 Guint length;
337 char *bufEnd;
338 char *bufPtr;
339 GBool needFree;
342 //------------------------------------------------------------------------
343 // EmbedStream
345 // This is a special stream type used for embedded streams (inline
346 // images). It reads directly from the base stream -- after the
347 // EmbedStream is deleted, reads from the base stream will proceed where
348 // the BaseStream left off. Note that this is very different behavior
349 // that creating a new FileStream (using makeSubStream).
350 //------------------------------------------------------------------------
352 class EmbedStream: public BaseStream {
353 public:
355 EmbedStream(Stream *strA, Object *dictA, GBool limitedA, Guint lengthA);
356 virtual ~EmbedStream();
357 virtual Stream *makeSubStream(Guint start, GBool limitedA,
358 Guint lengthA, Object *dictA);
359 virtual StreamKind getKind() { return str->getKind(); }
360 virtual void reset() {}
361 virtual int getChar();
362 virtual int lookChar();
363 virtual int getPos() { return str->getPos(); }
364 virtual void setPos(Guint pos, int dir = 0);
365 virtual Guint getStart();
366 virtual void moveStart(int delta);
368 private:
370 Stream *str;
371 GBool limited;
372 Guint length;
375 //------------------------------------------------------------------------
376 // ASCIIHexStream
377 //------------------------------------------------------------------------
379 class ASCIIHexStream: public FilterStream {
380 public:
382 ASCIIHexStream(Stream *strA);
383 virtual ~ASCIIHexStream();
384 virtual StreamKind getKind() { return strASCIIHex; }
385 virtual void reset();
386 virtual int getChar()
387 { int c = lookChar(); buf = EOF; return c; }
388 virtual int lookChar();
389 virtual int getPos() { return str->getPos(); }
390 virtual GString *getPSFilter(int psLevel, char *indent);
391 virtual GBool isBinary(GBool last = gTrue);
393 private:
395 int buf;
396 GBool eof;
399 //------------------------------------------------------------------------
400 // ASCII85Stream
401 //------------------------------------------------------------------------
403 class ASCII85Stream: public FilterStream {
404 public:
406 ASCII85Stream(Stream *strA);
407 virtual ~ASCII85Stream();
408 virtual StreamKind getKind() { return strASCII85; }
409 virtual void reset();
410 virtual int getChar()
411 { int ch = lookChar(); ++index; return ch; }
412 virtual int lookChar();
413 virtual GString *getPSFilter(int psLevel, char *indent);
414 virtual GBool isBinary(GBool last = gTrue);
416 private:
418 int c[5];
419 int b[4];
420 int index, n;
421 GBool eof;
424 //------------------------------------------------------------------------
425 // LZWStream
426 //------------------------------------------------------------------------
428 class LZWStream: public FilterStream {
429 public:
431 LZWStream(Stream *strA, int predictor, int columns, int colors,
432 int bits, int earlyA);
433 virtual ~LZWStream();
434 virtual StreamKind getKind() { return strLZW; }
435 virtual void reset();
436 virtual int getChar();
437 virtual int lookChar();
438 virtual int getRawChar();
439 virtual GString *getPSFilter(int psLevel, char *indent);
440 virtual GBool isBinary(GBool last = gTrue);
442 private:
444 StreamPredictor *pred; // predictor
445 int early; // early parameter
446 GBool eof; // true if at eof
447 int inputBuf; // input buffer
448 int inputBits; // number of bits in input buffer
449 struct { // decoding table
450 int length;
451 int head;
452 Guchar tail;
453 } table[4097];
454 int nextCode; // next code to be used
455 int nextBits; // number of bits in next code word
456 int prevCode; // previous code used in stream
457 int newChar; // next char to be added to table
458 Guchar seqBuf[4097]; // buffer for current sequence
459 int seqLength; // length of current sequence
460 int seqIndex; // index into current sequence
461 GBool first; // first code after a table clear
463 GBool processNextCode();
464 void clearTable();
465 int getCode();
468 //------------------------------------------------------------------------
469 // RunLengthStream
470 //------------------------------------------------------------------------
472 class RunLengthStream: public FilterStream {
473 public:
475 RunLengthStream(Stream *strA);
476 virtual ~RunLengthStream();
477 virtual StreamKind getKind() { return strRunLength; }
478 virtual void reset();
479 virtual int getChar()
480 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
481 virtual int lookChar()
482 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
483 virtual GString *getPSFilter(int psLevel, char *indent);
484 virtual GBool isBinary(GBool last = gTrue);
486 private:
488 char buf[128]; // buffer
489 char *bufPtr; // next char to read
490 char *bufEnd; // end of buffer
491 GBool eof;
493 GBool fillBuf();
496 //------------------------------------------------------------------------
497 // CCITTFaxStream
498 //------------------------------------------------------------------------
500 struct CCITTCodeTable;
502 class CCITTFaxStream: public FilterStream {
503 public:
505 CCITTFaxStream(Stream *strA, int encodingA, GBool endOfLineA,
506 GBool byteAlignA, int columnsA, int rowsA,
507 GBool endOfBlockA, GBool blackA);
508 virtual ~CCITTFaxStream();
509 virtual StreamKind getKind() { return strCCITTFax; }
510 virtual void reset();
511 virtual int getChar()
512 { int c = lookChar(); buf = EOF; return c; }
513 virtual int lookChar();
514 virtual GString *getPSFilter(int psLevel, char *indent);
515 virtual GBool isBinary(GBool last = gTrue);
517 private:
519 int encoding; // 'K' parameter
520 GBool endOfLine; // 'EndOfLine' parameter
521 GBool byteAlign; // 'EncodedByteAlign' parameter
522 int columns; // 'Columns' parameter
523 int rows; // 'Rows' parameter
524 GBool endOfBlock; // 'EndOfBlock' parameter
525 GBool black; // 'BlackIs1' parameter
526 GBool eof; // true if at eof
527 GBool nextLine2D; // true if next line uses 2D encoding
528 int row; // current row
529 int inputBuf; // input buffer
530 int inputBits; // number of bits in input buffer
531 short *refLine; // reference line changing elements
532 int b1; // index into refLine
533 short *codingLine; // coding line changing elements
534 int a0; // index into codingLine
535 int outputBits; // remaining ouput bits
536 int buf; // character buffer
538 short getTwoDimCode();
539 short getWhiteCode();
540 short getBlackCode();
541 short lookBits(int n);
542 void eatBits(int n) { if ((inputBits -= n) < 0) inputBits = 0; }
545 //------------------------------------------------------------------------
546 // DCTStream
547 //------------------------------------------------------------------------
549 // DCT component info
550 struct DCTCompInfo {
551 int id; // component ID
552 int hSample, vSample; // horiz/vert sampling resolutions
553 int quantTable; // quantization table number
554 int prevDC; // DC coefficient accumulator
557 struct DCTScanInfo {
558 GBool comp[4]; // comp[i] is set if component i is
559 // included in this scan
560 int numComps; // number of components in the scan
561 int dcHuffTable[4]; // DC Huffman table numbers
562 int acHuffTable[4]; // AC Huffman table numbers
563 int firstCoeff, lastCoeff; // first and last DCT coefficient
564 int ah, al; // successive approximation parameters
567 // DCT Huffman decoding table
568 struct DCTHuffTable {
569 Guchar firstSym[17]; // first symbol for this bit length
570 Gushort firstCode[17]; // first code for this bit length
571 Gushort numCodes[17]; // number of codes of this bit length
572 Guchar sym[256]; // symbols
575 class DCTStream: public FilterStream {
576 public:
578 DCTStream(Stream *strA);
579 virtual ~DCTStream();
580 virtual StreamKind getKind() { return strDCT; }
581 virtual void reset();
582 virtual int getChar();
583 virtual int lookChar();
584 virtual GString *getPSFilter(int psLevel, char *indent);
585 virtual GBool isBinary(GBool last = gTrue);
586 Stream *getRawStream() { return str; }
588 private:
590 GBool progressive; // set if in progressive mode
591 GBool interleaved; // set if in interleaved mode
592 int width, height; // image size
593 int mcuWidth, mcuHeight; // size of min coding unit, in data units
594 int bufWidth, bufHeight; // frameBuf size
595 DCTCompInfo compInfo[4]; // info for each component
596 DCTScanInfo scanInfo; // info for the current scan
597 int numComps; // number of components in image
598 int colorXform; // need YCbCr-to-RGB transform?
599 GBool gotJFIFMarker; // set if APP0 JFIF marker was present
600 GBool gotAdobeMarker; // set if APP14 Adobe marker was present
601 int restartInterval; // restart interval, in MCUs
602 Gushort quantTables[4][64]; // quantization tables
603 int numQuantTables; // number of quantization tables
604 DCTHuffTable dcHuffTables[4]; // DC Huffman tables
605 DCTHuffTable acHuffTables[4]; // AC Huffman tables
606 int numDCHuffTables; // number of DC Huffman tables
607 int numACHuffTables; // number of AC Huffman tables
608 Guchar *rowBuf[4][32]; // buffer for one MCU (non-progressive mode)
609 int *frameBuf[4]; // buffer for frame (progressive mode)
610 int comp, x, y, dy; // current position within image/MCU
611 int restartCtr; // MCUs left until restart
612 int restartMarker; // next restart marker
613 int eobRun; // number of EOBs left in the current run
614 int inputBuf; // input buffer for variable length codes
615 int inputBits; // number of valid bits in input buffer
617 void restart();
618 GBool readMCURow();
619 void readScan();
620 GBool readDataUnit(DCTHuffTable *dcHuffTable,
621 DCTHuffTable *acHuffTable,
622 int *prevDC, int data[64]);
623 GBool readProgressiveDataUnit(DCTHuffTable *dcHuffTable,
624 DCTHuffTable *acHuffTable,
625 int *prevDC, int data[64]);
626 void decodeImage();
627 void transformDataUnit(Gushort *quantTable,
628 int dataIn[64], Guchar dataOut[64]);
629 int readHuffSym(DCTHuffTable *table);
630 int readAmp(int size);
631 int readBit();
632 GBool readHeader();
633 GBool readBaselineSOF();
634 GBool readProgressiveSOF();
635 GBool readScanInfo();
636 GBool readQuantTables();
637 GBool readHuffmanTables();
638 GBool readRestartInterval();
639 GBool readJFIFMarker();
640 GBool readAdobeMarker();
641 GBool readTrailer();
642 int readMarker();
643 int read16();
646 //------------------------------------------------------------------------
647 // FlateStream
648 //------------------------------------------------------------------------
650 #define flateWindow 32768 // buffer size
651 #define flateMask (flateWindow-1)
652 #define flateMaxHuffman 15 // max Huffman code length
653 #define flateMaxCodeLenCodes 19 // max # code length codes
654 #define flateMaxLitCodes 288 // max # literal codes
655 #define flateMaxDistCodes 30 // max # distance codes
657 // Huffman code table entry
658 struct FlateCode {
659 Gushort len; // code length, in bits
660 Gushort val; // value represented by this code
663 struct FlateHuffmanTab {
664 FlateCode *codes;
665 int maxLen;
668 // Decoding info for length and distance code words
669 struct FlateDecode {
670 int bits; // # extra bits
671 int first; // first length/distance
674 class FlateStream: public FilterStream {
675 public:
677 FlateStream(Stream *strA, int predictor, int columns,
678 int colors, int bits);
679 virtual ~FlateStream();
680 virtual StreamKind getKind() { return strFlate; }
681 virtual void reset();
682 virtual int getChar();
683 virtual int lookChar();
684 virtual int getRawChar();
685 virtual GString *getPSFilter(int psLevel, char *indent);
686 virtual GBool isBinary(GBool last = gTrue);
688 private:
690 StreamPredictor *pred; // predictor
691 Guchar buf[flateWindow]; // output data buffer
692 int index; // current index into output buffer
693 int remain; // number valid bytes in output buffer
694 int codeBuf; // input buffer
695 int codeSize; // number of bits in input buffer
696 int // literal and distance code lengths
697 codeLengths[flateMaxLitCodes + flateMaxDistCodes];
698 FlateHuffmanTab litCodeTab; // literal code table
699 FlateHuffmanTab distCodeTab; // distance code table
700 GBool compressedBlock; // set if reading a compressed block
701 int blockLen; // remaining length of uncompressed block
702 GBool endOfBlock; // set when end of block is reached
703 GBool eof; // set when end of stream is reached
705 static int // code length code reordering
706 codeLenCodeMap[flateMaxCodeLenCodes];
707 static FlateDecode // length decoding info
708 lengthDecode[flateMaxLitCodes-257];
709 static FlateDecode // distance decoding info
710 distDecode[flateMaxDistCodes];
711 static FlateHuffmanTab // fixed literal code table
712 fixedLitCodeTab;
713 static FlateHuffmanTab // fixed distance code table
714 fixedDistCodeTab;
716 void readSome();
717 GBool startBlock();
718 void loadFixedCodes();
719 GBool readDynamicCodes();
720 void compHuffmanCodes(int *lengths, int n, FlateHuffmanTab *tab);
721 int getHuffmanCodeWord(FlateHuffmanTab *tab);
722 int getCodeWord(int bits);
725 //------------------------------------------------------------------------
726 // EOFStream
727 //------------------------------------------------------------------------
729 class EOFStream: public FilterStream {
730 public:
732 EOFStream(Stream *strA);
733 virtual ~EOFStream();
734 virtual StreamKind getKind() { return strWeird; }
735 virtual void reset() {}
736 virtual int getChar() { return EOF; }
737 virtual int lookChar() { return EOF; }
738 virtual GString *getPSFilter(int psLevel, char *indent) { return NULL; }
739 virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
742 //------------------------------------------------------------------------
743 // FixedLengthEncoder
744 //------------------------------------------------------------------------
746 class FixedLengthEncoder: public FilterStream {
747 public:
749 FixedLengthEncoder(Stream *strA, int lengthA);
750 ~FixedLengthEncoder();
751 virtual StreamKind getKind() { return strWeird; }
752 virtual void reset();
753 virtual int getChar();
754 virtual int lookChar();
755 virtual GString *getPSFilter(int psLevel, char *indent) { return NULL; }
756 virtual GBool isBinary(GBool last = gTrue);
757 virtual GBool isEncoder() { return gTrue; }
759 private:
761 int length;
762 int count;
765 //------------------------------------------------------------------------
766 // ASCIIHexEncoder
767 //------------------------------------------------------------------------
769 class ASCIIHexEncoder: public FilterStream {
770 public:
772 ASCIIHexEncoder(Stream *strA);
773 virtual ~ASCIIHexEncoder();
774 virtual StreamKind getKind() { return strWeird; }
775 virtual void reset();
776 virtual int getChar()
777 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
778 virtual int lookChar()
779 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
780 virtual GString *getPSFilter(int psLevel, char *indent) { return NULL; }
781 virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
782 virtual GBool isEncoder() { return gTrue; }
784 private:
786 char buf[4];
787 char *bufPtr;
788 char *bufEnd;
789 int lineLen;
790 GBool eof;
792 GBool fillBuf();
795 //------------------------------------------------------------------------
796 // ASCII85Encoder
797 //------------------------------------------------------------------------
799 class ASCII85Encoder: public FilterStream {
800 public:
802 ASCII85Encoder(Stream *strA);
803 virtual ~ASCII85Encoder();
804 virtual StreamKind getKind() { return strWeird; }
805 virtual void reset();
806 virtual int getChar()
807 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
808 virtual int lookChar()
809 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
810 virtual GString *getPSFilter(int psLevel, char *indent) { return NULL; }
811 virtual GBool isBinary(GBool last = gTrue) { return gFalse; }
812 virtual GBool isEncoder() { return gTrue; }
814 private:
816 char buf[8];
817 char *bufPtr;
818 char *bufEnd;
819 int lineLen;
820 GBool eof;
822 GBool fillBuf();
825 //------------------------------------------------------------------------
826 // RunLengthEncoder
827 //------------------------------------------------------------------------
829 class RunLengthEncoder: public FilterStream {
830 public:
832 RunLengthEncoder(Stream *strA);
833 virtual ~RunLengthEncoder();
834 virtual StreamKind getKind() { return strWeird; }
835 virtual void reset();
836 virtual int getChar()
837 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
838 virtual int lookChar()
839 { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
840 virtual GString *getPSFilter(int psLevel, char *indent) { return NULL; }
841 virtual GBool isBinary(GBool last = gTrue) { return gTrue; }
842 virtual GBool isEncoder() { return gTrue; }
844 private:
846 char buf[131];
847 char *bufPtr;
848 char *bufEnd;
849 char *nextEnd;
850 GBool eof;
852 GBool fillBuf();
855 //------------------------------------------------------------------------
856 // StrStream
857 //------------------------------------------------------------------------
859 class StrStream: public BaseStream {
860 public:
862 StrStream(GString *str, Object *dict1);
863 virtual ~StrStream();
864 virtual Stream *makeSubStream(Guint start, GBool limited, Guint length, Object *dict)
865 { return NULL; }
866 virtual StreamKind getKind() { return strString; }
867 virtual void reset() { bufPtr = buf; }
868 virtual int getChar()
869 { return bufPtr >= bufEnd ? EOF : (*bufPtr++ & 0xff); }
870 virtual int lookChar()
871 { return bufPtr >= bufEnd ? EOF : (*bufPtr & 0xff); }
872 virtual int getPos() { return bufPtr - buf; }
873 virtual void setPos(Guint pos1, int dir) { bufPtr = (dir < 0 ? bufEnd - pos1 : buf + pos1); }
874 virtual GBool isBinary(GBool last = gTrue) { return last; }
875 virtual Guint getStart() { return 0; }
876 virtual void moveStart(int delta) {}
878 private:
879 char *buf;
880 char *bufPtr;
881 char *bufEnd;
882 GString *str;
883 Object dict;
887 #endif