01: package SevenZip.Compression.RangeCoder;
02:
03: public class BitTreeDecoder {
04: short[] Models;
05: int NumBitLevels;
06:
07: public BitTreeDecoder(int numBitLevels) {
08: NumBitLevels = numBitLevels;
09: Models = new short[1 << numBitLevels];
10: }
11:
12: public void Init() {
13: Decoder.InitBitModels(Models);
14: }
15:
16: public int Decode(Decoder rangeDecoder) throws java.io.IOException {
17: int m = 1;
18: for (int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)
19: m = (m << 1) + rangeDecoder.DecodeBit(Models, m);
20: return m - (1 << NumBitLevels);
21: }
22:
23: public int ReverseDecode(Decoder rangeDecoder)
24: throws java.io.IOException {
25: int m = 1;
26: int symbol = 0;
27: for (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++) {
28: int bit = rangeDecoder.DecodeBit(Models, m);
29: m <<= 1;
30: m += bit;
31: symbol |= (bit << bitIndex);
32: }
33: return symbol;
34: }
35:
36: public static int ReverseDecode(short[] Models, int startIndex,
37: Decoder rangeDecoder, int NumBitLevels)
38: throws java.io.IOException {
39: int m = 1;
40: int symbol = 0;
41: for (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++) {
42: int bit = rangeDecoder.DecodeBit(Models, startIndex + m);
43: m <<= 1;
44: m += bit;
45: symbol |= (bit << bitIndex);
46: }
47: return symbol;
48: }
49: }
|