mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-14 22:11:38 -06:00
3.13
This commit is contained in:
66
7zip/Compress/Implode/DllExports.cpp
Executable file
66
7zip/Compress/Implode/DllExports.cpp
Executable file
@@ -0,0 +1,66 @@
|
||||
// DLLExports.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#define INITGUID
|
||||
|
||||
#include "Common/ComTry.h"
|
||||
#include "ImplodeDecoder.h"
|
||||
|
||||
// {23170F69-40C1-278B-0401-060000000000}
|
||||
DEFINE_GUID(CLSID_CCompressImplodeDecoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x04, 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
extern "C"
|
||||
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
STDAPI CreateObject(const GUID *clsid, const GUID *iid, void **outObject)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
*outObject = 0;
|
||||
if (*clsid != CLSID_CCompressImplodeDecoder)
|
||||
return CLASS_E_CLASSNOTAVAILABLE;
|
||||
if (*iid != IID_ICompressCoder)
|
||||
return E_NOINTERFACE;
|
||||
CMyComPtr<ICompressCoder> coder = (ICompressCoder *)new
|
||||
NCompress::NImplode::NDecoder::CCoder;
|
||||
*outObject = coder.Detach();
|
||||
COM_TRY_END
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDAPI GetNumberOfMethods(UINT32 *numMethods)
|
||||
{
|
||||
*numMethods = 1;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDAPI GetMethodProperty(UINT32 index, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
if (index != 0)
|
||||
return E_INVALIDARG;
|
||||
::VariantClear((tagVARIANT *)value);
|
||||
switch(propID)
|
||||
{
|
||||
case NMethodPropID::kID:
|
||||
{
|
||||
const char id[] = { 0x04, 0x01, 0x06 };
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(id, sizeof(id))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
case NMethodPropID::kName:
|
||||
if ((value->bstrVal = ::SysAllocString(L"Implode")) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
case NMethodPropID::kDecoder:
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(
|
||||
(const char *)&CLSID_CCompressImplodeDecoder, sizeof(GUID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
9
7zip/Compress/Implode/Implode.def
Executable file
9
7zip/Compress/Implode/Implode.def
Executable file
@@ -0,0 +1,9 @@
|
||||
; Implode.def
|
||||
|
||||
LIBRARY Implode.dll
|
||||
|
||||
EXPORTS
|
||||
CreateObject PRIVATE
|
||||
GetNumberOfMethods PRIVATE
|
||||
GetMethodProperty PRIVATE
|
||||
|
||||
181
7zip/Compress/Implode/Implode.dsp
Executable file
181
7zip/Compress/Implode/Implode.dsp
Executable file
@@ -0,0 +1,181 @@
|
||||
# Microsoft Developer Studio Project File - Name="Implode" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
|
||||
|
||||
CFG=Implode - 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 "Implode.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 "Implode.mak" CFG="Implode - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "Implode - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
|
||||
!MESSAGE "Implode - 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)" == "Implode - 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 "IMPLODE_EXPORTS" /YX /FD /c
|
||||
# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "IMPLODE_EXPORTS" /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\Implode.dll" /opt:NOWIN98
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "Implode - 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 "IMPLODE_EXPORTS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "IMPLODE_EXPORTS" /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\Implode.dll" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "Implode - Win32 Release"
|
||||
# Name "Implode - Win32 Debug"
|
||||
# Begin Group "Spec"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\DllExports.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\Implode.def
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\resource.h
|
||||
# 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 "7zip 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\LSBFDecoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\LSBFDecoder.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Common"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\NewHandler.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\NewHandler.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 Source File
|
||||
|
||||
SOURCE=.\ImplodeDecoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ImplodeDecoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ImplodeHuffmanDecoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\ImplodeHuffmanDecoder.h
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
29
7zip/Compress/Implode/Implode.dsw
Executable file
29
7zip/Compress/Implode/Implode.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: "Implode"=.\Implode.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
210
7zip/Compress/Implode/ImplodeDecoder.cpp
Executable file
210
7zip/Compress/Implode/ImplodeDecoder.cpp
Executable file
@@ -0,0 +1,210 @@
|
||||
// Implode/Decoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ImplodeDecoder.h"
|
||||
#include "Common/Defs.h"
|
||||
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NImplode {
|
||||
namespace NDecoder {
|
||||
|
||||
static const int kNumDistanceLowDirectBitsForBigDict = 7;
|
||||
static const int kNumDistanceLowDirectBitsForSmallDict = 6;
|
||||
|
||||
static const int kNumBitsInByte = 8;
|
||||
|
||||
static const int kLevelStructuresNumberFieldSize = kNumBitsInByte;
|
||||
static const int kLevelStructuresNumberAdditionalValue = 1;
|
||||
|
||||
static const int kNumLevelStructureLevelBits = 4;
|
||||
static const int kLevelStructureLevelAdditionalValue = 1;
|
||||
|
||||
static const int kNumLevelStructureRepNumberBits = 4;
|
||||
static const int kLevelStructureRepNumberAdditionalValue = 1;
|
||||
|
||||
|
||||
static const int kLiteralTableSize = (1 << kNumBitsInByte);
|
||||
static const int kDistanceTableSize = 64;
|
||||
static const int kLengthTableSize = 64;
|
||||
|
||||
static const UINT32 kHistorySize =
|
||||
(1 << MyMax(kNumDistanceLowDirectBitsForBigDict,
|
||||
kNumDistanceLowDirectBitsForSmallDict)) *
|
||||
kDistanceTableSize; // = 8 KB;
|
||||
|
||||
static const int kNumAdditionalLengthBits = 8;
|
||||
|
||||
static const UINT32 kMatchMinLenWhenLiteralsOn = 3;
|
||||
static const UINT32 kMatchMinLenWhenLiteralsOff = 2;
|
||||
|
||||
static const UINT32 kMatchMinLenMax = MyMax(kMatchMinLenWhenLiteralsOn,
|
||||
kMatchMinLenWhenLiteralsOff); // 3
|
||||
|
||||
static const UINT32 kMatchMaxLenMax = kMatchMinLenMax +
|
||||
(kLengthTableSize - 1) + (1 << kNumAdditionalLengthBits) - 1; // or 2
|
||||
|
||||
enum
|
||||
{
|
||||
kMatchId = 0,
|
||||
kLiteralId = 1
|
||||
};
|
||||
|
||||
|
||||
CCoder::CCoder():
|
||||
m_LiteralDecoder(kLiteralTableSize),
|
||||
m_LengthDecoder(kLengthTableSize),
|
||||
m_DistanceDecoder(kDistanceTableSize)
|
||||
{
|
||||
m_OutWindowStream.Create(kHistorySize/*, kMatchMaxLenMax*/);
|
||||
}
|
||||
|
||||
/*
|
||||
STDMETHODIMP CCoder::ReleaseStreams()
|
||||
{
|
||||
m_OutWindowStream.ReleaseStream();
|
||||
m_InBitStream.ReleaseStream();
|
||||
return S_OK;
|
||||
}
|
||||
*/
|
||||
|
||||
void CCoder::ReadLevelItems(NImplode::NHuffman::CDecoder &decoder,
|
||||
BYTE *levels, int numLevelItems)
|
||||
{
|
||||
int numCodedStructures = m_InBitStream.ReadBits(kNumBitsInByte) +
|
||||
kLevelStructuresNumberAdditionalValue;
|
||||
int currentIndex = 0;
|
||||
for(int i = 0; i < numCodedStructures; i++)
|
||||
{
|
||||
int level = m_InBitStream.ReadBits(kNumLevelStructureLevelBits) +
|
||||
kLevelStructureLevelAdditionalValue;
|
||||
int rep = m_InBitStream.ReadBits(kNumLevelStructureRepNumberBits) +
|
||||
kLevelStructureRepNumberAdditionalValue;
|
||||
if (currentIndex + rep > numLevelItems)
|
||||
throw CException(CException::kData);
|
||||
for(int j = 0; j < rep; j++)
|
||||
levels[currentIndex++] = level;
|
||||
}
|
||||
if (currentIndex != numLevelItems)
|
||||
throw CException(CException::kData);
|
||||
try
|
||||
{
|
||||
decoder.SetCodeLengths(levels);
|
||||
}
|
||||
catch(const NImplode::NHuffman::CDecoderException &)
|
||||
{
|
||||
throw CException(CException::kData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CCoder::ReadTables(void)
|
||||
{
|
||||
if (m_LiteralsOn)
|
||||
{
|
||||
BYTE literalLevels[kLiteralTableSize];
|
||||
ReadLevelItems(m_LiteralDecoder, literalLevels, kLiteralTableSize);
|
||||
}
|
||||
|
||||
BYTE lengthLevels[kLengthTableSize];
|
||||
ReadLevelItems(m_LengthDecoder, lengthLevels, kLengthTableSize);
|
||||
|
||||
BYTE distanceLevels[kDistanceTableSize];
|
||||
ReadLevelItems(m_DistanceDecoder, distanceLevels, kDistanceTableSize);
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
class CCoderReleaser
|
||||
{
|
||||
CCoder *m_Coder;
|
||||
public:
|
||||
CCoderReleaser(CCoder *coder): m_Coder(coder) {}
|
||||
~CCoderReleaser() { m_Coder->ReleaseStreams(); }
|
||||
};
|
||||
*/
|
||||
|
||||
STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream, const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (outSize == NULL)
|
||||
return E_INVALIDARG;
|
||||
UINT64 pos = 0, unPackSize = *outSize;
|
||||
|
||||
m_OutWindowStream.Init(outStream, false);
|
||||
m_InBitStream.Init(inStream);
|
||||
// CCoderReleaser coderReleaser(this);
|
||||
|
||||
ReadTables();
|
||||
|
||||
while(pos < unPackSize)
|
||||
{
|
||||
if (progress != NULL && pos % (1 << 16) == 0)
|
||||
{
|
||||
UINT64 packSize = m_InBitStream.GetProcessedSize();
|
||||
RINOK(progress->SetRatioInfo(&packSize, &pos));
|
||||
}
|
||||
if(m_InBitStream.ReadBits(1) == kMatchId) // match
|
||||
{
|
||||
UINT32 lowDistBits = m_InBitStream.ReadBits(m_NumDistanceLowDirectBits);
|
||||
UINT32 distance = (m_DistanceDecoder.DecodeSymbol(&m_InBitStream) <<
|
||||
m_NumDistanceLowDirectBits) + lowDistBits;
|
||||
|
||||
UINT32 lengthSymbol = m_LengthDecoder.DecodeSymbol(&m_InBitStream);
|
||||
UINT32 length = lengthSymbol + m_MinMatchLength;
|
||||
if (lengthSymbol == kLengthTableSize - 1) // special symbol = 63
|
||||
length += m_InBitStream.ReadBits(kNumAdditionalLengthBits);
|
||||
while(distance >= pos && length > 0)
|
||||
{
|
||||
m_OutWindowStream.PutOneByte(0);
|
||||
pos++;
|
||||
length--;
|
||||
}
|
||||
if (length > 0)
|
||||
m_OutWindowStream.CopyBackBlock(distance, length);
|
||||
pos += length;
|
||||
}
|
||||
else
|
||||
{
|
||||
BYTE b = BYTE(m_LiteralsOn ? m_LiteralDecoder.DecodeSymbol(&m_InBitStream) :
|
||||
m_InBitStream.ReadBits(kNumBitsInByte));
|
||||
m_OutWindowStream.PutOneByte(b);
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
if (pos > unPackSize)
|
||||
throw CException(CException::kData);
|
||||
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 CLZOutWindowException &e) { return e.ErrorCode; }
|
||||
catch(...) { return S_FALSE; }
|
||||
}
|
||||
|
||||
STDMETHODIMP CCoder::SetDecoderProperties(ISequentialInStream *inStream)
|
||||
{
|
||||
BYTE flag;
|
||||
UINT32 processedSize;
|
||||
RINOK(inStream->Read(&flag, sizeof(flag), &processedSize));
|
||||
if (processedSize != sizeof(flag))
|
||||
return E_INVALIDARG;
|
||||
m_BigDictionaryOn = ((flag & 2) != 0);
|
||||
m_NumDistanceLowDirectBits = m_BigDictionaryOn ?
|
||||
kNumDistanceLowDirectBitsForBigDict:
|
||||
kNumDistanceLowDirectBitsForSmallDict;
|
||||
m_LiteralsOn = ((flag & 4) != 0);
|
||||
m_MinMatchLength = m_LiteralsOn ?
|
||||
kMatchMinLenWhenLiteralsOn :
|
||||
kMatchMinLenWhenLiteralsOff;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}}}
|
||||
77
7zip/Compress/Implode/ImplodeDecoder.h
Executable file
77
7zip/Compress/Implode/ImplodeDecoder.h
Executable file
@@ -0,0 +1,77 @@
|
||||
// ImplodeDecoder.h
|
||||
|
||||
#ifndef __IMPLODE_DECODER_H
|
||||
#define __IMPLODE_DECODER_H
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
|
||||
#include "../../ICoder.h"
|
||||
#include "../LZ/LZOutWindow.h"
|
||||
|
||||
#include "ImplodeHuffmanDecoder.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NImplode {
|
||||
namespace NDecoder {
|
||||
|
||||
class CException
|
||||
{
|
||||
public:
|
||||
enum ECauseType
|
||||
{
|
||||
kData
|
||||
} m_Cause;
|
||||
CException(ECauseType cause): m_Cause(cause) {}
|
||||
};
|
||||
|
||||
class CCoder :
|
||||
public ICompressCoder,
|
||||
public ICompressSetDecoderProperties,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CLZOutWindow m_OutWindowStream;
|
||||
NStream::NLSBF::CDecoder<CInBuffer> m_InBitStream;
|
||||
|
||||
NImplode::NHuffman::CDecoder m_LiteralDecoder;
|
||||
NImplode::NHuffman::CDecoder m_LengthDecoder;
|
||||
NImplode::NHuffman::CDecoder m_DistanceDecoder;
|
||||
|
||||
|
||||
bool m_BigDictionaryOn;
|
||||
bool m_LiteralsOn;
|
||||
|
||||
int m_NumDistanceLowDirectBits;
|
||||
UINT32 m_MinMatchLength;
|
||||
|
||||
void ReadLevelItems(NImplode::NHuffman::CDecoder &table,
|
||||
BYTE *levels, int numLevelItems);
|
||||
void ReadTables();
|
||||
void DeCodeLevelTable(BYTE *newLevels, int numLevels);
|
||||
public:
|
||||
CCoder();
|
||||
|
||||
MY_UNKNOWN_IMP1(ICompressSetDecoderProperties)
|
||||
|
||||
// STDMETHOD(ReleaseStreams)();
|
||||
// STDMETHOD(Code)(UINT32 aSize, UINT32 &aProcessedSize);
|
||||
HRESULT (Flush)() { return m_OutWindowStream.Flush(); }
|
||||
|
||||
|
||||
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);
|
||||
|
||||
// ICompressSetDecoderProperties
|
||||
// STDMETHOD(SetCoderProperties)(PROPVARIANT *aProperties, UINT32 aNumProperties);
|
||||
STDMETHOD(SetDecoderProperties)(ISequentialInStream *inStream);
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
88
7zip/Compress/Implode/ImplodeHuffmanDecoder.cpp
Executable file
88
7zip/Compress/Implode/ImplodeHuffmanDecoder.cpp
Executable file
@@ -0,0 +1,88 @@
|
||||
// ImplodeHuffmanDecoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ImplodeHuffmanDecoder.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NImplode {
|
||||
namespace NHuffman {
|
||||
|
||||
CDecoder::CDecoder(UINT32 numSymbols):
|
||||
m_NumSymbols(numSymbols)
|
||||
{
|
||||
m_Symbols = new UINT32[m_NumSymbols];
|
||||
}
|
||||
|
||||
CDecoder::~CDecoder()
|
||||
{
|
||||
delete []m_Symbols;
|
||||
}
|
||||
|
||||
void CDecoder::SetCodeLengths(const BYTE *codeLengths)
|
||||
{
|
||||
// int lenCounts[kNumBitsInLongestCode + 1], tmpPositions[kNumBitsInLongestCode + 1];
|
||||
int lenCounts[kNumBitsInLongestCode + 2], tmpPositions[kNumBitsInLongestCode + 1];
|
||||
int i;
|
||||
for(i = 0; i <= kNumBitsInLongestCode; i++)
|
||||
lenCounts[i] = 0;
|
||||
UINT32 symbolIndex;
|
||||
for (symbolIndex = 0; symbolIndex < m_NumSymbols; symbolIndex++)
|
||||
lenCounts[codeLengths[symbolIndex]]++;
|
||||
// lenCounts[0] = 0;
|
||||
|
||||
// tmpPositions[0] = m_Positions[0] = m_Limitits[0] = 0;
|
||||
m_Limitits[kNumBitsInLongestCode + 1] = 0;
|
||||
m_Positions[kNumBitsInLongestCode + 1] = 0;
|
||||
lenCounts[kNumBitsInLongestCode + 1] = 0;
|
||||
|
||||
|
||||
UINT32 startPos = 0;
|
||||
static const UINT32 kMaxValue = (1 << kNumBitsInLongestCode);
|
||||
|
||||
for (i = kNumBitsInLongestCode; i > 0; i--)
|
||||
{
|
||||
startPos += lenCounts[i] << (kNumBitsInLongestCode - i);
|
||||
if (startPos > kMaxValue)
|
||||
throw CDecoderException();
|
||||
m_Limitits[i] = startPos;
|
||||
m_Positions[i] = m_Positions[i + 1] + lenCounts[i + 1];
|
||||
tmpPositions[i] = m_Positions[i] + lenCounts[i];
|
||||
|
||||
}
|
||||
|
||||
// if _ZIP_MODE do not throw exception for trees containing only one node
|
||||
// #ifndef _ZIP_MODE
|
||||
if (startPos != kMaxValue)
|
||||
throw CDecoderException();
|
||||
// #endif
|
||||
|
||||
for (symbolIndex = 0; symbolIndex < m_NumSymbols; symbolIndex++)
|
||||
if (codeLengths[symbolIndex] != 0)
|
||||
m_Symbols[--tmpPositions[codeLengths[symbolIndex]]] = symbolIndex;
|
||||
}
|
||||
|
||||
UINT32 CDecoder::DecodeSymbol(CInBit *inStream)
|
||||
{
|
||||
UINT32 numBits;
|
||||
UINT32 value = inStream->GetValue(kNumBitsInLongestCode);
|
||||
int i;
|
||||
for(i = kNumBitsInLongestCode; i > 0; i--)
|
||||
{
|
||||
if (value < m_Limitits[i])
|
||||
{
|
||||
numBits = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == 0)
|
||||
throw CDecoderException();
|
||||
inStream->MovePos(numBits);
|
||||
UINT32 index = m_Positions[numBits] +
|
||||
((value - m_Limitits[numBits + 1]) >> (kNumBitsInLongestCode - numBits));
|
||||
if (index >= m_NumSymbols)
|
||||
throw CDecoderException(); // test it
|
||||
return m_Symbols[index];
|
||||
}
|
||||
|
||||
}}}
|
||||
36
7zip/Compress/Implode/ImplodeHuffmanDecoder.h
Executable file
36
7zip/Compress/Implode/ImplodeHuffmanDecoder.h
Executable file
@@ -0,0 +1,36 @@
|
||||
// ImplodeHuffmanDecoder.h
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __IMPLODE_HUFFMAN_DECODER_H
|
||||
#define __IMPLODE_HUFFMAN_DECODER_H
|
||||
|
||||
#include "../../Common/LSBFDecoder.h"
|
||||
#include "../../Common/InBuffer.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NImplode {
|
||||
namespace NHuffman {
|
||||
|
||||
const int kNumBitsInLongestCode = 16;
|
||||
class CDecoderException{};
|
||||
|
||||
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_NumSymbols; // number of symbols in m_Symbols
|
||||
UINT32 *m_Symbols; // symbols: at first with len=1 then 2, ... 15.
|
||||
public:
|
||||
CDecoder(UINT32 numSymbols);
|
||||
~CDecoder();
|
||||
|
||||
void SetCodeLengths(const BYTE *codeLengths);
|
||||
UINT32 DecodeSymbol(CInBit *inStream);
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
3
7zip/Compress/Implode/StdAfx.cpp
Executable file
3
7zip/Compress/Implode/StdAfx.cpp
Executable file
@@ -0,0 +1,3 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "stdafx.h"
|
||||
8
7zip/Compress/Implode/StdAfx.h
Executable file
8
7zip/Compress/Implode/StdAfx.h
Executable file
@@ -0,0 +1,8 @@
|
||||
// stdafx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#endif
|
||||
15
7zip/Compress/Implode/resource.h
Executable file
15
7zip/Compress/Implode/resource.h
Executable file
@@ -0,0 +1,15 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Developer Studio generated include file.
|
||||
// Used by resource.rc
|
||||
//
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
121
7zip/Compress/Implode/resource.rc
Executable file
121
7zip/Compress/Implode/resource.rc
Executable file
@@ -0,0 +1,121 @@
|
||||
//Microsoft Developer Studio generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Russian resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT
|
||||
#pragma code_page(1251)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE DISCARDABLE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // Russian resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifndef _MAC
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 3,9,2,0
|
||||
PRODUCTVERSION 3,9,2,0
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "\0"
|
||||
VALUE "CompanyName", "Igor Pavlov\0"
|
||||
VALUE "FileDescription", "Implode Decoder\0"
|
||||
VALUE "FileVersion", "3, 9, 2, 0\0"
|
||||
VALUE "InternalName", "Implode\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 1999-2003 Igor Pavlov\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "Implode.dll\0"
|
||||
VALUE "PrivateBuild", "\0"
|
||||
VALUE "ProductName", "7-Zip\0"
|
||||
VALUE "ProductVersion", "3, 9, 2, 0\0"
|
||||
VALUE "SpecialBuild", "\0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // !_MAC
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
Reference in New Issue
Block a user