5
#include "ArjDecoder2.h"
11
static const UInt32 kHistorySize = 26624;
12
static const UInt32 kMatchMinLen = 3;
14
HRESULT CCoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
15
const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo * /* progress */)
20
if (!m_OutWindowStream.Create(kHistorySize))
22
if (!m_InBitStream.Create(1 << 20))
26
m_OutWindowStream.SetStream(outStream);
27
m_OutWindowStream.Init(false);
28
m_InBitStream.SetStream(inStream);
30
CCoderReleaser coderReleaser(this);
34
const UInt32 kStartWidth = 0;
35
const UInt32 kStopWidth = 7;
36
UInt32 power = 1 << kStartWidth;
39
for (width = kStartWidth; width < kStopWidth; width++)
41
if (m_InBitStream.ReadBits(1) == 0)
47
len += m_InBitStream.ReadBits(width);
50
m_OutWindowStream.PutByte((Byte)m_InBitStream.ReadBits(8));
56
len = len - 1 + kMatchMinLen;
57
const UInt32 kStartWidth = 9;
58
const UInt32 kStopWidth = 13;
59
UInt32 power = 1 << kStartWidth;
62
for (width = kStartWidth; width < kStopWidth; width++)
64
if (m_InBitStream.ReadBits(1) == 0)
70
distance += m_InBitStream.ReadBits(width);
73
m_OutWindowStream.CopyBlock(distance, len);
77
coderReleaser.NeedFlush = false;
78
return m_OutWindowStream.Flush();
81
STDMETHODIMP CCoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
82
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
84
try { return CodeReal(inStream, outStream, inSize, outSize, progress);}
85
catch(const CInBufferException &e) { return e.ErrorCode; }
86
catch(const CLzOutWindowException &e) { return e.ErrorCode; }
87
catch(...) { return S_FALSE; }