Back to index

tetex-bin  3.0
JArithmeticDecoder.h
Go to the documentation of this file.
00001 //========================================================================
00002 //
00003 // JArithmeticDecoder.h
00004 //
00005 // Arithmetic decoder used by the JBIG2 and JPEG2000 decoders.
00006 //
00007 // Copyright 2002-2004 Glyph & Cog, LLC
00008 //
00009 //========================================================================
00010 
00011 #ifndef JARITHMETICDECODER_H
00012 #define JARITHMETICDECODER_H
00013 
00014 #include <aconf.h>
00015 
00016 #ifdef USE_GCC_PRAGMAS
00017 #pragma interface
00018 #endif
00019 
00020 #include "gtypes.h"
00021 
00022 class Stream;
00023 
00024 //------------------------------------------------------------------------
00025 // JArithmeticDecoderStats
00026 //------------------------------------------------------------------------
00027 
00028 class JArithmeticDecoderStats {
00029 public:
00030 
00031   JArithmeticDecoderStats(int contextSizeA);
00032   ~JArithmeticDecoderStats();
00033   JArithmeticDecoderStats *copy();
00034   void reset();
00035   int getContextSize() { return contextSize; }
00036   void copyFrom(JArithmeticDecoderStats *stats);
00037   void setEntry(Guint cx, int i, int mps);
00038 
00039 private:
00040 
00041   Guchar *cxTab;            // cxTab[cx] = (i[cx] << 1) + mps[cx]
00042   int contextSize;
00043 
00044   friend class JArithmeticDecoder;
00045 };
00046 
00047 //------------------------------------------------------------------------
00048 // JArithmeticDecoder
00049 //------------------------------------------------------------------------
00050 
00051 class JArithmeticDecoder {
00052 public:
00053 
00054   JArithmeticDecoder();
00055   ~JArithmeticDecoder();
00056   void setStream(Stream *strA)
00057     { str = strA; dataLen = -1; }
00058   void setStream(Stream *strA, int dataLenA)
00059     { str = strA; dataLen = dataLenA; }
00060   void start();
00061   int decodeBit(Guint context, JArithmeticDecoderStats *stats);
00062   int decodeByte(Guint context, JArithmeticDecoderStats *stats);
00063 
00064   // Returns false for OOB, otherwise sets *<x> and returns true.
00065   GBool decodeInt(int *x, JArithmeticDecoderStats *stats);
00066 
00067   Guint decodeIAID(Guint codeLen,
00068                  JArithmeticDecoderStats *stats);
00069 
00070 private:
00071 
00072   Guint readByte();
00073   int decodeIntBit(JArithmeticDecoderStats *stats);
00074   void byteIn();
00075 
00076   static Guint qeTab[47];
00077   static int nmpsTab[47];
00078   static int nlpsTab[47];
00079   static int switchTab[47];
00080 
00081   Guint buf0, buf1;
00082   Guint c, a;
00083   int ct;
00084 
00085   Guint prev;               // for the integer decoder
00086 
00087   Stream *str;
00088   int dataLen;
00089 };
00090 
00091 #endif