Project Maintenance

This commit is contained in:
Gustave Monce
2021-08-09 20:21:09 +02:00
parent 9865ef7f79
commit 847ce0506d
411 changed files with 5922 additions and 54941 deletions
+16 -7
View File
@@ -2,18 +2,18 @@ using System;
namespace SevenZip.Compression.RangeCoder
{
class Encoder
internal class Encoder
{
public const uint kTopValue = (1 << 24);
System.IO.Stream Stream;
private System.IO.Stream Stream;
public UInt64 Low;
public uint Range;
uint _cacheSize;
byte _cache;
private uint _cacheSize;
private byte _cache;
long StartPosition;
private long StartPosition;
public void SetStream(System.IO.Stream stream)
{
@@ -38,7 +38,9 @@ namespace SevenZip.Compression.RangeCoder
public void FlushData()
{
for (int i = 0; i < 5; i++)
{
ShiftLow();
}
}
public void FlushStream()
@@ -64,7 +66,7 @@ namespace SevenZip.Compression.RangeCoder
public void ShiftLow()
{
if ((uint)Low < (uint)0xFF000000 || (uint)(Low >> 32) == 1)
if ((uint)Low < 0xFF000000 || (uint)(Low >> 32) == 1)
{
byte temp = _cache;
do
@@ -85,7 +87,10 @@ namespace SevenZip.Compression.RangeCoder
{
Range >>= 1;
if (((v >> i) & 1) == 1)
{
Low += Range;
}
if (Range < kTopValue)
{
Range <<= 8;
@@ -98,7 +103,9 @@ namespace SevenZip.Compression.RangeCoder
{
uint newBound = (Range >> numTotalBits) * size0;
if (symbol == 0)
{
Range = newBound;
}
else
{
Low += newBound;
@@ -119,7 +126,7 @@ namespace SevenZip.Compression.RangeCoder
}
}
class Decoder
internal class Decoder
{
public const uint kTopValue = (1 << 24);
public uint Range;
@@ -135,7 +142,9 @@ namespace SevenZip.Compression.RangeCoder
Code = 0;
Range = 0xFFFFFFFF;
for (int i = 0; i < 5; i++)
{
Code = (Code << 8) | (byte)Stream.ReadByte();
}
}
public void ReleaseStream()
+25 -15
View File
@@ -2,24 +2,28 @@ using System;
namespace SevenZip.Compression.RangeCoder
{
struct BitEncoder
internal struct BitEncoder
{
public const int kNumBitModelTotalBits = 11;
public const uint kBitModelTotal = (1 << kNumBitModelTotalBits);
const int kNumMoveBits = 5;
const int kNumMoveReducingBits = 2;
private const int kNumMoveBits = 5;
private const int kNumMoveReducingBits = 2;
public const int kNumBitPriceShiftBits = 6;
uint Prob;
private uint Prob;
public void Init() { Prob = kBitModelTotal >> 1; }
public void UpdateModel(uint symbol)
{
if (symbol == 0)
{
Prob += (kBitModelTotal - Prob) >> kNumMoveBits;
}
else
Prob -= (Prob) >> kNumMoveBits;
{
Prob -= Prob >> kNumMoveBits;
}
}
public void Encode(Encoder encoder, uint symbol)
@@ -36,7 +40,7 @@ namespace SevenZip.Compression.RangeCoder
{
encoder.Low += newBound;
encoder.Range -= newBound;
Prob -= (Prob) >> kNumMoveBits;
Prob -= Prob >> kNumMoveBits;
}
if (encoder.Range < Encoder.kTopValue)
{
@@ -45,7 +49,7 @@ namespace SevenZip.Compression.RangeCoder
}
}
private static UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits];
private static readonly UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits];
static BitEncoder()
{
@@ -55,40 +59,46 @@ namespace SevenZip.Compression.RangeCoder
UInt32 start = (UInt32)1 << (kNumBits - i - 1);
UInt32 end = (UInt32)1 << (kNumBits - i);
for (UInt32 j = start; j < end; j++)
{
ProbPrices[j] = ((UInt32)i << kNumBitPriceShiftBits) +
(((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));
}
}
}
public uint GetPrice(uint symbol)
{
return ProbPrices[(((Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];
return ProbPrices[(((Prob - symbol) ^ (-(int)symbol)) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];
}
public uint GetPrice0() { return ProbPrices[Prob >> kNumMoveReducingBits]; }
public uint GetPrice1() { return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits]; }
}
struct BitDecoder
internal struct BitDecoder
{
public const int kNumBitModelTotalBits = 11;
public const uint kBitModelTotal = (1 << kNumBitModelTotalBits);
const int kNumMoveBits = 5;
private const int kNumMoveBits = 5;
uint Prob;
private uint Prob;
public void UpdateModel(int numMoveBits, uint symbol)
{
if (symbol == 0)
{
Prob += (kBitModelTotal - Prob) >> numMoveBits;
}
else
Prob -= (Prob) >> numMoveBits;
{
Prob -= Prob >> numMoveBits;
}
}
public void Init() { Prob = kBitModelTotal >> 1; }
public uint Decode(RangeCoder.Decoder rangeDecoder)
public uint Decode(Decoder rangeDecoder)
{
uint newBound = (uint)(rangeDecoder.Range >> kNumBitModelTotalBits) * (uint)Prob;
uint newBound = (rangeDecoder.Range >> kNumBitModelTotalBits) * Prob;
if (rangeDecoder.Code < newBound)
{
rangeDecoder.Range = newBound;
@@ -104,7 +114,7 @@ namespace SevenZip.Compression.RangeCoder
{
rangeDecoder.Range -= newBound;
rangeDecoder.Code -= newBound;
Prob -= (Prob) >> kNumMoveBits;
Prob -= Prob >> kNumMoveBits;
if (rangeDecoder.Range < Decoder.kTopValue)
{
rangeDecoder.Code = (rangeDecoder.Code << 8) | (byte)rangeDecoder.Stream.ReadByte();
+16 -9
View File
@@ -2,10 +2,10 @@ using System;
namespace SevenZip.Compression.RangeCoder
{
struct BitTreeEncoder
internal struct BitTreeEncoder
{
BitEncoder[] Models;
int NumBitLevels;
private readonly BitEncoder[] Models;
private readonly int NumBitLevels;
public BitTreeEncoder(int numBitLevels)
{
@@ -16,7 +16,9 @@ namespace SevenZip.Compression.RangeCoder
public void Init()
{
for (uint i = 1; i < (1 << NumBitLevels); i++)
{
Models[i].Init();
}
}
public void Encode(Encoder rangeEncoder, UInt32 symbol)
@@ -100,10 +102,10 @@ namespace SevenZip.Compression.RangeCoder
}
}
struct BitTreeDecoder
internal struct BitTreeDecoder
{
BitDecoder[] Models;
int NumBitLevels;
private readonly BitDecoder[] Models;
private readonly int NumBitLevels;
public BitTreeDecoder(int numBitLevels)
{
@@ -114,18 +116,23 @@ namespace SevenZip.Compression.RangeCoder
public void Init()
{
for (uint i = 1; i < (1 << NumBitLevels); i++)
{
Models[i].Init();
}
}
public uint Decode(RangeCoder.Decoder rangeDecoder)
public uint Decode(Decoder rangeDecoder)
{
uint m = 1;
for (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)
{
m = (m << 1) + Models[m].Decode(rangeDecoder);
}
return m - ((uint)1 << NumBitLevels);
}
public uint ReverseDecode(RangeCoder.Decoder rangeDecoder)
public uint ReverseDecode(Decoder rangeDecoder)
{
uint m = 1;
uint symbol = 0;
@@ -140,7 +147,7 @@ namespace SevenZip.Compression.RangeCoder
}
public static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex,
RangeCoder.Decoder rangeDecoder, int NumBitLevels)
Decoder rangeDecoder, int NumBitLevels)
{
uint m = 1;
uint symbol = 0;