source: trunk/poppler/mypoppler/poppler/JArithmeticDecoder.h @ 2

Last change on this file since 2 was 2, checked in by Eugene Romanenko, 15 years ago

First import

File size: 2.6 KB
Line 
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//========================================================================
10
11#ifndef JARITHMETICDECODER_H
12#define JARITHMETICDECODER_H
13
14#ifdef USE_GCC_PRAGMAS
15#pragma interface
16#endif
17
18#include "goo/gtypes.h"
19
20class Stream;
21
22//------------------------------------------------------------------------
23// JArithmeticDecoderStats
24//------------------------------------------------------------------------
25
26class JArithmeticDecoderStats {
27public:
28
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);
36
37private:
38
39  Guchar *cxTab;                // cxTab[cx] = (i[cx] << 1) + mps[cx]
40  int contextSize;
41
42  friend class JArithmeticDecoder;
43};
44
45//------------------------------------------------------------------------
46// JArithmeticDecoder
47//------------------------------------------------------------------------
48
49class JArithmeticDecoder {
50public:
51
52  JArithmeticDecoder();
53  ~JArithmeticDecoder();
54
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; }
59
60  // Start decoding on a new stream.  This fills the byte buffers and
61  // runs INITDEC.
62  void start();
63
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);
69
70  // Read any leftover data in the stream.
71  void cleanup();
72
73  // Decode one bit.
74  int decodeBit(Guint context, JArithmeticDecoderStats *stats);
75
76  // Decode eight bits.
77  int decodeByte(Guint context, JArithmeticDecoderStats *stats);
78
79  // Returns false for OOB, otherwise sets *<x> and returns true.
80  GBool decodeInt(int *x, JArithmeticDecoderStats *stats);
81
82  Guint decodeIAID(Guint codeLen,
83                   JArithmeticDecoderStats *stats);
84
85private:
86
87  Guint readByte();
88  int decodeIntBit(JArithmeticDecoderStats *stats);
89  void byteIn();
90
91  static Guint qeTab[47];
92  static int nmpsTab[47];
93  static int nlpsTab[47];
94  static int switchTab[47];
95
96  Guint buf0, buf1;
97  Guint c, a;
98  int ct;
99
100  Guint prev;                   // for the integer decoder
101
102  Stream *str;
103  int dataLen;
104  GBool limitStream;
105};
106
107#endif
Note: See TracBrowser for help on using the repository browser.