Mercurial > vba-linux
comparison 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 |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 // BitmDecoder.h -- the Most Significant Bit of byte is First | |
2 | |
3 #ifndef __BITM_DECODER_H | |
4 #define __BITM_DECODER_H | |
5 | |
6 #include "../IStream.h" | |
7 | |
8 namespace NBitm { | |
9 | |
10 const int kNumBigValueBits = 8 * 4; | |
11 const int kNumValueBytes = 3; | |
12 const int kNumValueBits = 8 * kNumValueBytes; | |
13 | |
14 const UInt32 kMask = (1 << kNumValueBits) - 1; | |
15 | |
16 template<class TInByte> | |
17 class CDecoder | |
18 { | |
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();} | |
26 | |
27 void Init() | |
28 { | |
29 m_Stream.Init(); | |
30 m_BitPos = kNumBigValueBits; | |
31 Normalize(); | |
32 } | |
33 | |
34 UInt64 GetProcessedSize() const | |
35 { return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; } | |
36 UInt32 GetBitPosition() const { return (m_BitPos & 7); } | |
37 | |
38 void Normalize() | |
39 { | |
40 for (;m_BitPos >= 8; m_BitPos -= 8) | |
41 m_Value = (m_Value << 8) | m_Stream.ReadByte(); | |
42 } | |
43 | |
44 UInt32 GetValue(UInt32 numBits) const | |
45 { | |
46 // return (m_Value << m_BitPos) >> (kNumBigValueBits - numBits); | |
47 return ((m_Value >> (8 - m_BitPos)) & kMask) >> (kNumValueBits - numBits); | |
48 } | |
49 | |
50 void MovePos(UInt32 numBits) | |
51 { | |
52 m_BitPos += numBits; | |
53 Normalize(); | |
54 } | |
55 | |
56 UInt32 ReadBits(UInt32 numBits) | |
57 { | |
58 UInt32 res = GetValue(numBits); | |
59 MovePos(numBits); | |
60 return res; | |
61 } | |
62 }; | |
63 | |
64 } | |
65 | |
66 #endif |