1 // Compress/RangeCoder/RangeCoderBit.cpp
5 #include "RangeCoderBit.h"
8 namespace NRangeCoder {
10 UInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
11 static CPriceTables g_PriceTables;
13 CPriceTables::CPriceTables() { Init(); }
15 void CPriceTables::Init()
17 const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);
18 for(int i = kNumBits - 1; i >= 0; i--)
20 UInt32 start = 1 << (kNumBits - i - 1);
21 UInt32 end = 1 << (kNumBits - i);
22 for (UInt32 j = start; j < end; j++)
23 ProbPrices[j] = (i << kNumBitPriceShiftBits) +
24 (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));
28 // simplest: bad solution
29 for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)
30 ProbPrices[i] = kBitPrice;
34 const double kDummyMultMid = (1.0 / kBitPrice) / 2;
35 const double kDummyMultMid = 0;
37 double ln2 = log(double(2));
38 double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits));
39 for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)
40 ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice);
44 // experimental, slow, solution:
45 for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++)
47 const int kCyclesBits = 5;
48 const UInt32 kCycles = (1 << kCyclesBits);
50 UInt32 range = UInt32(-1);
52 for (UInt32 j = 0; j < kCycles; j++)
54 range >>= (kNumBitModelTotalBits - kNumMoveReducingBits);
56 while(range < (1 << 31))
62 bitCount <<= kNumBitPriceShiftBits;
64 for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--)
67 if (range > (1 << 31))
73 ProbPrices[i] = (bitCount
74 // + (1 << (kCyclesBits - 1))