1 
2 
GetChar()3 inline unsigned int RangeCoder::GetChar()
4 {
5   return(UnpackRead->GetChar());
6 }
7 
8 
InitDecoder(Unpack * UnpackRead)9 void RangeCoder::InitDecoder(Unpack *UnpackRead)
10 {
11   RangeCoder::UnpackRead=UnpackRead;
12 
13   low=code=0;
14   range=uint(-1);
15   for (int i=0;i < 4;i++)
16     code=(code << 8) | GetChar();
17 }
18 
19 
20 // (int) cast before "low" added only to suppress compiler warnings.
21 #define ARI_DEC_NORMALIZE(code,low,range,read)                           \
22 {                                                                        \
23   while ((low^(low+range))<TOP || range<BOT && ((range=-(int)low&(BOT-1)),1)) \
24   {                                                                      \
25     code=(code << 8) | read->GetChar();                                  \
26     range <<= 8;                                                         \
27     low <<= 8;                                                           \
28   }                                                                      \
29 }
30 
31 
GetCurrentCount()32 inline int RangeCoder::GetCurrentCount()
33 {
34   return (code-low)/(range /= SubRange.scale);
35 }
36 
37 
GetCurrentShiftCount(uint SHIFT)38 inline uint RangeCoder::GetCurrentShiftCount(uint SHIFT)
39 {
40   return (code-low)/(range >>= SHIFT);
41 }
42 
43 
Decode()44 inline void RangeCoder::Decode()
45 {
46   low += range*SubRange.LowCount;
47   range *= SubRange.HighCount-SubRange.LowCount;
48 }
49