mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-14 14:11:40 -06:00
4.20
This commit is contained in:
committed by
Kornel Lesiński
parent
8c1b5c7b7e
commit
3c510ba80b
@@ -1,13 +1,11 @@
|
||||
// Stream/MSBFEncoder.h
|
||||
// the Most Significant Bit of byte is First
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __STREAM_MSBFENCODER_H
|
||||
#define __STREAM_MSBFENCODER_H
|
||||
|
||||
#include "Common/Defs.h"
|
||||
#include "Interface/IInOutStreams.h"
|
||||
#include "../IStream.h"
|
||||
#include "OutBuffer.h"
|
||||
|
||||
namespace NStream {
|
||||
namespace NMSBF {
|
||||
@@ -16,12 +14,15 @@ template<class TOutByte>
|
||||
class CEncoder
|
||||
{
|
||||
TOutByte m_Stream;
|
||||
UINT32 m_BitPos;
|
||||
BYTE m_CurByte;
|
||||
int m_BitPos;
|
||||
Byte m_CurByte;
|
||||
public:
|
||||
void Init(ISequentialOutStream *aStream)
|
||||
bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
|
||||
void SetStream(ISequentialOutStream *outStream) { m_Stream.SetStream(outStream);}
|
||||
void ReleaseStream() { m_Stream.ReleaseStream(); }
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init(aStream);
|
||||
m_Stream.Init();
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
@@ -32,26 +33,19 @@ public:
|
||||
return m_Stream.Flush();
|
||||
}
|
||||
|
||||
void ReleaseStream()
|
||||
void WriteBits(UInt32 value, int numBits)
|
||||
{
|
||||
m_Stream.ReleaseStream();
|
||||
}
|
||||
|
||||
void WriteBits(UINT32 aValue, UINT32 aNumBits)
|
||||
{
|
||||
while(aNumBits > 0)
|
||||
while(numBits > 0)
|
||||
{
|
||||
UINT32 aNumNewBits = MyMin(aNumBits, m_BitPos);
|
||||
aNumBits -= aNumNewBits;
|
||||
int numNewBits = MyMin(numBits, m_BitPos);
|
||||
numBits -= numNewBits;
|
||||
|
||||
m_CurByte <<= numNewBits;
|
||||
UInt32 newBits = value >> numBits;
|
||||
m_CurByte |= Byte(newBits);
|
||||
value -= (newBits << numBits);
|
||||
|
||||
m_CurByte <<= aNumNewBits;
|
||||
UINT32 aNewBits = aValue >> aNumBits;
|
||||
m_CurByte |= BYTE(aNewBits);
|
||||
aValue -= (aNewBits << aNumBits);
|
||||
|
||||
|
||||
m_BitPos -= aNumNewBits;
|
||||
m_BitPos -= numNewBits;
|
||||
|
||||
if (m_BitPos == 0)
|
||||
{
|
||||
@@ -60,11 +54,10 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
UINT64 GetProcessedSize() const {
|
||||
return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; }
|
||||
UInt64 GetProcessedSize() const {
|
||||
return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) / 8; }
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user