Update to 7-Zip Version 21.02

This commit is contained in:
Tino Reichardt
2021-05-13 16:39:14 +02:00
parent 3724ecfedc
commit 48fa49f76c
620 changed files with 35032 additions and 10925 deletions

View File

@@ -15,8 +15,8 @@ namespace NPpmdZip {
CDecoder::CDecoder(bool fullFileMode):
_fullFileMode(fullFileMode)
{
_ppmd.Stream.In = &_inStream.vt;
Ppmd8_Construct(&_ppmd);
_ppmd.Stream.In = &_inStream.vt;
}
CDecoder::~CDecoder()
@@ -27,6 +27,8 @@ CDecoder::~CDecoder()
STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream *outStream,
const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress)
{
// try {
if (!_outStream.Alloc())
return E_OUTOFMEMORY;
if (!_inStream.Alloc(1 << 20))
@@ -43,9 +45,9 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream
return S_FALSE;
UInt32 val = GetUi16(buf);
UInt32 order = (val & 0xF) + 1;
unsigned order = (val & 0xF) + 1;
UInt32 mem = ((val >> 4) & 0xFF) + 1;
UInt32 restor = (val >> 12);
unsigned restor = (val >> 12);
if (order < 2 || restor > 2)
return S_FALSE;
@@ -57,7 +59,7 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream
if (!Ppmd8_Alloc(&_ppmd, mem << 20, &g_BigAlloc))
return E_OUTOFMEMORY;
if (!Ppmd8_RangeDec_Init(&_ppmd))
if (!Ppmd8_Init_RangeDec(&_ppmd))
return S_FALSE;
Ppmd8_Init(&_ppmd, order, restor);
}
@@ -79,21 +81,23 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream
}
}
Byte *data = _outStream.Buf;
size_t i = 0;
int sym = 0;
int sym;
Byte *buf = _outStream.Buf;
const Byte *lim = buf + size;
do
{
sym = Ppmd8_DecodeSymbol(&_ppmd);
if (_inStream.Extra || sym < 0)
break;
data[i] = (Byte)sym;
*buf++ = (Byte)sym;
}
while (++i != size);
while (buf != lim);
processedSize += i;
size_t cur = (size_t)(buf - _outStream.Buf);
processedSize += cur;
RINOK(WriteStream(outStream, _outStream.Buf, i));
RINOK(WriteStream(outStream, _outStream.Buf, cur));
RINOK(_inStream.Res);
if (_inStream.Extra)
@@ -133,6 +137,8 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, ISequentialOutStream
}
return S_OK;
// } catch (...) { return E_FAIL; }
}
@@ -158,21 +164,14 @@ void CEncProps::Normalize(int level)
if (level == 0) level = 1;
if (level > 9) level = 9;
if (MemSizeMB == (UInt32)(Int32)-1)
MemSizeMB = (1 << ((level > 8 ? 8 : level) - 1));
MemSizeMB = 1 << (level - 1);
const unsigned kMult = 16;
if ((MemSizeMB << 20) / kMult > ReduceSize)
{
for (UInt32 m = (1 << 20); m <= (1 << 28); m <<= 1)
for (UInt32 m = 1; m < MemSizeMB; m <<= 1)
if (ReduceSize <= (m << 20) / kMult)
{
if (ReduceSize <= m / kMult)
{
m >>= 20;
if (MemSizeMB > m)
MemSizeMB = m;
break;
}
MemSizeMB = m;
break;
}
}
if (Order == -1) Order = 3 + level;
if (Restor == -1)
Restor = level < 7 ?
@@ -197,6 +196,7 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIA
continue;
if (propID == NCoderPropID::kReduceSize)
{
props.ReduceSize = (UInt32)(Int32)-1;
if (prop.vt == VT_UI8 && prop.uhVal.QuadPart < (UInt32)(Int32)-1)
props.ReduceSize = (UInt32)prop.uhVal.QuadPart;
continue;
@@ -219,9 +219,9 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIA
case NCoderPropID::kNumThreads: break;
case NCoderPropID::kLevel: level = (int)v; break;
case NCoderPropID::kAlgorithm:
if (v > 1)
if (v >= PPMD8_RESTORE_METHOD_UNSUPPPORTED)
return E_INVALIDARG;
props.Restor = v;
props.Restor = (int)v;
break;
default: return E_INVALIDARG;
}
@@ -251,12 +251,14 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream
_outStream.Stream = outStream;
_outStream.Init();
Ppmd8_RangeEnc_Init(&_ppmd);
Ppmd8_Init(&_ppmd, _props.Order, _props.Restor);
Ppmd8_Init_RangeEnc(&_ppmd);
Ppmd8_Init(&_ppmd, (unsigned)_props.Order, (unsigned)_props.Restor);
UInt32 val = (UInt32)((_props.Order - 1) + ((_props.MemSizeMB - 1) << 4) + (_props.Restor << 12));
_outStream.WriteByte((Byte)(val & 0xFF));
_outStream.WriteByte((Byte)(val >> 8));
{
UInt32 val = (UInt32)(((unsigned)_props.Order - 1) + ((_props.MemSizeMB - 1) << 4) + ((unsigned)_props.Restor << 12));
_outStream.WriteByte((Byte)(val & 0xFF));
_outStream.WriteByte((Byte)(val >> 8));
}
RINOK(_outStream.Res);
UInt64 processed = 0;
@@ -267,15 +269,23 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream
if (size == 0)
{
Ppmd8_EncodeSymbol(&_ppmd, -1);
Ppmd8_RangeEnc_FlushData(&_ppmd);
Ppmd8_Flush_RangeEnc(&_ppmd);
return _outStream.Flush();
}
for (UInt32 i = 0; i < size; i++)
{
Ppmd8_EncodeSymbol(&_ppmd, _inStream.Buf[i]);
RINOK(_outStream.Res);
}
processed += size;
const Byte *buf = _inStream.Buf;
const Byte *lim = buf + size;
do
{
Ppmd8_EncodeSymbol(&_ppmd, *buf);
if (_outStream.Res != S_OK)
break;
}
while (++buf != lim);
RINOK(_outStream.Res);
if (progress)
{
const UInt64 outProccessed = _outStream.GetProcessed();
@@ -284,4 +294,7 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, ISequentialOutStream
}
}
}}