This commit is contained in:
Igor Pavlov
2017-04-30 00:00:00 +00:00
committed by Kornel
parent 603abd5528
commit 2efa10565a
442 changed files with 15479 additions and 8525 deletions

View File

@@ -104,7 +104,8 @@ bool CDecoder::ReadTables(void)
m_TablesOK = false;
Byte levelLevels[kLevelTableSize];
Byte newLevels[kMaxTableSize];
Byte lens[kMaxTableSize];
m_AudioMode = (ReadBits(1) == 1);
if (ReadBits(1) == 0)
@@ -134,16 +135,29 @@ bool CDecoder::ReadTables(void)
UInt32 sym = m_LevelDecoder.Decode(&m_InBitStream);
if (sym < kTableDirectLevels)
{
newLevels[i] = (Byte)((sym + m_LastLevels[i]) & kLevelMask);
lens[i] = (Byte)((sym + m_LastLevels[i]) & kLevelMask);
i++;
}
else
{
if (sym == kTableLevelRepNumber)
{
unsigned t = ReadBits(2) + 3;
for (unsigned reps = t; reps > 0 && i < numLevels; reps--, i++)
newLevels[i] = newLevels[i - 1];
unsigned num = ReadBits(2) + 3;
if (i == 0)
{
// return false;
continue; // original unRAR
}
num += i;
if (num > numLevels)
{
// return false;
num = numLevels; // original unRAR
}
Byte v = lens[(size_t)i - 1];
do
lens[i++] = v;
while (i < num);
}
else
{
@@ -154,8 +168,15 @@ bool CDecoder::ReadTables(void)
num = ReadBits(7) + 11;
else
return false;
for (; num > 0 && i < numLevels; num--)
newLevels[i++] = 0;
num += i;
if (num > numLevels)
{
// return false;
num = numLevels; // original unRAR
}
do
lens[i++] = 0;
while (i < num);
}
}
}
@@ -163,16 +184,16 @@ bool CDecoder::ReadTables(void)
if (m_AudioMode)
for (i = 0; i < m_NumChannels; i++)
{
RIF(m_MMDecoders[i].Build(&newLevels[i * kMMTableSize]));
RIF(m_MMDecoders[i].Build(&lens[i * kMMTableSize]));
}
else
{
RIF(m_MainDecoder.Build(&newLevels[0]));
RIF(m_DistDecoder.Build(&newLevels[kMainTableSize]));
RIF(m_LenDecoder.Build(&newLevels[kMainTableSize + kDistTableSize]));
RIF(m_MainDecoder.Build(&lens[0]));
RIF(m_DistDecoder.Build(&lens[kMainTableSize]));
RIF(m_LenDecoder.Build(&lens[kMainTableSize + kDistTableSize]));
}
memcpy(m_LastLevels, newLevels, kMaxTableSize);
memcpy(m_LastLevels, lens, kMaxTableSize);
m_TablesOK = true;
@@ -220,13 +241,11 @@ public:
bool CDecoder::DecodeMm(UInt32 pos)
{
while (pos-- > 0)
while (pos-- != 0)
{
UInt32 symbol = m_MMDecoders[m_MmFilter.CurrentChannel].Decode(&m_InBitStream);
if (symbol == 256)
return true;
if (symbol >= kMMTableSize)
return false;
if (symbol >= 256)
return symbol == 256;
/*
Byte byPredict = m_Predictor.Predict();
Byte byReal = (Byte)(byPredict - (Byte)symbol);
@@ -254,6 +273,8 @@ bool CDecoder::DecodeLz(Int32 pos)
}
else if (sym >= kMatchNumber)
{
if (sym >= kMainTableSize)
return false;
sym -= kMatchNumber;
length = kNormalMatchMinLen + UInt32(kLenStart[sym]) +
m_InBitStream.ReadBits(kLenDirectBits[sym]);
@@ -302,10 +323,9 @@ bool CDecoder::DecodeLz(Int32 pos)
m_InBitStream.ReadBits(kLen2DistDirectBits[sym]);
length = 2;
}
else if (sym == kReadTableNumber)
else // (sym == kReadTableNumber)
return true;
else
return false;
m_RepDists[m_RepDistPtr++ & 3] = distance;
m_LastLength = length;
if (!m_OutWindowStream.CopyBlock(distance, length))