1 //========================================================================
2 //
3 // JBIG2Stream.h
4 //
5 // Copyright 2002-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
8 
9 #ifndef JBIG2STREAM_H
10 #define JBIG2STREAM_H
11 
12 #include <aconf.h>
13 
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
17 
18 #include "gtypes.h"
19 #include "Object.h"
20 #include "Stream.h"
21 
22 class GList;
23 class JBIG2Segment;
24 class JBIG2Bitmap;
25 class JArithmeticDecoder;
26 class JArithmeticDecoderStats;
27 class JBIG2HuffmanDecoder;
28 struct JBIG2HuffmanTable;
29 class JBIG2MMRDecoder;
30 
31 //------------------------------------------------------------------------
32 
33 class JBIG2Stream: public FilterStream {
34 public:
35 
36   JBIG2Stream(Stream *strA, Object *globalsStreamA);
37   virtual ~JBIG2Stream();
getKind()38   virtual StreamKind getKind() { return strJBIG2; }
39   virtual void reset();
40   virtual void close();
41   virtual int getChar();
42   virtual int lookChar();
43   virtual GString *getPSFilter(int psLevel, char *indent);
44   virtual GBool isBinary(GBool last = gTrue);
45 
46 private:
47 
48   void readSegments();
49   GBool readSymbolDictSeg(Guint segNum, Guint length,
50 			  Guint *refSegs, Guint nRefSegs);
51   void readTextRegionSeg(Guint segNum, GBool imm,
52 			 GBool lossless, Guint length,
53 			 Guint *refSegs, Guint nRefSegs);
54   JBIG2Bitmap *readTextRegion(GBool huff, GBool refine,
55 			      int w, int h,
56 			      Guint numInstances,
57 			      Guint logStrips,
58 			      int numSyms,
59 			      JBIG2HuffmanTable *symCodeTab,
60 			      Guint symCodeLen,
61 			      JBIG2Bitmap **syms,
62 			      Guint defPixel, Guint combOp,
63 			      Guint transposed, Guint refCorner,
64 			      int sOffset,
65 			      JBIG2HuffmanTable *huffFSTable,
66 			      JBIG2HuffmanTable *huffDSTable,
67 			      JBIG2HuffmanTable *huffDTTable,
68 			      JBIG2HuffmanTable *huffRDWTable,
69 			      JBIG2HuffmanTable *huffRDHTable,
70 			      JBIG2HuffmanTable *huffRDXTable,
71 			      JBIG2HuffmanTable *huffRDYTable,
72 			      JBIG2HuffmanTable *huffRSizeTable,
73 			      Guint templ,
74 			      int *atx, int *aty);
75   void readPatternDictSeg(Guint segNum, Guint length);
76   void readHalftoneRegionSeg(Guint segNum, GBool imm,
77 			     GBool lossless, Guint length,
78 			     Guint *refSegs, Guint nRefSegs);
79   void readGenericRegionSeg(Guint segNum, GBool imm,
80 			    GBool lossless, Guint length);
81   void mmrAddPixels(int a1, int blackPixels,
82 		    int *codingLine, int *a0i, int w);
83   void mmrAddPixelsNeg(int a1, int blackPixels,
84 		       int *codingLine, int *a0i, int w);
85   JBIG2Bitmap *readGenericBitmap(GBool mmr, int w, int h,
86 				 int templ, GBool tpgdOn,
87 				 GBool useSkip, JBIG2Bitmap *skip,
88 				 int *atx, int *aty,
89 				 int mmrDataLength);
90   void readGenericRefinementRegionSeg(Guint segNum, GBool imm,
91 				      GBool lossless, Guint length,
92 				      Guint *refSegs,
93 				      Guint nRefSegs);
94   JBIG2Bitmap *readGenericRefinementRegion(int w, int h,
95 					   int templ, GBool tpgrOn,
96 					   JBIG2Bitmap *refBitmap,
97 					   int refDX, int refDY,
98 					   int *atx, int *aty);
99   void readPageInfoSeg(Guint length);
100   void readEndOfStripeSeg(Guint length);
101   void readProfilesSeg(Guint length);
102   void readCodeTableSeg(Guint segNum, Guint length);
103   void readExtensionSeg(Guint length);
104   JBIG2Segment *findSegment(Guint segNum);
105   void discardSegment(Guint segNum);
106   void resetGenericStats(Guint templ,
107 			 JArithmeticDecoderStats *prevStats);
108   void resetRefinementStats(Guint templ,
109 			    JArithmeticDecoderStats *prevStats);
110   void resetIntStats(int symCodeLen);
111   GBool readUByte(Guint *x);
112   GBool readByte(int *x);
113   GBool readUWord(Guint *x);
114   GBool readULong(Guint *x);
115   GBool readLong(int *x);
116 
117   Object globalsStream;
118   Guint pageW, pageH, curPageH;
119   Guint pageDefPixel;
120   JBIG2Bitmap *pageBitmap;
121   Guint defCombOp;
122   GList *segments;		// [JBIG2Segment]
123   GList *globalSegments;	// [JBIG2Segment]
124   Stream *curStr;
125   Guchar *dataPtr;
126   Guchar *dataEnd;
127 
128   JArithmeticDecoder *arithDecoder;
129   JArithmeticDecoderStats *genericRegionStats;
130   JArithmeticDecoderStats *refinementRegionStats;
131   JArithmeticDecoderStats *iadhStats;
132   JArithmeticDecoderStats *iadwStats;
133   JArithmeticDecoderStats *iaexStats;
134   JArithmeticDecoderStats *iaaiStats;
135   JArithmeticDecoderStats *iadtStats;
136   JArithmeticDecoderStats *iaitStats;
137   JArithmeticDecoderStats *iafsStats;
138   JArithmeticDecoderStats *iadsStats;
139   JArithmeticDecoderStats *iardxStats;
140   JArithmeticDecoderStats *iardyStats;
141   JArithmeticDecoderStats *iardwStats;
142   JArithmeticDecoderStats *iardhStats;
143   JArithmeticDecoderStats *iariStats;
144   JArithmeticDecoderStats *iaidStats;
145   JBIG2HuffmanDecoder *huffDecoder;
146   JBIG2MMRDecoder *mmrDecoder;
147 };
148 
149 #endif
150