mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-12 05:09:59 -06:00
4.20
This commit is contained in:
committed by
Kornel Lesiński
parent
8c1b5c7b7e
commit
3c510ba80b
@@ -4,43 +4,40 @@
|
||||
|
||||
#include "Decoder2.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
namespace NCompress{
|
||||
namespace NArj {
|
||||
namespace NDecoder2 {
|
||||
|
||||
static const UINT32 kHistorySize = 26624;
|
||||
static const UINT32 kMatchMaxLen = 256;
|
||||
static const UINT32 kMatchMinLen = 3;
|
||||
|
||||
CCoder::CCoder()
|
||||
{}
|
||||
static const UInt32 kHistorySize = 26624;
|
||||
static const UInt32 kMatchMaxLen = 256;
|
||||
static const UInt32 kMatchMinLen = 3;
|
||||
|
||||
STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (outSize == NULL)
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (!m_OutWindowStream.IsCreated())
|
||||
{
|
||||
try { m_OutWindowStream.Create(kHistorySize); }
|
||||
catch(...) { return E_OUTOFMEMORY; }
|
||||
}
|
||||
UINT64 pos = 0;
|
||||
m_OutWindowStream.Init(outStream, false);
|
||||
m_InBitStream.Init(inStream);
|
||||
if (!m_OutWindowStream.Create(kHistorySize))
|
||||
return E_OUTOFMEMORY;
|
||||
if (!m_InBitStream.Create(1 << 20))
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
UInt64 pos = 0;
|
||||
m_OutWindowStream.SetStream(outStream);
|
||||
m_OutWindowStream.Init(false);
|
||||
m_InBitStream.SetStream(inStream);
|
||||
m_InBitStream.Init();
|
||||
CCoderReleaser coderReleaser(this);
|
||||
|
||||
while(pos < *outSize)
|
||||
{
|
||||
const UINT32 kStartWidth = 0;
|
||||
const UINT32 kStopWidth = 7;
|
||||
UINT32 power = 1 << kStartWidth;
|
||||
UINT32 width;
|
||||
UINT32 len = 0;
|
||||
const UInt32 kStartWidth = 0;
|
||||
const UInt32 kStopWidth = 7;
|
||||
UInt32 power = 1 << kStartWidth;
|
||||
UInt32 width;
|
||||
UInt32 len = 0;
|
||||
for (width = kStartWidth; width < kStopWidth; width++)
|
||||
{
|
||||
if (m_InBitStream.ReadBits(1) == 0)
|
||||
@@ -52,18 +49,18 @@ STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
len += m_InBitStream.ReadBits(width);
|
||||
if (len == 0)
|
||||
{
|
||||
m_OutWindowStream.PutOneByte(m_InBitStream.ReadBits(8));
|
||||
m_OutWindowStream.PutByte(m_InBitStream.ReadBits(8));
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
len = len - 1 + kMatchMinLen;
|
||||
const UINT32 kStartWidth = 9;
|
||||
const UINT32 kStopWidth = 13;
|
||||
UINT32 power = 1 << kStartWidth;
|
||||
UINT32 width;
|
||||
UINT32 distance = 0;
|
||||
const UInt32 kStartWidth = 9;
|
||||
const UInt32 kStopWidth = 13;
|
||||
UInt32 power = 1 << kStartWidth;
|
||||
UInt32 width;
|
||||
UInt32 distance = 0;
|
||||
for (width = kStartWidth; width < kStopWidth; width++)
|
||||
{
|
||||
if (m_InBitStream.ReadBits(1) == 0)
|
||||
@@ -75,15 +72,16 @@ STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
distance += m_InBitStream.ReadBits(width);
|
||||
if (distance >= pos)
|
||||
throw "data error";
|
||||
m_OutWindowStream.CopyBackBlock(distance, len);
|
||||
m_OutWindowStream.CopyBlock(distance, len);
|
||||
pos += len;
|
||||
}
|
||||
}
|
||||
coderReleaser.NeedFlush = false;
|
||||
return m_OutWindowStream.Flush();
|
||||
}
|
||||
|
||||
STDMETHODIMP CCoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
try { return CodeReal(inStream, outStream, inSize, outSize, progress);}
|
||||
|
||||
Reference in New Issue
Block a user