mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-10 04:07:12 -06:00
4.59 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
3901bf0ab8
commit
173c07e166
@@ -16,7 +16,7 @@ static const UInt32 kMatchMinLen = 3;
|
||||
|
||||
// static const UInt32 kNC = 255 + kMatchMaxLen + 2 - kMatchMinLen;
|
||||
|
||||
void CCoder::MakeTable(int nchar, Byte *bitlen, int tablebits,
|
||||
void CCoder::MakeTable(int nchar, Byte *bitlen, int tablebits,
|
||||
UInt32 *table, int tablesize)
|
||||
{
|
||||
UInt32 count[17], weight[17], start[18], *p;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
/*
|
||||
// {23170F69-40C1-278B-0404-010000000000}
|
||||
DEFINE_GUID(CLSID_CCompressArjDecoder,
|
||||
DEFINE_GUID(CLSID_CCompressArjDecoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x04, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
*/
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ HRESULT CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (!m_OutWindowStream.Create(kHistorySize))
|
||||
return E_OUTOFMEMORY;
|
||||
return E_OUTOFMEMORY;
|
||||
if (!m_InBitStream.Create(1 << 20))
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
/*
|
||||
// {23170F69-40C1-278B-0404-020000000000}
|
||||
DEFINE_GUID(CLSID_CCompressArj2Decoder,
|
||||
DEFINE_GUID(CLSID_CCompressArj2Decoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x04, 0x04, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
*/
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
#ifdef MODE_64BIT
|
||||
typedef UInt64 CMtfVar;
|
||||
#define MTF_MOVS 3
|
||||
#else
|
||||
#else
|
||||
typedef UInt32 CMtfVar;
|
||||
#define MTF_MOVS 2
|
||||
#endif
|
||||
@@ -127,17 +127,17 @@ class CMtf8Decoder
|
||||
public:
|
||||
Byte Buffer[256];
|
||||
|
||||
Byte GetHead() const
|
||||
{
|
||||
Byte GetHead() const
|
||||
{
|
||||
if (SmallSize > 0)
|
||||
return SmallBuffer[kSmallSize - SmallSize];
|
||||
return Buffer[0];
|
||||
}
|
||||
|
||||
void Init(int size)
|
||||
{
|
||||
Size = size;
|
||||
SmallSize = 0;
|
||||
void Init(int size)
|
||||
{
|
||||
Size = size;
|
||||
SmallSize = 0;
|
||||
for (int i = 0; i < 16; i++)
|
||||
{
|
||||
Counts[i] = ((size >= 16) ? 16 : size);
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#endif
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
void Init() { _value = 0xFFFFFFFF; }
|
||||
void UpdateByte(Byte b) { _value = Table[(_value >> 24) ^ b] ^ (_value << 8); }
|
||||
void UpdateByte(unsigned int b) { _value = Table[(_value >> 24) ^ b] ^ (_value << 8); }
|
||||
UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; }
|
||||
UInt32 GetDigest() const { return _value ^ 0xFFFFFFFF; }
|
||||
};
|
||||
|
||||
class CBZip2CombinedCRC
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
CBZip2CombinedCRC(): _value(0){};
|
||||
void Init() { _value = 0; }
|
||||
void Update(UInt32 v) { _value = ((_value << 1) | (_value >> 31)) ^ v; }
|
||||
UInt32 GetDigest() const { return _value ; }
|
||||
UInt32 GetDigest() const { return _value ; }
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#include "BZip2Decoder.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
}
|
||||
|
||||
@@ -20,58 +20,58 @@ const UInt32 kNumThreadsMax = 4;
|
||||
|
||||
static const UInt32 kBufferSize = (1 << 17);
|
||||
|
||||
static Int16 kRandNums[512] = {
|
||||
619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
|
||||
985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
|
||||
733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
|
||||
419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
|
||||
878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
|
||||
862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
|
||||
150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
|
||||
170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
|
||||
73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
|
||||
909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
|
||||
641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
|
||||
161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
|
||||
382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
|
||||
98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
|
||||
227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
|
||||
469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
|
||||
184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
|
||||
715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
|
||||
951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
|
||||
652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
|
||||
645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
|
||||
609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
|
||||
653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
|
||||
411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
|
||||
170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
|
||||
857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
|
||||
669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
|
||||
944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
|
||||
344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
|
||||
897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
|
||||
433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
|
||||
686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
|
||||
946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
|
||||
978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
|
||||
680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
|
||||
707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
|
||||
297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
|
||||
134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
|
||||
343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
|
||||
140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
|
||||
170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
|
||||
369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
|
||||
804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
|
||||
896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
|
||||
661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
|
||||
768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
|
||||
61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
|
||||
372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
|
||||
780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
|
||||
920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
|
||||
645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
|
||||
static Int16 kRandNums[512] = {
|
||||
619, 720, 127, 481, 931, 816, 813, 233, 566, 247,
|
||||
985, 724, 205, 454, 863, 491, 741, 242, 949, 214,
|
||||
733, 859, 335, 708, 621, 574, 73, 654, 730, 472,
|
||||
419, 436, 278, 496, 867, 210, 399, 680, 480, 51,
|
||||
878, 465, 811, 169, 869, 675, 611, 697, 867, 561,
|
||||
862, 687, 507, 283, 482, 129, 807, 591, 733, 623,
|
||||
150, 238, 59, 379, 684, 877, 625, 169, 643, 105,
|
||||
170, 607, 520, 932, 727, 476, 693, 425, 174, 647,
|
||||
73, 122, 335, 530, 442, 853, 695, 249, 445, 515,
|
||||
909, 545, 703, 919, 874, 474, 882, 500, 594, 612,
|
||||
641, 801, 220, 162, 819, 984, 589, 513, 495, 799,
|
||||
161, 604, 958, 533, 221, 400, 386, 867, 600, 782,
|
||||
382, 596, 414, 171, 516, 375, 682, 485, 911, 276,
|
||||
98, 553, 163, 354, 666, 933, 424, 341, 533, 870,
|
||||
227, 730, 475, 186, 263, 647, 537, 686, 600, 224,
|
||||
469, 68, 770, 919, 190, 373, 294, 822, 808, 206,
|
||||
184, 943, 795, 384, 383, 461, 404, 758, 839, 887,
|
||||
715, 67, 618, 276, 204, 918, 873, 777, 604, 560,
|
||||
951, 160, 578, 722, 79, 804, 96, 409, 713, 940,
|
||||
652, 934, 970, 447, 318, 353, 859, 672, 112, 785,
|
||||
645, 863, 803, 350, 139, 93, 354, 99, 820, 908,
|
||||
609, 772, 154, 274, 580, 184, 79, 626, 630, 742,
|
||||
653, 282, 762, 623, 680, 81, 927, 626, 789, 125,
|
||||
411, 521, 938, 300, 821, 78, 343, 175, 128, 250,
|
||||
170, 774, 972, 275, 999, 639, 495, 78, 352, 126,
|
||||
857, 956, 358, 619, 580, 124, 737, 594, 701, 612,
|
||||
669, 112, 134, 694, 363, 992, 809, 743, 168, 974,
|
||||
944, 375, 748, 52, 600, 747, 642, 182, 862, 81,
|
||||
344, 805, 988, 739, 511, 655, 814, 334, 249, 515,
|
||||
897, 955, 664, 981, 649, 113, 974, 459, 893, 228,
|
||||
433, 837, 553, 268, 926, 240, 102, 654, 459, 51,
|
||||
686, 754, 806, 760, 493, 403, 415, 394, 687, 700,
|
||||
946, 670, 656, 610, 738, 392, 760, 799, 887, 653,
|
||||
978, 321, 576, 617, 626, 502, 894, 679, 243, 440,
|
||||
680, 879, 194, 572, 640, 724, 926, 56, 204, 700,
|
||||
707, 151, 457, 449, 797, 195, 791, 558, 945, 679,
|
||||
297, 59, 87, 824, 713, 663, 412, 693, 342, 606,
|
||||
134, 108, 571, 364, 631, 212, 174, 643, 304, 329,
|
||||
343, 97, 430, 751, 497, 314, 983, 374, 822, 928,
|
||||
140, 206, 73, 263, 980, 736, 876, 478, 430, 305,
|
||||
170, 514, 364, 692, 829, 82, 855, 953, 676, 246,
|
||||
369, 970, 294, 750, 807, 827, 150, 790, 288, 923,
|
||||
804, 378, 215, 828, 592, 281, 565, 555, 710, 82,
|
||||
896, 831, 547, 261, 524, 462, 293, 465, 502, 56,
|
||||
661, 821, 976, 991, 658, 869, 905, 758, 745, 193,
|
||||
768, 550, 608, 933, 378, 286, 215, 979, 792, 961,
|
||||
61, 688, 793, 644, 986, 403, 106, 366, 905, 644,
|
||||
372, 567, 466, 434, 645, 210, 389, 550, 919, 135,
|
||||
780, 773, 635, 389, 707, 100, 626, 958, 165, 504,
|
||||
920, 176, 193, 713, 857, 265, 203, 50, 668, 108,
|
||||
645, 990, 626, 197, 510, 357, 358, 850, 858, 364,
|
||||
936, 638
|
||||
};
|
||||
|
||||
@@ -113,15 +113,15 @@ UInt32 NO_INLINE ReadBit(NStream::NMSBF::CDecoder<CInBuffer> *m_InStream)
|
||||
return m_InStream->ReadBits(1);
|
||||
}
|
||||
|
||||
static HRESULT NO_INLINE ReadBlock(NStream::NMSBF::CDecoder<CInBuffer> *m_InStream,
|
||||
UInt32 *CharCounters, UInt32 blockSizeMax, Byte *m_Selectors, CHuffmanDecoder *m_HuffmanDecoders,
|
||||
static HRESULT NO_INLINE ReadBlock(NStream::NMSBF::CDecoder<CInBuffer> *m_InStream,
|
||||
UInt32 *CharCounters, UInt32 blockSizeMax, Byte *m_Selectors, CHuffmanDecoder *m_HuffmanDecoders,
|
||||
UInt32 *blockSizeRes, UInt32 *origPtrRes, bool *randRes)
|
||||
{
|
||||
*randRes = ReadBit(m_InStream) ? true : false;
|
||||
*origPtrRes = ReadBits(m_InStream, kNumOrigBits);
|
||||
|
||||
// in original code it compares OrigPtr to (UInt32)(10 + blockSizeMax)) : why ?
|
||||
if (*origPtrRes >= blockSizeMax)
|
||||
if (*origPtrRes >= blockSizeMax)
|
||||
return S_FALSE;
|
||||
|
||||
CMtf8Decoder mtf;
|
||||
@@ -131,7 +131,7 @@ static HRESULT NO_INLINE ReadBlock(NStream::NMSBF::CDecoder<CInBuffer> *m_InStre
|
||||
{
|
||||
Byte inUse16[16];
|
||||
int i;
|
||||
for (i = 0; i < 16; i++)
|
||||
for (i = 0; i < 16; i++)
|
||||
inUse16[i] = (Byte)ReadBit(m_InStream);
|
||||
for (i = 0; i < 256; i++)
|
||||
if (inUse16[i >> 4])
|
||||
@@ -139,7 +139,7 @@ static HRESULT NO_INLINE ReadBlock(NStream::NMSBF::CDecoder<CInBuffer> *m_InStre
|
||||
if (ReadBit(m_InStream))
|
||||
mtf.Add(numInUse++, (Byte)i);
|
||||
}
|
||||
if (numInUse == 0)
|
||||
if (numInUse == 0)
|
||||
return S_FALSE;
|
||||
// mtf.Init(numInUse);
|
||||
}
|
||||
@@ -164,11 +164,11 @@ static HRESULT NO_INLINE ReadBlock(NStream::NMSBF::CDecoder<CInBuffer> *m_InStre
|
||||
{
|
||||
int j = 0;
|
||||
while (ReadBit(m_InStream))
|
||||
if (++j >= numTables)
|
||||
if (++j >= numTables)
|
||||
return S_FALSE;
|
||||
Byte tmp = mtfPos[j];
|
||||
for (;j > 0; j--)
|
||||
mtfPos[j] = mtfPos[j - 1];
|
||||
for (;j > 0; j--)
|
||||
mtfPos[j] = mtfPos[j - 1];
|
||||
m_Selectors[i] = mtfPos[0] = tmp;
|
||||
}
|
||||
while(++i < numSelectors);
|
||||
@@ -180,19 +180,19 @@ static HRESULT NO_INLINE ReadBlock(NStream::NMSBF::CDecoder<CInBuffer> *m_InStre
|
||||
Byte lens[kMaxAlphaSize];
|
||||
int len = (int)ReadBits(m_InStream, kNumLevelsBits);
|
||||
int i;
|
||||
for (i = 0; i < alphaSize; i++)
|
||||
for (i = 0; i < alphaSize; i++)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if (len < 1 || len > kMaxHuffmanLen)
|
||||
if (len < 1 || len > kMaxHuffmanLen)
|
||||
return S_FALSE;
|
||||
if (!ReadBit(m_InStream))
|
||||
if (!ReadBit(m_InStream))
|
||||
break;
|
||||
len += 1 - (int)(ReadBit(m_InStream) << 1);
|
||||
}
|
||||
lens[i] = (Byte)len;
|
||||
}
|
||||
for (; i < kMaxAlphaSize; i++)
|
||||
for (; i < kMaxAlphaSize; i++)
|
||||
lens[i] = 0;
|
||||
if(!m_HuffmanDecoders[t].SetCodeLengths(lens))
|
||||
return S_FALSE;
|
||||
@@ -200,7 +200,7 @@ static HRESULT NO_INLINE ReadBlock(NStream::NMSBF::CDecoder<CInBuffer> *m_InStre
|
||||
while(++t < numTables);
|
||||
|
||||
{
|
||||
for (int i = 0; i < 256; i++)
|
||||
for (int i = 0; i < 256; i++)
|
||||
CharCounters[i] = 0;
|
||||
}
|
||||
|
||||
@@ -214,7 +214,7 @@ static HRESULT NO_INLINE ReadBlock(NStream::NMSBF::CDecoder<CInBuffer> *m_InStre
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (groupSize == 0)
|
||||
if (groupSize == 0)
|
||||
{
|
||||
if (groupIndex >= numSelectors)
|
||||
return S_FALSE;
|
||||
@@ -225,9 +225,9 @@ static HRESULT NO_INLINE ReadBlock(NStream::NMSBF::CDecoder<CInBuffer> *m_InStre
|
||||
|
||||
UInt32 nextSym = huffmanDecoder->DecodeSymbol(m_InStream);
|
||||
|
||||
if (nextSym < 2)
|
||||
if (nextSym < 2)
|
||||
{
|
||||
runCounter += ((UInt32)(nextSym + 1) << runPower++);
|
||||
runCounter += ((UInt32)(nextSym + 1) << runPower++);
|
||||
if (blockSizeMax - blockSize < runCounter)
|
||||
return S_FALSE;
|
||||
continue;
|
||||
@@ -236,22 +236,22 @@ static HRESULT NO_INLINE ReadBlock(NStream::NMSBF::CDecoder<CInBuffer> *m_InStre
|
||||
{
|
||||
UInt32 b = (UInt32)mtf.GetHead();
|
||||
CharCounters[b] += runCounter;
|
||||
do
|
||||
do
|
||||
CharCounters[256 + blockSize++] = b;
|
||||
while(--runCounter != 0);
|
||||
runPower = 0;
|
||||
}
|
||||
if (nextSym <= (UInt32)numInUse)
|
||||
}
|
||||
if (nextSym <= (UInt32)numInUse)
|
||||
{
|
||||
UInt32 b = (UInt32)mtf.GetAndMove((int)nextSym - 1);
|
||||
if (blockSize >= blockSizeMax)
|
||||
if (blockSize >= blockSizeMax)
|
||||
return S_FALSE;
|
||||
CharCounters[b]++;
|
||||
CharCounters[256 + blockSize++] = b;
|
||||
}
|
||||
else if (nextSym == (UInt32)numInUse + 1)
|
||||
else if (nextSym == (UInt32)numInUse + 1)
|
||||
break;
|
||||
else
|
||||
else
|
||||
return S_FALSE;
|
||||
}
|
||||
}
|
||||
@@ -263,7 +263,7 @@ void NO_INLINE DecodeBlock1(UInt32 *charCounters, UInt32 blockSize)
|
||||
{
|
||||
{
|
||||
UInt32 sum = 0;
|
||||
for (UInt32 i = 0; i < 256; i++)
|
||||
for (UInt32 i = 0; i < 256; i++)
|
||||
{
|
||||
sum += charCounters[i];
|
||||
charCounters[i] = sum - charCounters[i];
|
||||
@@ -388,7 +388,7 @@ static UInt32 NO_INLINE DecodeBlock2Rand(const UInt32 *tt, UInt32 blockSize, UIn
|
||||
tPos = tt[tPos >> 8];
|
||||
|
||||
{
|
||||
if (randToGo == 0)
|
||||
if (randToGo == 0)
|
||||
{
|
||||
b ^= 1;
|
||||
randToGo = kRandNums[randIndex++];
|
||||
@@ -443,8 +443,8 @@ HRESULT CDecoder::Create()
|
||||
Free();
|
||||
MtMode = (NumThreads > 1);
|
||||
m_NumThreadsPrev = NumThreads;
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
m_States = new CState[NumThreads];
|
||||
if (m_States == 0)
|
||||
return E_OUTOFMEMORY;
|
||||
@@ -461,7 +461,7 @@ HRESULT CDecoder::Create()
|
||||
{
|
||||
NumThreads = t;
|
||||
Free();
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -495,21 +495,21 @@ HRESULT CDecoder::ReadSignatures(bool &wasFinished, UInt32 &crc)
|
||||
crc = ReadCRC();
|
||||
if (s[0] == kFinSig0)
|
||||
{
|
||||
if (s[1] != kFinSig1 ||
|
||||
s[2] != kFinSig2 ||
|
||||
s[3] != kFinSig3 ||
|
||||
s[4] != kFinSig4 ||
|
||||
if (s[1] != kFinSig1 ||
|
||||
s[2] != kFinSig2 ||
|
||||
s[3] != kFinSig3 ||
|
||||
s[4] != kFinSig4 ||
|
||||
s[5] != kFinSig5)
|
||||
return S_FALSE;
|
||||
|
||||
wasFinished = true;
|
||||
return (crc == CombinedCRC.GetDigest()) ? S_OK : S_FALSE;
|
||||
}
|
||||
if (s[0] != kBlockSig0 ||
|
||||
s[1] != kBlockSig1 ||
|
||||
s[2] != kBlockSig2 ||
|
||||
s[3] != kBlockSig3 ||
|
||||
s[4] != kBlockSig4 ||
|
||||
if (s[0] != kBlockSig0 ||
|
||||
s[1] != kBlockSig1 ||
|
||||
s[2] != kBlockSig2 ||
|
||||
s[3] != kBlockSig3 ||
|
||||
s[4] != kBlockSig4 ||
|
||||
s[5] != kBlockSig5)
|
||||
return S_FALSE;
|
||||
CombinedCRC.Update(crc);
|
||||
@@ -543,10 +543,10 @@ HRESULT CDecoder::DecodeFile(bool &isBZ, ICompressProgressInfo *progress)
|
||||
int i;
|
||||
for (i = 0; i < 4; i++)
|
||||
s[i] = ReadByte();
|
||||
if (s[0] != kArSig0 ||
|
||||
s[1] != kArSig1 ||
|
||||
s[2] != kArSig2 ||
|
||||
s[3] <= kArSig3 ||
|
||||
if (s[0] != kArSig0 ||
|
||||
s[1] != kArSig1 ||
|
||||
s[2] != kArSig2 ||
|
||||
s[3] <= kArSig3 ||
|
||||
s[3] > kArSig3 + kBlockSizeMultMax)
|
||||
return S_OK;
|
||||
isBZ = true;
|
||||
@@ -595,11 +595,11 @@ HRESULT CDecoder::DecodeFile(bool &isBZ, ICompressProgressInfo *progress)
|
||||
|
||||
UInt32 blockSize, origPtr;
|
||||
bool randMode;
|
||||
RINOK(ReadBlock(&m_InStream, state.Counters, dicSize,
|
||||
m_Selectors, m_HuffmanDecoders,
|
||||
RINOK(ReadBlock(&m_InStream, state.Counters, dicSize,
|
||||
m_Selectors, m_HuffmanDecoders,
|
||||
&blockSize, &origPtr, &randMode));
|
||||
DecodeBlock1(state.Counters, blockSize);
|
||||
if ((randMode ?
|
||||
if ((randMode ?
|
||||
DecodeBlock2Rand(state.Counters + 256, blockSize, origPtr, m_OutStream) :
|
||||
DecodeBlock2(state.Counters + 256, blockSize, origPtr, m_OutStream)) != crc)
|
||||
return S_FALSE;
|
||||
@@ -698,7 +698,7 @@ void CState::ThreadFunc()
|
||||
UInt32 blockSize = 0, origPtr = 0;
|
||||
bool randMode = false;
|
||||
|
||||
try
|
||||
try
|
||||
{
|
||||
bool wasFinished;
|
||||
res = Decoder->ReadSignatures(wasFinished, crc);
|
||||
@@ -715,8 +715,8 @@ void CState::ThreadFunc()
|
||||
continue;
|
||||
}
|
||||
|
||||
res = ReadBlock(&Decoder->m_InStream, Counters, Decoder->BlockSizeMax,
|
||||
Decoder->m_Selectors, Decoder->m_HuffmanDecoders,
|
||||
res = ReadBlock(&Decoder->m_InStream, Counters, Decoder->BlockSizeMax,
|
||||
Decoder->m_Selectors, Decoder->m_HuffmanDecoders,
|
||||
&blockSize, &origPtr, &randMode);
|
||||
if (res != S_OK)
|
||||
{
|
||||
@@ -746,7 +746,7 @@ void CState::ThreadFunc()
|
||||
needFinish = Decoder->StreamWasFinished2;
|
||||
if (!needFinish)
|
||||
{
|
||||
if ((randMode ?
|
||||
if ((randMode ?
|
||||
DecodeBlock2Rand(Counters + 256, blockSize, origPtr, Decoder->m_OutStream) :
|
||||
DecodeBlock2(Counters + 256, blockSize, origPtr, Decoder->m_OutStream)) == crc)
|
||||
{
|
||||
|
||||
@@ -89,11 +89,11 @@ private:
|
||||
public:
|
||||
bool NeedFlush;
|
||||
CDecoderFlusher(CDecoder *decoder): _decoder(decoder), NeedFlush(true) {}
|
||||
~CDecoderFlusher()
|
||||
{
|
||||
~CDecoderFlusher()
|
||||
{
|
||||
if (NeedFlush)
|
||||
_decoder->Flush();
|
||||
_decoder->ReleaseStreams();
|
||||
_decoder->ReleaseStreams();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
#include "../../../../C/BwtSort.h"
|
||||
#include "../../../../C/HuffEnc.h"
|
||||
@@ -96,7 +96,7 @@ DWORD CThreadInfo::ThreadFunc()
|
||||
}
|
||||
HRESULT res = S_OK;
|
||||
bool needLeave = true;
|
||||
try
|
||||
try
|
||||
{
|
||||
UInt32 blockSize = Encoder->ReadRleBlock(m_Block);
|
||||
m_PackSize = Encoder->m_InStream.GetProcessedSize();
|
||||
@@ -127,7 +127,7 @@ DWORD CThreadInfo::ThreadFunc()
|
||||
#endif
|
||||
|
||||
CEncoder::CEncoder():
|
||||
NumPasses(1),
|
||||
NumPasses(1),
|
||||
m_OptimizeNumTables(false),
|
||||
m_BlockSizeMult(kBlockSizeMultMax)
|
||||
{
|
||||
@@ -150,8 +150,8 @@ HRESULT CEncoder::Create()
|
||||
RINOK_THREAD(CanStartWaitingEvent.CreateIfNotCreated());
|
||||
if (ThreadsInfo != 0 && m_NumThreadsPrev == NumThreads)
|
||||
return S_OK;
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
Free();
|
||||
MtMode = (NumThreads > 1);
|
||||
m_NumThreadsPrev = NumThreads;
|
||||
@@ -171,7 +171,7 @@ HRESULT CEncoder::Create()
|
||||
{
|
||||
NumThreads = t;
|
||||
Free();
|
||||
return res;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,8 +239,8 @@ void CThreadInfo::WriteBits2(UInt32 value, UInt32 numBits)
|
||||
{ m_OutStreamCurrent->WriteBits(value, numBits); }
|
||||
void CThreadInfo::WriteByte2(Byte b) { WriteBits2(b , 8); }
|
||||
void CThreadInfo::WriteBit2(bool v) { WriteBits2((v ? 1 : 0), 1); }
|
||||
void CThreadInfo::WriteCRC2(UInt32 v)
|
||||
{
|
||||
void CThreadInfo::WriteCRC2(UInt32 v)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
WriteByte2(((Byte)(v >> (24 - i * 8))));
|
||||
}
|
||||
@@ -249,8 +249,8 @@ void CEncoder::WriteBits(UInt32 value, UInt32 numBits)
|
||||
{ m_OutStream.WriteBits(value, numBits); }
|
||||
void CEncoder::WriteByte(Byte b) { WriteBits(b , 8); }
|
||||
void CEncoder::WriteBit(bool v) { WriteBits((v ? 1 : 0), 1); }
|
||||
void CEncoder::WriteCRC(UInt32 v)
|
||||
{
|
||||
void CEncoder::WriteCRC(UInt32 v)
|
||||
{
|
||||
for (int i = 0; i < 4; i++)
|
||||
WriteByte(((Byte)(v >> (24 - i * 8))));
|
||||
}
|
||||
@@ -274,21 +274,21 @@ void CThreadInfo::EncodeBlock(const Byte *block, UInt32 blockSize)
|
||||
bool inUse[256];
|
||||
bool inUse16[16];
|
||||
UInt32 i;
|
||||
for (i = 0; i < 256; i++)
|
||||
for (i = 0; i < 256; i++)
|
||||
inUse[i] = false;
|
||||
for (i = 0; i < 16; i++)
|
||||
for (i = 0; i < 16; i++)
|
||||
inUse16[i] = false;
|
||||
for (i = 0; i < blockSize; i++)
|
||||
inUse[block[i]] = true;
|
||||
for (i = 0; i < 256; i++)
|
||||
for (i = 0; i < 256; i++)
|
||||
if (inUse[i])
|
||||
{
|
||||
inUse16[i >> 4] = true;
|
||||
mtf.Buffer[numInUse++] = (Byte)i;
|
||||
}
|
||||
for (i = 0; i < 16; i++)
|
||||
for (i = 0; i < 16; i++)
|
||||
WriteBit2(inUse16[i]);
|
||||
for (i = 0; i < 256; i++)
|
||||
for (i = 0; i < 256; i++)
|
||||
if (inUse16[i >> 4])
|
||||
WriteBit2(inUse[i]);
|
||||
}
|
||||
@@ -307,7 +307,7 @@ void CThreadInfo::EncodeBlock(const Byte *block, UInt32 blockSize)
|
||||
UInt32 i = 0;
|
||||
const UInt32 *bsIndex = m_BlockSorterIndex;
|
||||
block--;
|
||||
do
|
||||
do
|
||||
{
|
||||
int pos = mtf.FindAndMove(block[bsIndex[i]]);
|
||||
if (pos == 0)
|
||||
@@ -376,10 +376,10 @@ void CThreadInfo::EncodeBlock(const Byte *block, UInt32 blockSize)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (numSymbols < 200) numTables = 2;
|
||||
else if (numSymbols < 600) numTables = 3;
|
||||
else if (numSymbols < 1200) numTables = 4;
|
||||
else if (numSymbols < 2400) numTables = 5;
|
||||
if (numSymbols < 200) numTables = 2;
|
||||
else if (numSymbols < 600) numTables = 3;
|
||||
else if (numSymbols < 1200) numTables = 4;
|
||||
else if (numSymbols < 2400) numTables = 5;
|
||||
else numTables = 6;
|
||||
}
|
||||
|
||||
@@ -397,10 +397,10 @@ void CThreadInfo::EncodeBlock(const Byte *block, UInt32 blockSize)
|
||||
UInt32 tFreq = remFreq / t;
|
||||
int ge = gs;
|
||||
UInt32 aFreq = 0;
|
||||
while (aFreq < tFreq) // && ge < alphaSize)
|
||||
while (aFreq < tFreq) // && ge < alphaSize)
|
||||
aFreq += symbolCounts[ge++];
|
||||
|
||||
if (ge - 1 > gs && t != numTables && t != 1 && (((numTables - t) & 1) == 1))
|
||||
if (ge - 1 > gs && t != numTables && t != 1 && (((numTables - t) & 1) == 1))
|
||||
aFreq -= symbolCounts[--ge];
|
||||
|
||||
Byte *lens = Lens[t - 1];
|
||||
@@ -427,7 +427,7 @@ void CThreadInfo::EncodeBlock(const Byte *block, UInt32 blockSize)
|
||||
{
|
||||
UInt32 mtfPos = 0;
|
||||
UInt32 g = 0;
|
||||
do
|
||||
do
|
||||
{
|
||||
UInt32 symbols[kGroupSize];
|
||||
int i = 0;
|
||||
@@ -523,7 +523,7 @@ void CThreadInfo::EncodeBlock(const Byte *block, UInt32 blockSize)
|
||||
WriteBit2(false);
|
||||
len++;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
WriteBit2(true);
|
||||
len--;
|
||||
@@ -547,7 +547,7 @@ void CThreadInfo::EncodeBlock(const Byte *block, UInt32 blockSize)
|
||||
UInt32 symbol = mtfs[mtfPos++];
|
||||
if (symbol >= 0xFF)
|
||||
symbol += mtfs[mtfPos++];
|
||||
if (groupSize == 0)
|
||||
if (groupSize == 0)
|
||||
{
|
||||
groupSize = kGroupSize;
|
||||
int t = m_Selectors[groupIndex++];
|
||||
@@ -587,7 +587,7 @@ UInt32 CThreadInfo::EncodeBlockWithHeaders(const Byte *block, UInt32 blockSize)
|
||||
int numReps = 0;
|
||||
Byte prevByte = block[0];
|
||||
UInt32 i = 0;
|
||||
do
|
||||
do
|
||||
{
|
||||
Byte b = block[i];
|
||||
if (numReps == kRleModeRepSize)
|
||||
@@ -627,7 +627,7 @@ void CThreadInfo::EncodeBlock2(const Byte *block, UInt32 blockSize, UInt32 numPa
|
||||
{
|
||||
UInt32 blockSize0 = blockSize / 2;
|
||||
for (;(block[blockSize0] == block[blockSize0 - 1] ||
|
||||
block[blockSize0 - 1] == block[blockSize0 - 2]) &&
|
||||
block[blockSize0 - 1] == block[blockSize0 - 2]) &&
|
||||
blockSize0 < blockSize; blockSize0++);
|
||||
if (blockSize0 < blockSize)
|
||||
{
|
||||
@@ -651,7 +651,7 @@ void CThreadInfo::EncodeBlock2(const Byte *block, UInt32 blockSize, UInt32 numPa
|
||||
{
|
||||
UInt32 size2 = endPos2 - startPos2;
|
||||
if (size2 < endPos - startPos)
|
||||
{
|
||||
{
|
||||
UInt32 numBytes = m_OutStreamCurrent->GetBytePos() - startBytePos2;
|
||||
Byte *buffer = m_OutStreamCurrent->GetStream();
|
||||
for (UInt32 i = 0; i < numBytes; i++)
|
||||
@@ -799,7 +799,7 @@ HRESULT CEncoder::CodeReal(ISequentialInStream *inStream,
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
CThreadInfo &ti =
|
||||
CThreadInfo &ti =
|
||||
#ifdef COMPRESS_BZIP2_MT
|
||||
ThreadsInfo[0];
|
||||
#else
|
||||
@@ -838,12 +838,12 @@ STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,
|
||||
catch(...) { return S_FALSE; }
|
||||
}
|
||||
|
||||
HRESULT CEncoder::SetCoderProperties(const PROPID *propIDs,
|
||||
HRESULT CEncoder::SetCoderProperties(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties)
|
||||
{
|
||||
for(UInt32 i = 0; i < numProperties; i++)
|
||||
{
|
||||
const PROPVARIANT &property = properties[i];
|
||||
const PROPVARIANT &property = properties[i];
|
||||
switch(propIDs[i])
|
||||
{
|
||||
case NCoderPropID::kNumPasses:
|
||||
|
||||
@@ -32,7 +32,7 @@ public:
|
||||
void Init()
|
||||
{
|
||||
m_Pos = 0;
|
||||
m_BitPos = 8;
|
||||
m_BitPos = 8;
|
||||
m_CurByte = 0;
|
||||
}
|
||||
|
||||
@@ -68,14 +68,14 @@ public:
|
||||
UInt32 GetPos() const { return m_Pos * 8 + (8 - m_BitPos); }
|
||||
Byte GetCurByte() const { return m_CurByte; }
|
||||
void SetPos(UInt32 bitPos)
|
||||
{
|
||||
{
|
||||
m_Pos = bitPos / 8;
|
||||
m_BitPos = 8 - ((int)bitPos & 7);
|
||||
m_BitPos = 8 - ((int)bitPos & 7);
|
||||
}
|
||||
void SetCurState(int bitPos, Byte curByte)
|
||||
{
|
||||
m_BitPos = 8 - bitPos;
|
||||
m_CurByte = curByte;
|
||||
{
|
||||
m_BitPos = 8 - bitPos;
|
||||
m_CurByte = curByte;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -143,7 +143,7 @@ public:
|
||||
|
||||
class CEncoder :
|
||||
public ICompressCoder,
|
||||
public ICompressSetCoderProperties,
|
||||
public ICompressSetCoderProperties,
|
||||
#ifdef COMPRESS_BZIP2_MT
|
||||
public ICompressSetCoderMt,
|
||||
#endif
|
||||
@@ -213,11 +213,11 @@ public:
|
||||
public:
|
||||
bool NeedFlush;
|
||||
CFlusher(CEncoder *coder): _coder(coder), NeedFlush(true) {}
|
||||
~CFlusher()
|
||||
{
|
||||
~CFlusher()
|
||||
{
|
||||
if (NeedFlush)
|
||||
_coder->Flush();
|
||||
_coder->ReleaseStreams();
|
||||
_coder->ReleaseStreams();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -234,7 +234,7 @@ public:
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties);
|
||||
|
||||
#ifdef COMPRESS_BZIP2_MT
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
@@ -23,16 +23,16 @@ public:
|
||||
};
|
||||
|
||||
#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \
|
||||
{ public: UInt32 SubFilter(Byte *data, UInt32 size); };
|
||||
{ public: UInt32 SubFilter(Byte *data, UInt32 size); };
|
||||
|
||||
#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \
|
||||
{ public: UInt32 SubFilter(Byte *data, UInt32 size); };
|
||||
{ public: UInt32 SubFilter(Byte *data, UInt32 size); };
|
||||
|
||||
#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \
|
||||
{ public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};
|
||||
{ public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};
|
||||
|
||||
#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \
|
||||
{ public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};
|
||||
{ public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};
|
||||
|
||||
#define MyClassA(Name, id, subId) \
|
||||
MyClassEncoderA(Name ## _Encoder) \
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include "StdAfx.h"
|
||||
#include "BranchMisc.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Bra.h"
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
@@ -4,8 +4,8 @@
|
||||
#define __X86_H
|
||||
|
||||
#include "BranchCoder.h"
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Bra.h"
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ struct CBranch86
|
||||
void x86Init() { x86_Convert_Init(_prevMask); }
|
||||
};
|
||||
|
||||
MyClassB(BCJ_x86, 0x01, 3, CBranch86 ,
|
||||
MyClassB(BCJ_x86, 0x01, 3, CBranch86 ,
|
||||
virtual void SubInit() { x86Init(); })
|
||||
|
||||
#endif
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include "StdAfx.h"
|
||||
#include "x86_2.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ HRESULT CEncoder::CodeReal(ISequentialInStream **inStreams,
|
||||
|
||||
if (endPos < 5)
|
||||
{
|
||||
// change it
|
||||
// change it
|
||||
for (bufferPos = 0; bufferPos < endPos; bufferPos++)
|
||||
{
|
||||
Byte b = _buffer[bufferPos];
|
||||
@@ -167,7 +167,7 @@ HRESULT CEncoder::CodeReal(ISequentialInStream **inStreams,
|
||||
continue;
|
||||
}
|
||||
Byte nextByte = _buffer[bufferPos + 4];
|
||||
UInt32 src =
|
||||
UInt32 src =
|
||||
(UInt32(nextByte) << 24) |
|
||||
(UInt32(_buffer[bufferPos + 3]) << 16) |
|
||||
(UInt32(_buffer[bufferPos + 2]) << 8) |
|
||||
@@ -185,14 +185,14 @@ HRESULT CEncoder::CodeReal(ISequentialInStream **inStreams,
|
||||
if (result == S_OK)
|
||||
{
|
||||
subStreamStartPos = subStreamEndPos;
|
||||
subStreamEndPos += subStreamSize;
|
||||
subStreamEndPos += subStreamSize;
|
||||
subStreamIndex++;
|
||||
}
|
||||
else if (result == S_FALSE || result == E_NOTIMPL)
|
||||
{
|
||||
getSubStreamSize.Release();
|
||||
subStreamStartPos = 0;
|
||||
subStreamEndPos = subStreamStartPos - 1;
|
||||
subStreamEndPos = subStreamStartPos - 1;
|
||||
}
|
||||
else
|
||||
return result;
|
||||
@@ -239,8 +239,8 @@ HRESULT CEncoder::CodeReal(ISequentialInStream **inStreams,
|
||||
if (progress != NULL)
|
||||
{
|
||||
/*
|
||||
const UInt64 compressedSize =
|
||||
_mainStream.GetProcessedSize() +
|
||||
const UInt64 compressedSize =
|
||||
_mainStream.GetProcessedSize() +
|
||||
_callStream.GetProcessedSize() +
|
||||
_jumpStream.GetProcessedSize() +
|
||||
_rangeEncoder.GetProcessedSize();
|
||||
@@ -320,8 +320,8 @@ HRESULT CDecoder::CodeReal(ISequentialInStream **inStreams,
|
||||
if (processedBytes >= (1 << 20) && progress != NULL)
|
||||
{
|
||||
/*
|
||||
const UInt64 compressedSize =
|
||||
_mainInStream.GetProcessedSize() +
|
||||
const UInt64 compressedSize =
|
||||
_mainInStream.GetProcessedSize() +
|
||||
_callStream.GetProcessedSize() +
|
||||
_jumpStream.GetProcessedSize() +
|
||||
_rangeDecoder.GetProcessedSize();
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
~CCoderReleaser() { _coder->ReleaseStreams(); }
|
||||
};
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
@@ -65,14 +65,14 @@ public:
|
||||
const UInt64 **outSizes,
|
||||
UInt32 numOutStreams,
|
||||
ICompressProgressInfo *progress);
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
class CDecoder:
|
||||
public ICompressCoder2,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
{
|
||||
public:
|
||||
CInBuffer _mainInStream;
|
||||
CInBuffer _callStream;
|
||||
@@ -100,7 +100,7 @@ public:
|
||||
~CCoderReleaser() { _coder->ReleaseStreams(); }
|
||||
};
|
||||
|
||||
public:
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
HRESULT CodeReal(ISequentialInStream **inStreams,
|
||||
const UInt64 **inSizes,
|
||||
@@ -116,7 +116,7 @@ public:
|
||||
const UInt64 **outSizes,
|
||||
UInt32 numOutStreams,
|
||||
ICompressProgressInfo *progress);
|
||||
};
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
#include "Common/MyCom.h"
|
||||
|
||||
// {23170F69-40C1-278B-0203-020000000000}
|
||||
DEFINE_GUID(CLSID_CCompressConvertByteSwap2,
|
||||
DEFINE_GUID(CLSID_CCompressConvertByteSwap2,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x02, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
// {23170F69-40C1-278B-0203-040000000000}
|
||||
DEFINE_GUID(CLSID_CCompressConvertByteSwap4,
|
||||
DEFINE_GUID(CLSID_CCompressConvertByteSwap4,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
class CByteSwap2:
|
||||
class CByteSwap2:
|
||||
public ICompressFilter,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -24,7 +24,7 @@ public:
|
||||
STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
|
||||
};
|
||||
|
||||
class CByteSwap4:
|
||||
class CByteSwap4:
|
||||
public ICompressFilter,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
@@ -8,11 +8,11 @@
|
||||
#include "../ICoder.h"
|
||||
|
||||
extern unsigned int g_NumCodecs;
|
||||
extern const CCodecInfo *g_Codecs[];
|
||||
extern const CCodecInfo *g_Codecs[];
|
||||
|
||||
static const UInt16 kDecodeId = 0x2790;
|
||||
|
||||
DEFINE_GUID(CLSID_CCodec,
|
||||
DEFINE_GUID(CLSID_CCodec,
|
||||
0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
static inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)
|
||||
@@ -40,7 +40,7 @@ static HRESULT SetClassID(CMethodId id, bool encode, PROPVARIANT *value)
|
||||
static HRESULT FindCodecClassId(const GUID *clsID, UInt32 isCoder2, bool isFilter, bool &encode, int &index)
|
||||
{
|
||||
index = -1;
|
||||
if (clsID->Data1 != CLSID_CCodec.Data1 ||
|
||||
if (clsID->Data1 != CLSID_CCodec.Data1 ||
|
||||
clsID->Data2 != CLSID_CCodec.Data2 ||
|
||||
(clsID->Data3 & ~1) != kDecodeId)
|
||||
return S_OK;
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ CCopyCoder::~CCopyCoder()
|
||||
}
|
||||
|
||||
STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 * /* inSize */, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
namespace NCompress {
|
||||
|
||||
class CCopyCoder:
|
||||
class CCopyCoder:
|
||||
public ICompressCoder,
|
||||
public ICompressGetInStreamProcessedSize,
|
||||
public CMyUnknownImp
|
||||
@@ -22,7 +22,7 @@ public:
|
||||
MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
@@ -5,4 +5,4 @@
|
||||
|
||||
#include "../../../Common/MyWindows.h"
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -38,30 +38,30 @@ const UInt32 kTableLevel0Number2 = kTableLevel0Number + 1;
|
||||
|
||||
const UInt32 kLevelMask = 0xF;
|
||||
|
||||
const Byte kLenStart32[kFixedLenTableSize] =
|
||||
const Byte kLenStart32[kFixedLenTableSize] =
|
||||
{0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224, 255, 0, 0};
|
||||
const Byte kLenStart64[kFixedLenTableSize] =
|
||||
const Byte kLenStart64[kFixedLenTableSize] =
|
||||
{0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224, 0, 0, 0};
|
||||
|
||||
const Byte kLenDirectBits32[kFixedLenTableSize] =
|
||||
const Byte kLenDirectBits32[kFixedLenTableSize] =
|
||||
{0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 0};
|
||||
const Byte kLenDirectBits64[kFixedLenTableSize] =
|
||||
const Byte kLenDirectBits64[kFixedLenTableSize] =
|
||||
{0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 16, 0, 0};
|
||||
|
||||
const UInt32 kDistStart[kDistTableSize64] =
|
||||
const UInt32 kDistStart[kDistTableSize64] =
|
||||
{0,1,2,3,4,6,8,12,16,24,32,48,64,96,128,192,256,384,512,768,
|
||||
1024,1536,2048,3072,4096,6144,8192,12288,16384,24576,32768,49152};
|
||||
const Byte kDistDirectBits[kDistTableSize64] =
|
||||
const Byte kDistDirectBits[kDistTableSize64] =
|
||||
{0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14};
|
||||
|
||||
const Byte kLevelDirectBits[3] = {2, 3, 7};
|
||||
|
||||
const Byte kCodeLengthAlphabetOrder[kLevelTableSize] = {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
|
||||
|
||||
const UInt32 kMatchMinLen = 3;
|
||||
const UInt32 kMatchMinLen = 3;
|
||||
const UInt32 kMatchMaxLen32 = kNumLenSymbols32 + kMatchMinLen - 1; //256 + 2
|
||||
const UInt32 kMatchMaxLen64 = kNumLenSymbols64 + kMatchMinLen - 1; //255 + 2
|
||||
const UInt32 kMatchMaxLen = kMatchMaxLen32;
|
||||
const UInt32 kMatchMaxLen = kMatchMaxLen32;
|
||||
|
||||
const int kFinalBlockFieldSize = 1;
|
||||
|
||||
@@ -124,7 +124,7 @@ struct CLevels
|
||||
litLenLevels[i] = 7;
|
||||
for (; i < 288; i++)
|
||||
litLenLevels[i] = 8;
|
||||
for (i = 0; i < kFixedDistTableSize; i++) // test it: InfoZip only uses kDistTableSize
|
||||
for (i = 0; i < kFixedDistTableSize; i++) // test it: InfoZip only uses kDistTableSize
|
||||
distLevels[i] = 5;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -11,10 +11,11 @@ namespace NDecoder {
|
||||
static const int kLenIdFinished = -1;
|
||||
static const int kLenIdNeedInit = -2;
|
||||
|
||||
CCoder::CCoder(bool deflate64Mode, bool deflateNSIS):
|
||||
_deflate64Mode(deflate64Mode),
|
||||
_deflateNSIS(deflateNSIS),
|
||||
_keepHistory(false) {}
|
||||
CCoder::CCoder(bool deflate64Mode, bool deflateNSIS):
|
||||
_deflate64Mode(deflate64Mode),
|
||||
_deflateNSIS(deflateNSIS),
|
||||
_keepHistory(false),
|
||||
ZlibMode(false) {}
|
||||
|
||||
UInt32 CCoder::ReadBits(int numBits)
|
||||
{
|
||||
@@ -99,7 +100,7 @@ bool CCoder::ReadTables(void)
|
||||
Byte levelLevels[kLevelTableSize];
|
||||
for (int i = 0; i < kLevelTableSize; i++)
|
||||
{
|
||||
int position = kCodeLengthAlphabetOrder[i];
|
||||
int position = kCodeLengthAlphabetOrder[i];
|
||||
if(i < numLevelCodes)
|
||||
levelLevels[position] = (Byte)ReadBits(kLevelFieldSize);
|
||||
else
|
||||
@@ -231,7 +232,7 @@ HRESULT CCoder::CodeSpec(UInt32 curSize)
|
||||
}
|
||||
|
||||
HRESULT CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
@@ -261,7 +262,15 @@ HRESULT CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
const UInt64 nowPos64 = m_OutWindowStream.GetProcessedSize() - start;
|
||||
RINOK(progress->SetRatioInfo(&inSize, &nowPos64));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_remainLen == kLenIdFinished && ZlibMode)
|
||||
{
|
||||
UInt32 currentBitPosition = m_InBitStream.GetBitPosition();
|
||||
int numBitsForAlign = (int)(currentBitPosition > 0 ? (8 - currentBitPosition): 0);
|
||||
ReadBits(numBitsForAlign);
|
||||
for (int i = 0; i < 4; i++)
|
||||
ZlibFooter[i] = (Byte)m_InBitStream.ReadBits(8);
|
||||
}
|
||||
flusher.NeedFlush = false;
|
||||
return Flush();
|
||||
}
|
||||
@@ -274,7 +283,7 @@ HRESULT CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
|
||||
#else
|
||||
|
||||
#define DEFLATE_TRY_BEGIN try {
|
||||
#define DEFLATE_TRY_BEGIN try {
|
||||
#define DEFLATE_TRY_END } \
|
||||
catch(const CInBufferException &e) { return e.ErrorCode; } \
|
||||
catch(const CLZOutWindowException &e) { return e.ErrorCode; } \
|
||||
|
||||
@@ -76,6 +76,9 @@ class CCoder:
|
||||
|
||||
HRESULT CodeSpec(UInt32 curSize);
|
||||
public:
|
||||
bool ZlibMode;
|
||||
Byte ZlibFooter[4];
|
||||
|
||||
CCoder(bool deflate64Mode, bool deflateNSIS = false);
|
||||
void SetKeepHistory(bool keepHistory) { _keepHistory = keepHistory; }
|
||||
|
||||
@@ -86,7 +89,7 @@ public:
|
||||
#ifndef NO_READ_FROM_CODER
|
||||
MY_UNKNOWN_IMP4(
|
||||
ICompressGetInStreamProcessedSize,
|
||||
ICompressSetInStream,
|
||||
ICompressSetInStream,
|
||||
ICompressSetOutStreamSize,
|
||||
ISequentialInStream
|
||||
)
|
||||
|
||||
@@ -8,16 +8,16 @@
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
#include "Common/ComTry.h"
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
#include "../../../../C/HuffEnc.h"
|
||||
}
|
||||
|
||||
#if _MSC_VER >= 1300
|
||||
#define NO_INLINE __declspec(noinline)
|
||||
#define NO_INLINE __declspec(noinline)
|
||||
#else
|
||||
#define NO_INLINE
|
||||
#define NO_INLINE
|
||||
#endif
|
||||
|
||||
namespace NCompress {
|
||||
@@ -34,7 +34,7 @@ static UInt32 kDivideBlockSizeMin = (1 << 6); // [1, (1 << 32)); ratio/speed tra
|
||||
static const UInt32 kMaxUncompressedBlockSize = ((1 << 16) - 1) * 1; // [1, (1 << 32))
|
||||
static const UInt32 kMatchArraySize = kMaxUncompressedBlockSize * 10; // [kMatchMaxLen * 2, (1 << 32))
|
||||
static const UInt32 kMatchArrayLimit = kMatchArraySize - kMatchMaxLen * 4 * sizeof(UInt16);
|
||||
static const UInt32 kBlockUncompressedSizeThreshold = kMaxUncompressedBlockSize -
|
||||
static const UInt32 kBlockUncompressedSizeThreshold = kMaxUncompressedBlockSize -
|
||||
kMatchMaxLen - kNumOpts;
|
||||
|
||||
static const int kMaxCodeBitLength = 11;
|
||||
@@ -148,9 +148,9 @@ HRESULT CCoder::Create()
|
||||
{
|
||||
_lzInWindow.btMode = _btMode ? 1 : 0;
|
||||
_lzInWindow.numHashBytes = 3;
|
||||
if (!MatchFinder_Create(&_lzInWindow,
|
||||
m_Deflate64Mode ? kHistorySize64 : kHistorySize32,
|
||||
kNumOpts + kMaxUncompressedBlockSize,
|
||||
if (!MatchFinder_Create(&_lzInWindow,
|
||||
m_Deflate64Mode ? kHistorySize64 : kHistorySize32,
|
||||
kNumOpts + kMaxUncompressedBlockSize,
|
||||
m_NumFastBytes, m_MatchMaxLen - m_NumFastBytes, &g_Alloc))
|
||||
return E_OUTOFMEMORY;
|
||||
if (!m_OutStream.Create(1 << 20))
|
||||
@@ -164,12 +164,12 @@ HRESULT CCoder::Create()
|
||||
}
|
||||
|
||||
// ICompressSetEncoderProperties2
|
||||
HRESULT CCoder::BaseSetEncoderProperties2(const PROPID *propIDs,
|
||||
HRESULT CCoder::BaseSetEncoderProperties2(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties)
|
||||
{
|
||||
for(UInt32 i = 0; i < numProperties; i++)
|
||||
{
|
||||
const PROPVARIANT &prop = properties[i];
|
||||
const PROPVARIANT &prop = properties[i];
|
||||
switch(propIDs[i])
|
||||
{
|
||||
case NCoderPropID::kNumPasses:
|
||||
@@ -207,7 +207,7 @@ HRESULT CCoder::BaseSetEncoderProperties2(const PROPID *propIDs,
|
||||
if (prop.vt != VT_UI4)
|
||||
return E_INVALIDARG;
|
||||
UInt32 maximize = prop.ulVal;
|
||||
_fastMode = (maximize == 0);
|
||||
_fastMode = (maximize == 0);
|
||||
_btMode = !_fastMode;
|
||||
break;
|
||||
}
|
||||
@@ -314,7 +314,7 @@ NO_INLINE UInt32 CCoder::Backward(UInt32 &backRes, UInt32 cur)
|
||||
while(cur > 0);
|
||||
backRes = m_Optimum[0].BackPrev;
|
||||
m_OptimumCurrentIndex = m_Optimum[0].PosPrev;
|
||||
return m_OptimumCurrentIndex;
|
||||
return m_OptimumCurrentIndex;
|
||||
}
|
||||
|
||||
NO_INLINE UInt32 CCoder::GetOptimal(UInt32 &backRes)
|
||||
@@ -339,7 +339,7 @@ NO_INLINE UInt32 CCoder::GetOptimal(UInt32 &backRes)
|
||||
|
||||
if(lenMain > m_NumFastBytes)
|
||||
{
|
||||
backRes = matchDistances[numDistancePairs - 1];
|
||||
backRes = matchDistances[numDistancePairs - 1];
|
||||
MovePos(lenMain - 1);
|
||||
return lenMain;
|
||||
}
|
||||
@@ -366,7 +366,7 @@ NO_INLINE UInt32 CCoder::GetOptimal(UInt32 &backRes)
|
||||
for (;;)
|
||||
{
|
||||
++cur;
|
||||
if(cur == lenEnd || cur == kNumOptsBase || m_Pos >= kMatchArrayLimit)
|
||||
if(cur == lenEnd || cur == kNumOptsBase || m_Pos >= kMatchArrayLimit)
|
||||
return Backward(backRes, cur);
|
||||
GetMatches();
|
||||
matchDistances = m_MatchDistances + 1;
|
||||
@@ -374,7 +374,7 @@ NO_INLINE UInt32 CCoder::GetOptimal(UInt32 &backRes)
|
||||
UInt32 numDistancePairs = m_MatchDistances[0];
|
||||
UInt32 newLen = 0;
|
||||
if(numDistancePairs != 0)
|
||||
{
|
||||
{
|
||||
newLen = matchDistances[numDistancePairs - 2];
|
||||
if(newLen > m_NumFastBytes)
|
||||
{
|
||||
@@ -386,10 +386,10 @@ NO_INLINE UInt32 CCoder::GetOptimal(UInt32 &backRes)
|
||||
return len;
|
||||
}
|
||||
}
|
||||
UInt32 curPrice = m_Optimum[cur].Price;
|
||||
UInt32 curPrice = m_Optimum[cur].Price;
|
||||
UInt32 curAnd1Price = curPrice + m_LiteralPrices[Inline_MatchFinder_GetIndexByte(&_lzInWindow, cur - m_AdditionalOffset)];
|
||||
COptimal &optimum = m_Optimum[cur + 1];
|
||||
if (curAnd1Price < optimum.Price)
|
||||
if (curAnd1Price < optimum.Price)
|
||||
{
|
||||
optimum.Price = curAnd1Price;
|
||||
optimum.PosPrev = (UInt16)cur;
|
||||
@@ -405,7 +405,7 @@ NO_INLINE UInt32 CCoder::GetOptimal(UInt32 &backRes)
|
||||
{
|
||||
UInt32 curAndLenPrice = curPrice + m_LenPrices[lenTest - kMatchMinLen];
|
||||
COptimal &optimum = m_Optimum[cur + lenTest];
|
||||
if (curAndLenPrice < optimum.Price)
|
||||
if (curAndLenPrice < optimum.Price)
|
||||
{
|
||||
optimum.Price = curAndLenPrice;
|
||||
optimum.PosPrev = (UInt16)cur;
|
||||
@@ -431,7 +431,7 @@ UInt32 CCoder::GetOptimalFast(UInt32 &backRes)
|
||||
if (numDistancePairs == 0)
|
||||
return 1;
|
||||
UInt32 lenMain = m_MatchDistances[numDistancePairs - 1];
|
||||
backRes = m_MatchDistances[numDistancePairs];
|
||||
backRes = m_MatchDistances[numDistancePairs];
|
||||
MovePos(lenMain - 1);
|
||||
return lenMain;
|
||||
}
|
||||
@@ -455,49 +455,49 @@ NO_INLINE void CCoder::LevelTableDummy(const Byte *levels, int numLevels, UInt32
|
||||
int count = 0;
|
||||
int maxCount = 7;
|
||||
int minCount = 4;
|
||||
if (nextLen == 0)
|
||||
if (nextLen == 0)
|
||||
{
|
||||
maxCount = 138;
|
||||
minCount = 3;
|
||||
}
|
||||
for (int n = 0; n < numLevels; n++)
|
||||
for (int n = 0; n < numLevels; n++)
|
||||
{
|
||||
int curLen = nextLen;
|
||||
int curLen = nextLen;
|
||||
nextLen = (n < numLevels - 1) ? levels[n + 1] : 0xFF;
|
||||
count++;
|
||||
if (count < maxCount && curLen == nextLen)
|
||||
if (count < maxCount && curLen == nextLen)
|
||||
continue;
|
||||
|
||||
if (count < minCount)
|
||||
if (count < minCount)
|
||||
freqs[curLen] += (UInt32)count;
|
||||
else if (curLen != 0)
|
||||
else if (curLen != 0)
|
||||
{
|
||||
if (curLen != prevLen)
|
||||
if (curLen != prevLen)
|
||||
{
|
||||
freqs[curLen]++;
|
||||
count--;
|
||||
}
|
||||
freqs[kTableLevelRepNumber]++;
|
||||
}
|
||||
else if (count <= 10)
|
||||
}
|
||||
else if (count <= 10)
|
||||
freqs[kTableLevel0Number]++;
|
||||
else
|
||||
else
|
||||
freqs[kTableLevel0Number2]++;
|
||||
|
||||
count = 0;
|
||||
count = 0;
|
||||
prevLen = curLen;
|
||||
|
||||
if (nextLen == 0)
|
||||
if (nextLen == 0)
|
||||
{
|
||||
maxCount = 138;
|
||||
minCount = 3;
|
||||
}
|
||||
else if (curLen == nextLen)
|
||||
}
|
||||
else if (curLen == nextLen)
|
||||
{
|
||||
maxCount = 6;
|
||||
minCount = 3;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
maxCount = 7;
|
||||
minCount = 4;
|
||||
@@ -520,57 +520,57 @@ NO_INLINE void CCoder::LevelTableCode(const Byte *levels, int numLevels, const B
|
||||
int count = 0;
|
||||
int maxCount = 7;
|
||||
int minCount = 4;
|
||||
if (nextLen == 0)
|
||||
if (nextLen == 0)
|
||||
{
|
||||
maxCount = 138;
|
||||
minCount = 3;
|
||||
}
|
||||
for (int n = 0; n < numLevels; n++)
|
||||
for (int n = 0; n < numLevels; n++)
|
||||
{
|
||||
int curLen = nextLen;
|
||||
int curLen = nextLen;
|
||||
nextLen = (n < numLevels - 1) ? levels[n + 1] : 0xFF;
|
||||
count++;
|
||||
if (count < maxCount && curLen == nextLen)
|
||||
if (count < maxCount && curLen == nextLen)
|
||||
continue;
|
||||
|
||||
if (count < minCount)
|
||||
for(int i = 0; i < count; i++)
|
||||
if (count < minCount)
|
||||
for(int i = 0; i < count; i++)
|
||||
WRITE_HF(curLen);
|
||||
else if (curLen != 0)
|
||||
else if (curLen != 0)
|
||||
{
|
||||
if (curLen != prevLen)
|
||||
if (curLen != prevLen)
|
||||
{
|
||||
WRITE_HF(curLen);
|
||||
count--;
|
||||
}
|
||||
WRITE_HF(kTableLevelRepNumber);
|
||||
WriteBits(count - 3, 2);
|
||||
}
|
||||
else if (count <= 10)
|
||||
}
|
||||
else if (count <= 10)
|
||||
{
|
||||
WRITE_HF(kTableLevel0Number);
|
||||
WriteBits(count - 3, 3);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
WRITE_HF(kTableLevel0Number2);
|
||||
WriteBits(count - 11, 7);
|
||||
}
|
||||
|
||||
count = 0;
|
||||
count = 0;
|
||||
prevLen = curLen;
|
||||
|
||||
if (nextLen == 0)
|
||||
if (nextLen == 0)
|
||||
{
|
||||
maxCount = 138;
|
||||
minCount = 3;
|
||||
}
|
||||
else if (curLen == nextLen)
|
||||
}
|
||||
else if (curLen == nextLen)
|
||||
{
|
||||
maxCount = 6;
|
||||
minCount = 3;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
maxCount = 7;
|
||||
minCount = 4;
|
||||
@@ -585,11 +585,11 @@ NO_INLINE void CCoder::MakeTables(unsigned maxHuffLen)
|
||||
}
|
||||
|
||||
NO_INLINE UInt32 Huffman_GetPrice(const UInt32 *freqs, const Byte *lens, UInt32 num)
|
||||
{
|
||||
{
|
||||
UInt32 price = 0;
|
||||
UInt32 i;
|
||||
for (i = 0; i < num; i++)
|
||||
price += lens[i] * freqs[i];
|
||||
price += lens[i] * freqs[i];
|
||||
return price;
|
||||
};
|
||||
|
||||
@@ -601,8 +601,8 @@ NO_INLINE UInt32 Huffman_GetPrice_Spec(const UInt32 *freqs, const Byte *lens, UI
|
||||
|
||||
NO_INLINE UInt32 CCoder::GetLzBlockPrice() const
|
||||
{
|
||||
return
|
||||
Huffman_GetPrice_Spec(mainFreqs, m_NewLevels.litLenLevels, kFixedMainTableSize, m_LenDirectBits, kSymbolMatch) +
|
||||
return
|
||||
Huffman_GetPrice_Spec(mainFreqs, m_NewLevels.litLenLevels, kFixedMainTableSize, m_LenDirectBits, kSymbolMatch) +
|
||||
Huffman_GetPrice_Spec(distFreqs, m_NewLevels.distLevels, kDistTableSize64, kDistDirectBits, 0);
|
||||
}
|
||||
|
||||
@@ -618,7 +618,7 @@ NO_INLINE void CCoder::TryBlock()
|
||||
{
|
||||
if (m_OptimumCurrentIndex == m_OptimumEndIndex)
|
||||
{
|
||||
if (m_Pos >= kMatchArrayLimit || BlockSizeRes >= blockSize || !m_SecondPass &&
|
||||
if (m_Pos >= kMatchArrayLimit || BlockSizeRes >= blockSize || !m_SecondPass &&
|
||||
((Inline_MatchFinder_GetNumAvailableBytes(&_lzInWindow) == 0) || m_ValueIndex >= m_ValueBlockSize))
|
||||
break;
|
||||
}
|
||||
@@ -678,7 +678,7 @@ NO_INLINE void CCoder::SetPrices(const CLevels &levels)
|
||||
}
|
||||
|
||||
NO_INLINE void Huffman_ReverseBits(UInt32 *codes, const Byte *lens, UInt32 num)
|
||||
{
|
||||
{
|
||||
for (UInt32 i = 0; i < num; i++)
|
||||
{
|
||||
UInt32 x = codes[i];
|
||||
@@ -760,7 +760,7 @@ NO_INLINE UInt32 CCoder::TryDynBlock(int tableIndex, UInt32 numPasses)
|
||||
{
|
||||
m_Pos = posTemp;
|
||||
TryBlock();
|
||||
unsigned numHuffBits =
|
||||
unsigned numHuffBits =
|
||||
(m_ValueIndex > 18000 ? 12 :
|
||||
(m_ValueIndex > 7000 ? 11 :
|
||||
(m_ValueIndex > 2000 ? 10 : 9)));
|
||||
@@ -789,7 +789,7 @@ NO_INLINE UInt32 CCoder::TryDynBlock(int tableIndex, UInt32 numPasses)
|
||||
m_NumLevelCodes = kNumLevelCodesMin;
|
||||
for (UInt32 i = 0; i < kLevelTableSize; i++)
|
||||
{
|
||||
Byte level = levelLens[kCodeLengthAlphabetOrder[i]];
|
||||
Byte level = levelLens[kCodeLengthAlphabetOrder[i]];
|
||||
if (level > 0 && i >= m_NumLevelCodes)
|
||||
m_NumLevelCodes = i + 1;
|
||||
m_LevelLevels[i] = level;
|
||||
@@ -891,7 +891,7 @@ void CCoder::CodeBlock(int tableIndex, bool finalBlock)
|
||||
distFreqs[i] = (UInt32)1 << (kMaxStaticHuffLen - m_NewLevels.distLevels[i]);
|
||||
MakeTables(kMaxStaticHuffLen);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
if (m_NumDivPasses > 1 || m_CheckStatic)
|
||||
TryDynBlock(tableIndex, 1);
|
||||
@@ -915,7 +915,7 @@ void CCoder::CodeBlock(int tableIndex, bool finalBlock)
|
||||
|
||||
SRes Read(void *object, void *data, size_t *size)
|
||||
{
|
||||
const UInt32 kStepSize = (UInt32)1 << 31;
|
||||
const UInt32 kStepSize = (UInt32)1 << 31;
|
||||
UInt32 curSize = ((*size < kStepSize) ? (UInt32)*size : kStepSize);
|
||||
HRESULT res = ((CSeqInStream *)object)->RealStream->Read(data, curSize, &curSize);
|
||||
*size = curSize;
|
||||
@@ -985,7 +985,7 @@ STDMETHODIMP CCOMCoder::Code(ISequentialInStream *inStream,
|
||||
ICompressProgressInfo *progress)
|
||||
{ return BaseCode(inStream, outStream, inSize, outSize, progress); }
|
||||
|
||||
STDMETHODIMP CCOMCoder::SetCoderProperties(const PROPID *propIDs,
|
||||
STDMETHODIMP CCOMCoder::SetCoderProperties(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties)
|
||||
{ return BaseSetEncoderProperties2(propIDs, properties, numProperties); }
|
||||
|
||||
@@ -994,7 +994,7 @@ STDMETHODIMP CCOMCoder64::Code(ISequentialInStream *inStream,
|
||||
ICompressProgressInfo *progress)
|
||||
{ return BaseCode(inStream, outStream, inSize, outSize, progress); }
|
||||
|
||||
STDMETHODIMP CCOMCoder64::SetCoderProperties(const PROPID *propIDs,
|
||||
STDMETHODIMP CCOMCoder64::SetCoderProperties(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties)
|
||||
{ return BaseSetEncoderProperties2(propIDs, properties, numProperties); }
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ public:
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
// ICompressSetCoderProperties
|
||||
HRESULT BaseSetEncoderProperties2(const PROPID *propIDs,
|
||||
HRESULT BaseSetEncoderProperties2(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties);
|
||||
};
|
||||
|
||||
@@ -188,7 +188,7 @@ public:
|
||||
|
||||
class CCOMCoder :
|
||||
public ICompressCoder,
|
||||
public ICompressSetCoderProperties,
|
||||
public ICompressSetCoderProperties,
|
||||
public CMyUnknownImp,
|
||||
public CCoder
|
||||
{
|
||||
@@ -199,7 +199,7 @@ public:
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
// ICompressSetCoderProperties
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties);
|
||||
};
|
||||
|
||||
@@ -216,7 +216,7 @@ public:
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
// ICompressSetCoderProperties
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
94
CPP/7zip/Compress/Deflate/ZlibDecoder.cpp
Executable file
94
CPP/7zip/Compress/Deflate/ZlibDecoder.cpp
Executable file
@@ -0,0 +1,94 @@
|
||||
// ZlibDecoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ZlibDecoder.h"
|
||||
#include "DeflateDecoder.h"
|
||||
#include "../../Common/StreamUtils.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NZlib {
|
||||
|
||||
#define DEFLATE_TRY_BEGIN try {
|
||||
#define DEFLATE_TRY_END } \
|
||||
catch(...) { return S_FALSE; }
|
||||
|
||||
#define ADLER_MOD 65521
|
||||
#define ADLER_LOOP_MAX 5550
|
||||
|
||||
static UInt32 Adler32_Update(UInt32 adler, const Byte *buf, size_t size)
|
||||
{
|
||||
UInt32 a = adler & 0xFFFF;
|
||||
UInt32 b = (adler >> 16) & 0xFFFF;
|
||||
while (size > 0)
|
||||
{
|
||||
unsigned curSize = (size > ADLER_LOOP_MAX) ? ADLER_LOOP_MAX : (unsigned )size;
|
||||
unsigned i;
|
||||
for (i = 0; i < curSize; i++)
|
||||
{
|
||||
a += buf[i];
|
||||
b += a;
|
||||
}
|
||||
buf += curSize;
|
||||
size -= curSize;
|
||||
a %= ADLER_MOD;
|
||||
b %= ADLER_MOD;
|
||||
}
|
||||
return (b << 16) + a;
|
||||
}
|
||||
|
||||
STDMETHODIMP COutStreamWithAdler::Write(const void *data, UInt32 size, UInt32 *processedSize)
|
||||
{
|
||||
HRESULT result = _stream->Write(data, size, &size);
|
||||
_adler = Adler32_Update(_adler, (const Byte *)data, size);
|
||||
if (processedSize != NULL)
|
||||
*processedSize = size;
|
||||
return result;
|
||||
}
|
||||
|
||||
HRESULT CDecoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
DEFLATE_TRY_BEGIN
|
||||
if (!AdlerStream)
|
||||
{
|
||||
AdlerSpec = new COutStreamWithAdler;
|
||||
AdlerStream = AdlerSpec;
|
||||
}
|
||||
if (!DeflateDecoder)
|
||||
{
|
||||
DeflateDecoderSpec = new NCompress::NDeflate::NDecoder::CCOMCoder;
|
||||
DeflateDecoderSpec->ZlibMode = true;
|
||||
DeflateDecoder = DeflateDecoderSpec;
|
||||
}
|
||||
|
||||
Byte buf[2];
|
||||
RINOK(ReadStream_FALSE(inStream, buf, 2));
|
||||
int method = buf[0] & 0xF;
|
||||
if (method != 8)
|
||||
return S_FALSE;
|
||||
// int dicSize = buf[0] >> 4;
|
||||
if ((((UInt32)buf[0] << 8) + buf[1]) % 31 != 0)
|
||||
return S_FALSE;
|
||||
if ((buf[1] & 0x20) != 0) // dictPresent
|
||||
return S_FALSE;
|
||||
// int level = (buf[1] >> 6);
|
||||
|
||||
AdlerSpec->SetStream(outStream);
|
||||
AdlerSpec->Init();
|
||||
HRESULT res = DeflateDecoder->Code(inStream, AdlerStream, inSize, outSize, progress);
|
||||
AdlerSpec->ReleaseStream();
|
||||
|
||||
if (res == S_OK)
|
||||
{
|
||||
const Byte *p = DeflateDecoderSpec->ZlibFooter;
|
||||
UInt32 adler = ((UInt32)p[0] << 24) | ((UInt32)p[1] << 16) | ((UInt32)p[2] << 8) | p[3];
|
||||
if (adler != AdlerSpec->GetAdler())
|
||||
return S_FALSE;
|
||||
}
|
||||
return res;
|
||||
DEFLATE_TRY_END
|
||||
}
|
||||
|
||||
}}
|
||||
47
CPP/7zip/Compress/Deflate/ZlibDecoder.h
Executable file
47
CPP/7zip/Compress/Deflate/ZlibDecoder.h
Executable file
@@ -0,0 +1,47 @@
|
||||
// ZlibDecoder.h
|
||||
|
||||
#ifndef __ZLIB_DECODER_H
|
||||
#define __ZLIB_DECODER_H
|
||||
|
||||
#include "DeflateDecoder.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NZlib {
|
||||
|
||||
const UInt32 ADLER_INIT_VAL = 1;
|
||||
|
||||
class COutStreamWithAdler:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CMyComPtr<ISequentialOutStream> _stream;
|
||||
UInt32 _adler;
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize);
|
||||
void SetStream(ISequentialOutStream *stream) { _stream = stream; }
|
||||
void ReleaseStream() { _stream.Release(); }
|
||||
void Init() { _adler = ADLER_INIT_VAL; }
|
||||
UInt32 GetAdler() const { return _adler; }
|
||||
};
|
||||
|
||||
class CDecoder:
|
||||
public ICompressCoder,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
COutStreamWithAdler *AdlerSpec;
|
||||
CMyComPtr<ISequentialOutStream> AdlerStream;
|
||||
|
||||
NCompress::NDeflate::NDecoder::CCOMCoder *DeflateDecoderSpec;
|
||||
CMyComPtr<ICompressCoder> DeflateDecoder;
|
||||
public:
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -10,22 +10,24 @@
|
||||
|
||||
static const unsigned int kNumCodecsMax = 32;
|
||||
unsigned int g_NumCodecs = 0;
|
||||
const CCodecInfo *g_Codecs[kNumCodecsMax];
|
||||
void RegisterCodec(const CCodecInfo *codecInfo)
|
||||
{
|
||||
const CCodecInfo *g_Codecs[kNumCodecsMax];
|
||||
void RegisterCodec(const CCodecInfo *codecInfo)
|
||||
{
|
||||
if (g_NumCodecs < kNumCodecsMax)
|
||||
g_Codecs[g_NumCodecs++] = codecInfo;
|
||||
g_Codecs[g_NumCodecs++] = codecInfo;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
extern "C"
|
||||
BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /*lpReserved*/)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static const UInt16 kDecodeId = 0x2790;
|
||||
|
||||
DEFINE_GUID(CLSID_CCodec,
|
||||
DEFINE_GUID(CLSID_CCodec,
|
||||
0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
STDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);
|
||||
|
||||
@@ -16,7 +16,7 @@ BOOL WINAPI DllMain(HINSTANCE /* hInstance */, DWORD /* dwReason */, LPVOID /*lp
|
||||
|
||||
static const UInt16 kDecodeId = 0x2790;
|
||||
|
||||
DEFINE_GUID(CLSID_CCodec,
|
||||
DEFINE_GUID(CLSID_CCodec,
|
||||
0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
STDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject);
|
||||
|
||||
@@ -13,8 +13,8 @@ const int kNumTableBits = 9;
|
||||
template <int kNumBitsMax, UInt32 m_NumSymbols>
|
||||
class CDecoder
|
||||
{
|
||||
UInt32 m_Limits[kNumBitsMax + 1]; // m_Limits[i] = value limit for symbols with length = i
|
||||
UInt32 m_Positions[kNumBitsMax + 1]; // m_Positions[i] = index in m_Symbols[] of first symbol with length = i
|
||||
UInt32 m_Limits[kNumBitsMax + 1]; // m_Limits[i] = value limit for symbols with length = i
|
||||
UInt32 m_Positions[kNumBitsMax + 1]; // m_Positions[i] = index in m_Symbols[] of first symbol with length = i
|
||||
UInt32 m_Symbols[m_NumSymbols];
|
||||
Byte m_Lengths[1 << kNumTableBits]; // Table oh length for short codes.
|
||||
|
||||
@@ -72,10 +72,10 @@ public:
|
||||
UInt32 value = bitStream->GetValue(kNumBitsMax);
|
||||
if (value < m_Limits[kNumTableBits])
|
||||
numBits = m_Lengths[value >> (kNumBitsMax - kNumTableBits)];
|
||||
else
|
||||
else
|
||||
for (numBits = kNumTableBits + 1; value >= m_Limits[numBits]; numBits++);
|
||||
bitStream->MovePos(numBits);
|
||||
UInt32 index = m_Positions[numBits] +
|
||||
UInt32 index = m_Positions[numBits] +
|
||||
((value - m_Limits[numBits - 1]) >> (kNumBitsMax - numBits));
|
||||
if (index >= m_NumSymbols)
|
||||
// throw CDecoderException(); // test it
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#endif
|
||||
@@ -19,8 +19,8 @@ public:
|
||||
CException(ECauseType cause): m_Cause(cause) {}
|
||||
};
|
||||
|
||||
static const int kNumDistanceLowDirectBitsForBigDict = 7;
|
||||
static const int kNumDistanceLowDirectBitsForSmallDict = 6;
|
||||
static const int kNumDistanceLowDirectBitsForBigDict = 7;
|
||||
static const int kNumDistanceLowDirectBitsForSmallDict = 6;
|
||||
|
||||
static const int kNumBitsInByte = 8;
|
||||
|
||||
@@ -38,14 +38,14 @@ static const int kLiteralTableSize = (1 << kNumBitsInByte);
|
||||
static const int kDistanceTableSize = 64;
|
||||
static const int kLengthTableSize = 64;
|
||||
|
||||
static const UInt32 kHistorySize =
|
||||
(1 << MyMax(kNumDistanceLowDirectBitsForBigDict,
|
||||
kNumDistanceLowDirectBitsForSmallDict)) *
|
||||
static const UInt32 kHistorySize =
|
||||
(1 << MyMax(kNumDistanceLowDirectBitsForBigDict,
|
||||
kNumDistanceLowDirectBitsForSmallDict)) *
|
||||
kDistanceTableSize; // = 8 KB;
|
||||
|
||||
static const int kNumAdditionalLengthBits = 8;
|
||||
|
||||
static const UInt32 kMatchMinLenWhenLiteralsOn = 3;
|
||||
static const UInt32 kMatchMinLenWhenLiteralsOn = 3;
|
||||
static const UInt32 kMatchMinLenWhenLiteralsOff = 2;
|
||||
|
||||
static const UInt32 kMatchMinLenMax = MyMax(kMatchMinLenWhenLiteralsOn,
|
||||
@@ -73,17 +73,17 @@ void CCoder::ReleaseStreams()
|
||||
m_InBitStream.ReleaseStream();
|
||||
}
|
||||
|
||||
bool CCoder::ReadLevelItems(NImplode::NHuffman::CDecoder &decoder,
|
||||
bool CCoder::ReadLevelItems(NImplode::NHuffman::CDecoder &decoder,
|
||||
Byte *levels, int numLevelItems)
|
||||
{
|
||||
int numCodedStructures = m_InBitStream.ReadBits(kNumBitsInByte) +
|
||||
int numCodedStructures = m_InBitStream.ReadBits(kNumBitsInByte) +
|
||||
kLevelStructuresNumberAdditionalValue;
|
||||
int currentIndex = 0;
|
||||
for(int i = 0; i < numCodedStructures; i++)
|
||||
{
|
||||
int level = m_InBitStream.ReadBits(kNumLevelStructureLevelBits) +
|
||||
int level = m_InBitStream.ReadBits(kNumLevelStructureLevelBits) +
|
||||
kLevelStructureLevelAdditionalValue;
|
||||
int rep = m_InBitStream.ReadBits(kNumLevelStructureRepNumberBits) +
|
||||
int rep = m_InBitStream.ReadBits(kNumLevelStructureRepNumberBits) +
|
||||
kLevelStructureRepNumberAdditionalValue;
|
||||
if (currentIndex + rep > numLevelItems)
|
||||
throw CException(CException::kData);
|
||||
@@ -208,12 +208,12 @@ STDMETHODIMP CCoder::SetDecoderProperties2(const Byte *data, UInt32 size)
|
||||
return E_INVALIDARG;
|
||||
Byte flag = data[0];
|
||||
m_BigDictionaryOn = ((flag & 2) != 0);
|
||||
m_NumDistanceLowDirectBits = m_BigDictionaryOn ?
|
||||
m_NumDistanceLowDirectBits = m_BigDictionaryOn ?
|
||||
kNumDistanceLowDirectBitsForBigDict:
|
||||
kNumDistanceLowDirectBitsForSmallDict;
|
||||
m_LiteralsOn = ((flag & 4) != 0);
|
||||
m_MinMatchLength = m_LiteralsOn ?
|
||||
kMatchMinLenWhenLiteralsOn :
|
||||
m_MinMatchLength = m_LiteralsOn ?
|
||||
kMatchMinLenWhenLiteralsOn :
|
||||
kMatchMinLenWhenLiteralsOff;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class CCoder :
|
||||
bool m_BigDictionaryOn;
|
||||
bool m_LiteralsOn;
|
||||
|
||||
int m_NumDistanceLowDirectBits;
|
||||
int m_NumDistanceLowDirectBits;
|
||||
UInt32 m_MinMatchLength;
|
||||
|
||||
bool ReadLevelItems(NImplode::NHuffman::CDecoder &table, Byte *levels, int numLevelItems);
|
||||
@@ -43,11 +43,11 @@ public:
|
||||
void ReleaseStreams();
|
||||
HRESULT (Flush)() { return m_OutWindowStream.Flush(); }
|
||||
|
||||
STDMETHOD(CodeReal)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
|
||||
STDMETHOD(CodeReal)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
|
||||
@@ -51,8 +51,8 @@ bool CDecoder::SetCodeLengths(const Byte *codeLengths)
|
||||
|
||||
}
|
||||
|
||||
// if _ZIP_MODE do not throw exception for trees containing only one node
|
||||
// #ifndef _ZIP_MODE
|
||||
// if _ZIP_MODE do not throw exception for trees containing only one node
|
||||
// #ifndef _ZIP_MODE
|
||||
if (startPos != kMaxValue)
|
||||
return false;
|
||||
// #endif
|
||||
@@ -79,7 +79,7 @@ UInt32 CDecoder::DecodeSymbol(CInBit *inStream)
|
||||
if (i == 0)
|
||||
return 0xFFFFFFFF;
|
||||
inStream->MovePos(numBits);
|
||||
UInt32 index = m_Positions[numBits] +
|
||||
UInt32 index = m_Positions[numBits] +
|
||||
((value - m_Limitits[numBits + 1]) >> (kNumBitsInLongestCode - numBits));
|
||||
if (index >= m_NumSymbols)
|
||||
return 0xFFFFFFFF;
|
||||
|
||||
@@ -16,8 +16,8 @@ typedef NStream::NLSBF::CDecoder<CInBuffer> CInBit;
|
||||
|
||||
class CDecoder
|
||||
{
|
||||
UInt32 m_Limitits[kNumBitsInLongestCode + 2]; // m_Limitits[i] = value limit for symbols with length = i
|
||||
UInt32 m_Positions[kNumBitsInLongestCode + 2]; // m_Positions[i] = index in m_Symbols[] of first symbol with length = i
|
||||
UInt32 m_Limitits[kNumBitsInLongestCode + 2]; // m_Limitits[i] = value limit for symbols with length = i
|
||||
UInt32 m_Positions[kNumBitsInLongestCode + 2]; // m_Positions[i] = index in m_Symbols[] of first symbol with length = i
|
||||
UInt32 m_NumSymbols; // number of symbols in m_Symbols
|
||||
UInt32 *m_Symbols; // symbols: at first with len=1 then 2, ... 15.
|
||||
public:
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
@@ -15,7 +15,7 @@ class CLZOutWindow: public COutBuffer
|
||||
public:
|
||||
void Init(bool solid = false);
|
||||
|
||||
// distance >= 0, len > 0,
|
||||
// distance >= 0, len > 0,
|
||||
bool CopyBlock(UInt32 distance, UInt32 len)
|
||||
{
|
||||
UInt32 pos = _pos - distance - 1;
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
pos = 0;
|
||||
_buffer[_pos++] = _buffer[pos++];
|
||||
if (_pos == _limitPos)
|
||||
FlushWithCheck();
|
||||
FlushWithCheck();
|
||||
}
|
||||
while(--len != 0);
|
||||
return true;
|
||||
@@ -50,7 +50,7 @@ public:
|
||||
{
|
||||
_buffer[_pos++] = b;
|
||||
if (_pos == _limitPos)
|
||||
FlushWithCheck();
|
||||
FlushWithCheck();
|
||||
}
|
||||
|
||||
Byte GetByte(UInt32 distance) const
|
||||
@@ -58,7 +58,7 @@ public:
|
||||
UInt32 pos = _pos - distance - 1;
|
||||
if (pos >= _bufferSize)
|
||||
pos += _bufferSize;
|
||||
return _buffer[pos];
|
||||
return _buffer[pos];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -3,4 +3,6 @@
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#endif
|
||||
#include "../../../Common/MyWindows.h"
|
||||
|
||||
#endif
|
||||
|
||||
403
CPP/7zip/Compress/LZMA/LZMA.dsp
Executable file
403
CPP/7zip/Compress/LZMA/LZMA.dsp
Executable file
@@ -0,0 +1,403 @@
|
||||
# Microsoft Developer Studio Project File - Name="LZMA" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=LZMA - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "LZMA.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "LZMA.mak" CFG="LZMA - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "LZMA - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "LZMA - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
MTL=midl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "LZMA - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMA_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "../../../" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMA_EXPORTS" /D "COMPRESS_MF_MT" /D "_7ZIP_LARGE_PAGES" /Yu"StdAfx.h" /FD /c
|
||||
# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "NDEBUG"
|
||||
# ADD RSC /l 0x419 /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-zip\Codecs\LZMA.dll" /opt:NOWIN98
|
||||
# SUBTRACT LINK32 /pdb:none /debug
|
||||
|
||||
!ELSEIF "$(CFG)" == "LZMA - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 1
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMA_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "../../../" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMA_EXPORTS" /D "COMPRESS_MF_MT" /D "_7ZIP_LARGE_PAGES" /Yu"StdAfx.h" /FD /GZ /c
|
||||
# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
|
||||
# ADD BASE RSC /l 0x419 /d "_DEBUG"
|
||||
# ADD RSC /l 0x419 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-zip\Codecs\LZMA.dll" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "LZMA - Win32 Release"
|
||||
# Name "LZMA - Win32 Debug"
|
||||
# Begin Group "Spec"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\Codec.def
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\CodecExports.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\DllExports.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.rc
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.cpp
|
||||
# ADD CPP /Yc"StdAfx.h"
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\StdAfx.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "7-zip Common"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\InBuffer.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\InBuffer.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\OutBuffer.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\OutBuffer.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\StreamUtils.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\StreamUtils.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "RangeCoder"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\RangeCoder\RangeCoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\RangeCoder\RangeCoderBit.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\RangeCoder\RangeCoderBit.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\RangeCoder\RangeCoderBitTree.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\RangeCoder\RangeCoderOpt.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Interface"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\ICoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\IStream.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "LZ"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\LZOutWindow.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\LZOutWindow.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Common"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\ComTry.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\Defs.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\Exception.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\MyCom.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\MyUnknown.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\MyWindows.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "C"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\7zCrc.c
|
||||
|
||||
!IF "$(CFG)" == "LZMA - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "LZMA - Win32 Debug"
|
||||
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\7zCrc.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Alloc.c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Alloc.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\IStream.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\LzFind.c
|
||||
|
||||
!IF "$(CFG)" == "LZMA - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "LZMA - Win32 Debug"
|
||||
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\LzFind.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\LzFindMt.c
|
||||
|
||||
!IF "$(CFG)" == "LZMA - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "LZMA - Win32 Debug"
|
||||
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\LzFindMt.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\LzHash.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\LzmaDec.c
|
||||
|
||||
!IF "$(CFG)" == "LZMA - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "LZMA - Win32 Debug"
|
||||
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\LzmaDec.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\LzmaEnc.c
|
||||
|
||||
!IF "$(CFG)" == "LZMA - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "LZMA - Win32 Debug"
|
||||
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\LzmaEnc.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Threads.c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Threads.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Types.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZMA.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZMADecoder.cpp
|
||||
|
||||
!IF "$(CFG)" == "LZMA - Win32 Release"
|
||||
|
||||
# ADD CPP /O2
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "LZMA - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZMADecoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZMAEncoder.cpp
|
||||
|
||||
!IF "$(CFG)" == "LZMA - Win32 Release"
|
||||
|
||||
# ADD CPP /O2 /FAs
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
|
||||
!ELSEIF "$(CFG)" == "LZMA - Win32 Debug"
|
||||
|
||||
!ENDIF
|
||||
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZMAEncoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZMARegister.cpp
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
29
CPP/7zip/Compress/LZMA/LZMA.dsw
Executable file
29
CPP/7zip/Compress/LZMA/LZMA.dsw
Executable file
@@ -0,0 +1,29 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "LZMA"=".\LZMA.dsp" - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
@@ -76,11 +76,11 @@ STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 * /* inSize */,
|
||||
ISequentialOutStream *outStream, const UInt64 * /* inSize */,
|
||||
const UInt64 *outSize, ICompressProgressInfo *progress)
|
||||
{
|
||||
if (_inBuf == 0)
|
||||
return S_FALSE;
|
||||
return S_FALSE;
|
||||
SetOutStreamSize(outSize);
|
||||
|
||||
for (;;)
|
||||
@@ -104,7 +104,7 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
||||
if (rem < curSize)
|
||||
{
|
||||
curSize = (SizeT)rem;
|
||||
/*
|
||||
/*
|
||||
// finishMode = LZMA_FINISH_END;
|
||||
we can't use LZMA_FINISH_END here to allow partial decoding
|
||||
*/
|
||||
@@ -141,7 +141,7 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&_inSizeProcessed, &_outSizeProcessed));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NO_READ_FROM_CODER
|
||||
@@ -169,7 +169,7 @@ STDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize)
|
||||
|
||||
SizeT outProcessed = size;
|
||||
ELzmaStatus status;
|
||||
SRes res = LzmaDec_DecodeToBuf(&_state, (Byte *)data, &outProcessed,
|
||||
SRes res = LzmaDec_DecodeToBuf(&_state, (Byte *)data, &outProcessed,
|
||||
_inBuf + _inPos, &inProcessed, LZMA_FINISH_ANY, &status);
|
||||
_inPos += (UInt32)inProcessed;
|
||||
_inSizeProcessed += inProcessed;
|
||||
|
||||
@@ -14,7 +14,7 @@ extern "C"
|
||||
namespace NCompress {
|
||||
namespace NLZMA {
|
||||
|
||||
class CDecoder:
|
||||
class CDecoder:
|
||||
public ICompressCoder,
|
||||
public ICompressSetDecoderProperties2,
|
||||
public ICompressGetInStreamProcessedSize,
|
||||
@@ -38,10 +38,10 @@ public:
|
||||
|
||||
#ifndef NO_READ_FROM_CODER
|
||||
MY_UNKNOWN_IMP5(
|
||||
ICompressSetDecoderProperties2,
|
||||
ICompressSetDecoderProperties2,
|
||||
ICompressGetInStreamProcessedSize,
|
||||
ICompressSetInStream,
|
||||
ICompressSetOutStreamSize,
|
||||
ICompressSetInStream,
|
||||
ICompressSetOutStreamSize,
|
||||
ISequentialInStream)
|
||||
#else
|
||||
MY_UNKNOWN_IMP2(
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
|
||||
#include "../../Common/StreamUtils.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
}
|
||||
|
||||
static HRESULT SResToHRESULT(SRes res)
|
||||
@@ -40,7 +40,7 @@ static HRESULT SResToHRESULT(SRes res)
|
||||
namespace NCompress {
|
||||
namespace NLZMA {
|
||||
|
||||
static const UInt32 kStreamStepSize = (UInt32)1 << 31;
|
||||
static const UInt32 kStreamStepSize = (UInt32)1 << 31;
|
||||
|
||||
static SRes MyRead(void *object, void *data, size_t *size)
|
||||
{
|
||||
@@ -122,7 +122,7 @@ static int ParseMatchFinder(const wchar_t *s, int *btMode, int *numHashBytes)
|
||||
return 1;
|
||||
}
|
||||
|
||||
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
|
||||
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties)
|
||||
{
|
||||
CLzmaEncProps props;
|
||||
@@ -154,7 +154,7 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
|
||||
case NCoderPropID::kEndMarker:
|
||||
if (prop.vt != VT_BOOL) return E_INVALIDARG; props.writeEndMark = (prop.boolVal == VARIANT_TRUE); break;
|
||||
case NCoderPropID::kMatchFinder:
|
||||
if (prop.vt != VT_BSTR) return E_INVALIDARG;
|
||||
if (prop.vt != VT_BSTR) return E_INVALIDARG;
|
||||
if (!ParseMatchFinder(prop.bstrVal, &props.btMode, &props.numHashBytes /* , &_matchFinderBase.skipModeBits */))
|
||||
return E_INVALIDARG; break;
|
||||
default:
|
||||
@@ -165,7 +165,7 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
|
||||
}
|
||||
|
||||
STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
|
||||
{
|
||||
{
|
||||
Byte props[LZMA_PROPS_SIZE];
|
||||
size_t size = LZMA_PROPS_SIZE;
|
||||
RINOK(LzmaEnc_WriteProperties(_encoder, props, &size));
|
||||
@@ -204,7 +204,7 @@ SRes CompressProgress(void *pp, UInt64 inSize, UInt64 outSize)
|
||||
}
|
||||
|
||||
STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 * /* inSize */,
|
||||
ISequentialOutStream *outStream, const UInt64 * /* inSize */,
|
||||
const UInt64 * /* outSize */,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ struct CSeqOutStream
|
||||
HRESULT Res;
|
||||
};
|
||||
|
||||
class CEncoder :
|
||||
class CEncoder :
|
||||
public ICompressCoder,
|
||||
public ICompressSetOutStream,
|
||||
public ICompressSetCoderProperties,
|
||||
@@ -50,12 +50,12 @@ public:
|
||||
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
// ICompressSetCoderProperties2
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties);
|
||||
|
||||
// ICompressWriteCoderProperties
|
||||
|
||||
61
CPP/7zip/Compress/LZMA/makefile
Executable file
61
CPP/7zip/Compress/LZMA/makefile
Executable file
@@ -0,0 +1,61 @@
|
||||
PROG = LZMA.dll
|
||||
DEF_FILE = ../Codec.def
|
||||
CFLAGS = $(CFLAGS) -I ../../../ \
|
||||
-DCOMPRESS_MF_MT \
|
||||
-D_7ZIP_LARGE_PAGES \
|
||||
|
||||
LIBS = $(LIBS) oleaut32.lib
|
||||
|
||||
COMPRESS_OBJS = \
|
||||
$O\CodecExports.obj \
|
||||
$O\DllExports.obj \
|
||||
|
||||
COMMON_OBJS = \
|
||||
$O\CRC.obj \
|
||||
|
||||
LZMA_OPT_OBJS = \
|
||||
$O\LZMADecoder.obj \
|
||||
$O\LZMAEncoder.obj \
|
||||
$O\LZMARegister.obj \
|
||||
|
||||
7ZIP_COMMON_OBJS = \
|
||||
$O\InBuffer.obj \
|
||||
$O\OutBuffer.obj \
|
||||
$O\StreamUtils.obj \
|
||||
|
||||
C_OBJS = \
|
||||
$O\Alloc.obj \
|
||||
$O\LzFind.obj \
|
||||
$O\LzFindMt.obj \
|
||||
$O\LzmaDec.obj \
|
||||
$O\LzmaEnc.obj \
|
||||
$O\Threads.obj \
|
||||
|
||||
!include "../../Crc2.mak"
|
||||
|
||||
OBJS = \
|
||||
$O\StdAfx.obj \
|
||||
$(COMPRESS_OBJS) \
|
||||
$(COMMON_OBJS) \
|
||||
$(LZMA_OPT_OBJS) \
|
||||
$(7ZIP_COMMON_OBJS) \
|
||||
$(C_OBJS) \
|
||||
$(CRC_OBJS) \
|
||||
$O\RangeCoderBit.obj \
|
||||
$O\resource.res
|
||||
|
||||
!include "../../../Build.mak"
|
||||
|
||||
$(COMPRESS_OBJS): ../$(*B).cpp
|
||||
$(COMPL)
|
||||
$(COMMON_OBJS): ../../../Common/$(*B).cpp
|
||||
$(COMPL)
|
||||
$(LZMA_OPT_OBJS): $(*B).cpp
|
||||
$(COMPL_O2)
|
||||
$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp
|
||||
$(COMPL)
|
||||
$O\RangeCoderBit.obj: ../RangeCoder/$(*B).cpp
|
||||
$(COMPL)
|
||||
$(C_OBJS): ../../../../C/$(*B).c
|
||||
$(COMPL_O2)
|
||||
!include "../../Crc.mak"
|
||||
3
CPP/7zip/Compress/LZMA/resource.rc
Executable file
3
CPP/7zip/Compress/LZMA/resource.rc
Executable file
@@ -0,0 +1,3 @@
|
||||
#include "../../MyVersionInfo.rc"
|
||||
|
||||
MY_VERSION_INFO_DLL("LZMA Codec", "LZMA")
|
||||
@@ -49,7 +49,7 @@ static inline bool IsItWindowsNT()
|
||||
{
|
||||
OSVERSIONINFO versionInfo;
|
||||
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
|
||||
if (!::GetVersionEx(&versionInfo))
|
||||
if (!::GetVersionEx(&versionInfo))
|
||||
return false;
|
||||
return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
|
||||
}
|
||||
@@ -80,7 +80,7 @@ enum Enum
|
||||
};
|
||||
}
|
||||
|
||||
static const CSwitchForm kSwitchForms[] =
|
||||
static const CSwitchForm kSwitchForms[] =
|
||||
{
|
||||
{ L"?", NSwitchType::kSimple, false },
|
||||
{ L"H", NSwitchType::kSimple, false },
|
||||
@@ -135,7 +135,7 @@ static void IncorrectCommand()
|
||||
PrintHelpAndExit("Incorrect command");
|
||||
}
|
||||
|
||||
static void WriteArgumentsToStringList(int numArguments, const char *arguments[],
|
||||
static void WriteArgumentsToStringList(int numArguments, const char *arguments[],
|
||||
UStringVector &strings)
|
||||
{
|
||||
for(int i = 1; i < numArguments; i++)
|
||||
@@ -176,7 +176,7 @@ int main2(int n, const char *args[])
|
||||
{
|
||||
fprintf(stderr, "Unsupported base types. Edit Common/Types.h and recompile");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
UStringVector commandStrings;
|
||||
WriteArgumentsToStringList(n, args, commandStrings);
|
||||
@@ -185,7 +185,7 @@ int main2(int n, const char *args[])
|
||||
{
|
||||
parser.ParseStrings(kSwitchForms, commandStrings);
|
||||
}
|
||||
catch(...)
|
||||
catch(...)
|
||||
{
|
||||
IncorrectCommand();
|
||||
}
|
||||
@@ -200,7 +200,7 @@ int main2(int n, const char *args[])
|
||||
int paramIndex = 0;
|
||||
if (paramIndex >= nonSwitchStrings.Size())
|
||||
IncorrectCommand();
|
||||
const UString &command = nonSwitchStrings[paramIndex++];
|
||||
const UString &command = nonSwitchStrings[paramIndex++];
|
||||
|
||||
bool dictionaryIsDefined = false;
|
||||
UInt32 dictionary = (UInt32)-1;
|
||||
@@ -268,12 +268,12 @@ int main2(int n, const char *args[])
|
||||
{
|
||||
if (paramIndex >= nonSwitchStrings.Size())
|
||||
IncorrectCommand();
|
||||
const UString &inputName = nonSwitchStrings[paramIndex++];
|
||||
const UString &inputName = nonSwitchStrings[paramIndex++];
|
||||
inStreamSpec = new CInFileStream;
|
||||
inStream = inStreamSpec;
|
||||
if (!inStreamSpec->Open(GetSystemString(inputName)))
|
||||
{
|
||||
fprintf(stderr, "\nError: can not open input file %s\n",
|
||||
fprintf(stderr, "\nError: can not open input file %s\n",
|
||||
(const char *)GetOemString(inputName));
|
||||
return 1;
|
||||
}
|
||||
@@ -290,12 +290,12 @@ int main2(int n, const char *args[])
|
||||
{
|
||||
if (paramIndex >= nonSwitchStrings.Size())
|
||||
IncorrectCommand();
|
||||
const UString &outputName = nonSwitchStrings[paramIndex++];
|
||||
const UString &outputName = nonSwitchStrings[paramIndex++];
|
||||
outStreamSpec = new COutFileStream;
|
||||
outStream = outStreamSpec;
|
||||
if (!outStreamSpec->Create(GetSystemString(outputName), true))
|
||||
{
|
||||
fprintf(stderr, "\nError: can not open output file %s\n",
|
||||
fprintf(stderr, "\nError: can not open output file %s\n",
|
||||
(const char *)GetOemString(outputName));
|
||||
return 1;
|
||||
}
|
||||
@@ -314,7 +314,7 @@ int main2(int n, const char *args[])
|
||||
Byte *inBuffer = 0;
|
||||
if (inSize != 0)
|
||||
{
|
||||
inBuffer = (Byte *)MyAlloc((size_t)inSize);
|
||||
inBuffer = (Byte *)MyAlloc((size_t)inSize);
|
||||
if (inBuffer == 0)
|
||||
throw kCantAllocate;
|
||||
}
|
||||
@@ -330,7 +330,7 @@ int main2(int n, const char *args[])
|
||||
outSize = (size_t)fileSize / 20 * 21 + (1 << 16);
|
||||
if (outSize != 0)
|
||||
{
|
||||
outBuffer = (Byte *)MyAlloc((size_t)outSize);
|
||||
outBuffer = (Byte *)MyAlloc((size_t)outSize);
|
||||
if (outBuffer == 0)
|
||||
throw kCantAllocate;
|
||||
}
|
||||
@@ -354,7 +354,7 @@ int main2(int n, const char *args[])
|
||||
throw "too big";
|
||||
if (outSize != 0)
|
||||
{
|
||||
outBuffer = (Byte *)MyAlloc(outSize);
|
||||
outBuffer = (Byte *)MyAlloc(outSize);
|
||||
if (outBuffer == 0)
|
||||
throw kCantAllocate;
|
||||
}
|
||||
@@ -414,7 +414,7 @@ int main2(int n, const char *args[])
|
||||
if (!GetNumber(parser[NKey::kPosBits].PostStrings[0], posStateBits))
|
||||
IncorrectCommand();
|
||||
|
||||
PROPID propIDs[] =
|
||||
PROPID propIDs[] =
|
||||
{
|
||||
NCoderPropID::kDictionarySize,
|
||||
NCoderPropID::kPosStateBits,
|
||||
@@ -480,12 +480,12 @@ int main2(int n, const char *args[])
|
||||
{
|
||||
fprintf(stderr, "\nError: Can not allocate memory\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (result != S_OK)
|
||||
{
|
||||
fprintf(stderr, "\nEncoder error = %X\n", (unsigned int)result);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -511,7 +511,7 @@ int main2(int n, const char *args[])
|
||||
{
|
||||
fprintf(stderr, "Decoder error");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (outStreamSpec != NULL)
|
||||
{
|
||||
@@ -527,14 +527,14 @@ int main2(int n, const char *args[])
|
||||
int MY_CDECL main(int n, const char *args[])
|
||||
{
|
||||
try { return main2(n, args); }
|
||||
catch(const char *s)
|
||||
{
|
||||
catch(const char *s)
|
||||
{
|
||||
fprintf(stderr, "\nError: %s\n", s);
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
catch(...)
|
||||
{
|
||||
fprintf(stderr, "\nError\n");
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
#include "../../../../C/7zCrc.h"
|
||||
}
|
||||
@@ -60,9 +60,9 @@ class CBaseRandomGenerator
|
||||
public:
|
||||
CBaseRandomGenerator() { Init(); }
|
||||
void Init() { A1 = 362436069; A2 = 521288629;}
|
||||
UInt32 GetRnd()
|
||||
UInt32 GetRnd()
|
||||
{
|
||||
return
|
||||
return
|
||||
((A1 = 36969 * (A1 & 0xffff) + (A1 >> 16)) << 16) +
|
||||
((A2 = 18000 * (A2 & 0xffff) + (A2 >> 16)) );
|
||||
}
|
||||
@@ -73,14 +73,14 @@ class CBenchBuffer
|
||||
public:
|
||||
size_t BufferSize;
|
||||
Byte *Buffer;
|
||||
CBenchBuffer(): Buffer(0) {}
|
||||
CBenchBuffer(): Buffer(0) {}
|
||||
virtual ~CBenchBuffer() { Free(); }
|
||||
void Free()
|
||||
{
|
||||
void Free()
|
||||
{
|
||||
::MidFree(Buffer);
|
||||
Buffer = 0;
|
||||
}
|
||||
bool Alloc(size_t bufferSize)
|
||||
bool Alloc(size_t bufferSize)
|
||||
{
|
||||
if (Buffer != 0 && BufferSize == bufferSize)
|
||||
return true;
|
||||
@@ -96,14 +96,14 @@ class CBenchRandomGenerator: public CBenchBuffer
|
||||
CBaseRandomGenerator *RG;
|
||||
public:
|
||||
void Set(CBaseRandomGenerator *rg) { RG = rg; }
|
||||
UInt32 GetVal(UInt32 &res, int numBits)
|
||||
UInt32 GetVal(UInt32 &res, int numBits)
|
||||
{
|
||||
UInt32 val = res & (((UInt32)1 << numBits) - 1);
|
||||
res >>= numBits;
|
||||
return val;
|
||||
}
|
||||
UInt32 GetLen(UInt32 &res)
|
||||
{
|
||||
UInt32 GetLen(UInt32 &res)
|
||||
{
|
||||
UInt32 len = GetVal(res, 2);
|
||||
return GetVal(res, 1 + len);
|
||||
}
|
||||
@@ -145,7 +145,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
class CBenchmarkInStream:
|
||||
class CBenchmarkInStream:
|
||||
public ISequentialInStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -179,7 +179,7 @@ STDMETHODIMP CBenchmarkInStream::Read(void *data, UInt32 size, UInt32 *processed
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
class CBenchmarkOutStream:
|
||||
class CBenchmarkOutStream:
|
||||
public ISequentialOutStream,
|
||||
public CBenchBuffer,
|
||||
public CMyUnknownImp
|
||||
@@ -187,8 +187,8 @@ class CBenchmarkOutStream:
|
||||
// bool _overflow;
|
||||
public:
|
||||
UInt32 Pos;
|
||||
// CBenchmarkOutStream(): _overflow(false) {}
|
||||
void Init()
|
||||
// CBenchmarkOutStream(): _overflow(false) {}
|
||||
void Init()
|
||||
{
|
||||
// _overflow = false;
|
||||
Pos = 0;
|
||||
@@ -214,7 +214,7 @@ STDMETHODIMP CBenchmarkOutStream::Write(const void *data, UInt32 size, UInt32 *p
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
class CCrcOutStream:
|
||||
class CCrcOutStream:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -251,7 +251,7 @@ static UInt64 GetTimeCount()
|
||||
return value.QuadPart;
|
||||
*/
|
||||
return GetTickCount();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static UInt64 GetFreq()
|
||||
@@ -261,7 +261,7 @@ static UInt64 GetFreq()
|
||||
return 1000000;
|
||||
#else
|
||||
return 1;
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
/*
|
||||
LARGE_INTEGER value;
|
||||
@@ -269,7 +269,7 @@ static UInt64 GetFreq()
|
||||
return value.QuadPart;
|
||||
*/
|
||||
return 1000;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef USE_POSIX_TIME
|
||||
@@ -284,7 +284,7 @@ static UInt64 GetUserTime()
|
||||
if (::GetProcessTimes(::GetCurrentProcess(), &creationTime, &exitTime, &kernelTime, &userTime) != 0)
|
||||
return GetTime64(userTime) + GetTime64(kernelTime);
|
||||
return (UInt64)GetTickCount() * 10000;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
static UInt64 GetUserFreq()
|
||||
@@ -293,18 +293,18 @@ static UInt64 GetUserFreq()
|
||||
return CLOCKS_PER_SEC;
|
||||
#else
|
||||
return 10000000;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
class CBenchProgressStatus
|
||||
{
|
||||
#ifdef BENCH_MT
|
||||
NWindows::NSynchronization::CCriticalSection CS;
|
||||
NWindows::NSynchronization::CCriticalSection CS;
|
||||
#endif
|
||||
public:
|
||||
HRESULT Res;
|
||||
bool EncodeMode;
|
||||
void SetResult(HRESULT res)
|
||||
void SetResult(HRESULT res)
|
||||
{
|
||||
#ifdef BENCH_MT
|
||||
NWindows::NSynchronization::CCriticalSectionLock lock(CS);
|
||||
@@ -450,7 +450,7 @@ UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt
|
||||
}
|
||||
|
||||
#ifdef EXTERNAL_LZMA
|
||||
typedef UInt32 (WINAPI * CreateObjectPointer)(const GUID *clsID,
|
||||
typedef UInt32 (WINAPI * CreateObjectPointer)(const GUID *clsID,
|
||||
const GUID *interfaceID, void **outObject);
|
||||
#endif
|
||||
|
||||
@@ -571,9 +571,9 @@ HRESULT CEncoderInfo::Init(UInt32 dictionarySize, UInt32 numThreads, CBaseRandom
|
||||
return E_OUTOFMEMORY;
|
||||
propStreamSpec->Init();
|
||||
|
||||
PROPID propIDs[] =
|
||||
{
|
||||
NCoderPropID::kDictionarySize,
|
||||
PROPID propIDs[] =
|
||||
{
|
||||
NCoderPropID::kDictionarySize,
|
||||
NCoderPropID::kMultiThread
|
||||
};
|
||||
const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]);
|
||||
@@ -664,13 +664,13 @@ HRESULT LzmaBench(
|
||||
#endif
|
||||
UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback)
|
||||
{
|
||||
UInt32 numEncoderThreads =
|
||||
UInt32 numEncoderThreads =
|
||||
#ifdef BENCH_MT
|
||||
(numThreads > 1 ? numThreads / 2 : 1);
|
||||
#else
|
||||
1;
|
||||
#endif
|
||||
UInt32 numSubDecoderThreads =
|
||||
UInt32 numSubDecoderThreads =
|
||||
#ifdef BENCH_MT
|
||||
(numThreads > 1 ? 2 : 1);
|
||||
#else
|
||||
@@ -838,7 +838,7 @@ HRESULT LzmaBench(
|
||||
|
||||
|
||||
inline UInt64 GetLZMAUsage(bool multiThread, UInt32 dictionary)
|
||||
{
|
||||
{
|
||||
UInt32 hs = dictionary - 1;
|
||||
hs |= (hs >> 1);
|
||||
hs |= (hs >> 2);
|
||||
@@ -849,7 +849,7 @@ inline UInt64 GetLZMAUsage(bool multiThread, UInt32 dictionary)
|
||||
if (hs > (1 << 24))
|
||||
hs >>= 1;
|
||||
hs++;
|
||||
return ((hs + (1 << 16)) + (UInt64)dictionary * 2) * 4 + (UInt64)dictionary * 3 / 2 +
|
||||
return ((hs + (1 << 16)) + (UInt64)dictionary * 2) * 4 + (UInt64)dictionary * 3 / 2 +
|
||||
(1 << 20) + (multiThread ? (6 << 20) : 0);
|
||||
}
|
||||
|
||||
@@ -905,10 +905,10 @@ struct CCrcThreads
|
||||
Items[i].Wait();
|
||||
NumThreads = 0;
|
||||
}
|
||||
~CCrcThreads()
|
||||
{
|
||||
~CCrcThreads()
|
||||
{
|
||||
WaitAll();
|
||||
delete []Items;
|
||||
delete []Items;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -12,8 +12,8 @@
|
||||
struct CBenchInfo
|
||||
{
|
||||
UInt64 GlobalTime;
|
||||
UInt64 GlobalFreq;
|
||||
UInt64 UserTime;
|
||||
UInt64 GlobalFreq;
|
||||
UInt64 UserTime;
|
||||
UInt64 UserFreq;
|
||||
UInt64 UnpackSize;
|
||||
UInt64 PackSize;
|
||||
|
||||
@@ -24,18 +24,18 @@ struct CTotalBenchRes
|
||||
UInt64 Usage;
|
||||
UInt64 RPU;
|
||||
void Init() { NumIterations = 0; Rating = 0; Usage = 0; RPU = 0; }
|
||||
void Normalize()
|
||||
{
|
||||
if (NumIterations == 0)
|
||||
void Normalize()
|
||||
{
|
||||
if (NumIterations == 0)
|
||||
return;
|
||||
Rating /= NumIterations;
|
||||
Usage /= NumIterations;
|
||||
RPU /= NumIterations;
|
||||
Rating /= NumIterations;
|
||||
Usage /= NumIterations;
|
||||
RPU /= NumIterations;
|
||||
NumIterations = 1;
|
||||
}
|
||||
void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2)
|
||||
{
|
||||
Rating = (r1.Rating + r2.Rating) / 2;
|
||||
void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2)
|
||||
{
|
||||
Rating = (r1.Rating + r2.Rating) / 2;
|
||||
Usage = (r1.Usage + r2.Usage) / 2;
|
||||
RPU = (r1.RPU + r2.RPU) / 2;
|
||||
NumIterations = (r1.NumIterations + r2.NumIterations) / 2;
|
||||
@@ -168,7 +168,7 @@ HRESULT LzmaBenchCon(
|
||||
if (!CrcInternalTest())
|
||||
return S_FALSE;
|
||||
#ifdef BENCH_MT
|
||||
UInt64 ramSize = NWindows::NSystem::GetRamSize(); //
|
||||
UInt64 ramSize = NWindows::NSystem::GetRamSize(); //
|
||||
UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();
|
||||
PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs);
|
||||
if (numThreads == (UInt32)-1)
|
||||
|
||||
@@ -12,7 +12,7 @@ endif
|
||||
ifdef IS_MINGW
|
||||
FILE_IO =FileIO
|
||||
FILE_IO_2 =Windows/$(FILE_IO)
|
||||
LIB2 = -luuid
|
||||
LIB2 = -luuid
|
||||
else
|
||||
FILE_IO =C_FileIO
|
||||
FILE_IO_2 =Common/$(FILE_IO)
|
||||
|
||||
@@ -21,28 +21,28 @@ UInt32 CCoder::ReadBits(int numBits) { return m_InBitStream.ReadBits(numBits);
|
||||
HRESULT CCoder::ReadLevelTable()
|
||||
{
|
||||
int n = ReadBits(kNumLevelBits);
|
||||
if (n == 0)
|
||||
if (n == 0)
|
||||
{
|
||||
m_LevelHuffman.Symbol = ReadBits(kNumLevelBits);
|
||||
if (m_LevelHuffman.Symbol >= kNumLevelSymbols)
|
||||
return S_FALSE;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
if (n > kNumLevelSymbols)
|
||||
return S_FALSE;
|
||||
m_LevelHuffman.Symbol = -1;
|
||||
Byte lens[kNumLevelSymbols];
|
||||
int i = 0;
|
||||
while (i < n)
|
||||
while (i < n)
|
||||
{
|
||||
int c = m_InBitStream.ReadBits(3);
|
||||
if (c == 7)
|
||||
while (ReadBits(1))
|
||||
if (c == 7)
|
||||
while (ReadBits(1))
|
||||
if (c++ > kMaxHuffmanLen)
|
||||
return S_FALSE;
|
||||
lens[i++] = (Byte)c;
|
||||
if (i == kNumSpecLevelSymbols)
|
||||
if (i == kNumSpecLevelSymbols)
|
||||
{
|
||||
c = ReadBits(2);
|
||||
while (--c >= 0)
|
||||
@@ -65,18 +65,18 @@ HRESULT CCoder::ReadPTable(int numBits)
|
||||
if (m_PHuffmanDecoder.Symbol >= kNumDistanceSymbols)
|
||||
return S_FALSE;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
if (n > kNumDistanceSymbols)
|
||||
return S_FALSE;
|
||||
m_PHuffmanDecoder.Symbol = -1;
|
||||
Byte lens[kNumDistanceSymbols];
|
||||
int i = 0;
|
||||
while (i < n)
|
||||
while (i < n)
|
||||
{
|
||||
int c = m_InBitStream.ReadBits(3);
|
||||
if (c == 7)
|
||||
while (ReadBits(1))
|
||||
if (c == 7)
|
||||
while (ReadBits(1))
|
||||
{
|
||||
if (c > kMaxHuffmanLen)
|
||||
return S_FALSE;
|
||||
@@ -94,23 +94,23 @@ HRESULT CCoder::ReadPTable(int numBits)
|
||||
HRESULT CCoder::ReadCTable()
|
||||
{
|
||||
int n = ReadBits(kNumCBits);
|
||||
if (n == 0)
|
||||
if (n == 0)
|
||||
{
|
||||
m_CHuffmanDecoder.Symbol = ReadBits(kNumCBits);
|
||||
if (m_CHuffmanDecoder.Symbol >= kNumCSymbols)
|
||||
return S_FALSE;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
if (n > kNumCSymbols)
|
||||
return S_FALSE;
|
||||
m_CHuffmanDecoder.Symbol = -1;
|
||||
Byte lens[kNumCSymbols];
|
||||
int i = 0;
|
||||
while (i < n)
|
||||
while (i < n)
|
||||
{
|
||||
int c = m_LevelHuffman.Decode(&m_InBitStream);
|
||||
if (c < kNumSpecLevelSymbols)
|
||||
if (c < kNumSpecLevelSymbols)
|
||||
{
|
||||
if (c == 0)
|
||||
c = 1;
|
||||
@@ -156,9 +156,9 @@ STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
CCoderReleaser coderReleaser(this);
|
||||
|
||||
int pbit;
|
||||
if (m_NumDictBits <= 13)
|
||||
if (m_NumDictBits <= 13)
|
||||
pbit = 4;
|
||||
else
|
||||
else
|
||||
pbit = 5;
|
||||
|
||||
UInt32 blockSize = 0;
|
||||
@@ -167,7 +167,7 @@ STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
{
|
||||
// for (i = 0; i < dictSize; i++) dtext[i] = 0x20;
|
||||
|
||||
if (blockSize == 0)
|
||||
if (blockSize == 0)
|
||||
{
|
||||
if (progress != NULL)
|
||||
{
|
||||
@@ -181,7 +181,7 @@ STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
}
|
||||
blockSize--;
|
||||
UInt32 c = m_CHuffmanDecoder.Decode(&m_InBitStream);
|
||||
if (c < 256)
|
||||
if (c < 256)
|
||||
{
|
||||
m_OutWindowStream.PutByte((Byte)c);
|
||||
pos++;
|
||||
|
||||
@@ -74,7 +74,7 @@ class CCoder :
|
||||
};
|
||||
friend class CCoderReleaser;
|
||||
|
||||
void MakeTable(int nchar, Byte *bitlen, int tablebits,
|
||||
void MakeTable(int nchar, Byte *bitlen, int tablebits,
|
||||
UInt32 *table, int tablesize);
|
||||
|
||||
UInt32 ReadBits(int numBits);
|
||||
|
||||
@@ -40,7 +40,7 @@ const int kLevelSymbolSame = 19;
|
||||
const int kLevelSymbolZerosStartValue = 4;
|
||||
const int kLevelSymbolZerosNumBits = 4;
|
||||
|
||||
const int kLevelSymbolZerosBigStartValue = kLevelSymbolZerosStartValue +
|
||||
const int kLevelSymbolZerosBigStartValue = kLevelSymbolZerosStartValue +
|
||||
(1 << kLevelSymbolZerosNumBits);
|
||||
const int kLevelSymbolZerosBigNumBits = 5;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ void Cx86ConvertOutStream::MakeTranslation()
|
||||
Int32 pos = (Int32)(m_ProcessedSize + i - 1);
|
||||
if (absValue >= -pos && absValue < (Int32)m_TranslationSize)
|
||||
{
|
||||
UInt32 offset = (absValue >= 0) ?
|
||||
UInt32 offset = (absValue >= 0) ?
|
||||
absValue - pos :
|
||||
absValue + m_TranslationSize;
|
||||
for(j = 0; j < 4; j++)
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace NLzx {
|
||||
|
||||
const int kUncompressedBlockSize = 1 << 15;
|
||||
|
||||
class Cx86ConvertOutStream:
|
||||
class Cx86ConvertOutStream:
|
||||
public ISequentialOutStream,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
// LzxDecoder.cpp
|
||||
// LzxDecoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "LzxDecoder.h"
|
||||
|
||||
#include "Common/Defs.h"
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
}
|
||||
#include "Windows/Defs.h"
|
||||
@@ -307,7 +307,7 @@ HRESULT CDecoder::CodeSpec(UInt32 curSize)
|
||||
}
|
||||
|
||||
HRESULT CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
@@ -338,7 +338,7 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
UInt64 nowPos64 = m_OutWindowStream.GetProcessedSize() - start;
|
||||
RINOK(progress->SetRatioInfo(&inSize, &nowPos64));
|
||||
}
|
||||
}
|
||||
}
|
||||
flusher.NeedFlush = false;
|
||||
return Flush();
|
||||
}
|
||||
@@ -374,7 +374,7 @@ STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)
|
||||
}
|
||||
|
||||
HRESULT CDecoder::SetParams(int numDictBits)
|
||||
{
|
||||
{
|
||||
if (numDictBits < kNumDictionaryBitsMin || numDictBits > kNumDictionaryBitsMax)
|
||||
return E_INVALIDARG;
|
||||
UInt32 numPosSlots;
|
||||
|
||||
@@ -36,10 +36,10 @@ public:
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init();
|
||||
m_BitPos = kNumBigValueBits;
|
||||
m_BitPos = kNumBigValueBits;
|
||||
}
|
||||
|
||||
UInt64 GetProcessedSize() const
|
||||
UInt64 GetProcessedSize() const
|
||||
{ return m_Stream.GetProcessedSize() - (kNumBigValueBits - m_BitPos) / 8; }
|
||||
|
||||
int GetBitPosition() const { return m_BitPos & 0xF; }
|
||||
@@ -57,7 +57,7 @@ public:
|
||||
|
||||
UInt32 GetValue(int numBits) const
|
||||
{
|
||||
return ((m_Value >> ((32 - kNumValueBits) - m_BitPos)) & kBitDecoderValueMask) >>
|
||||
return ((m_Value >> ((32 - kNumValueBits) - m_BitPos)) & kBitDecoderValueMask) >>
|
||||
(kNumValueBits - numBits);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public:
|
||||
};
|
||||
}
|
||||
|
||||
class CDecoder :
|
||||
class CDecoder :
|
||||
public ICompressCoder,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
@@ -135,8 +135,8 @@ class CDecoder :
|
||||
|
||||
HRESULT CodeSpec(UInt32 size);
|
||||
|
||||
HRESULT CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
HRESULT CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
public:
|
||||
@@ -148,8 +148,8 @@ public:
|
||||
STDMETHOD(Flush)();
|
||||
|
||||
// ICompressCoder interface
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
|
||||
@@ -15,42 +15,42 @@ namespace NPPMD {
|
||||
const int INT_BITS=7, PERIOD_BITS=7, TOT_BITS=INT_BITS+PERIOD_BITS,
|
||||
INTERVAL=1 << INT_BITS, BIN_SCALE=1 << TOT_BITS, MAX_FREQ=124;
|
||||
|
||||
struct SEE2_CONTEXT
|
||||
{
|
||||
struct SEE2_CONTEXT
|
||||
{
|
||||
// SEE-contexts for PPM-contexts with masked symbols
|
||||
UInt16 Summ;
|
||||
Byte Shift, Count;
|
||||
void init(int InitVal) { Summ = (UInt16)(InitVal << (Shift=PERIOD_BITS-4)); Count=4; }
|
||||
unsigned int getMean()
|
||||
unsigned int getMean()
|
||||
{
|
||||
unsigned int RetVal=(Summ >> Shift);
|
||||
unsigned int RetVal=(Summ >> Shift);
|
||||
Summ = (UInt16)(Summ - RetVal);
|
||||
return RetVal+(RetVal == 0);
|
||||
}
|
||||
void update()
|
||||
void update()
|
||||
{
|
||||
if (Shift < PERIOD_BITS && --Count == 0)
|
||||
if (Shift < PERIOD_BITS && --Count == 0)
|
||||
{
|
||||
Summ <<= 1;
|
||||
Summ <<= 1;
|
||||
Count = (Byte)(3 << Shift++);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
struct PPM_CONTEXT
|
||||
struct PPM_CONTEXT
|
||||
{
|
||||
UInt16 NumStats; // sizeof(UInt16) > sizeof(Byte)
|
||||
UInt16 NumStats; // sizeof(UInt16) > sizeof(Byte)
|
||||
UInt16 SummFreq;
|
||||
|
||||
struct STATE
|
||||
{
|
||||
Byte Symbol, Freq;
|
||||
struct STATE
|
||||
{
|
||||
Byte Symbol, Freq;
|
||||
UInt16 SuccessorLow;
|
||||
UInt16 SuccessorHigh;
|
||||
|
||||
UInt32 GetSuccessor() const { return SuccessorLow | ((UInt32)SuccessorHigh << 16); }
|
||||
void SetSuccessor(UInt32 v)
|
||||
{
|
||||
void SetSuccessor(UInt32 v)
|
||||
{
|
||||
SuccessorLow = (UInt16)(v & 0xFFFF);
|
||||
SuccessorHigh = (UInt16)((v >> 16) & 0xFFFF);
|
||||
}
|
||||
@@ -62,11 +62,11 @@ struct PPM_CONTEXT
|
||||
PPM_CONTEXT* createChild(CSubAllocator &subAllocator, STATE* pStats, STATE& FirstState)
|
||||
{
|
||||
PPM_CONTEXT* pc = (PPM_CONTEXT*) subAllocator.AllocContext();
|
||||
if (pc)
|
||||
if (pc)
|
||||
{
|
||||
pc->NumStats = 1;
|
||||
pc->NumStats = 1;
|
||||
pc->oneState() = FirstState;
|
||||
pc->Suffix = subAllocator.GetOffset(this);
|
||||
pc->Suffix = subAllocator.GetOffset(this);
|
||||
pStats->SetSuccessor(subAllocator.GetOffsetNoCheck(pc));
|
||||
}
|
||||
return pc;
|
||||
@@ -97,7 +97,7 @@ struct CInfo
|
||||
HiBitsFlag = HB2Flag[FoundState->Symbol];
|
||||
return BinSumm[rs.Freq - 1][
|
||||
PrevSuccess + NS2BSIndx[numStates - 1] +
|
||||
HiBitsFlag + 2 * HB2Flag[rs.Symbol] +
|
||||
HiBitsFlag + 2 * HB2Flag[rs.Symbol] +
|
||||
((RunLength >> 26) & 0x20)];
|
||||
}
|
||||
|
||||
@@ -110,19 +110,19 @@ struct CInfo
|
||||
{
|
||||
int i, k, m;
|
||||
memset(CharMask,0,sizeof(CharMask));
|
||||
SubAllocator.InitSubAllocator();
|
||||
SubAllocator.InitSubAllocator();
|
||||
InitRL = -((MaxOrder < 12) ? MaxOrder : 12) - 1;
|
||||
MinContext = MaxContext = (PPM_CONTEXT*) SubAllocator.AllocContext();
|
||||
MinContext->Suffix = 0;
|
||||
MinContext->Suffix = 0;
|
||||
OrderFall = MaxOrder;
|
||||
MinContext->SummFreq = (UInt16)((MinContext->NumStats = 256) + 1);
|
||||
FoundState = (PPM_CONTEXT::STATE*)SubAllocator.AllocUnits(256 / 2);
|
||||
MinContext->Stats = SubAllocator.GetOffsetNoCheck(FoundState);
|
||||
PrevSuccess = 0;
|
||||
for (RunLength = InitRL, i = 0; i < 256; i++)
|
||||
for (RunLength = InitRL, i = 0; i < 256; i++)
|
||||
{
|
||||
PPM_CONTEXT::STATE &state = FoundState[i];
|
||||
state.Symbol = (Byte)i;
|
||||
state.Symbol = (Byte)i;
|
||||
state.Freq = 1;
|
||||
state.SetSuccessor(0);
|
||||
}
|
||||
@@ -131,7 +131,7 @@ struct CInfo
|
||||
for ( m=0; m < 64; m += 8)
|
||||
BinSumm[i][k + m] = (UInt16)(BIN_SCALE - InitBinEsc[k] / (i + 2));
|
||||
for (i = 0; i < 25; i++)
|
||||
for (k = 0; k < 16; k++)
|
||||
for (k = 0; k < 16; k++)
|
||||
SEE2Cont[i][k].init(5*i+10);
|
||||
}
|
||||
|
||||
@@ -139,39 +139,39 @@ struct CInfo
|
||||
{
|
||||
int i, k, m ,Step;
|
||||
EscCount=PrintCount=1;
|
||||
if (maxOrder < 2)
|
||||
if (maxOrder < 2)
|
||||
{
|
||||
memset(CharMask,0,sizeof(CharMask));
|
||||
OrderFall = MaxOrder;
|
||||
OrderFall = MaxOrder;
|
||||
MinContext = MaxContext;
|
||||
while (MinContext->Suffix != 0)
|
||||
while (MinContext->Suffix != 0)
|
||||
{
|
||||
MinContext = GetContextNoCheck(MinContext->Suffix);
|
||||
MinContext = GetContextNoCheck(MinContext->Suffix);
|
||||
OrderFall--;
|
||||
}
|
||||
FoundState = GetState(MinContext->Stats);
|
||||
MinContext = MaxContext;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
MaxOrder = maxOrder;
|
||||
MaxOrder = maxOrder;
|
||||
RestartModelRare();
|
||||
NS2BSIndx[0] = 2 * 0;
|
||||
NS2BSIndx[0] = 2 * 0;
|
||||
NS2BSIndx[1] = 2 * 1;
|
||||
memset(NS2BSIndx + 2, 2 * 2, 9);
|
||||
memset(NS2BSIndx + 2, 2 * 2, 9);
|
||||
memset(NS2BSIndx + 11, 2 * 3, 256 - 11);
|
||||
for (i = 0; i < 3; i++)
|
||||
for (i = 0; i < 3; i++)
|
||||
NS2Indx[i] = (Byte)i;
|
||||
for (m = i, k = Step = 1; i < 256; i++)
|
||||
for (m = i, k = Step = 1; i < 256; i++)
|
||||
{
|
||||
NS2Indx[i] = (Byte)m;
|
||||
if ( !--k )
|
||||
{
|
||||
k = ++Step;
|
||||
m++;
|
||||
if ( !--k )
|
||||
{
|
||||
k = ++Step;
|
||||
m++;
|
||||
}
|
||||
}
|
||||
memset(HB2Flag, 0, 0x40);
|
||||
memset(HB2Flag, 0, 0x40);
|
||||
memset(HB2Flag + 0x40, 0x08, 0x100 - 0x40);
|
||||
DummySEE2Cont.Shift = PERIOD_BITS;
|
||||
}
|
||||
@@ -186,59 +186,59 @@ struct CInfo
|
||||
PPM_CONTEXT *pc = MinContext;
|
||||
PPM_CONTEXT *UpBranch = GetContext(FoundState->GetSuccessor());
|
||||
PPM_CONTEXT::STATE * p, * ps[MAX_O], ** pps = ps;
|
||||
if ( !skip )
|
||||
if ( !skip )
|
||||
{
|
||||
*pps++ = FoundState;
|
||||
if ( !pc->Suffix )
|
||||
if ( !pc->Suffix )
|
||||
goto NO_LOOP;
|
||||
}
|
||||
if ( p1 )
|
||||
if ( p1 )
|
||||
{
|
||||
p = p1;
|
||||
p = p1;
|
||||
pc = GetContext(pc->Suffix);
|
||||
goto LOOP_ENTRY;
|
||||
}
|
||||
do
|
||||
do
|
||||
{
|
||||
pc = GetContext(pc->Suffix);
|
||||
if (pc->NumStats != 1)
|
||||
if (pc->NumStats != 1)
|
||||
{
|
||||
if ((p = GetStateNoCheck(pc->Stats))->Symbol != FoundState->Symbol)
|
||||
do { p++; } while (p->Symbol != FoundState->Symbol);
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
p = &(pc->oneState());
|
||||
LOOP_ENTRY:
|
||||
if (GetContext(p->GetSuccessor()) != UpBranch)
|
||||
if (GetContext(p->GetSuccessor()) != UpBranch)
|
||||
{
|
||||
pc = GetContext(p->GetSuccessor());
|
||||
pc = GetContext(p->GetSuccessor());
|
||||
break;
|
||||
}
|
||||
*pps++ = p;
|
||||
}
|
||||
}
|
||||
while ( pc->Suffix );
|
||||
NO_LOOP:
|
||||
if (pps == ps)
|
||||
if (pps == ps)
|
||||
return pc;
|
||||
UpState.Symbol = *(Byte*) UpBranch;
|
||||
UpState.SetSuccessor(SubAllocator.GetOffset(UpBranch) + 1);
|
||||
if (pc->NumStats != 1)
|
||||
if (pc->NumStats != 1)
|
||||
{
|
||||
if ((p = GetStateNoCheck(pc->Stats))->Symbol != UpState.Symbol)
|
||||
do { p++; } while (p->Symbol != UpState.Symbol);
|
||||
unsigned int cf = p->Freq-1;
|
||||
unsigned int s0 = pc->SummFreq - pc->NumStats - cf;
|
||||
UpState.Freq = (Byte)(1 + ((2 * cf <= s0) ? (5 * cf > s0) :
|
||||
UpState.Freq = (Byte)(1 + ((2 * cf <= s0) ? (5 * cf > s0) :
|
||||
((2 * cf + 3 * s0 - 1) / (2 * s0))));
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
UpState.Freq = pc->oneState().Freq;
|
||||
do
|
||||
do
|
||||
{
|
||||
pc = pc->createChild(SubAllocator, *--pps, UpState);
|
||||
if ( !pc )
|
||||
if ( !pc )
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
while (pps != ps);
|
||||
return pc;
|
||||
}
|
||||
@@ -248,46 +248,46 @@ NO_LOOP:
|
||||
PPM_CONTEXT::STATE fs = *FoundState, * p = NULL;
|
||||
PPM_CONTEXT* pc, * Successor;
|
||||
unsigned int ns1, ns, cf, sf, s0;
|
||||
if (fs.Freq < MAX_FREQ / 4 && MinContext->Suffix != 0)
|
||||
if (fs.Freq < MAX_FREQ / 4 && MinContext->Suffix != 0)
|
||||
{
|
||||
pc = GetContextNoCheck(MinContext->Suffix);
|
||||
|
||||
if (pc->NumStats != 1)
|
||||
if (pc->NumStats != 1)
|
||||
{
|
||||
if ((p = GetStateNoCheck(pc->Stats))->Symbol != fs.Symbol)
|
||||
if ((p = GetStateNoCheck(pc->Stats))->Symbol != fs.Symbol)
|
||||
{
|
||||
do { p++; } while (p->Symbol != fs.Symbol);
|
||||
if (p[0].Freq >= p[-1].Freq)
|
||||
if (p[0].Freq >= p[-1].Freq)
|
||||
{
|
||||
_PPMD_SWAP(p[0],p[-1]);
|
||||
_PPMD_SWAP(p[0],p[-1]);
|
||||
p--;
|
||||
}
|
||||
}
|
||||
if (p->Freq < MAX_FREQ-9)
|
||||
if (p->Freq < MAX_FREQ-9)
|
||||
{
|
||||
p->Freq += 2;
|
||||
p->Freq += 2;
|
||||
pc->SummFreq += 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
p = &(pc->oneState());
|
||||
p = &(pc->oneState());
|
||||
p->Freq = (Byte)(p->Freq + ((p->Freq < 32) ? 1 : 0));
|
||||
}
|
||||
}
|
||||
if ( !OrderFall )
|
||||
if ( !OrderFall )
|
||||
{
|
||||
MinContext = MaxContext = CreateSuccessors(true, p);
|
||||
FoundState->SetSuccessor(SubAllocator.GetOffset(MinContext));
|
||||
if (MinContext == 0)
|
||||
if (MinContext == 0)
|
||||
goto RESTART_MODEL;
|
||||
return;
|
||||
}
|
||||
*SubAllocator.pText++ = fs.Symbol;
|
||||
*SubAllocator.pText++ = fs.Symbol;
|
||||
Successor = (PPM_CONTEXT*) SubAllocator.pText;
|
||||
if (SubAllocator.pText >= SubAllocator.UnitsStart)
|
||||
if (SubAllocator.pText >= SubAllocator.UnitsStart)
|
||||
goto RESTART_MODEL;
|
||||
if (fs.GetSuccessor() != 0)
|
||||
if (fs.GetSuccessor() != 0)
|
||||
{
|
||||
if ((Byte *)GetContext(fs.GetSuccessor()) <= SubAllocator.pText)
|
||||
{
|
||||
@@ -296,60 +296,60 @@ NO_LOOP:
|
||||
if (cs == NULL)
|
||||
goto RESTART_MODEL;
|
||||
}
|
||||
if ( !--OrderFall )
|
||||
if ( !--OrderFall )
|
||||
{
|
||||
Successor = GetContext(fs.GetSuccessor());
|
||||
SubAllocator.pText -= (MaxContext != MinContext);
|
||||
}
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
FoundState->SetSuccessor(SubAllocator.GetOffsetNoCheck(Successor));
|
||||
FoundState->SetSuccessor(SubAllocator.GetOffsetNoCheck(Successor));
|
||||
fs.SetSuccessor(SubAllocator.GetOffsetNoCheck(MinContext));
|
||||
}
|
||||
s0 = MinContext->SummFreq - (ns = MinContext->NumStats) - (fs.Freq - 1);
|
||||
for (pc = MaxContext; pc != MinContext; pc = GetContext(pc->Suffix))
|
||||
for (pc = MaxContext; pc != MinContext; pc = GetContext(pc->Suffix))
|
||||
{
|
||||
if ((ns1 = pc->NumStats) != 1)
|
||||
if ((ns1 = pc->NumStats) != 1)
|
||||
{
|
||||
if ((ns1 & 1) == 0)
|
||||
if ((ns1 & 1) == 0)
|
||||
{
|
||||
void *ppp = SubAllocator.ExpandUnits(GetState(pc->Stats), ns1 >> 1);
|
||||
pc->Stats = SubAllocator.GetOffset(ppp);
|
||||
if (!ppp)
|
||||
if (!ppp)
|
||||
goto RESTART_MODEL;
|
||||
}
|
||||
pc->SummFreq = (UInt16)(pc->SummFreq + (2 * ns1 < ns) + 2 * ((4 * ns1 <= ns) &
|
||||
(pc->SummFreq <= 8 * ns1)));
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
p = (PPM_CONTEXT::STATE*) SubAllocator.AllocUnits(1);
|
||||
if ( !p )
|
||||
if ( !p )
|
||||
goto RESTART_MODEL;
|
||||
*p = pc->oneState();
|
||||
*p = pc->oneState();
|
||||
pc->Stats = SubAllocator.GetOffsetNoCheck(p);
|
||||
if (p->Freq < MAX_FREQ / 4 - 1)
|
||||
if (p->Freq < MAX_FREQ / 4 - 1)
|
||||
p->Freq <<= 1;
|
||||
else
|
||||
else
|
||||
p->Freq = MAX_FREQ - 4;
|
||||
pc->SummFreq = (UInt16)(p->Freq + InitEsc + (ns > 3));
|
||||
}
|
||||
cf = 2 * fs.Freq * (pc->SummFreq+6);
|
||||
cf = 2 * fs.Freq * (pc->SummFreq+6);
|
||||
sf = s0 + pc->SummFreq;
|
||||
if (cf < 6 * sf)
|
||||
if (cf < 6 * sf)
|
||||
{
|
||||
cf = 1 + (cf > sf)+(cf >= 4 * sf);
|
||||
pc->SummFreq += 3;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
cf = 4 + (cf >= 9 * sf) + (cf >= 12 * sf) + (cf >= 15 * sf);
|
||||
pc->SummFreq = (UInt16)(pc->SummFreq + cf);
|
||||
}
|
||||
p = GetState(pc->Stats) + ns1;
|
||||
p = GetState(pc->Stats) + ns1;
|
||||
p->SetSuccessor(SubAllocator.GetOffset(Successor));
|
||||
p->Symbol = fs.Symbol;
|
||||
p->Symbol = fs.Symbol;
|
||||
p->Freq = (Byte)cf;
|
||||
pc->NumStats = (UInt16)++ns1;
|
||||
}
|
||||
@@ -357,27 +357,27 @@ NO_LOOP:
|
||||
return;
|
||||
RESTART_MODEL:
|
||||
RestartModelRare();
|
||||
EscCount = 0;
|
||||
EscCount = 0;
|
||||
PrintCount = 0xFF;
|
||||
}
|
||||
|
||||
void ClearMask()
|
||||
{
|
||||
EscCount = 1;
|
||||
EscCount = 1;
|
||||
memset(CharMask, 0, sizeof(CharMask));
|
||||
// if (++PrintCount == 0)
|
||||
// if (++PrintCount == 0)
|
||||
// PrintInfo(DecodedFile,EncodedFile);
|
||||
}
|
||||
|
||||
void update1(PPM_CONTEXT::STATE* p)
|
||||
{
|
||||
(FoundState = p)->Freq += 4;
|
||||
(FoundState = p)->Freq += 4;
|
||||
MinContext->SummFreq += 4;
|
||||
if (p[0].Freq > p[-1].Freq)
|
||||
if (p[0].Freq > p[-1].Freq)
|
||||
{
|
||||
_PPMD_SWAP(p[0],p[-1]);
|
||||
_PPMD_SWAP(p[0],p[-1]);
|
||||
FoundState = --p;
|
||||
if (p->Freq > MAX_FREQ)
|
||||
if (p->Freq > MAX_FREQ)
|
||||
rescale();
|
||||
}
|
||||
}
|
||||
@@ -387,27 +387,27 @@ RESTART_MODEL:
|
||||
{
|
||||
(FoundState = p)->Freq += 4;
|
||||
MinContext->SummFreq += 4;
|
||||
if (p->Freq > MAX_FREQ)
|
||||
if (p->Freq > MAX_FREQ)
|
||||
rescale();
|
||||
EscCount++;
|
||||
EscCount++;
|
||||
RunLength = InitRL;
|
||||
}
|
||||
|
||||
SEE2_CONTEXT* makeEscFreq2(int Diff, UInt32 &scale)
|
||||
{
|
||||
SEE2_CONTEXT* psee2c;
|
||||
if (MinContext->NumStats != 256)
|
||||
if (MinContext->NumStats != 256)
|
||||
{
|
||||
psee2c = SEE2Cont[NS2Indx[Diff-1]] +
|
||||
psee2c = SEE2Cont[NS2Indx[Diff-1]] +
|
||||
(Diff < (GetContext(MinContext->Suffix))->NumStats - MinContext->NumStats) +
|
||||
2 * (MinContext->SummFreq < 11 * MinContext->NumStats) +
|
||||
4 * (NumMasked > Diff) +
|
||||
2 * (MinContext->SummFreq < 11 * MinContext->NumStats) +
|
||||
4 * (NumMasked > Diff) +
|
||||
HiBitsFlag;
|
||||
scale = psee2c->getMean();
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
psee2c = &DummySEE2Cont;
|
||||
psee2c = &DummySEE2Cont;
|
||||
scale = 1;
|
||||
}
|
||||
return psee2c;
|
||||
@@ -420,37 +420,37 @@ RESTART_MODEL:
|
||||
int OldNS = MinContext->NumStats, i = MinContext->NumStats - 1, Adder, EscFreq;
|
||||
PPM_CONTEXT::STATE* p1, * p;
|
||||
PPM_CONTEXT::STATE *stats = GetStateNoCheck(MinContext->Stats);
|
||||
for (p = FoundState; p != stats; p--)
|
||||
for (p = FoundState; p != stats; p--)
|
||||
_PPMD_SWAP(p[0], p[-1]);
|
||||
stats->Freq += 4;
|
||||
stats->Freq += 4;
|
||||
MinContext->SummFreq += 4;
|
||||
EscFreq = MinContext->SummFreq - p->Freq;
|
||||
EscFreq = MinContext->SummFreq - p->Freq;
|
||||
Adder = (OrderFall != 0);
|
||||
p->Freq = (Byte)((p->Freq + Adder) >> 1);
|
||||
MinContext->SummFreq = p->Freq;
|
||||
do
|
||||
do
|
||||
{
|
||||
EscFreq -= (++p)->Freq;
|
||||
p->Freq = (Byte)((p->Freq + Adder) >> 1);
|
||||
MinContext->SummFreq = (UInt16)(MinContext->SummFreq + p->Freq);
|
||||
if (p[0].Freq > p[-1].Freq)
|
||||
if (p[0].Freq > p[-1].Freq)
|
||||
{
|
||||
PPM_CONTEXT::STATE tmp = *(p1 = p);
|
||||
do
|
||||
{
|
||||
p1[0] = p1[-1];
|
||||
}
|
||||
do
|
||||
{
|
||||
p1[0] = p1[-1];
|
||||
}
|
||||
while (--p1 != stats && tmp.Freq > p1[-1].Freq);
|
||||
*p1 = tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
while ( --i );
|
||||
if (p->Freq == 0)
|
||||
if (p->Freq == 0)
|
||||
{
|
||||
do { i++; } while ((--p)->Freq == 0);
|
||||
EscFreq += i;
|
||||
MinContext->NumStats = (UInt16)(MinContext->NumStats - i);
|
||||
if (MinContext->NumStats == 1)
|
||||
if (MinContext->NumStats == 1)
|
||||
{
|
||||
PPM_CONTEXT::STATE tmp = *stats;
|
||||
do { tmp.Freq = (Byte)(tmp.Freq - (tmp.Freq >> 1)); EscFreq >>= 1; } while (EscFreq > 1);
|
||||
@@ -471,10 +471,10 @@ RESTART_MODEL:
|
||||
PPM_CONTEXT *c = GetContext(FoundState->GetSuccessor());
|
||||
if (!OrderFall && (Byte *)c > SubAllocator.pText)
|
||||
MinContext = MaxContext = c;
|
||||
else
|
||||
else
|
||||
{
|
||||
UpdateModel();
|
||||
if (EscCount == 0)
|
||||
if (EscCount == 0)
|
||||
ClearMask();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,23 +30,23 @@ struct CDecodeInfo: public CInfo
|
||||
{
|
||||
void DecodeBinSymbol(CRangeDecoderVirt *rangeDecoder)
|
||||
{
|
||||
PPM_CONTEXT::STATE& rs = MinContext->oneState();
|
||||
PPM_CONTEXT::STATE& rs = MinContext->oneState();
|
||||
UInt16& bs = GetBinSumm(rs, GetContextNoCheck(MinContext->Suffix)->NumStats);
|
||||
if (rangeDecoder->DecodeBit(bs, TOT_BITS) == 0)
|
||||
if (rangeDecoder->DecodeBit(bs, TOT_BITS) == 0)
|
||||
{
|
||||
FoundState = &rs;
|
||||
rs.Freq = (Byte)(rs.Freq + (rs.Freq < 128 ? 1: 0));
|
||||
bs = (UInt16)(bs + INTERVAL - GET_MEAN(bs, PERIOD_BITS, 2));
|
||||
PrevSuccess = 1;
|
||||
RunLength++;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
bs = (UInt16)(bs - GET_MEAN(bs, PERIOD_BITS, 2));
|
||||
InitEsc = ExpEscape[bs >> 10];
|
||||
NumMasked = 1;
|
||||
NumMasked = 1;
|
||||
CharMask[rs.Symbol] = EscCount;
|
||||
PrevSuccess = 0;
|
||||
PrevSuccess = 0;
|
||||
FoundState = NULL;
|
||||
}
|
||||
}
|
||||
@@ -55,12 +55,12 @@ struct CDecodeInfo: public CInfo
|
||||
{
|
||||
PPM_CONTEXT::STATE* p = GetStateNoCheck(MinContext->Stats);
|
||||
int i, count, hiCnt;
|
||||
if ((count = rangeDecoder->GetThreshold(MinContext->SummFreq)) < (hiCnt = p->Freq))
|
||||
if ((count = rangeDecoder->GetThreshold(MinContext->SummFreq)) < (hiCnt = p->Freq))
|
||||
{
|
||||
PrevSuccess = (2 * hiCnt > MinContext->SummFreq);
|
||||
RunLength += PrevSuccess;
|
||||
rangeDecoder->Decode(0, p->Freq); // MinContext->SummFreq);
|
||||
(FoundState = p)->Freq = (Byte)(hiCnt += 4);
|
||||
(FoundState = p)->Freq = (Byte)(hiCnt += 4);
|
||||
MinContext->SummFreq += 4;
|
||||
if (hiCnt > MAX_FREQ)
|
||||
rescale();
|
||||
@@ -69,12 +69,12 @@ struct CDecodeInfo: public CInfo
|
||||
PrevSuccess = 0;
|
||||
i = MinContext->NumStats - 1;
|
||||
while ((hiCnt += (++p)->Freq) <= count)
|
||||
if (--i == 0)
|
||||
if (--i == 0)
|
||||
{
|
||||
HiBitsFlag = HB2Flag[FoundState->Symbol];
|
||||
rangeDecoder->Decode(hiCnt, MinContext->SummFreq - hiCnt); // , MinContext->SummFreq);
|
||||
CharMask[p->Symbol] = EscCount;
|
||||
i = (NumMasked = MinContext->NumStats)-1;
|
||||
i = (NumMasked = MinContext->NumStats)-1;
|
||||
FoundState = NULL;
|
||||
do { CharMask[(--p)->Symbol] = EscCount; } while ( --i );
|
||||
return;
|
||||
@@ -91,57 +91,57 @@ struct CDecodeInfo: public CInfo
|
||||
SEE2_CONTEXT* psee2c = makeEscFreq2(i, freqSum);
|
||||
PPM_CONTEXT::STATE* ps[256], ** pps = ps, * p = GetStateNoCheck(MinContext->Stats)-1;
|
||||
hiCnt = 0;
|
||||
do
|
||||
do
|
||||
{
|
||||
do { p++; } while (CharMask[p->Symbol] == EscCount);
|
||||
hiCnt += p->Freq;
|
||||
hiCnt += p->Freq;
|
||||
*pps++ = p;
|
||||
}
|
||||
}
|
||||
while ( --i );
|
||||
|
||||
freqSum += hiCnt;
|
||||
count = rangeDecoder->GetThreshold(freqSum);
|
||||
|
||||
p = *(pps = ps);
|
||||
if (count < hiCnt)
|
||||
if (count < hiCnt)
|
||||
{
|
||||
hiCnt = 0;
|
||||
while ((hiCnt += p->Freq) <= count)
|
||||
while ((hiCnt += p->Freq) <= count)
|
||||
p=*++pps;
|
||||
rangeDecoder->Decode(hiCnt - p->Freq, p->Freq); // , freqSum);
|
||||
|
||||
psee2c->update();
|
||||
psee2c->update();
|
||||
update2(p);
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
rangeDecoder->Decode(hiCnt, freqSum - hiCnt); // , freqSum);
|
||||
|
||||
i = MinContext->NumStats - NumMasked;
|
||||
i = MinContext->NumStats - NumMasked;
|
||||
pps--;
|
||||
do { CharMask[(*++pps)->Symbol] = EscCount; } while ( --i );
|
||||
psee2c->Summ = (UInt16)(psee2c->Summ + freqSum);
|
||||
psee2c->Summ = (UInt16)(psee2c->Summ + freqSum);
|
||||
NumMasked = MinContext->NumStats;
|
||||
}
|
||||
}
|
||||
|
||||
int DecodeSymbol(CRangeDecoderVirt *rangeDecoder)
|
||||
{
|
||||
if (MinContext->NumStats != 1)
|
||||
if (MinContext->NumStats != 1)
|
||||
DecodeSymbol1(rangeDecoder);
|
||||
else
|
||||
else
|
||||
DecodeBinSymbol(rangeDecoder);
|
||||
while ( !FoundState )
|
||||
while ( !FoundState )
|
||||
{
|
||||
do
|
||||
do
|
||||
{
|
||||
OrderFall++;
|
||||
OrderFall++;
|
||||
MinContext = GetContext(MinContext->Suffix);
|
||||
if (MinContext == 0)
|
||||
if (MinContext == 0)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
while (MinContext->NumStats == NumMasked);
|
||||
DecodeSymbol2(rangeDecoder);
|
||||
DecodeSymbol2(rangeDecoder);
|
||||
}
|
||||
Byte symbol = FoundState->Symbol;
|
||||
NextContext();
|
||||
|
||||
@@ -27,7 +27,7 @@ STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *properties, UInt32 size
|
||||
|
||||
if (!_rangeDecoder.Create(1 << 20))
|
||||
return E_OUTOFMEMORY;
|
||||
if (!_info.SubAllocator.StartSubAllocator(_usedMemorySize))
|
||||
if (!_info.SubAllocator.StartSubAllocator(_usedMemorySize))
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
return S_OK;
|
||||
@@ -123,7 +123,7 @@ STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
|
||||
#else
|
||||
|
||||
#define PPMD_TRY_BEGIN try {
|
||||
#define PPMD_TRY_BEGIN try {
|
||||
#define PPMD_TRY_END } \
|
||||
catch(const CInBufferException &e) { return e.ErrorCode; } \
|
||||
catch(const COutBufferException &e) { return e.ErrorCode; } \
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
namespace NCompress {
|
||||
namespace NPPMD {
|
||||
|
||||
class CDecoder :
|
||||
class CDecoder :
|
||||
public ICompressCoder,
|
||||
public ICompressSetDecoderProperties2,
|
||||
#ifndef NO_READ_FROM_CODER
|
||||
@@ -43,9 +43,9 @@ public:
|
||||
|
||||
#ifndef NO_READ_FROM_CODER
|
||||
MY_UNKNOWN_IMP4(
|
||||
ICompressSetDecoderProperties2,
|
||||
ICompressSetInStream,
|
||||
ICompressSetOutStreamSize,
|
||||
ICompressSetDecoderProperties2,
|
||||
ICompressSetInStream,
|
||||
ICompressSetOutStreamSize,
|
||||
ISequentialInStream)
|
||||
#else
|
||||
MY_UNKNOWN_IMP1(
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
HRESULT Flush() { return _outStream.Flush(); }
|
||||
|
||||
STDMETHOD(CodeReal)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ struct CEncodeInfo: public CInfo
|
||||
|
||||
void EncodeBinSymbol(int symbol, NRangeCoder::CEncoder *rangeEncoder)
|
||||
{
|
||||
PPM_CONTEXT::STATE& rs = MinContext->oneState();
|
||||
PPM_CONTEXT::STATE& rs = MinContext->oneState();
|
||||
UInt16 &bs = GetBinSumm(rs, GetContextNoCheck(MinContext->Suffix)->NumStats);
|
||||
if (rs.Symbol == symbol)
|
||||
if (rs.Symbol == symbol)
|
||||
{
|
||||
FoundState = &rs;
|
||||
rs.Freq = (Byte)(rs.Freq + (rs.Freq < 128 ? 1: 0));
|
||||
@@ -24,15 +24,15 @@ struct CEncodeInfo: public CInfo
|
||||
bs = (UInt16)(bs + INTERVAL - GET_MEAN(bs, PERIOD_BITS, 2));
|
||||
PrevSuccess = 1;
|
||||
RunLength++;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
rangeEncoder->EncodeBit(bs, TOT_BITS, 1);
|
||||
bs = (UInt16)(bs - GET_MEAN(bs, PERIOD_BITS, 2));
|
||||
InitEsc = ExpEscape[bs >> 10];
|
||||
NumMasked = 1;
|
||||
NumMasked = 1;
|
||||
CharMask[rs.Symbol] = EscCount;
|
||||
PrevSuccess = 0;
|
||||
PrevSuccess = 0;
|
||||
FoundState = NULL;
|
||||
}
|
||||
}
|
||||
@@ -40,27 +40,27 @@ struct CEncodeInfo: public CInfo
|
||||
void EncodeSymbol1(int symbol, NRangeCoder::CEncoder *rangeEncoder)
|
||||
{
|
||||
PPM_CONTEXT::STATE* p = GetStateNoCheck(MinContext->Stats);
|
||||
if (p->Symbol == symbol)
|
||||
if (p->Symbol == symbol)
|
||||
{
|
||||
PrevSuccess = (2 * (p->Freq) > MinContext->SummFreq);
|
||||
RunLength += PrevSuccess;
|
||||
rangeEncoder->Encode(0, p->Freq, MinContext->SummFreq);
|
||||
(FoundState = p)->Freq += 4;
|
||||
(FoundState = p)->Freq += 4;
|
||||
MinContext->SummFreq += 4;
|
||||
if (p->Freq > MAX_FREQ)
|
||||
if (p->Freq > MAX_FREQ)
|
||||
rescale();
|
||||
return;
|
||||
}
|
||||
PrevSuccess = 0;
|
||||
int LoCnt = p->Freq, i = MinContext->NumStats - 1;
|
||||
while ((++p)->Symbol != symbol)
|
||||
while ((++p)->Symbol != symbol)
|
||||
{
|
||||
LoCnt += p->Freq;
|
||||
if (--i == 0)
|
||||
if (--i == 0)
|
||||
{
|
||||
HiBitsFlag = HB2Flag[FoundState->Symbol];
|
||||
CharMask[p->Symbol] = EscCount;
|
||||
i=(NumMasked = MinContext->NumStats)-1;
|
||||
i=(NumMasked = MinContext->NumStats)-1;
|
||||
FoundState = NULL;
|
||||
do { CharMask[(--p)->Symbol] = EscCount; } while ( --i );
|
||||
rangeEncoder->Encode(LoCnt, MinContext->SummFreq - LoCnt, MinContext->SummFreq);
|
||||
@@ -76,16 +76,16 @@ struct CEncodeInfo: public CInfo
|
||||
int hiCnt, i = MinContext->NumStats - NumMasked;
|
||||
UInt32 scale;
|
||||
SEE2_CONTEXT* psee2c = makeEscFreq2(i, scale);
|
||||
PPM_CONTEXT::STATE* p = GetStateNoCheck(MinContext->Stats) - 1;
|
||||
PPM_CONTEXT::STATE* p = GetStateNoCheck(MinContext->Stats) - 1;
|
||||
hiCnt = 0;
|
||||
do
|
||||
do
|
||||
{
|
||||
do { p++; } while (CharMask[p->Symbol] == EscCount);
|
||||
hiCnt += p->Freq;
|
||||
if (p->Symbol == symbol)
|
||||
if (p->Symbol == symbol)
|
||||
goto SYMBOL_FOUND;
|
||||
CharMask[p->Symbol] = EscCount;
|
||||
}
|
||||
}
|
||||
while ( --i );
|
||||
|
||||
rangeEncoder->Encode(hiCnt, scale, hiCnt + scale);
|
||||
@@ -98,40 +98,40 @@ SYMBOL_FOUND:
|
||||
|
||||
UInt32 highCount = hiCnt;
|
||||
UInt32 lowCount = highCount - p->Freq;
|
||||
if ( --i )
|
||||
if ( --i )
|
||||
{
|
||||
PPM_CONTEXT::STATE* p1 = p;
|
||||
do
|
||||
do
|
||||
{
|
||||
do { p1++; } while (CharMask[p1->Symbol] == EscCount);
|
||||
hiCnt += p1->Freq;
|
||||
}
|
||||
}
|
||||
while ( --i );
|
||||
}
|
||||
// SubRange.scale += hiCnt;
|
||||
scale += hiCnt;
|
||||
rangeEncoder->Encode(lowCount, highCount - lowCount, scale);
|
||||
psee2c->update();
|
||||
psee2c->update();
|
||||
update2(p);
|
||||
}
|
||||
|
||||
void EncodeSymbol(int c, NRangeCoder::CEncoder *rangeEncoder)
|
||||
{
|
||||
if (MinContext->NumStats != 1)
|
||||
EncodeSymbol1(c, rangeEncoder);
|
||||
else
|
||||
EncodeBinSymbol(c, rangeEncoder);
|
||||
while ( !FoundState )
|
||||
if (MinContext->NumStats != 1)
|
||||
EncodeSymbol1(c, rangeEncoder);
|
||||
else
|
||||
EncodeBinSymbol(c, rangeEncoder);
|
||||
while ( !FoundState )
|
||||
{
|
||||
do
|
||||
do
|
||||
{
|
||||
OrderFall++;
|
||||
OrderFall++;
|
||||
MinContext = GetContext(MinContext->Suffix);
|
||||
if (MinContext == 0)
|
||||
if (MinContext == 0)
|
||||
return; // S_OK;
|
||||
}
|
||||
}
|
||||
while (MinContext->NumStats == NumMasked);
|
||||
EncodeSymbol2(c, rangeEncoder);
|
||||
EncodeSymbol2(c, rangeEncoder);
|
||||
}
|
||||
NextContext();
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
namespace NCompress {
|
||||
namespace NPPMD {
|
||||
|
||||
const UInt32 kMinMemSize = (1 << 11);
|
||||
const UInt32 kMinMemSize = (1 << 11);
|
||||
const UInt32 kMinOrder = 2;
|
||||
|
||||
/*
|
||||
@@ -31,7 +31,7 @@ class CCounter
|
||||
{
|
||||
public:
|
||||
CCounter() {}
|
||||
~CCounter()
|
||||
~CCounter()
|
||||
{
|
||||
ofstream ofs("Res.dat");
|
||||
ofs << "innerEncode1 = " << setw(10) << g_NumInner << endl;
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
CCounter g_Counter;
|
||||
*/
|
||||
|
||||
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
|
||||
STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties)
|
||||
{
|
||||
for (UInt32 i = 0; i < numProperties; i++)
|
||||
@@ -75,7 +75,7 @@ STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs,
|
||||
}
|
||||
|
||||
STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream)
|
||||
{
|
||||
{
|
||||
const UInt32 kPropSize = 5;
|
||||
Byte properties[kPropSize];
|
||||
properties[0] = _order;
|
||||
@@ -95,7 +95,7 @@ CEncoder::CEncoder():
|
||||
|
||||
|
||||
HRESULT CEncoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 * /* inSize */, const UInt64 * /* outSize */,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
@@ -103,7 +103,7 @@ HRESULT CEncoder::CodeReal(ISequentialInStream *inStream,
|
||||
return E_OUTOFMEMORY;
|
||||
if (!_rangeEncoder.Create(1 << 20))
|
||||
return E_OUTOFMEMORY;
|
||||
if (!_info.SubAllocator.StartSubAllocator(_usedMemorySize))
|
||||
if (!_info.SubAllocator.StartSubAllocator(_usedMemorySize))
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
_inStream.SetStream(inStream);
|
||||
@@ -125,12 +125,12 @@ HRESULT CEncoder::CodeReal(ISequentialInStream *inStream,
|
||||
Byte symbol;
|
||||
if (!_inStream.ReadByte(symbol))
|
||||
{
|
||||
// here we can write End Mark for stream version.
|
||||
// here we can write End Mark for stream version.
|
||||
// In current version this feature is not used.
|
||||
// _info.EncodeSymbol(-1, &_rangeEncoder);
|
||||
// _info.EncodeSymbol(-1, &_rangeEncoder);
|
||||
return S_OK;
|
||||
}
|
||||
_info.EncodeSymbol(symbol, &_rangeEncoder);
|
||||
_info.EncodeSymbol(symbol, &_rangeEncoder);
|
||||
}
|
||||
while (--size != 0);
|
||||
if (progress != NULL)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
namespace NCompress {
|
||||
namespace NPPMD {
|
||||
|
||||
class CEncoder :
|
||||
class CEncoder :
|
||||
public ICompressCoder,
|
||||
public ICompressSetCoderProperties,
|
||||
public ICompressWriteCoderProperties,
|
||||
@@ -67,7 +67,7 @@ public:
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties);
|
||||
|
||||
STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
|
||||
#include "PPMDType.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
}
|
||||
|
||||
@@ -19,19 +19,19 @@ const UINT UNIT_SIZE=12, N_INDEXES=N1+N2+N3+N4;
|
||||
const UInt32 kExtraSize = (UNIT_SIZE * 3);
|
||||
const UInt32 kMaxMemBlockSize = 0xFFFFFFFF - kExtraSize;
|
||||
|
||||
struct MEM_BLK
|
||||
struct MEM_BLK
|
||||
{
|
||||
UInt16 Stamp, NU;
|
||||
UInt32 Next, Prev;
|
||||
void InsertAt(Byte *Base, UInt32 p)
|
||||
void InsertAt(Byte *Base, UInt32 p)
|
||||
{
|
||||
Prev = p;
|
||||
MEM_BLK *pp = (MEM_BLK *)(Base + p);
|
||||
Next = pp->Next;
|
||||
pp->Next = ((MEM_BLK *)(Base + Next))->Prev = (UInt32)((Byte *)this - Base);
|
||||
}
|
||||
void Remove(Byte *Base)
|
||||
{
|
||||
void Remove(Byte *Base)
|
||||
{
|
||||
((MEM_BLK *)(Base + Prev))->Next = Next;
|
||||
((MEM_BLK *)(Base + Next))->Prev = Prev;
|
||||
}
|
||||
@@ -71,13 +71,13 @@ public:
|
||||
MEM_BLK *GetBlk(UInt32 offset) const { return (MEM_BLK *)(Base + offset); }
|
||||
UInt32 *GetNode(UInt32 offset) const { return (UInt32 *)(Base + offset); }
|
||||
|
||||
void InsertNode(void* p, int indx)
|
||||
void InsertNode(void* p, int indx)
|
||||
{
|
||||
*(UInt32 *)p = FreeList[indx];
|
||||
FreeList[indx] = GetOffsetNoCheck(p);
|
||||
}
|
||||
|
||||
void* RemoveNode(int indx)
|
||||
void* RemoveNode(int indx)
|
||||
{
|
||||
UInt32 offset = FreeList[indx];
|
||||
UInt32 *p = GetNode(offset);
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
{
|
||||
int i, UDiff = Indx2Units[oldIndx] - Indx2Units[newIndx];
|
||||
Byte* p = ((Byte*)pv) + U2B(Indx2Units[newIndx]);
|
||||
if (Indx2Units[i = Units2Indx[UDiff-1]] != UDiff)
|
||||
if (Indx2Units[i = Units2Indx[UDiff-1]] != UDiff)
|
||||
{
|
||||
InsertNode(p, --i);
|
||||
p += U2B(i = Indx2Units[i]);
|
||||
@@ -103,7 +103,7 @@ public:
|
||||
UInt32 GetUsedMemory() const
|
||||
{
|
||||
UInt32 RetVal = SubAllocatorSize - (UInt32)(HiUnit - LoUnit) - (UInt32)(UnitsStart - pText);
|
||||
for (UInt32 i = 0; i < N_INDEXES; i++)
|
||||
for (UInt32 i = 0; i < N_INDEXES; i++)
|
||||
for (UInt32 pn = FreeList[i]; pn != 0; RetVal -= (UInt32)Indx2Units[i] * UNIT_SIZE)
|
||||
pn = *GetNode(pn);
|
||||
return (RetVal >> 2);
|
||||
@@ -111,9 +111,9 @@ public:
|
||||
|
||||
UInt32 GetSubAllocatorSize() const { return SubAllocatorSize; }
|
||||
|
||||
void StopSubAllocator()
|
||||
void StopSubAllocator()
|
||||
{
|
||||
if (SubAllocatorSize != 0)
|
||||
if (SubAllocatorSize != 0)
|
||||
{
|
||||
BigFree(Base);
|
||||
SubAllocatorSize = 0;
|
||||
@@ -123,7 +123,7 @@ public:
|
||||
|
||||
bool StartSubAllocator(UInt32 size)
|
||||
{
|
||||
if (SubAllocatorSize == size)
|
||||
if (SubAllocatorSize == size)
|
||||
return true;
|
||||
StopSubAllocator();
|
||||
if (size == 0)
|
||||
@@ -134,7 +134,7 @@ public:
|
||||
return false;
|
||||
HeapStart = Base + UNIT_SIZE; // we need such code to support NULL;
|
||||
}
|
||||
SubAllocatorSize = size;
|
||||
SubAllocatorSize = size;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ public:
|
||||
for (k++; i < N1 + N2 + N3 ;i++,k += 3) Indx2Units[i] = (Byte)k;
|
||||
for (k++; i < N1 + N2 + N3 + N4; i++, k += 4) Indx2Units[i] = (Byte)k;
|
||||
GlueCount = 0;
|
||||
for (k = i = 0; k < 128; k++)
|
||||
for (k = i = 0; k < 128; k++)
|
||||
{
|
||||
i += (Indx2Units[i] < k+1);
|
||||
Units2Indx[k] = (Byte)i;
|
||||
@@ -173,7 +173,7 @@ public:
|
||||
ps0->Next = ps0->Prev = s0;
|
||||
|
||||
for (i = 0; i < N_INDEXES; i++)
|
||||
while (FreeList[i] != 0)
|
||||
while (FreeList[i] != 0)
|
||||
{
|
||||
MEM_BLK *pp = (MEM_BLK *)RemoveNode(i);
|
||||
pp->InsertAt(Base, s0);
|
||||
@@ -192,14 +192,14 @@ public:
|
||||
pp->NU = (UInt16)(pp->NU + pp1->NU);
|
||||
}
|
||||
}
|
||||
while ((p = ps0->Next) != s0)
|
||||
while ((p = ps0->Next) != s0)
|
||||
{
|
||||
MEM_BLK *pp = GetBlk(p);
|
||||
pp->Remove(Base);
|
||||
int sz;
|
||||
for (sz = pp->NU; sz > 128; sz -= 128, p += 128 * UNIT_SIZE)
|
||||
InsertNode(Base + p, N_INDEXES - 1);
|
||||
if (Indx2Units[i = Units2Indx[sz-1]] != sz)
|
||||
if (Indx2Units[i = Units2Indx[sz-1]] != sz)
|
||||
{
|
||||
int k = sz - Indx2Units[--i];
|
||||
InsertNode(Base + p + (sz - k) * UNIT_SIZE, k - 1);
|
||||
@@ -209,7 +209,7 @@ public:
|
||||
}
|
||||
void* AllocUnitsRare(int indx)
|
||||
{
|
||||
if ( !GlueCount )
|
||||
if ( !GlueCount )
|
||||
{
|
||||
GlueCount = 255;
|
||||
GlueFreeBlocks();
|
||||
@@ -217,11 +217,11 @@ public:
|
||||
return RemoveNode(indx);
|
||||
}
|
||||
int i = indx;
|
||||
do
|
||||
do
|
||||
{
|
||||
if (++i == N_INDEXES)
|
||||
if (++i == N_INDEXES)
|
||||
{
|
||||
GlueCount--;
|
||||
GlueCount--;
|
||||
i = U2B(Indx2Units[indx]);
|
||||
return (UnitsStart - pText > i) ? (UnitsStart -= i) : (NULL);
|
||||
}
|
||||
@@ -259,9 +259,9 @@ public:
|
||||
if (i0 == i1)
|
||||
return oldPtr;
|
||||
void* ptr = AllocUnits(oldNU + 1);
|
||||
if (ptr)
|
||||
if (ptr)
|
||||
{
|
||||
memcpy(ptr, oldPtr, U2B(oldNU));
|
||||
memcpy(ptr, oldPtr, U2B(oldNU));
|
||||
InsertNode(oldPtr, i0);
|
||||
}
|
||||
return ptr;
|
||||
@@ -272,14 +272,14 @@ public:
|
||||
int i0 = Units2Indx[oldNU - 1], i1 = Units2Indx[newNU - 1];
|
||||
if (i0 == i1)
|
||||
return oldPtr;
|
||||
if (FreeList[i1] != 0)
|
||||
if (FreeList[i1] != 0)
|
||||
{
|
||||
void* ptr = RemoveNode(i1);
|
||||
memcpy(ptr, oldPtr, U2B(newNU));
|
||||
InsertNode(oldPtr,i0);
|
||||
InsertNode(oldPtr,i0);
|
||||
return ptr;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
{
|
||||
SplitBlock(oldPtr, i0, i1);
|
||||
return oldPtr;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Written and distributed to public domain by Dmitry Shkarin 1997, *
|
||||
* 1999-2001 *
|
||||
* Contents: compilation parameters and miscelaneous definitions *
|
||||
* Comments: system & compiler dependent file
|
||||
* Comments: system & compiler dependent file
|
||||
|
||||
* modified by Igor Pavlov (2004-08-29).
|
||||
****************************************************************************/
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
@@ -62,7 +62,7 @@ HRESULT CDecoder::CodeSpec(UInt32 curSize)
|
||||
_outWindowStream.PutByte(b);
|
||||
curSize--;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
selector -= kNumLitSelectors;
|
||||
unsigned int len = selector + kMatchMinLen;
|
||||
@@ -105,7 +105,7 @@ HRESULT CDecoder::CodeSpec(UInt32 curSize)
|
||||
}
|
||||
|
||||
HRESULT CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
@@ -134,7 +134,7 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
UInt64 nowPos64 = _outWindowStream.GetProcessedSize() - start;
|
||||
RINOK(progress->SetRatioInfo(&inSize, &nowPos64));
|
||||
}
|
||||
}
|
||||
}
|
||||
flusher.NeedFlush = false;
|
||||
return Flush();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public:
|
||||
void Init()
|
||||
{
|
||||
m_Stream.Init();
|
||||
m_Value = 0x10000;
|
||||
m_Value = 0x10000;
|
||||
}
|
||||
|
||||
UInt64 GetProcessedSize() const { return m_Stream.GetProcessedSize(); }
|
||||
@@ -45,7 +45,7 @@ public:
|
||||
{
|
||||
UInt32 res = 0;
|
||||
do
|
||||
res = (res << 1) | ReadBit();
|
||||
res = (res << 1) | ReadBit();
|
||||
while(--numBits != 0);
|
||||
return res;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public:
|
||||
|
||||
UInt64 GetProcessedSize() const { return Stream.GetProcessedSize(); }
|
||||
|
||||
UInt32 GetThreshold(UInt32 total) const
|
||||
UInt32 GetThreshold(UInt32 total) const
|
||||
{
|
||||
return ((Code + 1) * total - 1) / Range; // & 0xFFFF is not required;
|
||||
}
|
||||
@@ -111,9 +111,9 @@ public:
|
||||
Low += offset;
|
||||
for (;;)
|
||||
{
|
||||
if ((Low & 0x8000) != (high & 0x8000))
|
||||
if ((Low & 0x8000) != (high & 0x8000))
|
||||
{
|
||||
if ((Low & 0x4000) == 0 || (high & 0x4000) != 0)
|
||||
if ((Low & 0x4000) == 0 || (high & 0x4000) != 0)
|
||||
break;
|
||||
Low &= 0x3FFF;
|
||||
high |= 0x4000;
|
||||
@@ -156,7 +156,7 @@ public:
|
||||
unsigned int i;
|
||||
for (i = 1; Freqs[i] > threshold; i++);
|
||||
rangeDecoder->Decode(Freqs[i], Freqs[i - 1], Freqs[0]);
|
||||
unsigned int res = Values[--i];
|
||||
unsigned int res = Values[--i];
|
||||
do
|
||||
Freqs[i] += kUpdateStep;
|
||||
while(i-- != 0);
|
||||
@@ -201,7 +201,7 @@ public:
|
||||
|
||||
}
|
||||
|
||||
class CDecoder:
|
||||
class CDecoder:
|
||||
public ICompressCoder,
|
||||
public ICompressSetInStream,
|
||||
public ICompressSetOutStreamSize,
|
||||
@@ -231,7 +231,7 @@ class CDecoder:
|
||||
HRESULT CodeSpec(UInt32 size);
|
||||
public:
|
||||
MY_UNKNOWN_IMP2(
|
||||
ICompressSetInStream,
|
||||
ICompressSetInStream,
|
||||
ICompressSetOutStreamSize)
|
||||
|
||||
void ReleaseStreams()
|
||||
@@ -246,15 +246,15 @@ public:
|
||||
public:
|
||||
bool NeedFlush;
|
||||
CDecoderFlusher(CDecoder *decoder): _decoder(decoder), NeedFlush(true) {}
|
||||
~CDecoderFlusher()
|
||||
{
|
||||
~CDecoderFlusher()
|
||||
{
|
||||
if (NeedFlush)
|
||||
_decoder->Flush();
|
||||
_decoder->ReleaseStreams();
|
||||
_decoder->ReleaseStreams();
|
||||
}
|
||||
};
|
||||
|
||||
HRESULT Flush() { return _outWindowStream.Flush(); }
|
||||
HRESULT Flush() { return _outWindowStream.Flush(); }
|
||||
|
||||
HRESULT CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
|
||||
void FlushData()
|
||||
{
|
||||
// Low += 1;
|
||||
// Low += 1;
|
||||
for(int i = 0; i < 5; i++)
|
||||
ShiftLow();
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
|
||||
void ShiftLow()
|
||||
{
|
||||
if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0)
|
||||
if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0)
|
||||
{
|
||||
Byte temp = _cache;
|
||||
do
|
||||
@@ -65,10 +65,10 @@ public:
|
||||
temp = 0xFF;
|
||||
}
|
||||
while(--_cacheSize != 0);
|
||||
_cache = (Byte)((UInt32)Low >> 24);
|
||||
}
|
||||
_cacheSize++;
|
||||
Low = (UInt32)Low << 8;
|
||||
_cache = (Byte)((UInt32)Low >> 24);
|
||||
}
|
||||
_cacheSize++;
|
||||
Low = (UInt32)Low << 8;
|
||||
}
|
||||
|
||||
void EncodeDirectBits(UInt32 value, int numBits)
|
||||
@@ -149,7 +149,7 @@ public:
|
||||
UInt32 DecodeDirectBits(int numTotalBits)
|
||||
{
|
||||
UInt32 range = Range;
|
||||
UInt32 code = Code;
|
||||
UInt32 code = Code;
|
||||
UInt32 result = 0;
|
||||
for (int i = numTotalBits; i != 0; i--)
|
||||
{
|
||||
@@ -169,7 +169,7 @@ public:
|
||||
if (range < kTopValue)
|
||||
{
|
||||
code = (code << 8) | Stream.ReadByte();
|
||||
range <<= 8;
|
||||
range <<= 8;
|
||||
}
|
||||
}
|
||||
Range = range;
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace NRangeCoder {
|
||||
|
||||
UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
|
||||
|
||||
struct CPriceTables { CPriceTables()
|
||||
struct CPriceTables { CPriceTables()
|
||||
{
|
||||
for (UInt32 i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits))
|
||||
{
|
||||
|
||||
@@ -108,7 +108,7 @@ public:
|
||||
};
|
||||
|
||||
template <int numMoveBits>
|
||||
void ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models,
|
||||
void ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models,
|
||||
CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol)
|
||||
{
|
||||
UInt32 modelIndex = 1;
|
||||
@@ -122,7 +122,7 @@ void ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models,
|
||||
}
|
||||
|
||||
template <int numMoveBits>
|
||||
UInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models,
|
||||
UInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models,
|
||||
UInt32 NumBitLevels, UInt32 symbol)
|
||||
{
|
||||
UInt32 price = 0;
|
||||
@@ -138,7 +138,7 @@ UInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models,
|
||||
}
|
||||
|
||||
template <int numMoveBits>
|
||||
UInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models,
|
||||
UInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models,
|
||||
CDecoder *rangeDecoder, int NumBitLevels)
|
||||
{
|
||||
UInt32 modelIndex = 1;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#define RC_INIT_VAR \
|
||||
UInt32 range = rangeDecoder->Range; \
|
||||
UInt32 code = rangeDecoder->Code;
|
||||
UInt32 code = rangeDecoder->Code;
|
||||
|
||||
#define RC_FLUSH_VAR \
|
||||
rangeDecoder->Range = range; \
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Rar1Decoder.cpp
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// a program that creates RAR archives
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Rar15Decoder.h
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// a program that creates RAR archives
|
||||
|
||||
#ifndef __RAR10_DECODER_H
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Rar2Decoder.cpp
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// a program that creates RAR archives
|
||||
|
||||
#include "StdAfx.h"
|
||||
@@ -56,7 +56,7 @@ Byte CFilter::Decode(int &channelDelta, Byte deltaByte)
|
||||
case 1: if (K1 >= -16) K1--; break;
|
||||
case 2: if (K1 < 16) K1++; break;
|
||||
case 3: if (K2 >= -16) K2--; break;
|
||||
case 4: if (K2 < 16) K2++; break;
|
||||
case 4: if (K2 < 16) K2++; break;
|
||||
case 5: if (K3 >= -16) K3--; break;
|
||||
case 6: if (K3 < 16) K3++; break;
|
||||
case 7: if (K4 >= -16) K4--; break;
|
||||
@@ -143,7 +143,7 @@ bool CDecoder::ReadTables(void)
|
||||
num = ReadBits(3) + 3;
|
||||
else if (number == kTableLevel0Number2)
|
||||
num = ReadBits(7) + 11;
|
||||
else
|
||||
else
|
||||
return false;
|
||||
for (;num > 0 && i < numLevels; num--)
|
||||
newLevels[i++] = 0;
|
||||
@@ -170,8 +170,8 @@ bool CDecoder::ReadLastTables()
|
||||
// it differs a little from pure RAR sources;
|
||||
// UInt64 ttt = m_InBitStream.GetProcessedSize() + 2;
|
||||
// + 2 works for: return 0xFF; in CInBuffer::ReadByte.
|
||||
if (m_InBitStream.GetProcessedSize() + 7 <= m_PackSize) // test it: probably incorrect;
|
||||
// if (m_InBitStream.GetProcessedSize() + 2 <= m_PackSize) // test it: probably incorrect;
|
||||
if (m_InBitStream.GetProcessedSize() + 7 <= m_PackSize) // test it: probably incorrect;
|
||||
// if (m_InBitStream.GetProcessedSize() + 2 <= m_PackSize) // test it: probably incorrect;
|
||||
if (m_AudioMode)
|
||||
{
|
||||
UInt32 symbol = m_MMDecoders[m_MmFilter.CurrentChannel].DecodeSymbol(&m_InBitStream);
|
||||
@@ -180,7 +180,7 @@ bool CDecoder::ReadLastTables()
|
||||
if (symbol >= kMMTableSize)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
UInt32 number = m_MainDecoder.DecodeSymbol(&m_InBitStream);
|
||||
if (number == kReadTableNumber)
|
||||
@@ -239,7 +239,7 @@ bool CDecoder::DecodeLz(Int32 pos)
|
||||
else if (number >= kMatchNumber)
|
||||
{
|
||||
number -= kMatchNumber;
|
||||
length = kNormalMatchMinLen + UInt32(kLenStart[number]) +
|
||||
length = kNormalMatchMinLen + UInt32(kLenStart[number]) +
|
||||
m_InBitStream.ReadBits(kLenDirectBits[number]);
|
||||
number = m_DistDecoder.DecodeSymbol(&m_InBitStream);
|
||||
if (number >= kDistTableSize)
|
||||
@@ -280,7 +280,7 @@ bool CDecoder::DecodeLz(Int32 pos)
|
||||
else if (number < kReadTableNumber)
|
||||
{
|
||||
number -= kLen2Number;
|
||||
distance = kLen2DistStarts[number] +
|
||||
distance = kLen2DistStarts[number] +
|
||||
m_InBitStream.ReadBits(kLen2DistDirectBits[number]);
|
||||
length = 2;
|
||||
}
|
||||
@@ -324,7 +324,7 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
InitStructures();
|
||||
if (unPackSize == 0)
|
||||
{
|
||||
if (m_InBitStream.GetProcessedSize() + 2 <= m_PackSize) // test it: probably incorrect;
|
||||
if (m_InBitStream.GetProcessedSize() + 2 <= m_PackSize) // test it: probably incorrect;
|
||||
if (!ReadTables())
|
||||
return S_FALSE;
|
||||
return S_OK;
|
||||
@@ -340,7 +340,7 @@ HRESULT CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
if (blockSize > unPackSize - pos)
|
||||
blockSize = (UInt32)(unPackSize - pos);
|
||||
UInt64 blockStartPos = m_OutWindowStream.GetProcessedSize();
|
||||
if (m_AudioMode)
|
||||
if (m_AudioMode)
|
||||
{
|
||||
if (!DecodeMm(blockSize))
|
||||
return S_FALSE;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Rar2Decoder.h
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// a program that creates RAR archives
|
||||
|
||||
#ifndef __RAR2DECODER_H
|
||||
@@ -67,9 +67,9 @@ const UInt32 kDistLimit2 = 0x101 - 1;
|
||||
const UInt32 kDistLimit3 = 0x2000 - 1;
|
||||
const UInt32 kDistLimit4 = 0x40000 - 1;
|
||||
|
||||
const UInt32 kMatchMaxLen = 255 + 2;
|
||||
const UInt32 kMatchMaxLenMax = 255 + 5;
|
||||
const UInt32 kNormalMatchMinLen = 3;
|
||||
const UInt32 kMatchMaxLen = 255 + 2;
|
||||
const UInt32 kMatchMaxLenMax = 255 + 5;
|
||||
const UInt32 kNormalMatchMinLen = 3;
|
||||
|
||||
namespace NMultimedia {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Rar3Decoder.cpp
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// a program that creates RAR archives
|
||||
|
||||
#include "StdAfx.h"
|
||||
@@ -19,7 +19,7 @@ static const UInt32 kSymbolLen2 = kSymbolRep + kNumReps;
|
||||
static const Byte kLenStart[kLenTableSize] = {0,1,2,3,4,5,6,7,8,10,12,14,16,20,24,28,32,40,48,56,64,80,96,112,128,160,192,224};
|
||||
static const Byte kLenDirectBits[kLenTableSize] = {0,0,0,0,0,0,0,0,1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5};
|
||||
|
||||
static const Byte kDistDirectBits[kDistTableSize] =
|
||||
static const Byte kDistDirectBits[kDistTableSize] =
|
||||
{0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,
|
||||
16,16,16,16,16,16,16,16,16,16,16,16,16,16,
|
||||
18,18,18,18,18,18,18,18,18,18,18,18};
|
||||
@@ -32,12 +32,12 @@ static const Byte kLen2DistDirectBits[kNumLen2Symbols]={2,2,3, 4, 5, 6, 6, 6};
|
||||
static const UInt32 kDistLimit3 = 0x2000 - 2;
|
||||
static const UInt32 kDistLimit4 = 0x40000 - 2;
|
||||
|
||||
static const UInt32 kNormalMatchMinLen = 3;
|
||||
static const UInt32 kNormalMatchMinLen = 3;
|
||||
|
||||
static const UInt32 kVmDataSizeMax = 1 << 16;
|
||||
static const UInt32 kVmCodeSizeMax = 1 << 16;
|
||||
|
||||
CDecoder::CDecoder():
|
||||
CDecoder::CDecoder():
|
||||
_window(0),
|
||||
_winPos(0),
|
||||
_wrPtr(0),
|
||||
@@ -382,7 +382,7 @@ HRESULT CDecoder::InitPPM()
|
||||
// SubAlloc.StartSubAllocator(MaxMB+1);
|
||||
// StartModelRare(maxOrder);
|
||||
|
||||
if (!_ppm.SubAllocator.StartSubAllocator((maxMB + 1) << 20))
|
||||
if (!_ppm.SubAllocator.StartSubAllocator((maxMB + 1) << 20))
|
||||
return E_OUTOFMEMORY;
|
||||
_ppm.MaxOrder = 0;
|
||||
_ppm.StartModelRare(maxOrder);
|
||||
@@ -667,7 +667,7 @@ HRESULT CDecoder::DecodeLZ(bool &keepDecompressing)
|
||||
return S_FALSE;
|
||||
length = 2 + kLenStart[number] + m_InBitStream.ReadBits(kLenDirectBits[number]);
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
rep3 = rep2;
|
||||
rep2 = rep1;
|
||||
@@ -709,7 +709,7 @@ HRESULT CDecoder::DecodeLZ(bool &keepDecompressing)
|
||||
PrevAlignCount = kNumAlignReps;
|
||||
rep0 += PrevAlignBits;
|
||||
}
|
||||
else
|
||||
else
|
||||
return S_FALSE;
|
||||
}
|
||||
}
|
||||
@@ -784,8 +784,8 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
if (inSize == NULL || outSize == NULL)
|
||||
return E_INVALIDARG;
|
||||
|
||||
@@ -815,11 +815,11 @@ STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream,
|
||||
|
||||
CCoderReleaser coderReleaser(this);
|
||||
_unpackSize = *outSize;
|
||||
return CodeReal(progress);
|
||||
return CodeReal(progress);
|
||||
}
|
||||
catch(const CInBufferException &e) { return e.ErrorCode; }
|
||||
catch(...) { return S_FALSE; }
|
||||
// CNewException is possible here. But probably CNewException is caused
|
||||
// CNewException is possible here. But probably CNewException is caused
|
||||
// by error in data stream.
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Rar3Decoder.h
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// a program that creates RAR archives
|
||||
|
||||
#ifndef __RAR3DECODER_H
|
||||
@@ -50,11 +50,11 @@ public:
|
||||
m_Stream.Init();
|
||||
m_BitPos = 0;
|
||||
m_Value = 0;
|
||||
// m_BitPos = kNumBigValueBits;
|
||||
// m_BitPos = kNumBigValueBits;
|
||||
// Normalize();
|
||||
}
|
||||
|
||||
UInt64 GetProcessedSize() const
|
||||
UInt64 GetProcessedSize() const
|
||||
{ return m_Stream.GetProcessedSize() - (m_BitPos) / 8; }
|
||||
UInt32 GetBitPosition() const { return ((8 - m_BitPos) & 7); }
|
||||
|
||||
@@ -110,7 +110,7 @@ public:
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
while ((Low ^ (Low + Range)) < kTopValue ||
|
||||
while ((Low ^ (Low + Range)) < kTopValue ||
|
||||
Range < kBot && ((Range = (0 - Low) & (kBot - 1)), 1))
|
||||
{
|
||||
Code = (Code << 8) | m_Stream.ReadByte();
|
||||
@@ -190,7 +190,7 @@ class CDecoder:
|
||||
UInt32 _wrPtr;
|
||||
UInt64 _lzSize;
|
||||
UInt64 _unpackSize;
|
||||
UInt64 _writtenFileSize; // if it's > _unpackSize, then _unpackSize only written
|
||||
UInt64 _writtenFileSize; // if it's > _unpackSize, then _unpackSize only written
|
||||
CMyComPtr<ISequentialOutStream> _outStream;
|
||||
NHuffman::CDecoder<kNumHuffmanBits, kMainTableSize> m_MainDecoder;
|
||||
NHuffman::CDecoder<kNumHuffmanBits, kDistTableSize> m_DistDecoder;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
// Rar3Vm.cpp
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// a program that creates RAR archives
|
||||
|
||||
/*
|
||||
Note:
|
||||
Due to performance considerations Rar VM may set Flags C incorrectly
|
||||
for some operands (SHL x, 0, ... ).
|
||||
Due to performance considerations Rar VM may set Flags C incorrectly
|
||||
for some operands (SHL x, 0, ... ).
|
||||
Check implementation of concrete VM command
|
||||
to see if it sets flags right.
|
||||
*/
|
||||
@@ -14,10 +14,10 @@ Note:
|
||||
|
||||
#include "Rar3Vm.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
#include "../../../../C/7zCrc.h"
|
||||
#include "../../../../C/7zCrc.h"
|
||||
}
|
||||
|
||||
namespace NCompress {
|
||||
@@ -121,7 +121,7 @@ CVm::~CVm()
|
||||
|
||||
// CVm::Execute can change CProgram object: it clears progarm if VM returns error.
|
||||
|
||||
bool CVm::Execute(CProgram *prg, const CProgramInitState *initState,
|
||||
bool CVm::Execute(CProgram *prg, const CProgramInitState *initState,
|
||||
CBlockRef &outBlockRef, CRecordVector<Byte> &outGlobalData)
|
||||
{
|
||||
memcpy(R, initState->InitR, sizeof(initState->InitR));
|
||||
@@ -762,14 +762,14 @@ void CVm::ReadVmProgram(const Byte *code, UInt32 codeSize, CProgram *prg)
|
||||
|
||||
#ifdef RARVM_STANDARD_FILTERS
|
||||
|
||||
enum EStandardFilter
|
||||
enum EStandardFilter
|
||||
{
|
||||
SF_E8,
|
||||
SF_E8E9,
|
||||
SF_ITANIUM,
|
||||
SF_RGB,
|
||||
SF_AUDIO,
|
||||
SF_DELTA,
|
||||
SF_E8,
|
||||
SF_E8E9,
|
||||
SF_ITANIUM,
|
||||
SF_RGB,
|
||||
SF_AUDIO,
|
||||
SF_DELTA,
|
||||
SF_UPCASE
|
||||
};
|
||||
|
||||
@@ -778,7 +778,7 @@ struct StandardFilterSignature
|
||||
UInt32 Length;
|
||||
UInt32 CRC;
|
||||
EStandardFilter Type;
|
||||
}
|
||||
}
|
||||
kStdFilters[]=
|
||||
{
|
||||
53, 0xad576887, SF_E8,
|
||||
@@ -813,7 +813,7 @@ void CVm::PrepareProgram(const Byte *code, UInt32 codeSize, CProgram *prg)
|
||||
prg->Commands.Clear();
|
||||
#ifdef RARVM_STANDARD_FILTERS
|
||||
prg->StandardFilterIndex = -1;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
if (xorSum == code[0] && codeSize > 0)
|
||||
{
|
||||
@@ -821,7 +821,7 @@ void CVm::PrepareProgram(const Byte *code, UInt32 codeSize, CProgram *prg)
|
||||
prg->StandardFilterIndex = FindStandardFilter(code, codeSize);
|
||||
if (prg->StandardFilterIndex >= 0)
|
||||
return;
|
||||
#endif
|
||||
#endif
|
||||
// 1 byte for checksum
|
||||
ReadVmProgram(code + 1, codeSize - 1, prg);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// Rar3Vm.h
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// According to unRAR license, this code may not be used to develop
|
||||
// a program that creates RAR archives
|
||||
|
||||
#ifndef __RAR3VM_H
|
||||
@@ -65,7 +65,7 @@ enum ECommand
|
||||
CMD_SHL, CMD_SHR, CMD_SAR, CMD_NEG, CMD_PUSHA,CMD_POPA, CMD_PUSHF,CMD_POPF,
|
||||
CMD_MOVZX,CMD_MOVSX,CMD_XCHG, CMD_MUL, CMD_DIV, CMD_ADC, CMD_SBB, CMD_PRINT,
|
||||
|
||||
CMD_MOVB, CMD_CMPB, CMD_ADDB, CMD_SUBB, CMD_INCB, CMD_DECB,
|
||||
CMD_MOVB, CMD_CMPB, CMD_ADDB, CMD_SUBB, CMD_INCB, CMD_DECB,
|
||||
CMD_XORB, CMD_ANDB, CMD_ORB, CMD_TESTB,CMD_NEGB,
|
||||
CMD_SHLB, CMD_SHRB, CMD_SARB, CMD_MULB
|
||||
};
|
||||
@@ -168,7 +168,7 @@ public:
|
||||
bool Create();
|
||||
void PrepareProgram(const Byte *code, UInt32 codeSize, CProgram *prg);
|
||||
void SetMemory(UInt32 pos, const Byte *data, UInt32 dataSize);
|
||||
bool Execute(CProgram *prg, const CProgramInitState *initState,
|
||||
bool Execute(CProgram *prg, const CProgramInitState *initState,
|
||||
CBlockRef &outBlockRef, CRecordVector<Byte> &outGlobalData);
|
||||
const Byte *GetDataPointer(UInt32 offset) const { return Mem + offset; }
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#include "ShrinkDecoder.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
}
|
||||
#include "../../Common/InBuffer.h"
|
||||
@@ -17,7 +17,7 @@ namespace NShrink {
|
||||
|
||||
static const UInt32 kBufferSize = (1 << 20);
|
||||
|
||||
static const int kNumMinBits = 9;
|
||||
static const int kNumMinBits = 9;
|
||||
|
||||
STDMETHODIMP CDecoder ::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 * /* outSize */,
|
||||
@@ -90,7 +90,7 @@ STDMETHODIMP CDecoder ::CodeReal(ISequentialInStream *inStream,
|
||||
head++;
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
return S_FALSE;
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
namespace NCompress {
|
||||
namespace NShrink {
|
||||
|
||||
const int kNumMaxBits = 13;
|
||||
const UInt32 kNumItems = 1 << kNumMaxBits;
|
||||
const int kNumMaxBits = 13;
|
||||
const UInt32 kNumItems = 1 << kNumMaxBits;
|
||||
|
||||
class CDecoder :
|
||||
public ICompressCoder,
|
||||
@@ -25,11 +25,11 @@ class CDecoder :
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(CodeReal)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
|
||||
STDMETHOD(CodeReal)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
};
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
@@ -1,3 +0,0 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
@@ -4,57 +4,37 @@
|
||||
|
||||
#include "ZDecoder.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
}
|
||||
|
||||
#include "../../Common/InBuffer.h"
|
||||
#include "../../Common/OutBuffer.h"
|
||||
#include "../../Common/LSBFDecoder.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NZ {
|
||||
|
||||
static const UInt32 kBufferSize = (1 << 20);
|
||||
static const Byte kNumBitsMask = 0x1F;
|
||||
static const Byte kBlockModeMask = 0x80;
|
||||
static const int kNumMinBits = 9;
|
||||
static const int kNumMaxBits = 16;
|
||||
static const Byte kNumBitsMask = 0x1F;
|
||||
static const Byte kBlockModeMask = 0x80;
|
||||
static const int kNumMinBits = 9;
|
||||
static const int kNumMaxBits = 16;
|
||||
|
||||
void CDecoder::Free()
|
||||
{
|
||||
MyFree(_parents);
|
||||
_parents = 0;
|
||||
MyFree(_suffixes);
|
||||
_suffixes = 0;
|
||||
MyFree(_stack);
|
||||
_stack = 0;
|
||||
MyFree(_parents); _parents = 0;
|
||||
MyFree(_suffixes); _suffixes = 0;
|
||||
MyFree(_stack); _stack = 0;
|
||||
}
|
||||
|
||||
bool CDecoder::Alloc(size_t numItems)
|
||||
{
|
||||
Free();
|
||||
_parents = (UInt16 *)MyAlloc(numItems * sizeof(UInt16));
|
||||
if (_parents == 0)
|
||||
return false;
|
||||
_suffixes = (Byte *)MyAlloc(numItems * sizeof(Byte));
|
||||
if (_suffixes == 0)
|
||||
return false;
|
||||
_stack = (Byte *)MyAlloc(numItems * sizeof(Byte));
|
||||
return _stack != 0;
|
||||
}
|
||||
|
||||
CDecoder::~CDecoder()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
CDecoder::~CDecoder() { Free(); }
|
||||
|
||||
STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 * /* outSize */,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
NStream::NLSBF::CBaseDecoder<CInBuffer> inBuffer;
|
||||
CInBuffer inBuffer;
|
||||
COutBuffer outBuffer;
|
||||
|
||||
if (!inBuffer.Create(kBufferSize))
|
||||
@@ -72,13 +52,13 @@ STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
return S_FALSE;
|
||||
UInt32 numItems = 1 << maxbits;
|
||||
bool blockMode = ((_properties & kBlockModeMask) != 0);
|
||||
if (!blockMode)
|
||||
return E_NOTIMPL;
|
||||
|
||||
if (maxbits != _numMaxBits || _parents == 0 || _suffixes == 0 || _stack == 0)
|
||||
{
|
||||
if (!Alloc(numItems))
|
||||
return E_OUTOFMEMORY;
|
||||
Free();
|
||||
_parents = (UInt16 *)MyAlloc(numItems * sizeof(UInt16)); if (_parents == 0) return E_OUTOFMEMORY;
|
||||
_suffixes = (Byte *)MyAlloc(numItems * sizeof(Byte)); if (_suffixes == 0) return E_OUTOFMEMORY;
|
||||
_stack = (Byte *)MyAlloc(numItems * sizeof(Byte)); if (_stack == 0) return E_OUTOFMEMORY;
|
||||
_numMaxBits = maxbits;
|
||||
}
|
||||
|
||||
@@ -88,25 +68,40 @@ STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
|
||||
bool needPrev = false;
|
||||
|
||||
int keepBits = 0;
|
||||
unsigned bitPos = 0;
|
||||
unsigned numBufBits = 0;
|
||||
|
||||
Byte buf[kNumMaxBits + 4];
|
||||
|
||||
_parents[256] = 0; // virus protection
|
||||
_suffixes[256] = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
if (keepBits < numBits)
|
||||
keepBits = numBits * 8;
|
||||
UInt32 symbol = inBuffer.ReadBits(numBits);
|
||||
if (inBuffer.ExtraBitsWereRead())
|
||||
if (numBufBits == bitPos)
|
||||
{
|
||||
numBufBits = (unsigned)inBuffer.ReadBytes(buf, numBits) * 8;
|
||||
bitPos = 0;
|
||||
UInt64 nowPos = outBuffer.GetProcessedSize();
|
||||
if (progress != NULL && nowPos - prevPos >= (1 << 18))
|
||||
{
|
||||
prevPos = nowPos;
|
||||
UInt64 packSize = inBuffer.GetProcessedSize();
|
||||
RINOK(progress->SetRatioInfo(&packSize, &nowPos));
|
||||
}
|
||||
}
|
||||
unsigned bytePos = bitPos >> 3;
|
||||
UInt32 symbol = buf[bytePos] | ((UInt32)buf[bytePos + 1] << 8) | ((UInt32)buf[bytePos + 2] << 16);
|
||||
symbol >>= (bitPos & 7);
|
||||
symbol &= (1 << numBits) - 1;
|
||||
bitPos += numBits;
|
||||
if (bitPos > numBufBits)
|
||||
break;
|
||||
keepBits -= numBits;
|
||||
if (symbol >= head)
|
||||
return S_FALSE;
|
||||
if (blockMode && symbol == 256)
|
||||
{
|
||||
for (;keepBits > 0; keepBits--)
|
||||
inBuffer.ReadBits(1);
|
||||
numBufBits = bitPos = 0;
|
||||
numBits = kNumMinBits;
|
||||
head = 257;
|
||||
needPrev = false;
|
||||
@@ -126,8 +121,9 @@ STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
if (symbol == head - 1)
|
||||
_stack[0] = (Byte)cur;
|
||||
}
|
||||
while (i > 0)
|
||||
do
|
||||
outBuffer.WriteByte((_stack[--i]));
|
||||
while (i > 0);
|
||||
if (head < numItems)
|
||||
{
|
||||
needPrev = true;
|
||||
@@ -136,21 +132,13 @@ STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
{
|
||||
if (numBits < maxbits)
|
||||
{
|
||||
numBufBits = bitPos = 0;
|
||||
numBits++;
|
||||
keepBits = numBits * 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
needPrev = false;
|
||||
|
||||
UInt64 nowPos = outBuffer.GetProcessedSize();
|
||||
if (progress != NULL && nowPos - prevPos > (1 << 18))
|
||||
{
|
||||
prevPos = nowPos;
|
||||
UInt64 packSize = inBuffer.GetProcessedSize();
|
||||
RINOK(progress->SetRatioInfo(&packSize, &nowPos));
|
||||
}
|
||||
}
|
||||
return outBuffer.Flush();
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ public:
|
||||
CDecoder(): _properties(0), _numMaxBits(0), _parents(0), _suffixes(0), _stack(0) {};
|
||||
~CDecoder();
|
||||
void Free();
|
||||
bool Alloc(size_t numItems);
|
||||
|
||||
MY_UNKNOWN_IMP1(ICompressSetDecoderProperties2)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user