Mercurial > vba-linux
view src/win32/7zip/7z/CPP/7zip/Compress/BitmDecoder.h @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
line wrap: on
line source
1 // BitmDecoder.h -- the Most Significant Bit of byte is First3 #ifndef __BITM_DECODER_H4 #define __BITM_DECODER_H6 #include "../IStream.h"8 namespace NBitm {10 const int kNumBigValueBits = 8 * 4;11 const int kNumValueBytes = 3;12 const int kNumValueBits = 8 * kNumValueBytes;14 const UInt32 kMask = (1 << kNumValueBits) - 1;16 template<class TInByte>17 class CDecoder18 {19 UInt32 m_BitPos;20 UInt32 m_Value;21 public:22 TInByte m_Stream;23 bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }24 void SetStream(ISequentialInStream *inStream) { m_Stream.SetStream(inStream);}25 void ReleaseStream() { m_Stream.ReleaseStream();}27 void Init()28 {29 m_Stream.Init();30 m_BitPos = kNumBigValueBits;31 Normalize();32 }34 UInt64 GetProcessedSize() const35 { return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }36 UInt32 GetBitPosition() const { return (m_BitPos & 7); }38 void Normalize()39 {40 for (;m_BitPos >= 8; m_BitPos -= 8)41 m_Value = (m_Value << 8) | m_Stream.ReadByte();42 }44 UInt32 GetValue(UInt32 numBits) const45 {46 // return (m_Value << m_BitPos) >> (kNumBigValueBits - numBits);47 return ((m_Value >> (8 - m_BitPos)) & kMask) >> (kNumValueBits - numBits);48 }50 void MovePos(UInt32 numBits)51 {52 m_BitPos += numBits;53 Normalize();54 }56 UInt32 ReadBits(UInt32 numBits)57 {58 UInt32 res = GetValue(numBits);59 MovePos(numBits);60 return res;61 }62 };64 }66 #endif