beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / poppler / JArithmeticDecoder.h
blob3c3e6fed0e5a326421f52dce1eba7c1ecf787bc4
1 //========================================================================
2 //
3 // JArithmeticDecoder.h
4 //
5 // Arithmetic decoder used by the JBIG2 and JPEG2000 decoders.
6 //
7 // Copyright 2002-2004 Glyph & Cog, LLC
8 //
9 //========================================================================
11 #ifndef JARITHMETICDECODER_H
12 #define JARITHMETICDECODER_H
14 #ifdef USE_GCC_PRAGMAS
15 #pragma interface
16 #endif
18 #include "goo/gtypes.h"
20 class Stream;
22 //------------------------------------------------------------------------
23 // JArithmeticDecoderStats
24 //------------------------------------------------------------------------
26 class JArithmeticDecoderStats {
27 public:
29 JArithmeticDecoderStats(int contextSizeA);
30 ~JArithmeticDecoderStats();
31 JArithmeticDecoderStats *copy();
32 void reset();
33 int getContextSize() { return contextSize; }
34 void copyFrom(JArithmeticDecoderStats *stats);
35 void setEntry(Guint cx, int i, int mps);
37 private:
39 Guchar *cxTab; // cxTab[cx] = (i[cx] << 1) + mps[cx]
40 int contextSize;
42 friend class JArithmeticDecoder;
45 //------------------------------------------------------------------------
46 // JArithmeticDecoder
47 //------------------------------------------------------------------------
49 class JArithmeticDecoder {
50 public:
52 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
61 // runs INITDEC.
62 void start();
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
67 // packets/layers.)
68 void restart(int dataLenA);
70 // Read any leftover data in the stream.
71 void cleanup();
73 // Decode one bit.
74 int decodeBit(Guint context, JArithmeticDecoderStats *stats);
76 // Decode eight bits.
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; }
88 private:
90 Guint readByte();
91 int decodeIntBit(JArithmeticDecoderStats *stats);
92 void byteIn();
94 static Guint qeTab[47];
95 static int nmpsTab[47];
96 static int nlpsTab[47];
97 static int switchTab[47];
99 Guint buf0, buf1;
100 Guint c, a;
101 int ct;
103 Guint prev; // for the integer decoder
105 Stream *str;
106 Guint nBytesRead;
107 int dataLen;
108 GBool limitStream;
111 #endif