1370b324cSopenharmony_cipackage SevenZip.Compression.RangeCoder; 2370b324cSopenharmony_ci 3370b324cSopenharmony_cipublic class BitTreeDecoder 4370b324cSopenharmony_ci{ 5370b324cSopenharmony_ci short[] Models; 6370b324cSopenharmony_ci int NumBitLevels; 7370b324cSopenharmony_ci 8370b324cSopenharmony_ci public BitTreeDecoder(int numBitLevels) 9370b324cSopenharmony_ci { 10370b324cSopenharmony_ci NumBitLevels = numBitLevels; 11370b324cSopenharmony_ci Models = new short[1 << numBitLevels]; 12370b324cSopenharmony_ci } 13370b324cSopenharmony_ci 14370b324cSopenharmony_ci public void Init() 15370b324cSopenharmony_ci { 16370b324cSopenharmony_ci Decoder.InitBitModels(Models); 17370b324cSopenharmony_ci } 18370b324cSopenharmony_ci 19370b324cSopenharmony_ci public int Decode(Decoder rangeDecoder) throws java.io.IOException 20370b324cSopenharmony_ci { 21370b324cSopenharmony_ci int m = 1; 22370b324cSopenharmony_ci for (int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--) 23370b324cSopenharmony_ci m = (m << 1) + rangeDecoder.DecodeBit(Models, m); 24370b324cSopenharmony_ci return m - (1 << NumBitLevels); 25370b324cSopenharmony_ci } 26370b324cSopenharmony_ci 27370b324cSopenharmony_ci public int ReverseDecode(Decoder rangeDecoder) throws java.io.IOException 28370b324cSopenharmony_ci { 29370b324cSopenharmony_ci int m = 1; 30370b324cSopenharmony_ci int symbol = 0; 31370b324cSopenharmony_ci for (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++) 32370b324cSopenharmony_ci { 33370b324cSopenharmony_ci int bit = rangeDecoder.DecodeBit(Models, m); 34370b324cSopenharmony_ci m <<= 1; 35370b324cSopenharmony_ci m += bit; 36370b324cSopenharmony_ci symbol |= (bit << bitIndex); 37370b324cSopenharmony_ci } 38370b324cSopenharmony_ci return symbol; 39370b324cSopenharmony_ci } 40370b324cSopenharmony_ci 41370b324cSopenharmony_ci public static int ReverseDecode(short[] Models, int startIndex, 42370b324cSopenharmony_ci Decoder rangeDecoder, int NumBitLevels) throws java.io.IOException 43370b324cSopenharmony_ci { 44370b324cSopenharmony_ci int m = 1; 45370b324cSopenharmony_ci int symbol = 0; 46370b324cSopenharmony_ci for (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++) 47370b324cSopenharmony_ci { 48370b324cSopenharmony_ci int bit = rangeDecoder.DecodeBit(Models, startIndex + m); 49370b324cSopenharmony_ci m <<= 1; 50370b324cSopenharmony_ci m += bit; 51370b324cSopenharmony_ci symbol |= (bit << bitIndex); 52370b324cSopenharmony_ci } 53370b324cSopenharmony_ci return symbol; 54370b324cSopenharmony_ci } 55370b324cSopenharmony_ci} 56