1 //========================================================================
3 // JArithmeticDecoder.h
5 // Arithmetic decoder used by the JBIG2 and JPEG2000 decoders.
7 // Copyright 2002-2004 Glyph & Cog, LLC
9 //========================================================================
11 #ifndef JARITHMETICDECODER_H
12 #define JARITHMETICDECODER_H
14 #ifdef USE_GCC_PRAGMAS
18 #include "goo/gtypes.h"
22 //------------------------------------------------------------------------
23 // JArithmeticDecoderStats
24 //------------------------------------------------------------------------
26 class JArithmeticDecoderStats
{
29 JArithmeticDecoderStats(int contextSizeA
);
30 ~JArithmeticDecoderStats();
31 JArithmeticDecoderStats
*copy();
33 int getContextSize() { return contextSize
; }
34 void copyFrom(JArithmeticDecoderStats
*stats
);
35 void setEntry(Guint cx
, int i
, int mps
);
39 Guchar
*cxTab
; // cxTab[cx] = (i[cx] << 1) + mps[cx]
42 friend class JArithmeticDecoder
;
45 //------------------------------------------------------------------------
47 //------------------------------------------------------------------------
49 class JArithmeticDecoder
{
53 ~JArithmeticDecoder();
55 void setStream(Stream
*strA
)
56 { str
= strA
; dataLen
= 0; limitStream
= gFalse
; }
57 void setStream(Stream
*strA
, int dataLenA
)
58 { str
= strA
; dataLen
= dataLenA
; limitStream
= gTrue
; }
60 // Start decoding on a new stream. This fills the byte buffers and
64 // Restart decoding on an interrupted stream. This refills the
65 // buffers if needed, but does not run INITDEC. (This is used in
66 // JPEG 2000 streams when codeblock data is split across multiple
68 void restart(int dataLenA
);
70 // Read any leftover data in the stream.
74 int decodeBit(Guint context
, JArithmeticDecoderStats
*stats
);
77 int decodeByte(Guint context
, JArithmeticDecoderStats
*stats
);
79 // Returns false for OOB, otherwise sets *<x> and returns true.
80 GBool
decodeInt(int *x
, JArithmeticDecoderStats
*stats
);
82 Guint
decodeIAID(Guint codeLen
,
83 JArithmeticDecoderStats
*stats
);
85 void resetByteCounter() { nBytesRead
= 0; }
86 Guint
getByteCounter() { return nBytesRead
; }
91 int decodeIntBit(JArithmeticDecoderStats
*stats
);
94 static Guint qeTab
[47];
95 static int nmpsTab
[47];
96 static int nlpsTab
[47];
97 static int switchTab
[47];
103 Guint prev
; // for the integer decoder