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