source: trunk/poppler/mypoppler/poppler/Stream.h @ 461

Last change on this file since 461 was 461, checked in by Silvan Scherrer, 11 years ago

poppler update to 0.14.2

File size: 29.9 KB
Line 
1//========================================================================
2//
3// Stream.h
4//
5// Copyright 1996-2003 Glyph & Cog, LLC
6//
7//========================================================================
8
9//========================================================================
10//
11// Modified under the Poppler project - http://poppler.freedesktop.org
12//
13// All changes made under the Poppler project to this file are licensed
14// under GPL version 2 or later
15//
16// Copyright (C) 2005 Jeff Muizelaar <jeff@infidigm.net>
17// Copyright (C) 2008 Julien Rebetez <julien@fhtagn.net>
18// Copyright (C) 2008 Albert Astals Cid <aacid@kde.org>
19// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
20// Copyright (C) 2009 Stefan Thomas <thomas@eload24.com>
21// Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
22//
23// To see a description of the changes please see the Changelog file that
24// came with your tarball or type make ChangeLog if you are building from git
25//
26//========================================================================
27
28#ifndef STREAM_H
29#define STREAM_H
30
31#ifdef USE_GCC_PRAGMAS
32#pragma interface
33#endif
34
35#include <stdio.h>
36#include "goo/gtypes.h"
37#include "goo/GooVector.h"
38#include "Object.h"
39
40class BaseStream;
41class CachedFile;
42
43//------------------------------------------------------------------------
44
45enum StreamKind {
46  strFile,
47  strCachedFile,
48  strASCIIHex,
49  strASCII85,
50  strLZW,
51  strRunLength,
52  strCCITTFax,
53  strDCT,
54  strFlate,
55  strJBIG2,
56  strJPX,
57  strWeird                      // internal-use stream types
58};
59
60enum StreamColorSpaceMode {
61  streamCSNone,
62  streamCSDeviceGray,
63  streamCSDeviceRGB,
64  streamCSDeviceCMYK
65};
66
67//------------------------------------------------------------------------
68
69// This is in Stream.h instead of Decrypt.h to avoid really annoying
70// include file dependency loops.
71enum CryptAlgorithm {
72  cryptRC4,
73  cryptAES
74};
75
76//------------------------------------------------------------------------
77
78typedef struct _ByteRange {
79  Guint offset;
80  Guint length;
81} ByteRange;
82
83//------------------------------------------------------------------------
84// Stream (base class)
85//------------------------------------------------------------------------
86
87class Stream {
88public:
89
90  // Constructor.
91  Stream();
92
93  // Destructor.
94  virtual ~Stream();
95
96  // Reference counting.
97  int incRef() { return ++ref; }
98  int decRef() { return --ref; }
99
100  // Get kind of stream.
101  virtual StreamKind getKind() = 0;
102
103  // Reset stream to beginning.
104  virtual void reset() = 0;
105
106  // Close down the stream.
107  virtual void close();
108
109  // Get next char from stream.
110  virtual int getChar() = 0;
111
112  // Peek at next char in stream.
113  virtual int lookChar() = 0;
114
115  // Get next char from stream without using the predictor.
116  // This is only used by StreamPredictor.
117  virtual int getRawChar();
118
119  // Get next char directly from stream source, without filtering it
120  virtual int getUnfilteredChar () = 0;
121
122  // Resets the stream without reading anything (even not the headers)
123  // WARNING: Reading the stream with something else than getUnfilteredChar
124  // may lead to unexcepted behaviour until you call reset ()
125  virtual void unfilteredReset () = 0;
126
127  // Get next line from stream.
128  virtual char *getLine(char *buf, int size);
129
130  // Get current position in file.
131  virtual int getPos() = 0;
132
133  // Go to a position in the stream.  If <dir> is negative, the
134  // position is from the end of the file; otherwise the position is
135  // from the start of the file.
136  virtual void setPos(Guint pos, int dir = 0) = 0;
137
138  // Get PostScript command for the filter(s).
139  virtual GooString *getPSFilter(int psLevel, char *indent);
140
141  // Does this stream type potentially contain non-printable chars?
142  virtual GBool isBinary(GBool last = gTrue) = 0;
143
144  // Get the BaseStream of this stream.
145  virtual BaseStream *getBaseStream() = 0;
146
147  // Get the stream after the last decoder (this may be a BaseStream
148  // or a DecryptStream).
149  virtual Stream *getUndecodedStream() = 0;
150
151  // Get the dictionary associated with this stream.
152  virtual Dict *getDict() = 0;
153
154  // Is this an encoding filter?
155  virtual GBool isEncoder() { return gFalse; }
156
157  // Get image parameters which are defined by the stream contents.
158  virtual void getImageParams(int * /*bitsPerComponent*/,
159                              StreamColorSpaceMode * /*csMode*/) {}
160
161  // Return the next stream in the "stack".
162  virtual Stream *getNextStream() { return NULL; }
163
164  // Add filters to this stream according to the parameters in <dict>.
165  // Returns the new stream.
166  Stream *addFilters(Object *dict);
167
168private:
169
170  Stream *makeFilter(char *name, Stream *str, Object *params);
171
172  int ref;                      // reference count
173};
174
175
176 //------------------------------------------------------------------------
177// OutStream
178//
179// This is the base class for all streams that output to a file
180//------------------------------------------------------------------------
181class OutStream {
182public:
183  // Constructor.
184  OutStream ();
185
186  // Desctructor.
187  virtual ~OutStream ();
188
189  // Reference counting.
190  int incRef() { return ++ref; }
191  int decRef() { return --ref; }
192
193  // Close the stream
194  virtual void close() = 0;
195
196  // Return position in stream
197  virtual int getPos() = 0;
198
199  // Put a char in the stream
200  virtual void put (char c) = 0;
201
202  //FIXME
203  // Printf-like function                         2,3 because the first arg is class instance ?
204  virtual void printf (const char *format, ...) = 0 ; //__attribute__((format(printf, 2,3))) = 0;
205
206private:
207  int ref; // reference count
208   
209};
210
211//------------------------------------------------------------------------
212// FileOutStream
213//------------------------------------------------------------------------
214class FileOutStream : public OutStream {
215public:
216  FileOutStream (FILE* fa, Guint startA);
217
218  virtual ~FileOutStream ();
219
220  virtual void close();
221
222  virtual int getPos();
223
224  virtual void put (char c);
225
226  virtual void printf (const char *format, ...);
227private:
228  FILE *f;
229  Guint start;
230
231};
232
233
234//------------------------------------------------------------------------
235// BaseStream
236//
237// This is the base class for all streams that read directly from a file.
238//------------------------------------------------------------------------
239
240class BaseStream: public Stream {
241public:
242
243  BaseStream(Object *dictA);
244  virtual ~BaseStream();
245  virtual Stream *makeSubStream(Guint start, GBool limited,
246                                Guint length, Object *dict) = 0;
247  virtual void setPos(Guint pos, int dir = 0) = 0;
248  virtual GBool isBinary(GBool last = gTrue) { return last; }
249  virtual BaseStream *getBaseStream() { return this; }
250  virtual Stream *getUndecodedStream() { return this; }
251  virtual Dict *getDict() { return dict.getDict(); }
252  virtual GooString *getFileName() { return NULL; }
253
254  // Get/set position of first byte of stream within the file.
255  virtual Guint getStart() = 0;
256  virtual void moveStart(int delta) = 0;
257
258private:
259
260  Object dict;
261};
262
263//------------------------------------------------------------------------
264// FilterStream
265//
266// This is the base class for all streams that filter another stream.
267//------------------------------------------------------------------------
268
269class FilterStream: public Stream {
270public:
271
272  FilterStream(Stream *strA);
273  virtual ~FilterStream();
274  virtual void close();
275  virtual int getPos() { return str->getPos(); }
276  virtual void setPos(Guint pos, int dir = 0);
277  virtual BaseStream *getBaseStream() { return str->getBaseStream(); }
278  virtual Stream *getUndecodedStream() { return str->getUndecodedStream(); }
279  virtual Dict *getDict() { return str->getDict(); }
280  virtual Stream *getNextStream() { return str; }
281
282  virtual int getUnfilteredChar () { return str->getUnfilteredChar(); }
283  virtual void unfilteredReset () { str->unfilteredReset(); }
284
285protected:
286
287  Stream *str;
288};
289
290//------------------------------------------------------------------------
291// ImageStream
292//------------------------------------------------------------------------
293
294class ImageStream {
295public:
296
297  // Create an image stream object for an image with the specified
298  // parameters.  Note that these are the actual image parameters,
299  // which may be different from the predictor parameters.
300  ImageStream(Stream *strA, int widthA, int nCompsA, int nBitsA);
301
302  ~ImageStream();
303
304  // Reset the stream.
305  void reset();
306
307  // Close the stream previously reset
308  void close();
309
310  // Gets the next pixel from the stream.  <pix> should be able to hold
311  // at least nComps elements.  Returns false at end of file.
312  GBool getPixel(Guchar *pix);
313
314  // Returns a pointer to the next line of pixels.  Returns NULL at
315  // end of file.
316  Guchar *getLine();
317
318  // Skip an entire line from the image.
319  void skipLine();
320
321private:
322
323  Stream *str;                  // base stream
324  int width;                    // pixels per line
325  int nComps;                   // components per pixel
326  int nBits;                    // bits per component
327  int nVals;                    // components per line
328  Guchar *imgLine;              // line buffer
329  int imgIdx;                   // current index in imgLine
330};
331
332//------------------------------------------------------------------------
333// StreamPredictor
334//------------------------------------------------------------------------
335
336class StreamPredictor {
337public:
338
339  // Create a predictor object.  Note that the parameters are for the
340  // predictor, and may not match the actual image parameters.
341  StreamPredictor(Stream *strA, int predictorA,
342                  int widthA, int nCompsA, int nBitsA);
343
344  ~StreamPredictor();
345
346  GBool isOk() { return ok; }
347
348  int lookChar();
349  int getChar();
350
351private:
352
353  GBool getNextLine();
354
355  Stream *str;                  // base stream
356  int predictor;                // predictor
357  int width;                    // pixels per line
358  int nComps;                   // components per pixel
359  int nBits;                    // bits per component
360  int nVals;                    // components per line
361  int pixBytes;                 // bytes per pixel
362  int rowBytes;                 // bytes per line
363  Guchar *predLine;             // line buffer
364  int predIdx;                  // current index in predLine
365  GBool ok;
366};
367
368//------------------------------------------------------------------------
369// FileStream
370//------------------------------------------------------------------------
371
372#define fileStreamBufSize 256
373
374class FileStream: public BaseStream {
375public:
376
377  FileStream(FILE *fA, Guint startA, GBool limitedA,
378             Guint lengthA, Object *dictA);
379  virtual ~FileStream();
380  virtual Stream *makeSubStream(Guint startA, GBool limitedA,
381                                Guint lengthA, Object *dictA);
382  virtual StreamKind getKind() { return strFile; }
383  virtual void reset();
384  virtual void close();
385  virtual int getChar()
386    { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
387  virtual int lookChar()
388    { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
389  virtual int getPos() { return bufPos + (bufPtr - buf); }
390  virtual void setPos(Guint pos, int dir = 0);
391  virtual Guint getStart() { return start; }
392  virtual void moveStart(int delta);
393
394  virtual int getUnfilteredChar () { return getChar(); }
395  virtual void unfilteredReset () { reset(); }
396
397private:
398
399  GBool fillBuf();
400
401  FILE *f;
402  Guint start;
403  GBool limited;
404  Guint length;
405  char buf[fileStreamBufSize];
406  char *bufPtr;
407  char *bufEnd;
408  Guint bufPos;
409  int savePos;
410  GBool saved;
411};
412
413//------------------------------------------------------------------------
414// CachedFileStream
415//------------------------------------------------------------------------
416
417#define cachedStreamBufSize 1024
418
419class CachedFileStream: public BaseStream {
420public:
421
422  CachedFileStream(CachedFile *ccA, Guint startA, GBool limitedA,
423             Guint lengthA, Object *dictA);
424  virtual ~CachedFileStream();
425  virtual Stream *makeSubStream(Guint startA, GBool limitedA,
426                                Guint lengthA, Object *dictA);
427  virtual StreamKind getKind() { return strCachedFile; }
428  virtual void reset();
429  virtual void close();
430  virtual int getChar()
431    { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
432  virtual int lookChar()
433    { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
434  virtual int getPos() { return bufPos + (bufPtr - buf); }
435  virtual void setPos(Guint pos, int dir = 0);
436  virtual Guint getStart() { return start; }
437  virtual void moveStart(int delta);
438
439  virtual int getUnfilteredChar () { return getChar(); }
440  virtual void unfilteredReset () { reset(); }
441
442private:
443
444  GBool fillBuf();
445
446  CachedFile *cc;
447  Guint start;
448  GBool limited;
449  Guint length;
450  char buf[cachedStreamBufSize];
451  char *bufPtr;
452  char *bufEnd;
453  Guint bufPos;
454  int savePos;
455  GBool saved;
456};
457
458
459//------------------------------------------------------------------------
460// MemStream
461//------------------------------------------------------------------------
462
463class MemStream: public BaseStream {
464public:
465
466  MemStream(char *bufA, Guint startA, Guint lengthA, Object *dictA);
467  virtual ~MemStream();
468  virtual Stream *makeSubStream(Guint start, GBool limited,
469                                Guint lengthA, Object *dictA);
470  virtual StreamKind getKind() { return strWeird; }
471  virtual void reset();
472  virtual void close();
473  virtual int getChar()
474    { return (bufPtr < bufEnd) ? (*bufPtr++ & 0xff) : EOF; }
475  virtual int lookChar()
476    { return (bufPtr < bufEnd) ? (*bufPtr & 0xff) : EOF; }
477  virtual int getPos() { return (int)(bufPtr - buf); }
478  virtual void setPos(Guint pos, int dir = 0);
479  virtual Guint getStart() { return start; }
480  virtual void moveStart(int delta);
481
482  //if needFree = true, the stream will delete buf when it is destroyed
483  //otherwise it will not touch it. Default value is false
484  virtual void setNeedFree (GBool val) { needFree = val; }
485
486  virtual int getUnfilteredChar () { return getChar(); }
487  virtual void unfilteredReset () { reset (); } 
488
489private:
490
491  char *buf;
492  Guint start;
493  Guint length;
494  char *bufEnd;
495  char *bufPtr;
496  GBool needFree;
497};
498
499//------------------------------------------------------------------------
500// EmbedStream
501//
502// This is a special stream type used for embedded streams (inline
503// images).  It reads directly from the base stream -- after the
504// EmbedStream is deleted, reads from the base stream will proceed where
505// the BaseStream left off.  Note that this is very different behavior
506// that creating a new FileStream (using makeSubStream).
507//------------------------------------------------------------------------
508
509class EmbedStream: public BaseStream {
510public:
511
512  EmbedStream(Stream *strA, Object *dictA, GBool limitedA, Guint lengthA);
513  virtual ~EmbedStream();
514  virtual Stream *makeSubStream(Guint start, GBool limitedA,
515                                Guint lengthA, Object *dictA);
516  virtual StreamKind getKind() { return str->getKind(); }
517  virtual void reset() {}
518  virtual int getChar();
519  virtual int lookChar();
520  virtual int getPos() { return str->getPos(); }
521  virtual void setPos(Guint pos, int dir = 0);
522  virtual Guint getStart();
523  virtual void moveStart(int delta);
524
525  virtual int getUnfilteredChar () { return str->getUnfilteredChar(); }
526  virtual void unfilteredReset () { str->unfilteredReset(); }
527
528
529private:
530
531  Stream *str;
532  GBool limited;
533  Guint length;
534};
535
536//------------------------------------------------------------------------
537// ASCIIHexStream
538//------------------------------------------------------------------------
539
540class ASCIIHexStream: public FilterStream {
541public:
542
543  ASCIIHexStream(Stream *strA);
544  virtual ~ASCIIHexStream();
545  virtual StreamKind getKind() { return strASCIIHex; }
546  virtual void reset();
547  virtual int getChar()
548    { int c = lookChar(); buf = EOF; return c; }
549  virtual int lookChar();
550  virtual GooString *getPSFilter(int psLevel, char *indent);
551  virtual GBool isBinary(GBool last = gTrue);
552
553private:
554
555  int buf;
556  GBool eof;
557};
558
559//------------------------------------------------------------------------
560// ASCII85Stream
561//------------------------------------------------------------------------
562
563class ASCII85Stream: public FilterStream {
564public:
565
566  ASCII85Stream(Stream *strA);
567  virtual ~ASCII85Stream();
568  virtual StreamKind getKind() { return strASCII85; }
569  virtual void reset();
570  virtual int getChar()
571    { int ch = lookChar(); ++index; return ch; }
572  virtual int lookChar();
573  virtual GooString *getPSFilter(int psLevel, char *indent);
574  virtual GBool isBinary(GBool last = gTrue);
575
576private:
577
578  int c[5];
579  int b[4];
580  int index, n;
581  GBool eof;
582};
583
584//------------------------------------------------------------------------
585// LZWStream
586//------------------------------------------------------------------------
587
588class LZWStream: public FilterStream {
589public:
590
591  LZWStream(Stream *strA, int predictor, int columns, int colors,
592            int bits, int earlyA);
593  virtual ~LZWStream();
594  virtual StreamKind getKind() { return strLZW; }
595  virtual void reset();
596  virtual int getChar();
597  virtual int lookChar();
598  virtual int getRawChar();
599  virtual GooString *getPSFilter(int psLevel, char *indent);
600  virtual GBool isBinary(GBool last = gTrue);
601
602private:
603
604  StreamPredictor *pred;        // predictor
605  int early;                    // early parameter
606  GBool eof;                    // true if at eof
607  int inputBuf;                 // input buffer
608  int inputBits;                // number of bits in input buffer
609  struct {                      // decoding table
610    int length;
611    int head;
612    Guchar tail;
613  } table[4097];
614  int nextCode;                 // next code to be used
615  int nextBits;                 // number of bits in next code word
616  int prevCode;                 // previous code used in stream
617  int newChar;                  // next char to be added to table
618  Guchar seqBuf[4097];          // buffer for current sequence
619  int seqLength;                // length of current sequence
620  int seqIndex;                 // index into current sequence
621  GBool first;                  // first code after a table clear
622
623  GBool processNextCode();
624  void clearTable();
625  int getCode();
626};
627
628//------------------------------------------------------------------------
629// RunLengthStream
630//------------------------------------------------------------------------
631
632class RunLengthStream: public FilterStream {
633public:
634
635  RunLengthStream(Stream *strA);
636  virtual ~RunLengthStream();
637  virtual StreamKind getKind() { return strRunLength; }
638  virtual void reset();
639  virtual int getChar()
640    { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
641  virtual int lookChar()
642    { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
643  virtual GooString *getPSFilter(int psLevel, char *indent);
644  virtual GBool isBinary(GBool last = gTrue);
645
646private:
647
648  char buf[128];                // buffer
649  char *bufPtr;                 // next char to read
650  char *bufEnd;                 // end of buffer
651  GBool eof;
652
653  GBool fillBuf();
654};
655
656//------------------------------------------------------------------------
657// CCITTFaxStream
658//------------------------------------------------------------------------
659
660struct CCITTCodeTable;
661
662class CCITTFaxStream: public FilterStream {
663public:
664
665  CCITTFaxStream(Stream *strA, int encodingA, GBool endOfLineA,
666                 GBool byteAlignA, int columnsA, int rowsA,
667                 GBool endOfBlockA, GBool blackA);
668  virtual ~CCITTFaxStream();
669  virtual StreamKind getKind() { return strCCITTFax; }
670  virtual void reset();
671  virtual int getChar()
672    { int c = lookChar(); buf = EOF; return c; }
673  virtual int lookChar();
674  virtual GooString *getPSFilter(int psLevel, char *indent);
675  virtual GBool isBinary(GBool last = gTrue);
676
677  virtual void unfilteredReset ();
678
679private:
680
681  int encoding;                 // 'K' parameter
682  GBool endOfLine;              // 'EndOfLine' parameter
683  GBool byteAlign;              // 'EncodedByteAlign' parameter
684  int columns;                  // 'Columns' parameter
685  int rows;                     // 'Rows' parameter
686  GBool endOfBlock;             // 'EndOfBlock' parameter
687  GBool black;                  // 'BlackIs1' parameter
688  GBool eof;                    // true if at eof
689  GBool nextLine2D;             // true if next line uses 2D encoding
690  int row;                      // current row
691  int inputBuf;                 // input buffer
692  int inputBits;                // number of bits in input buffer
693  int *codingLine;              // coding line changing elements
694  int *refLine;                 // reference line changing elements
695  int a0i;                      // index into codingLine
696  GBool err;                    // error on current line
697  int outputBits;               // remaining ouput bits
698  int buf;                      // character buffer
699
700  void addPixels(int a1, int black);
701  void addPixelsNeg(int a1, int black);
702  short getTwoDimCode();
703  short getWhiteCode();
704  short getBlackCode();
705  short lookBits(int n);
706  void eatBits(int n) { if ((inputBits -= n) < 0) inputBits = 0; }
707};
708
709#ifndef ENABLE_LIBJPEG
710//------------------------------------------------------------------------
711// DCTStream
712//------------------------------------------------------------------------
713
714// DCT component info
715struct DCTCompInfo {
716  int id;                       // component ID
717  int hSample, vSample;         // horiz/vert sampling resolutions
718  int quantTable;               // quantization table number
719  int prevDC;                   // DC coefficient accumulator
720};
721
722struct DCTScanInfo {
723  GBool comp[4];                // comp[i] is set if component i is
724                                //   included in this scan
725  int numComps;                 // number of components in the scan
726  int dcHuffTable[4];           // DC Huffman table numbers
727  int acHuffTable[4];           // AC Huffman table numbers
728  int firstCoeff, lastCoeff;    // first and last DCT coefficient
729  int ah, al;                   // successive approximation parameters
730};
731
732// DCT Huffman decoding table
733struct DCTHuffTable {
734  Guchar firstSym[17];          // first symbol for this bit length
735  Gushort firstCode[17];        // first code for this bit length
736  Gushort numCodes[17];         // number of codes of this bit length
737  Guchar sym[256];              // symbols
738};
739
740class DCTStream: public FilterStream {
741public:
742
743  DCTStream(Stream *strA, int colorXformA);
744  virtual ~DCTStream();
745  virtual StreamKind getKind() { return strDCT; }
746  virtual void reset();
747  virtual void close();
748  virtual int getChar();
749  virtual int lookChar();
750  virtual GooString *getPSFilter(int psLevel, char *indent);
751  virtual GBool isBinary(GBool last = gTrue);
752  Stream *getRawStream() { return str; }
753
754  virtual void unfilteredReset();
755
756private:
757
758  GBool progressive;            // set if in progressive mode
759  GBool interleaved;            // set if in interleaved mode
760  int width, height;            // image size
761  int mcuWidth, mcuHeight;      // size of min coding unit, in data units
762  int bufWidth, bufHeight;      // frameBuf size
763  DCTCompInfo compInfo[4];      // info for each component
764  DCTScanInfo scanInfo;         // info for the current scan
765  int numComps;                 // number of components in image
766  int colorXform;               // color transform: -1 = unspecified
767                                //                   0 = none
768                                //                   1 = YUV/YUVK -> RGB/CMYK
769  GBool gotJFIFMarker;          // set if APP0 JFIF marker was present
770  GBool gotAdobeMarker;         // set if APP14 Adobe marker was present
771  int restartInterval;          // restart interval, in MCUs
772  Gushort quantTables[4][64];   // quantization tables
773  int numQuantTables;           // number of quantization tables
774  DCTHuffTable dcHuffTables[4]; // DC Huffman tables
775  DCTHuffTable acHuffTables[4]; // AC Huffman tables
776  int numDCHuffTables;          // number of DC Huffman tables
777  int numACHuffTables;          // number of AC Huffman tables
778  Guchar *rowBuf[4][32];        // buffer for one MCU (non-progressive mode)
779  int *frameBuf[4];             // buffer for frame (progressive mode)
780  int comp, x, y, dy;           // current position within image/MCU
781  int restartCtr;               // MCUs left until restart
782  int restartMarker;            // next restart marker
783  int eobRun;                   // number of EOBs left in the current run
784  int inputBuf;                 // input buffer for variable length codes
785  int inputBits;                // number of valid bits in input buffer
786
787  void restart();
788  GBool readMCURow();
789  void readScan();
790  GBool readDataUnit(DCTHuffTable *dcHuffTable,
791                     DCTHuffTable *acHuffTable,
792                     int *prevDC, int data[64]);
793  GBool readProgressiveDataUnit(DCTHuffTable *dcHuffTable,
794                                DCTHuffTable *acHuffTable,
795                                int *prevDC, int data[64]);
796  void decodeImage();
797  void transformDataUnit(Gushort *quantTable,
798                         int dataIn[64], Guchar dataOut[64]);
799  int readHuffSym(DCTHuffTable *table);
800  int readAmp(int size);
801  int readBit();
802  GBool readHeader();
803  GBool readBaselineSOF();
804  GBool readProgressiveSOF();
805  GBool readScanInfo();
806  GBool readQuantTables();
807  GBool readHuffmanTables();
808  GBool readRestartInterval();
809  GBool readJFIFMarker();
810  GBool readAdobeMarker();
811  GBool readTrailer();
812  int readMarker();
813  int read16();
814};
815
816#endif
817
818#ifndef ENABLE_ZLIB
819//------------------------------------------------------------------------
820// FlateStream
821//------------------------------------------------------------------------
822
823#define flateWindow          32768    // buffer size
824#define flateMask            (flateWindow-1)
825#define flateMaxHuffman         15    // max Huffman code length
826#define flateMaxCodeLenCodes    19    // max # code length codes
827#define flateMaxLitCodes       288    // max # literal codes
828#define flateMaxDistCodes       30    // max # distance codes
829
830// Huffman code table entry
831struct FlateCode {
832  Gushort len;                  // code length, in bits
833  Gushort val;                  // value represented by this code
834};
835
836struct FlateHuffmanTab {
837  FlateCode *codes;
838  int maxLen;
839};
840
841// Decoding info for length and distance code words
842struct FlateDecode {
843  int bits;                     // # extra bits
844  int first;                    // first length/distance
845};
846
847class FlateStream: public FilterStream {
848public:
849
850  FlateStream(Stream *strA, int predictor, int columns,
851              int colors, int bits);
852  virtual ~FlateStream();
853  virtual StreamKind getKind() { return strFlate; }
854  virtual void reset();
855  virtual int getChar();
856  virtual int lookChar();
857  virtual int getRawChar();
858  virtual GooString *getPSFilter(int psLevel, char *indent);
859  virtual GBool isBinary(GBool last = gTrue);
860  virtual void unfilteredReset ();
861
862private:
863
864  StreamPredictor *pred;        // predictor
865  Guchar buf[flateWindow];      // output data buffer
866  int index;                    // current index into output buffer
867  int remain;                   // number valid bytes in output buffer
868  int codeBuf;                  // input buffer
869  int codeSize;                 // number of bits in input buffer
870  int                           // literal and distance code lengths
871    codeLengths[flateMaxLitCodes + flateMaxDistCodes];
872  FlateHuffmanTab litCodeTab;   // literal code table
873  FlateHuffmanTab distCodeTab;  // distance code table
874  GBool compressedBlock;        // set if reading a compressed block
875  int blockLen;                 // remaining length of uncompressed block
876  GBool endOfBlock;             // set when end of block is reached
877  GBool eof;                    // set when end of stream is reached
878
879  static int                    // code length code reordering
880    codeLenCodeMap[flateMaxCodeLenCodes];
881  static FlateDecode            // length decoding info
882    lengthDecode[flateMaxLitCodes-257];
883  static FlateDecode            // distance decoding info
884    distDecode[flateMaxDistCodes];
885  static FlateHuffmanTab        // fixed literal code table
886    fixedLitCodeTab;
887  static FlateHuffmanTab        // fixed distance code table
888    fixedDistCodeTab;
889
890  void readSome();
891  GBool startBlock();
892  void loadFixedCodes();
893  GBool readDynamicCodes();
894  void compHuffmanCodes(int *lengths, int n, FlateHuffmanTab *tab);
895  int getHuffmanCodeWord(FlateHuffmanTab *tab);
896  int getCodeWord(int bits);
897};
898#endif
899
900//------------------------------------------------------------------------
901// EOFStream
902//------------------------------------------------------------------------
903
904class EOFStream: public FilterStream {
905public:
906
907  EOFStream(Stream *strA);
908  virtual ~EOFStream();
909  virtual StreamKind getKind() { return strWeird; }
910  virtual void reset() {}
911  virtual int getChar() { return EOF; }
912  virtual int lookChar() { return EOF; }
913  virtual GooString *getPSFilter(int /*psLevel*/, char * /*indent*/)  { return NULL; }
914  virtual GBool isBinary(GBool /*last = gTrue*/) { return gFalse; }
915};
916
917//------------------------------------------------------------------------
918// FixedLengthEncoder
919//------------------------------------------------------------------------
920
921class FixedLengthEncoder: public FilterStream {
922public:
923
924  FixedLengthEncoder(Stream *strA, int lengthA);
925  ~FixedLengthEncoder();
926  virtual StreamKind getKind() { return strWeird; }
927  virtual void reset();
928  virtual int getChar();
929  virtual int lookChar();
930  virtual GooString *getPSFilter(int /*psLevel*/, char * /*indent*/) { return NULL; }
931  virtual GBool isBinary(GBool /*last = gTrue*/);
932  virtual GBool isEncoder() { return gTrue; }
933
934private:
935
936  int length;
937  int count;
938};
939
940//------------------------------------------------------------------------
941// ASCIIHexEncoder
942//------------------------------------------------------------------------
943
944class ASCIIHexEncoder: public FilterStream {
945public:
946
947  ASCIIHexEncoder(Stream *strA);
948  virtual ~ASCIIHexEncoder();
949  virtual StreamKind getKind() { return strWeird; }
950  virtual void reset();
951  virtual int getChar()
952    { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
953  virtual int lookChar()
954    { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
955  virtual GooString *getPSFilter(int /*psLevel*/, char * /*indent*/) { return NULL; }
956  virtual GBool isBinary(GBool /*last = gTrue*/) { return gFalse; }
957  virtual GBool isEncoder() { return gTrue; }
958
959private:
960
961  char buf[4];
962  char *bufPtr;
963  char *bufEnd;
964  int lineLen;
965  GBool eof;
966
967  GBool fillBuf();
968};
969
970//------------------------------------------------------------------------
971// ASCII85Encoder
972//------------------------------------------------------------------------
973
974class ASCII85Encoder: public FilterStream {
975public:
976
977  ASCII85Encoder(Stream *strA);
978  virtual ~ASCII85Encoder();
979  virtual StreamKind getKind() { return strWeird; }
980  virtual void reset();
981  virtual int getChar()
982    { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
983  virtual int lookChar()
984    { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
985  virtual GooString *getPSFilter(int /*psLevel*/, char * /*indent*/) { return NULL; }
986  virtual GBool isBinary(GBool /*last = gTrue*/) { return gFalse; }
987  virtual GBool isEncoder() { return gTrue; }
988
989private:
990
991  char buf[8];
992  char *bufPtr;
993  char *bufEnd;
994  int lineLen;
995  GBool eof;
996
997  GBool fillBuf();
998};
999
1000//------------------------------------------------------------------------
1001// RunLengthEncoder
1002//------------------------------------------------------------------------
1003
1004class RunLengthEncoder: public FilterStream {
1005public:
1006
1007  RunLengthEncoder(Stream *strA);
1008  virtual ~RunLengthEncoder();
1009  virtual StreamKind getKind() { return strWeird; }
1010  virtual void reset();
1011  virtual int getChar()
1012    { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr++ & 0xff); }
1013  virtual int lookChar()
1014    { return (bufPtr >= bufEnd && !fillBuf()) ? EOF : (*bufPtr & 0xff); }
1015  virtual GooString *getPSFilter(int /*psLevel*/, char * /*indent*/) { return NULL; }
1016  virtual GBool isBinary(GBool /*last = gTrue*/) { return gTrue; }
1017  virtual GBool isEncoder() { return gTrue; }
1018
1019private:
1020
1021  char buf[131];
1022  char *bufPtr;
1023  char *bufEnd;
1024  char *nextEnd;
1025  GBool eof;
1026
1027  GBool fillBuf();
1028};
1029
1030#endif
Note: See TracBrowser for help on using the repository browser.