coder.cpp 1.2 KB

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