mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-14 08:11:35 -06:00
4.58 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
bd1fa36322
commit
3901bf0ab8
@@ -71,13 +71,12 @@ public:
|
||||
Low = (UInt32)Low << 8;
|
||||
}
|
||||
|
||||
void EncodeDirectBits(UInt32 value, int numTotalBits)
|
||||
void EncodeDirectBits(UInt32 value, int numBits)
|
||||
{
|
||||
for (int i = numTotalBits - 1; i >= 0; i--)
|
||||
for (numBits--; numBits >= 0; numBits--)
|
||||
{
|
||||
Range >>= 1;
|
||||
if (((value >> i) & 1) == 1)
|
||||
Low += Range;
|
||||
Low += Range & (0 - ((value >> numBits) & 1));
|
||||
if (Range < kTopValue)
|
||||
{
|
||||
Range <<= 8;
|
||||
|
||||
@@ -7,74 +7,30 @@
|
||||
namespace NCompress {
|
||||
namespace NRangeCoder {
|
||||
|
||||
UInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
|
||||
static CPriceTables g_PriceTables;
|
||||
UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
|
||||
|
||||
CPriceTables::CPriceTables() { Init(); }
|
||||
|
||||
void CPriceTables::Init()
|
||||
struct CPriceTables { CPriceTables()
|
||||
{
|
||||
const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);
|
||||
for(int i = kNumBits - 1; i >= 0; i--)
|
||||
for (UInt32 i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
|
||||
{
|
||||
UInt32 start = 1 << (kNumBits - i - 1);
|
||||
UInt32 end = 1 << (kNumBits - i);
|
||||
for (UInt32 j = start; j < end; j++)
|
||||
ProbPrices[j] = (i << kNumBitPriceShiftBits) +
|
||||
(((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));
|
||||
}
|
||||
|
||||
/*
|
||||
// simplest: bad solution
|
||||
for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)
|
||||
ProbPrices[i] = kBitPrice;
|
||||
*/
|
||||
|
||||
/*
|
||||
const double kDummyMultMid = (1.0 / kBitPrice) / 2;
|
||||
const double kDummyMultMid = 0;
|
||||
// float solution
|
||||
double ln2 = log(double(2));
|
||||
double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits));
|
||||
for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)
|
||||
ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice);
|
||||
*/
|
||||
|
||||
/*
|
||||
// experimental, slow, solution:
|
||||
for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)
|
||||
{
|
||||
const int kCyclesBits = 5;
|
||||
const UInt32 kCycles = (1 << kCyclesBits);
|
||||
|
||||
UInt32 range = UInt32(-1);
|
||||
const int kCyclesBits = kNumBitPriceShiftBits;
|
||||
UInt32 w = i;
|
||||
UInt32 bitCount = 0;
|
||||
for (UInt32 j = 0; j < kCycles; j++)
|
||||
for (int j = 0; j < kCyclesBits; j++)
|
||||
{
|
||||
range >>= (kNumBitModelTotalBits - kNumMoveReducingBits);
|
||||
range *= i;
|
||||
while(range < (1 << 31))
|
||||
w = w * w;
|
||||
bitCount <<= 1;
|
||||
while (w >= ((UInt32)1 << 16))
|
||||
{
|
||||
range <<= 1;
|
||||
w >>= 1;
|
||||
bitCount++;
|
||||
}
|
||||
}
|
||||
bitCount <<= kNumBitPriceShiftBits;
|
||||
range -= (1 << 31);
|
||||
for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--)
|
||||
{
|
||||
range <<= 1;
|
||||
if (range > (1 << 31))
|
||||
{
|
||||
bitCount += (1 << k);
|
||||
range -= (1 << 31);
|
||||
}
|
||||
}
|
||||
ProbPrices[i] = (bitCount
|
||||
// + (1 << (kCyclesBits - 1))
|
||||
) >> kCyclesBits;
|
||||
ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount);
|
||||
}
|
||||
*/
|
||||
}
|
||||
};
|
||||
|
||||
static CPriceTables g_PriceTables;
|
||||
|
||||
}}
|
||||
|
||||
@@ -11,18 +11,12 @@ namespace NRangeCoder {
|
||||
const int kNumBitModelTotalBits = 11;
|
||||
const UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);
|
||||
|
||||
const int kNumMoveReducingBits = 2;
|
||||
const int kNumMoveReducingBits = 4;
|
||||
|
||||
const int kNumBitPriceShiftBits = 6;
|
||||
const int kNumBitPriceShiftBits = 4;
|
||||
const UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;
|
||||
|
||||
class CPriceTables
|
||||
{
|
||||
public:
|
||||
static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
|
||||
static void Init();
|
||||
CPriceTables();
|
||||
};
|
||||
extern UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
|
||||
|
||||
template <int numMoveBits>
|
||||
class CBitModel
|
||||
@@ -74,11 +68,10 @@ public:
|
||||
}
|
||||
UInt32 GetPrice(UInt32 symbol) const
|
||||
{
|
||||
return CPriceTables::ProbPrices[
|
||||
(((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];
|
||||
return ProbPrices[(this->Prob ^ ((-(int)symbol)) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];
|
||||
}
|
||||
UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }
|
||||
UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; }
|
||||
UInt32 GetPrice0() const { return ProbPrices[this->Prob >> kNumMoveReducingBits]; }
|
||||
UInt32 GetPrice1() const { return ProbPrices[(this->Prob ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]; }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class CBitTreeEncoder
|
||||
public:
|
||||
void Init()
|
||||
{
|
||||
for(UInt32 i = 1; i < (1 << NumBitLevels); i++)
|
||||
for(UInt32 i = 0; i < (1 << NumBitLevels); i++)
|
||||
Models[i].Init();
|
||||
}
|
||||
void Encode(CEncoder *rangeEncoder, UInt32 symbol)
|
||||
@@ -74,7 +74,7 @@ class CBitTreeDecoder
|
||||
public:
|
||||
void Init()
|
||||
{
|
||||
for(UInt32 i = 1; i < (1 << NumBitLevels); i++)
|
||||
for(UInt32 i = 0; i < (1 << NumBitLevels); i++)
|
||||
Models[i].Init();
|
||||
}
|
||||
UInt32 Decode(CDecoder *rangeDecoder)
|
||||
|
||||
Reference in New Issue
Block a user