"Fossies" - the Fresh Open Source Software Archive

Member "unrar/coder.cpp" (4 May 2022, 1264 Bytes) of package /linux/misc/unrarsrc-6.1.7.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "coder.cpp" see the Fossies "Dox" file reference documentation.

    1 
    2 
    3 inline unsigned int RangeCoder::GetChar()
    4 {
    5   return(UnpackRead->GetChar());
    6 }
    7 
    8 
    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 
   32 inline int RangeCoder::GetCurrentCount() 
   33 {
   34   return (code-low)/(range /= SubRange.scale);
   35 }
   36 
   37 
   38 inline uint RangeCoder::GetCurrentShiftCount(uint SHIFT) 
   39 {
   40   return (code-low)/(range >>= SHIFT);
   41 }
   42 
   43 
   44 inline void RangeCoder::Decode()
   45 {
   46   low += range*SubRange.LowCount;
   47   range *= SubRange.HighCount-SubRange.LowCount;
   48 }