mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-09 20:07:04 -06:00
4.26 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
af1fe52701
commit
31e7b924e8
@@ -15,12 +15,11 @@ const UInt32 kValueTableBits = 9;
|
||||
template <int kNumBitsInLongestCode, UInt32 m_NumSymbols>
|
||||
class CDecoder
|
||||
{
|
||||
UInt32 m_Limitits[kNumBitsInLongestCode + 1]; // m_Limitits[i] = value limit for symbols with length = i
|
||||
UInt32 m_Limits[kNumBitsInLongestCode + 1]; // m_Limits[i] = value limit for symbols with length = i
|
||||
UInt32 m_Positions[kNumBitsInLongestCode + 1]; // m_Positions[i] = index in m_Symbols[] of first symbol with length = i
|
||||
UInt32 m_Symbols[m_NumSymbols]; // symbols: at first with len = 1 then 2, ... 15.
|
||||
Byte m_Lengths[1 << kValueTableBits];
|
||||
public:
|
||||
void SetNumSymbols(UInt32 numSymbols) { m_NumSymbols = numSymbols; }
|
||||
void SetCodeLengths(const Byte *codeLengths);
|
||||
template <class TBitDecoder>
|
||||
UInt32 DecodeSymbol(TBitDecoder *bitStream)
|
||||
@@ -29,15 +28,15 @@ public:
|
||||
|
||||
UInt32 value = bitStream->GetValue(kNumBitsInLongestCode);
|
||||
|
||||
if (value < m_Limitits[kValueTableBits])
|
||||
if (value < m_Limits[kValueTableBits])
|
||||
numBits = m_Lengths[value >> (kNumBitsInLongestCode - kValueTableBits)];
|
||||
else
|
||||
for (numBits = kValueTableBits + 1; numBits < kNumBitsInLongestCode; numBits++)
|
||||
if (value < m_Limitits[numBits])
|
||||
if (value < m_Limits[numBits])
|
||||
break;
|
||||
bitStream->MovePos(numBits);
|
||||
UInt32 index = m_Positions[numBits] +
|
||||
((value - m_Limitits[numBits - 1]) >> (kNumBitsInLongestCode - numBits));
|
||||
((value - m_Limits[numBits - 1]) >> (kNumBitsInLongestCode - numBits));
|
||||
if (index >= m_NumSymbols)
|
||||
throw CDecoderException(); // test it
|
||||
return m_Symbols[index];
|
||||
@@ -60,7 +59,7 @@ void CDecoder<kNumBitsInLongestCode, m_NumSymbols>::SetCodeLengths(const Byte *c
|
||||
lenCounts[codeLength]++;
|
||||
}
|
||||
lenCounts[0] = 0;
|
||||
tmpPositions[0] = m_Positions[0] = m_Limitits[0] = 0;
|
||||
tmpPositions[0] = m_Positions[0] = m_Limits[0] = 0;
|
||||
UInt32 startPos = 0;
|
||||
UInt32 index = 0;
|
||||
const UInt32 kMaxValue = (1 << kNumBitsInLongestCode);
|
||||
@@ -69,13 +68,13 @@ void CDecoder<kNumBitsInLongestCode, m_NumSymbols>::SetCodeLengths(const Byte *c
|
||||
startPos += lenCounts[i] << (kNumBitsInLongestCode - i);
|
||||
if (startPos > kMaxValue)
|
||||
throw CDecoderException();
|
||||
m_Limitits[i] = startPos;
|
||||
m_Limits[i] = startPos;
|
||||
m_Positions[i] = m_Positions[i - 1] + lenCounts[i - 1];
|
||||
tmpPositions[i] = m_Positions[i];
|
||||
|
||||
if(i <= kValueTableBits)
|
||||
{
|
||||
UInt32 limit = (m_Limitits[i] >> (kNumBitsInLongestCode - kValueTableBits)); // change it
|
||||
UInt32 limit = (m_Limits[i] >> (kNumBitsInLongestCode - kValueTableBits)); // change it
|
||||
memset(m_Lengths + index, Byte(i), limit - index);
|
||||
index = limit;
|
||||
}
|
||||
|
||||
@@ -22,9 +22,12 @@ bool CLZInWindow::Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 kee
|
||||
{
|
||||
Free();
|
||||
_blockSize = blockSize;
|
||||
_bufferBase = (Byte *)::BigAlloc(_blockSize);
|
||||
if (_blockSize != 0)
|
||||
_bufferBase = (Byte *)::BigAlloc(_blockSize);
|
||||
}
|
||||
_pointerToLastSafePosition = _bufferBase + _blockSize - keepSizeAfter;
|
||||
if (_blockSize == 0)
|
||||
return true;
|
||||
return (_bufferBase != 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,6 +34,8 @@ extern "C"
|
||||
|
||||
using namespace NCommandLineParser;
|
||||
|
||||
static const char *kCantAllocate = "Can not allocate memory";
|
||||
|
||||
namespace NKey {
|
||||
enum Enum
|
||||
{
|
||||
@@ -129,7 +131,7 @@ static bool GetNumber(const wchar_t *s, UInt32 &value)
|
||||
|
||||
int main2(int n, const char *args[])
|
||||
{
|
||||
fprintf(stderr, "\nLZMA 4.23 Copyright (c) 1999-2005 Igor Pavlov 2005-06-29\n");
|
||||
fprintf(stderr, "\nLZMA 4.26 Copyright (c) 1999-2005 Igor Pavlov 2005-08-02\n");
|
||||
|
||||
if (n == 1)
|
||||
{
|
||||
@@ -258,9 +260,13 @@ int main2(int n, const char *args[])
|
||||
if (fileSize > 0xF0000000)
|
||||
throw "File is too big";
|
||||
UInt32 inSize = (UInt32)fileSize;
|
||||
Byte *inBuffer = (Byte *)MyAlloc((size_t)inSize);
|
||||
if (inBuffer == 0)
|
||||
throw "Can not allocate memory";
|
||||
Byte *inBuffer = 0;
|
||||
if (inSize != 0)
|
||||
{
|
||||
inBuffer = (Byte *)MyAlloc((size_t)inSize);
|
||||
if (inBuffer == 0)
|
||||
throw kCantAllocate;
|
||||
}
|
||||
|
||||
UInt32 processedSize;
|
||||
if (inStream->Read(inBuffer, (UInt32)inSize, &processedSize) != S_OK)
|
||||
@@ -268,15 +274,18 @@ int main2(int n, const char *args[])
|
||||
if ((UInt32)inSize != processedSize)
|
||||
throw "Read size error";
|
||||
|
||||
Byte *outBuffer;
|
||||
Byte *outBuffer = 0;
|
||||
size_t outSizeProcessed;
|
||||
if (encodeMode)
|
||||
{
|
||||
// we allocate 105% of original size for output buffer
|
||||
size_t outSize = (size_t)fileSize / 20 * 21 + (1 << 16);
|
||||
outBuffer = (Byte *)MyAlloc((size_t)outSize);
|
||||
if (outBuffer == 0)
|
||||
throw "Can not allocate memory";
|
||||
if (outSize != 0)
|
||||
{
|
||||
outBuffer = (Byte *)MyAlloc((size_t)outSize);
|
||||
if (outBuffer == 0)
|
||||
throw kCantAllocate;
|
||||
}
|
||||
if (!dictionaryIsDefined)
|
||||
dictionary = 1 << 23;
|
||||
int res = LzmaRamEncode(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed,
|
||||
@@ -292,10 +301,12 @@ int main2(int n, const char *args[])
|
||||
size_t outSize;
|
||||
if (LzmaRamGetUncompressedSize(inBuffer, inSize, &outSize) != 0)
|
||||
throw "data error";
|
||||
outBuffer = (Byte *)MyAlloc(outSize);
|
||||
if (outBuffer == 0)
|
||||
throw "Can not allocate memory";
|
||||
|
||||
if (outSize != 0)
|
||||
{
|
||||
outBuffer = (Byte *)MyAlloc(outSize);
|
||||
if (outBuffer == 0)
|
||||
throw kCantAllocate;
|
||||
}
|
||||
int res = LzmaRamDecompress(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, malloc, free);
|
||||
if (res != 0)
|
||||
throw "LzmaDecoder error";
|
||||
|
||||
@@ -177,10 +177,13 @@ int LzmaRamEncode(
|
||||
bool useFilter = (filterMode != SZ_FILTER_NO);
|
||||
if (useFilter)
|
||||
{
|
||||
filteredStream = (Byte *)MyAlloc(inSize);
|
||||
if (filteredStream == 0)
|
||||
return SZE_OUTOFMEMORY;
|
||||
memmove(filteredStream, inBuffer, inSize);
|
||||
if (inSize != 0)
|
||||
{
|
||||
filteredStream = (Byte *)MyAlloc(inSize);
|
||||
if (filteredStream == 0)
|
||||
return SZE_OUTOFMEMORY;
|
||||
memmove(filteredStream, inBuffer, inSize);
|
||||
}
|
||||
UInt32 _prevMask;
|
||||
UInt32 _prevPos;
|
||||
x86_Convert_Init(_prevMask, _prevPos);
|
||||
|
||||
@@ -3,7 +3,7 @@ LzmaStateTest.c
|
||||
Test application for LZMA Decoder (State version)
|
||||
|
||||
This file written and distributed to public domain by Igor Pavlov.
|
||||
This file is part of LZMA SDK 4.21 (2005-06-08)
|
||||
This file is part of LZMA SDK 4.26 (2005-08-02)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -85,11 +85,16 @@ int main3(FILE *inFile, FILE *outFile, char *rs)
|
||||
if (state.Probs == 0)
|
||||
return PrintError(rs, kCantAllocateMessage);
|
||||
|
||||
state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);
|
||||
if (state.Dictionary == 0)
|
||||
if (state.Properties.DictionarySize == 0)
|
||||
state.Dictionary = 0;
|
||||
else
|
||||
{
|
||||
free(state.Probs);
|
||||
return PrintError(rs, kCantAllocateMessage);
|
||||
state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);
|
||||
if (state.Dictionary == 0)
|
||||
{
|
||||
free(state.Probs);
|
||||
return PrintError(rs, kCantAllocateMessage);
|
||||
}
|
||||
}
|
||||
|
||||
/* Decompress */
|
||||
@@ -155,7 +160,7 @@ int main2(int numArgs, const char *args[], char *rs)
|
||||
FILE *outFile = 0;
|
||||
int res;
|
||||
|
||||
sprintf(rs + strlen(rs), "\nLZMA Decoder 4.21 Copyright (c) 1999-2005 Igor Pavlov 2005-06-08\n");
|
||||
sprintf(rs + strlen(rs), "\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov 2005-08-02\n");
|
||||
if (numArgs < 2 || numArgs > 3)
|
||||
{
|
||||
sprintf(rs + strlen(rs), "\nUsage: lzmadec file.lzma [outFile]\n");
|
||||
|
||||
@@ -3,7 +3,7 @@ LzmaTest.c
|
||||
Test application for LZMA Decoder
|
||||
|
||||
This file written and distributed to public domain by Igor Pavlov.
|
||||
This file is part of LZMA SDK 4.22 (2005-06-10)
|
||||
This file is part of LZMA SDK 4.26 (2005-08-02)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -17,13 +17,21 @@ const char *kCantWriteMessage = "Can not write output file";
|
||||
const char *kCantAllocateMessage = "Can not allocate memory";
|
||||
|
||||
size_t MyReadFile(FILE *file, void *data, size_t size)
|
||||
{ return fread(data, 1, size, file); }
|
||||
{
|
||||
if (size == 0)
|
||||
return 0;
|
||||
return fread(data, 1, size, file);
|
||||
}
|
||||
|
||||
int MyReadFileAndCheck(FILE *file, void *data, size_t size)
|
||||
{ return (MyReadFile(file, data, size) == size);}
|
||||
|
||||
size_t MyWriteFile(FILE *file, const void *data, size_t size)
|
||||
{ return fwrite(data, 1, size, file); }
|
||||
{
|
||||
if (size == 0)
|
||||
return 0;
|
||||
return fwrite(data, 1, size, file);
|
||||
}
|
||||
|
||||
int MyWriteFileAndCheck(FILE *file, const void *data, size_t size)
|
||||
{ return (MyWriteFile(file, data, size) == size); }
|
||||
@@ -145,23 +153,32 @@ int main3(FILE *inFile, FILE *outFile, char *rs)
|
||||
state.Probs = (CProb *)malloc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb));
|
||||
|
||||
#ifdef _LZMA_OUT_READ
|
||||
state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);
|
||||
if (state.Properties.DictionarySize == 0)
|
||||
state.Dictionary = 0;
|
||||
else
|
||||
state.Dictionary = (unsigned char *)malloc(state.Properties.DictionarySize);
|
||||
#else
|
||||
outStream = (unsigned char *)malloc(outSizeFull);
|
||||
if (outSizeFull == 0)
|
||||
outStream = 0;
|
||||
else
|
||||
outStream = (unsigned char *)malloc(outSizeFull);
|
||||
#endif
|
||||
|
||||
#ifndef _LZMA_IN_CB
|
||||
inStream = (unsigned char *)malloc(compressedSize);
|
||||
if (compressedSize == 0)
|
||||
inStream = 0;
|
||||
else
|
||||
inStream = (unsigned char *)malloc(compressedSize);
|
||||
#endif
|
||||
|
||||
if (state.Probs == 0
|
||||
#ifdef _LZMA_OUT_READ
|
||||
|| state.Dictionary == 0
|
||||
|| state.Dictionary == 0 && state.Properties.DictionarySize != 0
|
||||
#else
|
||||
|| outStream == 0
|
||||
|| outStream == 0 && outSizeFull != 0
|
||||
#endif
|
||||
#ifndef _LZMA_IN_CB
|
||||
|| inStream == 0
|
||||
|| inStream == 0 && compressedSize != 0
|
||||
#endif
|
||||
)
|
||||
{
|
||||
@@ -290,7 +307,7 @@ int main2(int numArgs, const char *args[], char *rs)
|
||||
FILE *outFile = 0;
|
||||
int res;
|
||||
|
||||
sprintf(rs + strlen(rs), "\nLZMA Decoder 4.21 Copyright (c) 1999-2005 Igor Pavlov 2005-06-08\n");
|
||||
sprintf(rs + strlen(rs), "\nLZMA Decoder 4.26 Copyright (c) 1999-2005 Igor Pavlov 2005-08-02\n");
|
||||
if (numArgs < 2 || numArgs > 3)
|
||||
{
|
||||
sprintf(rs + strlen(rs), "\nUsage: lzmadec file.lzma [outFile]\n");
|
||||
|
||||
216
7zip/Compress/Lzh/LzhDecoder.cpp
Executable file
216
7zip/Compress/Lzh/LzhDecoder.cpp
Executable file
@@ -0,0 +1,216 @@
|
||||
// LzhDecoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "LzhDecoder.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
namespace NCompress{
|
||||
namespace NLzh {
|
||||
namespace NDecoder {
|
||||
|
||||
static const UInt32 kHistorySize = (1 << 16);
|
||||
|
||||
static const int kBlockSizeBits = 16;
|
||||
static const int kNumCBits = 9;
|
||||
static const int kNumLevelBits = 5; // smallest integer such that (1 << kNumLevelBits) > kNumLevelSymbols/
|
||||
|
||||
UInt32 CCoder::ReadBits(int numBits) { return m_InBitStream.ReadBits(numBits); }
|
||||
|
||||
HRESULT CCoder::ReadLevelTable()
|
||||
{
|
||||
int n = ReadBits(kNumLevelBits);
|
||||
if (n == 0)
|
||||
{
|
||||
m_LevelHuffman.Symbol = ReadBits(kNumLevelBits);
|
||||
if (m_LevelHuffman.Symbol >= kNumLevelSymbols)
|
||||
return S_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (n > kNumLevelSymbols)
|
||||
return S_FALSE;
|
||||
m_LevelHuffman.Symbol = -1;
|
||||
Byte lens[kNumLevelSymbols];
|
||||
int i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
int c = m_InBitStream.ReadBits(3);
|
||||
if (c == 7)
|
||||
while (ReadBits(1))
|
||||
if (c++ > kMaxHuffmanLen)
|
||||
return S_FALSE;
|
||||
lens[i++] = (Byte)c;
|
||||
if (i == kNumSpecLevelSymbols)
|
||||
{
|
||||
c = ReadBits(2);
|
||||
while (--c >= 0)
|
||||
lens[i++] = 0;
|
||||
}
|
||||
}
|
||||
while (i < kNumLevelSymbols)
|
||||
lens[i++] = 0;
|
||||
m_LevelHuffman.SetCodeLengths(lens);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CCoder::ReadPTable(int numBits)
|
||||
{
|
||||
int n = ReadBits(numBits);
|
||||
if (n == 0)
|
||||
{
|
||||
m_PHuffmanDecoder.Symbol = ReadBits(numBits);
|
||||
if (m_PHuffmanDecoder.Symbol >= kNumDistanceSymbols)
|
||||
return S_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (n > kNumDistanceSymbols)
|
||||
return S_FALSE;
|
||||
m_PHuffmanDecoder.Symbol = -1;
|
||||
Byte lens[kNumDistanceSymbols];
|
||||
int i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
int c = m_InBitStream.ReadBits(3);
|
||||
if (c == 7)
|
||||
while (ReadBits(1))
|
||||
{
|
||||
if (c > kMaxHuffmanLen)
|
||||
return S_FALSE;
|
||||
c++;
|
||||
}
|
||||
lens[i++] = (Byte)c;
|
||||
}
|
||||
while (i < kNumDistanceSymbols)
|
||||
lens[i++] = 0;
|
||||
m_PHuffmanDecoder.SetCodeLengths(lens);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CCoder::ReadCTable()
|
||||
{
|
||||
int n = ReadBits(kNumCBits);
|
||||
if (n == 0)
|
||||
{
|
||||
m_CHuffmanDecoder.Symbol = ReadBits(kNumCBits);
|
||||
if (m_CHuffmanDecoder.Symbol >= kNumCSymbols)
|
||||
return S_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (n > kNumCSymbols)
|
||||
return S_FALSE;
|
||||
m_CHuffmanDecoder.Symbol = -1;
|
||||
Byte lens[kNumCSymbols];
|
||||
int i = 0;
|
||||
while (i < n)
|
||||
{
|
||||
int c = m_LevelHuffman.Decode(&m_InBitStream);
|
||||
if (c < kNumSpecLevelSymbols)
|
||||
{
|
||||
if (c == 0)
|
||||
c = 1;
|
||||
else if (c == 1)
|
||||
c = ReadBits(4) + 3;
|
||||
else
|
||||
c = ReadBits(kNumCBits) + 20;
|
||||
while (--c >= 0)
|
||||
{
|
||||
if (i > kNumCSymbols)
|
||||
return S_FALSE;
|
||||
lens[i++] = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
lens[i++] = c - 2;
|
||||
}
|
||||
while (i < kNumCSymbols)
|
||||
lens[i++] = 0;
|
||||
m_CHuffmanDecoder.SetCodeLengths(lens);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (outSize == NULL)
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (!m_OutWindowStream.Create(kHistorySize))
|
||||
return E_OUTOFMEMORY;
|
||||
if (!m_InBitStream.Create(1 << 20))
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
UInt64 pos = 0;
|
||||
m_OutWindowStream.SetStream(outStream);
|
||||
m_OutWindowStream.Init(false);
|
||||
m_InBitStream.SetStream(inStream);
|
||||
m_InBitStream.Init();
|
||||
|
||||
CCoderReleaser coderReleaser(this);
|
||||
|
||||
int pbit;
|
||||
if (m_NumDictBits <= 13)
|
||||
pbit = 4;
|
||||
else
|
||||
pbit = 5;
|
||||
|
||||
UInt32 blockSize = 0;
|
||||
|
||||
while(pos < *outSize)
|
||||
{
|
||||
// for (i = 0; i < dictSize; i++) dtext[i] = 0x20;
|
||||
|
||||
if (blockSize == 0)
|
||||
{
|
||||
if (progress != NULL)
|
||||
{
|
||||
UInt64 packSize = m_InBitStream.GetProcessedSize();
|
||||
RINOK(progress->SetRatioInfo(&packSize, &pos));
|
||||
}
|
||||
blockSize = ReadBits(kBlockSizeBits);
|
||||
ReadLevelTable();
|
||||
ReadCTable();
|
||||
RINOK(ReadPTable(pbit));
|
||||
}
|
||||
blockSize--;
|
||||
UInt32 c = m_CHuffmanDecoder.Decode(&m_InBitStream);
|
||||
if (c < 256)
|
||||
{
|
||||
m_OutWindowStream.PutByte((Byte)c);
|
||||
pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
// offset = (interface->method == LARC_METHOD_NUM) ? 0x100 - 2 : 0x100 - 3;
|
||||
UInt32 len = c - 256 + kMinMatch;
|
||||
UInt32 distance = m_PHuffmanDecoder.Decode(&m_InBitStream);
|
||||
if (distance != 0)
|
||||
distance = (1 << (distance - 1)) + ReadBits(distance - 1);
|
||||
pos += len;
|
||||
if (distance >= pos)
|
||||
throw 1;
|
||||
m_OutWindowStream.CopyBlock(distance, len);
|
||||
}
|
||||
}
|
||||
coderReleaser.NeedFlush = false;
|
||||
return m_OutWindowStream.Flush();
|
||||
}
|
||||
|
||||
STDMETHODIMP CCoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
try { return CodeReal(inStream, outStream, inSize, outSize, progress);}
|
||||
catch(const CInBufferException &e) { return e.ErrorCode; }
|
||||
catch(const CLZOutWindowException &e) { return e.ErrorCode; }
|
||||
catch(...) { return S_FALSE; }
|
||||
}
|
||||
|
||||
}}}
|
||||
103
7zip/Compress/Lzh/LzhDecoder.h
Executable file
103
7zip/Compress/Lzh/LzhDecoder.h
Executable file
@@ -0,0 +1,103 @@
|
||||
// LzhDecoder.h
|
||||
|
||||
#ifndef __COMPRESS_LZH_DECODER_H
|
||||
#define __COMPRESS_LZH_DECODER_H
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
#include "../../ICoder.h"
|
||||
#include "../../Common/MSBFDecoder.h"
|
||||
#include "../../Common/InBuffer.h"
|
||||
#include "../Huffman/HuffmanDecoder.h"
|
||||
#include "../LZ/LZOutWindow.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NLzh {
|
||||
namespace NDecoder {
|
||||
|
||||
const int kMaxHuffmanLen = 16; // Check it
|
||||
|
||||
const int kNumSpecLevelSymbols = 3;
|
||||
const int kNumLevelSymbols = kNumSpecLevelSymbols + kMaxHuffmanLen;
|
||||
|
||||
const int kDictBitsMax = 16;
|
||||
const int kNumDistanceSymbols = kDictBitsMax + 1;
|
||||
|
||||
const int kMaxMatch = 256;
|
||||
const int kMinMatch = 3;
|
||||
const int kNumCSymbols = 256 + kMaxMatch + 2 - kMinMatch;
|
||||
|
||||
template <UInt32 m_NumSymbols>
|
||||
class CHuffmanDecoder:public NCompress::NHuffman::CDecoder<kMaxHuffmanLen, m_NumSymbols>
|
||||
{
|
||||
public:
|
||||
int Symbol;
|
||||
template <class TBitDecoder>
|
||||
UInt32 Decode(TBitDecoder *bitStream)
|
||||
{
|
||||
if (Symbol >= 0)
|
||||
return (UInt32)Symbol;
|
||||
return DecodeSymbol(bitStream);
|
||||
}
|
||||
};
|
||||
|
||||
class CCoder :
|
||||
public ICompressCoder,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CLZOutWindow m_OutWindowStream;
|
||||
NStream::NMSBF::CDecoder<CInBuffer> m_InBitStream;
|
||||
|
||||
int m_NumDictBits;
|
||||
|
||||
CHuffmanDecoder<kNumLevelSymbols> m_LevelHuffman;
|
||||
CHuffmanDecoder<kNumDistanceSymbols> m_PHuffmanDecoder;
|
||||
CHuffmanDecoder<kNumCSymbols> m_CHuffmanDecoder;
|
||||
|
||||
void CCoder::ReleaseStreams()
|
||||
{
|
||||
m_OutWindowStream.ReleaseStream();
|
||||
m_InBitStream.ReleaseStream();
|
||||
}
|
||||
|
||||
class CCoderReleaser
|
||||
{
|
||||
CCoder *m_Coder;
|
||||
public:
|
||||
bool NeedFlush;
|
||||
CCoderReleaser(CCoder *coder): m_Coder(coder), NeedFlush(true) {}
|
||||
~CCoderReleaser()
|
||||
{
|
||||
if (NeedFlush)
|
||||
m_Coder->m_OutWindowStream.Flush();
|
||||
m_Coder->ReleaseStreams();
|
||||
}
|
||||
};
|
||||
friend class CCoderReleaser;
|
||||
|
||||
void MakeTable(int nchar, Byte *bitlen, int tablebits,
|
||||
UInt32 *table, int tablesize);
|
||||
|
||||
UInt32 ReadBits(int numBits);
|
||||
HRESULT ReadLevelTable();
|
||||
HRESULT ReadPTable(int numBits);
|
||||
HRESULT ReadCTable();
|
||||
|
||||
public:
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
STDMETHOD(CodeReal)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
void SetDictionary(int numDictBits) { m_NumDictBits = numDictBits; }
|
||||
CCoder(): m_NumDictBits(0) {}
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -109,8 +109,11 @@ public:
|
||||
if (SubAllocatorSize == size)
|
||||
return true;
|
||||
StopSubAllocator();
|
||||
if ((HeapStart = (Byte *)::BigAlloc(size)) == 0)
|
||||
return false;
|
||||
if (size == 0)
|
||||
HeapStart = 0;
|
||||
else
|
||||
if ((HeapStart = (Byte *)::BigAlloc(size)) == 0)
|
||||
return false;
|
||||
SubAllocatorSize = size;
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user