diff options
author | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-03-25 17:53:14 +0100 |
---|---|---|
committer | wolfbeast <mcwerewolf@wolfbeast.com> | 2019-03-25 17:53:14 +0100 |
commit | f2902217b38cf2e16e851ae84d61247f8e828180 (patch) | |
tree | 0156a6db6aa8b4d87bf041ece5cf5229c59fe9de /other-licenses/7zstub/src/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java | |
parent | 917a2c450f08ab4c934c9938319f10a1114272b4 (diff) | |
download | UXP-f2902217b38cf2e16e851ae84d61247f8e828180.tar UXP-f2902217b38cf2e16e851ae84d61247f8e828180.tar.gz UXP-f2902217b38cf2e16e851ae84d61247f8e828180.tar.lz UXP-f2902217b38cf2e16e851ae84d61247f8e828180.tar.xz UXP-f2902217b38cf2e16e851ae84d61247f8e828180.zip |
Update the 7z installer stub source to 18.05.
Tag #1022
Diffstat (limited to 'other-licenses/7zstub/src/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java')
-rw-r--r-- | other-licenses/7zstub/src/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/other-licenses/7zstub/src/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java b/other-licenses/7zstub/src/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java new file mode 100644 index 000000000..b4c0a0721 --- /dev/null +++ b/other-licenses/7zstub/src/Java/SevenZip/Compression/RangeCoder/BitTreeEncoder.java @@ -0,0 +1,99 @@ +package SevenZip.Compression.RangeCoder;
+import java.io.IOException;
+
+public class BitTreeEncoder
+{
+ short[] Models;
+ int NumBitLevels;
+
+ public BitTreeEncoder(int numBitLevels)
+ {
+ NumBitLevels = numBitLevels;
+ Models = new short[1 << numBitLevels];
+ }
+
+ public void Init()
+ {
+ Decoder.InitBitModels(Models);
+ }
+
+ public void Encode(Encoder rangeEncoder, int symbol) throws IOException
+ {
+ int m = 1;
+ for (int bitIndex = NumBitLevels; bitIndex != 0; )
+ {
+ bitIndex--;
+ int bit = (symbol >>> bitIndex) & 1;
+ rangeEncoder.Encode(Models, m, bit);
+ m = (m << 1) | bit;
+ }
+ }
+
+ public void ReverseEncode(Encoder rangeEncoder, int symbol) throws IOException
+ {
+ int m = 1;
+ for (int i = 0; i < NumBitLevels; i++)
+ {
+ int bit = symbol & 1;
+ rangeEncoder.Encode(Models, m, bit);
+ m = (m << 1) | bit;
+ symbol >>= 1;
+ }
+ }
+
+ public int GetPrice(int symbol)
+ {
+ int price = 0;
+ int m = 1;
+ for (int bitIndex = NumBitLevels; bitIndex != 0; )
+ {
+ bitIndex--;
+ int bit = (symbol >>> bitIndex) & 1;
+ price += Encoder.GetPrice(Models[m], bit);
+ m = (m << 1) + bit;
+ }
+ return price;
+ }
+
+ public int ReverseGetPrice(int symbol)
+ {
+ int price = 0;
+ int m = 1;
+ for (int i = NumBitLevels; i != 0; i--)
+ {
+ int bit = symbol & 1;
+ symbol >>>= 1;
+ price += Encoder.GetPrice(Models[m], bit);
+ m = (m << 1) | bit;
+ }
+ return price;
+ }
+
+ public static int ReverseGetPrice(short[] Models, int startIndex,
+ int NumBitLevels, int symbol)
+ {
+ int price = 0;
+ int m = 1;
+ for (int i = NumBitLevels; i != 0; i--)
+ {
+ int bit = symbol & 1;
+ symbol >>>= 1;
+ price += Encoder.GetPrice(Models[startIndex + m], bit);
+ m = (m << 1) | bit;
+ }
+ return price;
+ }
+
+ public static void ReverseEncode(short[] Models, int startIndex,
+ Encoder rangeEncoder, int NumBitLevels, int symbol) throws IOException
+ {
+ int m = 1;
+ for (int i = 0; i < NumBitLevels; i++)
+ {
+ int bit = symbol & 1;
+ rangeEncoder.Encode(Models, startIndex + m, bit);
+ m = (m << 1) | bit;
+ symbol >>= 1;
+ }
+ }
+}
|