1 //========================================================================
5 // Copyright 2002-2003 Glyph & Cog, LLC
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2009 David Benjamin <davidben@mit.edu>
17 // Copyright (C) 2013 Adrian Johnson <ajohnson@redneon.com>
18 // Copyright (C) 2015 Suzuki Toshiya <mpsuzuki@hiroshima-u.ac.jp>
20 // To see a description of the changes please see the Changelog file that
21 // came with your tarball or type make ChangeLog if you are building from git
23 //========================================================================
28 #ifdef USE_GCC_PRAGMAS
32 #include "goo/gtypes.h"
39 class JArithmeticDecoder
;
40 class JArithmeticDecoderStats
;
41 class JBIG2HuffmanDecoder
;
42 struct JBIG2HuffmanTable
;
43 class JBIG2MMRDecoder
;
45 //------------------------------------------------------------------------
47 class JBIG2Stream
: public FilterStream
{
50 JBIG2Stream(Stream
*strA
, Object
*globalsStreamA
, Object
*globalsStreamRefA
);
51 virtual ~JBIG2Stream();
52 virtual StreamKind
getKind() { return strJBIG2
; }
55 virtual Goffset
getPos();
56 virtual int getChar();
57 virtual int lookChar();
58 virtual GooString
*getPSFilter(int psLevel
, const char *indent
);
59 virtual GBool
isBinary(GBool last
= gTrue
);
60 virtual Object
*getGlobalsStream() { return &globalsStream
; }
61 virtual Ref
getGlobalsStreamRef() { return globalsStreamRef
; }
64 virtual GBool
hasGetChars() { return true; }
65 virtual int getChars(int nChars
, Guchar
*buffer
);
68 GBool
readSymbolDictSeg(Guint segNum
, Guint length
,
69 Guint
*refSegs
, Guint nRefSegs
);
70 void readTextRegionSeg(Guint segNum
, GBool imm
,
71 GBool lossless
, Guint length
,
72 Guint
*refSegs
, Guint nRefSegs
);
73 JBIG2Bitmap
*readTextRegion(GBool huff
, GBool refine
,
78 JBIG2HuffmanTable
*symCodeTab
,
81 Guint defPixel
, Guint combOp
,
82 Guint transposed
, Guint refCorner
,
84 JBIG2HuffmanTable
*huffFSTable
,
85 JBIG2HuffmanTable
*huffDSTable
,
86 JBIG2HuffmanTable
*huffDTTable
,
87 JBIG2HuffmanTable
*huffRDWTable
,
88 JBIG2HuffmanTable
*huffRDHTable
,
89 JBIG2HuffmanTable
*huffRDXTable
,
90 JBIG2HuffmanTable
*huffRDYTable
,
91 JBIG2HuffmanTable
*huffRSizeTable
,
94 void readPatternDictSeg(Guint segNum
, Guint length
);
95 void readHalftoneRegionSeg(Guint segNum
, GBool imm
,
96 GBool lossless
, Guint length
,
97 Guint
*refSegs
, Guint nRefSegs
);
98 void readGenericRegionSeg(Guint segNum
, GBool imm
,
99 GBool lossless
, Guint length
);
100 void mmrAddPixels(int a1
, int blackPixels
,
101 int *codingLine
, int *a0i
, int w
);
102 void mmrAddPixelsNeg(int a1
, int blackPixels
,
103 int *codingLine
, int *a0i
, int w
);
104 JBIG2Bitmap
*readGenericBitmap(GBool mmr
, int w
, int h
,
105 int templ
, GBool tpgdOn
,
106 GBool useSkip
, JBIG2Bitmap
*skip
,
109 void readGenericRefinementRegionSeg(Guint segNum
, GBool imm
,
110 GBool lossless
, Guint length
,
113 JBIG2Bitmap
*readGenericRefinementRegion(int w
, int h
,
114 int templ
, GBool tpgrOn
,
115 JBIG2Bitmap
*refBitmap
,
116 int refDX
, int refDY
,
118 void readPageInfoSeg(Guint length
);
119 void readEndOfStripeSeg(Guint length
);
120 void readProfilesSeg(Guint length
);
121 void readCodeTableSeg(Guint segNum
, Guint length
);
122 void readExtensionSeg(Guint length
);
123 JBIG2Segment
*findSegment(Guint segNum
);
124 void discardSegment(Guint segNum
);
125 void resetGenericStats(Guint templ
,
126 JArithmeticDecoderStats
*prevStats
);
127 void resetRefinementStats(Guint templ
,
128 JArithmeticDecoderStats
*prevStats
);
129 void resetIntStats(int symCodeLen
);
130 GBool
readUByte(Guint
*x
);
131 GBool
readByte(int *x
);
132 GBool
readUWord(Guint
*x
);
133 GBool
readULong(Guint
*x
);
134 GBool
readLong(int *x
);
136 Object globalsStream
;
137 Ref globalsStreamRef
;
138 Guint pageW
, pageH
, curPageH
;
140 JBIG2Bitmap
*pageBitmap
;
142 GooList
*segments
; // [JBIG2Segment]
143 GooList
*globalSegments
; // [JBIG2Segment]
148 JArithmeticDecoder
*arithDecoder
;
149 JArithmeticDecoderStats
*genericRegionStats
;
150 JArithmeticDecoderStats
*refinementRegionStats
;
151 JArithmeticDecoderStats
*iadhStats
;
152 JArithmeticDecoderStats
*iadwStats
;
153 JArithmeticDecoderStats
*iaexStats
;
154 JArithmeticDecoderStats
*iaaiStats
;
155 JArithmeticDecoderStats
*iadtStats
;
156 JArithmeticDecoderStats
*iaitStats
;
157 JArithmeticDecoderStats
*iafsStats
;
158 JArithmeticDecoderStats
*iadsStats
;
159 JArithmeticDecoderStats
*iardxStats
;
160 JArithmeticDecoderStats
*iardyStats
;
161 JArithmeticDecoderStats
*iardwStats
;
162 JArithmeticDecoderStats
*iardhStats
;
163 JArithmeticDecoderStats
*iariStats
;
164 JArithmeticDecoderStats
*iaidStats
;
165 JBIG2HuffmanDecoder
*huffDecoder
;
166 JBIG2MMRDecoder
*mmrDecoder
;