File: coder.cpp

package info (click to toggle)
unrar-nonfree 1%3A4.1.4-1%2Bdeb7u1
  • links: PTS
  • area: non-free
  • in suites: wheezy
  • size: 1,120 kB
  • sloc: cpp: 21,159; makefile: 32; sh: 10
file content (48 lines) | stat: -rw-r--r-- 1,264 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48


inline unsigned int RangeCoder::GetChar()
{
  return(UnpackRead->GetChar());
}


void RangeCoder::InitDecoder(Unpack *UnpackRead)
{
  RangeCoder::UnpackRead=UnpackRead;

  low=code=0;
  range=uint(-1);
  for (int i=0;i < 4;i++)
    code=(code << 8) | GetChar();
}


// (int) cast before "low" added only to suppress compiler warnings.
#define ARI_DEC_NORMALIZE(code,low,range,read)                           \
{                                                                        \
  while ((low^(low+range))<TOP || range<BOT && ((range=-(int)low&(BOT-1)),1)) \
  {                                                                      \
    code=(code << 8) | read->GetChar();                                  \
    range <<= 8;                                                         \
    low <<= 8;                                                           \
  }                                                                      \
}


inline int RangeCoder::GetCurrentCount() 
{
  return (code-low)/(range /= SubRange.scale);
}


inline uint RangeCoder::GetCurrentShiftCount(uint SHIFT) 
{
  return (code-low)/(range >>= SHIFT);
}


inline void RangeCoder::Decode()
{
  low += range*SubRange.LowCount;
  range *= SubRange.HighCount-SubRange.LowCount;
}