From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- .../7zstub/src/7zip/Common/MSBFDecoder.h | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 other-licenses/7zstub/src/7zip/Common/MSBFDecoder.h (limited to 'other-licenses/7zstub/src/7zip/Common/MSBFDecoder.h') diff --git a/other-licenses/7zstub/src/7zip/Common/MSBFDecoder.h b/other-licenses/7zstub/src/7zip/Common/MSBFDecoder.h new file mode 100644 index 000000000..dad00ecab --- /dev/null +++ b/other-licenses/7zstub/src/7zip/Common/MSBFDecoder.h @@ -0,0 +1,69 @@ +// MSBFDecoder.h +// the Most Significant Bit of byte is First + +#ifndef __STREAM_MSBFDECODER_H +#define __STREAM_MSBFDECODER_H + +#include "../../Common/Types.h" +#include "../IStream.h" + +namespace NStream { +namespace NMSBF { + +const int kNumBigValueBits = 8 * 4; +const int kNumValueBytes = 3; +const int kNumValueBits = 8 * kNumValueBytes; + +const UInt32 kMask = (1 << kNumValueBits) - 1; + +template +class CDecoder +{ + UInt32 m_BitPos; + UInt32 m_Value; +public: + TInByte m_Stream; + bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); } + void SetStream(ISequentialInStream *inStream) { m_Stream.SetStream(inStream);} + void ReleaseStream() { m_Stream.ReleaseStream();} + + void Init() + { + m_Stream.Init(); + m_BitPos = kNumBigValueBits; + Normalize(); + } + + UInt64 GetProcessedSize() const + { return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; } + UInt32 GetBitPosition() const { return (m_BitPos & 7); } + + void Normalize() + { + for (;m_BitPos >= 8; m_BitPos -= 8) + m_Value = (m_Value << 8) | m_Stream.ReadByte(); + } + + UInt32 GetValue(UInt32 numBits) const + { + // return (m_Value << m_BitPos) >> (kNumBigValueBits - numBits); + return ((m_Value >> (8 - m_BitPos)) & kMask) >> (kNumValueBits - numBits); + } + + void MovePos(UInt32 numBits) + { + m_BitPos += numBits; + Normalize(); + } + + UInt32 ReadBits(UInt32 numBits) + { + UInt32 res = GetValue(numBits); + MovePos(numBits); + return res; + } +}; + +}} + +#endif -- cgit v1.2.3