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
16 #ifdef USE_GCC_PRAGMAS
24 //------------------------------------------------------------------------
25 // JArithmeticDecoderStats
26 //------------------------------------------------------------------------
28 class JArithmeticDecoderStats {
31 JArithmeticDecoderStats(int contextSizeA);
32 ~JArithmeticDecoderStats();
33 JArithmeticDecoderStats *copy();
35 int getContextSize() { return contextSize; }
36 void copyFrom(JArithmeticDecoderStats *stats);
37 void setEntry(Guint cx, int i, int mps);
41 Guchar *cxTab; // cxTab[cx] = (i[cx] << 1) + mps[cx]
44 friend class JArithmeticDecoder;
47 //------------------------------------------------------------------------
49 //------------------------------------------------------------------------
51 class JArithmeticDecoder {
55 ~JArithmeticDecoder();
56 void setStream(Stream *strA)
57 { str = strA; dataLen = -1; }
58 void setStream(Stream *strA, int dataLenA)
59 { str = strA; dataLen = dataLenA; }
61 int decodeBit(Guint context, JArithmeticDecoderStats *stats);
62 int decodeByte(Guint context, JArithmeticDecoderStats *stats);
64 // Returns false for OOB, otherwise sets *<x> and returns true.
65 GBool decodeInt(int *x, JArithmeticDecoderStats *stats);
67 Guint decodeIAID(Guint codeLen,
68 JArithmeticDecoderStats *stats);
73 int decodeIntBit(JArithmeticDecoderStats *stats);
76 static Guint qeTab[47];
77 static int nmpsTab[47];
78 static int nlpsTab[47];
79 static int switchTab[47];
85 Guint prev; // for the integer decoder