5
#include "ArjDecoder2.h"
11
static const UInt32 kHistorySize = 26624;
12
// static const UInt32 kMatchMaxLen = 256;
13
static const UInt32 kMatchMinLen = 3;
15
HRESULT CCoder::CodeReal(ISequentialInStream *inStream,
16
ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize,
17
ICompressProgressInfo * /* progress */)
22
if (!m_OutWindowStream.Create(kHistorySize))
24
if (!m_InBitStream.Create(1 << 20))
28
m_OutWindowStream.SetStream(outStream);
29
m_OutWindowStream.Init(false);
30
m_InBitStream.SetStream(inStream);
32
CCoderReleaser coderReleaser(this);
36
const UInt32 kStartWidth = 0;
37
const UInt32 kStopWidth = 7;
38
UInt32 power = 1 << kStartWidth;
41
for (width = kStartWidth; width < kStopWidth; width++)
43
if (m_InBitStream.ReadBits(1) == 0)
49
len += m_InBitStream.ReadBits(width);
52
m_OutWindowStream.PutByte((Byte)m_InBitStream.ReadBits(8));
58
len = len - 1 + kMatchMinLen;
59
const UInt32 kStartWidth = 9;
60
const UInt32 kStopWidth = 13;
61
UInt32 power = 1 << kStartWidth;
64
for (width = kStartWidth; width < kStopWidth; width++)
66
if (m_InBitStream.ReadBits(1) == 0)
72
distance += m_InBitStream.ReadBits(width);
75
m_OutWindowStream.CopyBlock(distance, len);
79
coderReleaser.NeedFlush = false;
80
return m_OutWindowStream.Flush();
83
STDMETHODIMP CCoder::Code(ISequentialInStream *inStream,
84
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
85
ICompressProgressInfo *progress)
87
try { return CodeReal(inStream, outStream, inSize, outSize, progress);}
88
catch(const CInBufferException &e) { return e.ErrorCode; }
89
catch(const CLZOutWindowException &e) { return e.ErrorCode; }
90
catch(...) { return S_FALSE; }