4.33 beta

This commit is contained in:
Igor Pavlov
2006-02-05 00:00:00 +00:00
committed by Kornel Lesiński
parent e8d0636d7a
commit 02516d3fce
80 changed files with 2185 additions and 3957 deletions

View File

@@ -8,39 +8,22 @@
namespace NStream {
namespace NLSBF {
void CEncoder::WriteBits(UInt32 value, UInt32 numBits)
void CEncoder::WriteBits(UInt32 value, int numBits)
{
while(numBits > 0)
{
UInt32 numNewBits = MyMin(numBits, m_BitPos);
numBits -= numNewBits;
UInt32 mask = (1 << numNewBits) - 1;
m_CurByte |= (value & mask) << (8 - m_BitPos);
value >>= numNewBits;
m_BitPos -= numNewBits;
if (m_BitPos == 0)
if (numBits < m_BitPos)
{
m_Stream.WriteByte(m_CurByte);
m_BitPos = 8;
m_CurByte = 0;
m_CurByte |= (value & ((1 << numBits) - 1)) << (8 - m_BitPos);
m_BitPos -= numBits;
return;
}
numBits -= m_BitPos;
m_Stream.WriteByte((Byte)(m_CurByte | (value << (8 - m_BitPos))));
value >>= m_BitPos;
m_BitPos = 8;
m_CurByte = 0;
}
}
void CReverseEncoder::WriteBits(UInt32 value, UInt32 numBits)
{
UInt32 reverseValue = 0;
for(UInt32 i = 0; i < numBits; i++)
{
reverseValue <<= 1;
reverseValue |= value & 1;
value >>= 1;
}
m_Encoder->WriteBits(reverseValue, numBits);
}
}}

View File

@@ -12,7 +12,7 @@ namespace NLSBF {
class CEncoder
{
COutBuffer m_Stream;
UInt32 m_BitPos;
int m_BitPos;
Byte m_CurByte;
public:
bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
@@ -26,23 +26,25 @@ public:
}
HRESULT Flush()
{
if(m_BitPos < 8)
WriteBits(0, m_BitPos);
FlushByte();
return m_Stream.Flush();
}
void WriteBits(UInt32 value, UInt32 numBits);
void FlushByte()
{
if(m_BitPos < 8)
m_Stream.WriteByte(m_CurByte);
m_BitPos = 8;
m_CurByte = 0;
}
void WriteBits(UInt32 value, int numBits);
UInt32 GetBitPosition() const { return (8 - m_BitPos); }
UInt64 GetProcessedSize() const {
return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; }
void WriteByte(Byte b) { m_Stream.WriteByte(b);}
};
class CReverseEncoder
{
CEncoder *m_Encoder;
public:
void Init(CEncoder *encoder) { m_Encoder = encoder; }
void WriteBits(UInt32 value, UInt32 numBits);
};
}}

View File

@@ -37,21 +37,17 @@ public:
{
while(numBits > 0)
{
int numNewBits = MyMin(numBits, m_BitPos);
numBits -= numNewBits;
m_CurByte <<= numNewBits;
UInt32 newBits = value >> numBits;
m_CurByte |= Byte(newBits);
value -= (newBits << numBits);
m_BitPos -= numNewBits;
if (m_BitPos == 0)
if (numBits < m_BitPos)
{
m_Stream.WriteByte(m_CurByte);
m_BitPos = 8;
m_CurByte |= ((Byte)value << (m_BitPos -= numBits));
return;
}
numBits -= m_BitPos;
UInt32 newBits = (value >> numBits);
value -= (newBits << numBits);
m_Stream.WriteByte(m_CurByte | (Byte)newBits);
m_BitPos = 8;
m_CurByte = 0;
}
}
UInt64 GetProcessedSize() const {