1 package SevenZip.Compression.RangeCoder;
2 import java.io.IOException;
6 static final int kTopMask = ~((1 << 24) - 1);
8 static final int kNumBitModelTotalBits = 11;
9 static final int kBitModelTotal = (1 << kNumBitModelTotalBits);
10 static final int kNumMoveBits = 5;
15 java.io.InputStream Stream;
17 public final void SetStream(java.io.InputStream stream)
22 public final void ReleaseStream()
27 public final void Init() throws IOException
31 for (int i = 0; i < 5; i++)
32 Code = (Code << 8) | Stream.read();
35 public final int DecodeDirectBits(int numTotalBits) throws IOException
38 for (int i = numTotalBits; i != 0; i--)
41 int t = ((Code - Range) >>> 31);
42 Code -= Range & (t - 1);
43 result = (result << 1) | (1 - t);
45 if ((Range & kTopMask) == 0)
47 Code = (Code << 8) | Stream.read();
54 public int DecodeBit(short []probs, int index) throws IOException
56 int prob = probs[index];
57 int newBound = (Range >>> kNumBitModelTotalBits) * prob;
58 if ((Code ^ 0x80000000) < (newBound ^ 0x80000000))
61 probs[index] = (short)(prob + ((kBitModelTotal - prob) >>> kNumMoveBits));
62 if ((Range & kTopMask) == 0)
64 Code = (Code << 8) | Stream.read();
73 probs[index] = (short)(prob - ((prob) >>> kNumMoveBits));
74 if ((Range & kTopMask) == 0)
76 Code = (Code << 8) | Stream.read();
83 public static void InitBitModels(short []probs)
85 for (int i = 0; i < probs.length; i++)
86 probs[i] = (kBitModelTotal >>> 1);