other-licenses/7zstub/src/7zip/Common/LSBFEncoder.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/7zstub/src/7zip/Common/LSBFEncoder.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,51 @@
     1.4 +// Stream/LSBFEncoder.h
     1.5 +
     1.6 +#ifndef __STREAM_LSBFENCODER_H
     1.7 +#define __STREAM_LSBFENCODER_H
     1.8 +
     1.9 +#include "../IStream.h"
    1.10 +#include "OutBuffer.h"
    1.11 +
    1.12 +namespace NStream {
    1.13 +namespace NLSBF {
    1.14 +
    1.15 +class CEncoder
    1.16 +{
    1.17 +  COutBuffer m_Stream;
    1.18 +  int m_BitPos;
    1.19 +  Byte m_CurByte;
    1.20 +public:
    1.21 +  bool Create(UInt32 bufferSize) { return m_Stream.Create(bufferSize); }
    1.22 +  void SetStream(ISequentialOutStream *outStream) { m_Stream.SetStream(outStream); }
    1.23 +  void ReleaseStream() { m_Stream.ReleaseStream(); }
    1.24 +  void Init()
    1.25 +  {
    1.26 +    m_Stream.Init();
    1.27 +    m_BitPos = 8; 
    1.28 +    m_CurByte = 0;
    1.29 +  }
    1.30 +  HRESULT Flush()
    1.31 +  {
    1.32 +    FlushByte();
    1.33 +    return m_Stream.Flush();
    1.34 +  }
    1.35 +  
    1.36 +  void FlushByte()
    1.37 +  {
    1.38 +    if(m_BitPos < 8)
    1.39 +      m_Stream.WriteByte(m_CurByte);
    1.40 +    m_BitPos = 8; 
    1.41 +    m_CurByte = 0;
    1.42 +  }
    1.43 +
    1.44 +  void WriteBits(UInt32 value, int numBits);
    1.45 +  UInt32 GetBitPosition() const {  return (8 - m_BitPos); }
    1.46 +  UInt64 GetProcessedSize() const { 
    1.47 +      return m_Stream.GetProcessedSize() + (8 - m_BitPos + 7) /8; }
    1.48 +  void WriteByte(Byte b) { m_Stream.WriteByte(b);}
    1.49 +};
    1.50 +
    1.51 +
    1.52 +}}
    1.53 +
    1.54 +#endif

mercurial