File indexing completed on 2025-12-10 10:23:47
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027 #ifndef JARITHMETICDECODER_H
0028 #define JARITHMETICDECODER_H
0029
0030 class Stream;
0031
0032
0033
0034
0035
0036 class JArithmeticDecoderStats
0037 {
0038 public:
0039 explicit JArithmeticDecoderStats(int contextSizeA);
0040 ~JArithmeticDecoderStats();
0041 JArithmeticDecoderStats(const JArithmeticDecoderStats &) = delete;
0042 JArithmeticDecoderStats &operator=(const JArithmeticDecoderStats &) = delete;
0043 JArithmeticDecoderStats *copy();
0044 void reset();
0045 int getContextSize() { return contextSize; }
0046 void copyFrom(JArithmeticDecoderStats *stats);
0047 void setEntry(unsigned int cx, int i, int mps);
0048 bool isValid() const { return cxTab != nullptr; }
0049
0050 private:
0051 unsigned char *cxTab;
0052 int contextSize;
0053
0054 friend class JArithmeticDecoder;
0055 };
0056
0057
0058
0059
0060
0061 class JArithmeticDecoder
0062 {
0063 public:
0064 JArithmeticDecoder();
0065 ~JArithmeticDecoder();
0066 JArithmeticDecoder(const JArithmeticDecoder &) = delete;
0067 JArithmeticDecoder &operator=(const JArithmeticDecoder &) = delete;
0068
0069 void setStream(Stream *strA)
0070 {
0071 str = strA;
0072 dataLen = 0;
0073 limitStream = false;
0074 }
0075 void setStream(Stream *strA, int dataLenA)
0076 {
0077 str = strA;
0078 dataLen = dataLenA;
0079 limitStream = true;
0080 }
0081
0082
0083
0084 void start();
0085
0086
0087
0088
0089
0090 void restart(int dataLenA);
0091
0092
0093 void cleanup();
0094
0095
0096 int decodeBit(unsigned int context, JArithmeticDecoderStats *stats);
0097
0098
0099 int decodeByte(unsigned int context, JArithmeticDecoderStats *stats);
0100
0101
0102 bool decodeInt(int *x, JArithmeticDecoderStats *stats);
0103
0104 unsigned int decodeIAID(unsigned int codeLen, JArithmeticDecoderStats *stats);
0105
0106 void resetByteCounter() { nBytesRead = 0; }
0107 unsigned int getByteCounter() { return nBytesRead; }
0108
0109 private:
0110 unsigned int readByte();
0111 int decodeIntBit(JArithmeticDecoderStats *stats);
0112 void byteIn();
0113
0114 static const unsigned int qeTab[47];
0115 static const int nmpsTab[47];
0116 static const int nlpsTab[47];
0117 static const int switchTab[47];
0118
0119 unsigned int buf0, buf1;
0120 unsigned int c, a;
0121 int ct;
0122
0123 unsigned int prev;
0124
0125 Stream *str;
0126 unsigned int nBytesRead;
0127 int dataLen;
0128 bool limitStream;
0129 };
0130
0131 #endif