mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-15 04:11:46 -06:00
3.13
This commit is contained in:
88
7zip/Compress/LZMA/DllExports.cpp
Executable file
88
7zip/Compress/LZMA/DllExports.cpp
Executable file
@@ -0,0 +1,88 @@
|
||||
// DLLExports.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
// #include <initguid.h>
|
||||
#define INITGUID
|
||||
|
||||
#include "LZMAEncoder.h"
|
||||
#include "LZMADecoder.h"
|
||||
#include "../../../Common/ComTry.h"
|
||||
|
||||
// {23170F69-40C1-278B-0301-010000000000}
|
||||
DEFINE_GUID(CLSID_CLZMADecoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
// {23170F69-40C1-278B-0301-010000000100}
|
||||
DEFINE_GUID(CLSID_CLZMAEncoder,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x03, 0x01, 0x01, 0x00, 0x00, 0x00, 0x01, 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;
|
||||
int correctInterface = (*iid == IID_ICompressCoder);
|
||||
CMyComPtr<ICompressCoder> coder;
|
||||
if (*clsid == CLSID_CLZMADecoder)
|
||||
{
|
||||
if (!correctInterface)
|
||||
return E_NOINTERFACE;
|
||||
coder = (ICompressCoder *)new NCompress::NLZMA::CDecoder();
|
||||
}
|
||||
else if (*clsid == CLSID_CLZMAEncoder)
|
||||
{
|
||||
if (!correctInterface)
|
||||
return E_NOINTERFACE;
|
||||
coder = (ICompressCoder *)new NCompress::NLZMA::CEncoder();
|
||||
}
|
||||
else
|
||||
return CLASS_E_CLASSNOTAVAILABLE;
|
||||
*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[] = { 0x03, 0x01, 0x01 };
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(id, sizeof(id))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
case NMethodPropID::kName:
|
||||
if ((value->bstrVal = ::SysAllocString(L"LZMA")) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
case NMethodPropID::kDecoder:
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(
|
||||
(const char *)&CLSID_CLZMADecoder, sizeof(GUID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
case NMethodPropID::kEncoder:
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(
|
||||
(const char *)&CLSID_CLZMAEncoder, sizeof(GUID))) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
7
7zip/Compress/LZMA/LZMA.def
Executable file
7
7zip/Compress/LZMA/LZMA.def
Executable file
@@ -0,0 +1,7 @@
|
||||
LIBRARY LZMA
|
||||
|
||||
EXPORTS
|
||||
CreateObject
|
||||
GetNumberOfMethods
|
||||
GetMethodProperty
|
||||
|
||||
463
7zip/Compress/LZMA/LZMA.dsp
Executable file
463
7zip/Compress/LZMA/LZMA.dsp
Executable file
@@ -0,0 +1,463 @@
|
||||
# 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_BT" /D "COMPRESS_MF_PAT" /D "COMPRESS_MF_HC" /D "COMPRESS_MF_MT" /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_BT" /D "COMPRESS_MF_PAT" /D "COMPRESS_MF_HC" /D "COMPRESS_MF_MT" /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=.\DllExports.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZMA.def
|
||||
# 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
|
||||
# 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=..\MatchFinders\IMatchFinder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\IMyUnknown.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\IStream.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "LZ"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Group "MT"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\MT\MT.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=..\LZ\MT\MT.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Pat"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\Patricia\Pat.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\Patricia\Pat2.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\Patricia\Pat2H.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\Patricia\Pat2R.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\Patricia\Pat3H.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\Patricia\Pat4H.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\Patricia\PatMain.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "BT"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\BinTree\BinTree.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\BinTree\BinTree2.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\BinTree\BinTree3.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\BinTree\BinTree4.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\BinTree\BinTree4b.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\BinTree\BinTreeMain.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\BinTree\BinTreeMF.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\BinTree\BinTreeMFMain.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "HC"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\HashChain\HC.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\HashChain\HC2.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\HashChain\HC3.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\HashChain\HC4.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\HashChain\HC4b.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\HashChain\HCMain.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\HashChain\HCMF.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\HashChain\HCMFMain.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\IMatchFinder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\LZInWindow.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZ\LZInWindow.h
|
||||
# End Source File
|
||||
# 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\AlignedBuffer.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\AlignedBuffer.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\ComTry.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\CRC.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\CRC.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\NewHandler.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\NewHandler.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Windows"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Windows\Synchronization.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Windows\Synchronization.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
|
||||
# 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=.\LZMALen.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=.\LZMALen.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LZMALiteral.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=.\LZMALiteral.h
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
||||
29
7zip/Compress/LZMA/LZMA.dsw
Executable file
29
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>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
96
7zip/Compress/LZMA/LZMA.h
Executable file
96
7zip/Compress/LZMA/LZMA.h
Executable file
@@ -0,0 +1,96 @@
|
||||
// LZMA.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#include "LZMALen.h"
|
||||
|
||||
#ifndef __LZMA_H
|
||||
#define __LZMA_H
|
||||
|
||||
namespace NCompress {
|
||||
namespace NLZMA {
|
||||
|
||||
const UINT32 kNumRepDistances = 4;
|
||||
|
||||
const BYTE kNumStates = 12;
|
||||
|
||||
const BYTE kLiteralNextStates[kNumStates] = {0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5};
|
||||
const BYTE kMatchNextStates[kNumStates] = {7, 7, 7, 7, 7, 7, 7, 10, 10, 10, 10, 10};
|
||||
const BYTE kRepNextStates[kNumStates] = {8, 8, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11};
|
||||
const BYTE kShortRepNextStates[kNumStates]= {9, 9, 9, 9, 9, 9, 9, 11, 11, 11, 11, 11};
|
||||
|
||||
class CState
|
||||
{
|
||||
public:
|
||||
BYTE Index;
|
||||
void Init()
|
||||
{ Index = 0; }
|
||||
void UpdateChar()
|
||||
{ Index = kLiteralNextStates[Index]; }
|
||||
void UpdateMatch()
|
||||
{ Index = kMatchNextStates[Index]; }
|
||||
void UpdateRep()
|
||||
{ Index = kRepNextStates[Index]; }
|
||||
void UpdateShortRep()
|
||||
{ Index = kShortRepNextStates[Index]; }
|
||||
};
|
||||
|
||||
class CBaseCoder
|
||||
{
|
||||
protected:
|
||||
CState _state;
|
||||
BYTE _previousByte;
|
||||
bool _peviousIsMatch;
|
||||
UINT32 _repDistances[kNumRepDistances];
|
||||
void Init()
|
||||
{
|
||||
_state.Init();
|
||||
_previousByte = 0;
|
||||
_peviousIsMatch = false;
|
||||
for(int i = 0 ; i < kNumRepDistances; i++)
|
||||
_repDistances[i] = 0;
|
||||
}
|
||||
};
|
||||
|
||||
const int kNumPosSlotBits = 6;
|
||||
const int kDicLogSizeMin = 0;
|
||||
const int kDicLogSizeMax = 32;
|
||||
const int kDistTableSizeMax = kDicLogSizeMax * 2;
|
||||
|
||||
const UINT32 kNumLenToPosStates = 4;
|
||||
inline UINT32 GetLenToPosState(UINT32 len)
|
||||
{
|
||||
len -= 2;
|
||||
if (len < kNumLenToPosStates)
|
||||
return len;
|
||||
return kNumLenToPosStates - 1;
|
||||
}
|
||||
|
||||
const UINT32 kMatchMinLen = 2;
|
||||
|
||||
const UINT32 kMatchMaxLen = kMatchMinLen + NLength::kNumSymbolsTotal - 1;
|
||||
|
||||
const int kNumAlignBits = 4;
|
||||
const UINT32 kAlignTableSize = 1 << kNumAlignBits;
|
||||
const UINT32 kAlignMask = (kAlignTableSize - 1);
|
||||
|
||||
const UINT32 kStartPosModelIndex = 4;
|
||||
const UINT32 kEndPosModelIndex = 14;
|
||||
const UINT32 kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;
|
||||
|
||||
const UINT32 kNumFullDistances = 1 << (kEndPosModelIndex / 2);
|
||||
|
||||
const UINT32 kMainChoiceLiteralIndex = 0;
|
||||
const UINT32 kMainChoiceMatchIndex = 1;
|
||||
|
||||
const UINT32 kMatchChoiceDistanceIndex= 0;
|
||||
const UINT32 kMatchChoiceRepetitionIndex = 1;
|
||||
|
||||
const int kNumMoveBits = 5;
|
||||
|
||||
const int kNumLitPosStatesBitsEncodingMax = 4;
|
||||
const int kNumLitContextBitsMax = 8;
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
356
7zip/Compress/LZMA/LZMADecoder.cpp
Executable file
356
7zip/Compress/LZMA/LZMADecoder.cpp
Executable file
@@ -0,0 +1,356 @@
|
||||
// LZMADecoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "LZMADecoder.h"
|
||||
#include "../../../Common/Defs.h"
|
||||
#include "../../../Common/ComTry.h"
|
||||
|
||||
/*
|
||||
#include "fstream.h"
|
||||
#include "iomanip.h"
|
||||
|
||||
ofstream ofs("res.dat");
|
||||
|
||||
const int kNumCounters = 3;
|
||||
UINT32 g_Counter[kNumCounters];
|
||||
class C1
|
||||
{
|
||||
public:
|
||||
~C1()
|
||||
{
|
||||
for (int i = 0; i < kNumCounters; i++)
|
||||
ofs << setw(10) << g_Counter[i] << endl;
|
||||
}
|
||||
} g_C1;
|
||||
*/
|
||||
|
||||
/*
|
||||
const UINT32 kLenTableMax = 20;
|
||||
const UINT32 kNumDists = NCompress::NLZMA::kDistTableSizeMax / 2;
|
||||
UINT32 g_Counts[kLenTableMax][kNumDists];
|
||||
class C1
|
||||
{
|
||||
public:
|
||||
~C1 ()
|
||||
{
|
||||
UINT32 sums[kLenTableMax];
|
||||
for (int len = 2; len < kLenTableMax; len++)
|
||||
{
|
||||
sums[len] = 0;
|
||||
for (int dist = 0; dist < kNumDists; dist++)
|
||||
sums[len] += g_Counts[len][dist];
|
||||
if (sums[len] == 0)
|
||||
sums[len] = 1;
|
||||
}
|
||||
for (int dist = 0; dist < kNumDists; dist++)
|
||||
{
|
||||
ofs << setw(4) << dist << " ";
|
||||
for (int len = 2; len < kLenTableMax; len++)
|
||||
{
|
||||
ofs << setw(4) << g_Counts[len][dist] * 1000 / sums[len];
|
||||
}
|
||||
ofs << endl;
|
||||
}
|
||||
}
|
||||
} g_Class;
|
||||
|
||||
void UpdateStat(UINT32 len, UINT32 dist)
|
||||
{
|
||||
if (len >= kLenTableMax)
|
||||
len = kLenTableMax - 1;
|
||||
g_Counts[len][dist / 2]++;
|
||||
}
|
||||
*/
|
||||
|
||||
namespace NCompress {
|
||||
namespace NLZMA {
|
||||
|
||||
HRESULT CDecoder::SetDictionarySize(UINT32 dictionarySize)
|
||||
{
|
||||
if (_dictionarySize != dictionarySize)
|
||||
{
|
||||
_dictionarySize = dictionarySize;
|
||||
_dictionarySizeCheck = MyMax(_dictionarySize, UINT32(1));
|
||||
UINT32 blockSize = MyMax(_dictionarySizeCheck, UINT32(1 << 12));
|
||||
try
|
||||
{
|
||||
_outWindowStream.Create(blockSize /*, kMatchMaxLen */);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CDecoder::SetLiteralProperties(
|
||||
UINT32 numLiteralPosStateBits, UINT32 numLiteralContextBits)
|
||||
{
|
||||
if (numLiteralPosStateBits > 8)
|
||||
return E_INVALIDARG;
|
||||
if (numLiteralContextBits > 8)
|
||||
return E_INVALIDARG;
|
||||
_literalDecoder.Create(numLiteralPosStateBits, numLiteralContextBits);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CDecoder::SetPosBitsProperties(UINT32 numPosStateBits)
|
||||
{
|
||||
if (numPosStateBits > NLength::kNumPosStatesBitsMax)
|
||||
return E_INVALIDARG;
|
||||
UINT32 numPosStates = 1 << numPosStateBits;
|
||||
_lenDecoder.Create(numPosStates);
|
||||
_repMatchLenDecoder.Create(numPosStates);
|
||||
_posStateMask = numPosStates - 1;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
CDecoder::CDecoder():
|
||||
_dictionarySize((UINT32)-1)
|
||||
{
|
||||
Create();
|
||||
}
|
||||
|
||||
HRESULT CDecoder::Create()
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
for(int i = 0; i < kNumPosModels; i++)
|
||||
_posDecoders[i].Create(((kStartPosModelIndex + i) >> 1) - 1);
|
||||
COM_TRY_END
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
|
||||
HRESULT CDecoder::Init(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream)
|
||||
{
|
||||
_rangeDecoder.Init(inStream);
|
||||
|
||||
_outWindowStream.Init(outStream);
|
||||
|
||||
int i;
|
||||
for(i = 0; i < kNumStates; i++)
|
||||
{
|
||||
for (UINT32 j = 0; j <= _posStateMask; j++)
|
||||
{
|
||||
_mainChoiceDecoders[i][j].Init();
|
||||
_matchRepShortChoiceDecoders[i][j].Init();
|
||||
}
|
||||
_matchChoiceDecoders[i].Init();
|
||||
_matchRepChoiceDecoders[i].Init();
|
||||
_matchRep1ChoiceDecoders[i].Init();
|
||||
_matchRep2ChoiceDecoders[i].Init();
|
||||
}
|
||||
|
||||
_literalDecoder.Init();
|
||||
|
||||
// _repMatchLenDecoder.Init();
|
||||
|
||||
for (i = 0; i < kNumLenToPosStates; i++)
|
||||
_posSlotDecoder[i].Init();
|
||||
|
||||
for(i = 0; i < kNumPosModels; i++)
|
||||
_posDecoders[i].Init();
|
||||
|
||||
_lenDecoder.Init();
|
||||
_repMatchLenDecoder.Init();
|
||||
|
||||
_posAlignDecoder.Init();
|
||||
return S_OK;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
/*
|
||||
if (outSize == NULL)
|
||||
return E_INVALIDARG;
|
||||
*/
|
||||
|
||||
Init(inStream, outStream);
|
||||
CDecoderFlusher flusher(this);
|
||||
|
||||
CState state;
|
||||
state.Init();
|
||||
bool peviousIsMatch = false;
|
||||
BYTE previousByte = 0;
|
||||
UINT32 repDistances[kNumRepDistances];
|
||||
for(int i = 0 ; i < kNumRepDistances; i++)
|
||||
repDistances[i] = 0;
|
||||
|
||||
UINT64 nowPos64 = 0;
|
||||
UINT64 size = (outSize == NULL) ? (UINT64)(INT64)(-1) : *outSize;
|
||||
while(nowPos64 < size)
|
||||
{
|
||||
UINT64 nextPos = MyMin(nowPos64 + (1 << 18), size);
|
||||
while(nowPos64 < nextPos)
|
||||
{
|
||||
UINT32 posState = UINT32(nowPos64) & _posStateMask;
|
||||
if (_mainChoiceDecoders[state.Index][posState].Decode(&_rangeDecoder) == kMainChoiceLiteralIndex)
|
||||
{
|
||||
state.UpdateChar();
|
||||
if(peviousIsMatch)
|
||||
{
|
||||
BYTE matchByte = _outWindowStream.GetOneByte(0 - repDistances[0] - 1);
|
||||
previousByte = _literalDecoder.DecodeWithMatchByte(&_rangeDecoder,
|
||||
UINT32(nowPos64), previousByte, matchByte);
|
||||
peviousIsMatch = false;
|
||||
}
|
||||
else
|
||||
previousByte = _literalDecoder.DecodeNormal(&_rangeDecoder,
|
||||
UINT32(nowPos64), previousByte);
|
||||
_outWindowStream.PutOneByte(previousByte);
|
||||
nowPos64++;
|
||||
}
|
||||
else
|
||||
{
|
||||
peviousIsMatch = true;
|
||||
UINT32 distance, len;
|
||||
if(_matchChoiceDecoders[state.Index].Decode(&_rangeDecoder) ==
|
||||
kMatchChoiceRepetitionIndex)
|
||||
{
|
||||
if(_matchRepChoiceDecoders[state.Index].Decode(&_rangeDecoder) == 0)
|
||||
{
|
||||
if(_matchRepShortChoiceDecoders[state.Index][posState].Decode(&_rangeDecoder) == 0)
|
||||
{
|
||||
state.UpdateShortRep();
|
||||
previousByte = _outWindowStream.GetOneByte(0 - repDistances[0] - 1);
|
||||
_outWindowStream.PutOneByte(previousByte);
|
||||
nowPos64++;
|
||||
continue;
|
||||
}
|
||||
distance = repDistances[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
if(_matchRep1ChoiceDecoders[state.Index].Decode(&_rangeDecoder) == 0)
|
||||
distance = repDistances[1];
|
||||
else
|
||||
{
|
||||
if (_matchRep2ChoiceDecoders[state.Index].Decode(&_rangeDecoder) == 0)
|
||||
distance = repDistances[2];
|
||||
else
|
||||
{
|
||||
distance = repDistances[3];
|
||||
repDistances[3] = repDistances[2];
|
||||
}
|
||||
repDistances[2] = repDistances[1];
|
||||
}
|
||||
repDistances[1] = repDistances[0];
|
||||
repDistances[0] = distance;
|
||||
}
|
||||
len = _repMatchLenDecoder.Decode(&_rangeDecoder, posState) + kMatchMinLen;
|
||||
state.UpdateRep();
|
||||
}
|
||||
else
|
||||
{
|
||||
len = kMatchMinLen + _lenDecoder.Decode(&_rangeDecoder, posState);
|
||||
state.UpdateMatch();
|
||||
UINT32 posSlot = _posSlotDecoder[GetLenToPosState(len)].Decode(&_rangeDecoder);
|
||||
if (posSlot >= kStartPosModelIndex)
|
||||
{
|
||||
UINT32 numDirectBits = (posSlot >> 1) - 1;
|
||||
distance = ((2 | (posSlot & 1)) << numDirectBits);
|
||||
|
||||
if (posSlot < kEndPosModelIndex)
|
||||
distance += _posDecoders[posSlot - kStartPosModelIndex].Decode(&_rangeDecoder);
|
||||
else
|
||||
{
|
||||
distance += (_rangeDecoder.DecodeDirectBits(
|
||||
numDirectBits - kNumAlignBits) << kNumAlignBits);
|
||||
distance += _posAlignDecoder.Decode(&_rangeDecoder);
|
||||
}
|
||||
}
|
||||
else
|
||||
distance = posSlot;
|
||||
|
||||
repDistances[3] = repDistances[2];
|
||||
repDistances[2] = repDistances[1];
|
||||
repDistances[1] = repDistances[0];
|
||||
repDistances[0] = distance;
|
||||
// UpdateStat(len, posSlot);
|
||||
}
|
||||
if (distance >= nowPos64 || distance >= _dictionarySizeCheck)
|
||||
{
|
||||
if (distance == (UINT32)(-1) && size == (UINT64)(INT64)(-1))
|
||||
{
|
||||
flusher.NeedFlush = false;
|
||||
return Flush();
|
||||
}
|
||||
throw "data error";
|
||||
}
|
||||
_outWindowStream.CopyBackBlock(distance, len);
|
||||
nowPos64 += len;
|
||||
previousByte = _outWindowStream.GetOneByte(0 - 1);
|
||||
}
|
||||
}
|
||||
if (progress != NULL)
|
||||
{
|
||||
UINT64 inSize = _rangeDecoder.GetProcessedSize();
|
||||
RINOK(progress->SetRatioInfo(&inSize, &nowPos64));
|
||||
}
|
||||
}
|
||||
flusher.NeedFlush = false;
|
||||
return Flush();
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::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; }
|
||||
}
|
||||
|
||||
|
||||
static HRESULT DecodeProperties(ISequentialInStream *inStream,
|
||||
UINT32 &numPosStateBits,
|
||||
UINT32 &numLiteralPosStateBits,
|
||||
UINT32 &numLiteralContextBits,
|
||||
UINT32 &dictionarySize)
|
||||
{
|
||||
UINT32 processesedSize;
|
||||
|
||||
BYTE firstByte;
|
||||
RINOK(inStream->Read(&firstByte, sizeof(firstByte), &processesedSize));
|
||||
if (processesedSize != sizeof(firstByte))
|
||||
return E_INVALIDARG;
|
||||
|
||||
numLiteralContextBits = firstByte % 9;
|
||||
BYTE remainder = firstByte / 9;
|
||||
numLiteralPosStateBits = remainder % 5;
|
||||
numPosStateBits = remainder / 5;
|
||||
|
||||
RINOK(inStream->Read(&dictionarySize, sizeof(dictionarySize), &processesedSize));
|
||||
if (processesedSize != sizeof(dictionarySize))
|
||||
return E_INVALIDARG;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::SetDecoderProperties(ISequentialInStream *inStream)
|
||||
{
|
||||
UINT32 numPosStateBits;
|
||||
UINT32 numLiteralPosStateBits;
|
||||
UINT32 numLiteralContextBits;
|
||||
UINT32 dictionarySize;
|
||||
RINOK(DecodeProperties(inStream,
|
||||
numPosStateBits,
|
||||
numLiteralPosStateBits,
|
||||
numLiteralContextBits,
|
||||
dictionarySize));
|
||||
RINOK(SetDictionarySize(dictionarySize));
|
||||
RINOK(SetLiteralProperties(numLiteralPosStateBits, numLiteralContextBits));
|
||||
RINOK(SetPosBitsProperties(numPosStateBits));
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}}
|
||||
107
7zip/Compress/LZMA/LZMADecoder.h
Executable file
107
7zip/Compress/LZMA/LZMADecoder.h
Executable file
@@ -0,0 +1,107 @@
|
||||
// LZMA/Decoder.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __LZMA_DECODER_H
|
||||
#define __LZMA_DECODER_H
|
||||
|
||||
#include "../../ICoder.h"
|
||||
#include "../../../Common/MyCom.h"
|
||||
#include "../LZ/LZOutWindow.h"
|
||||
|
||||
#include "LZMA.h"
|
||||
#include "LZMALen.h"
|
||||
#include "LZMALiteral.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NLZMA {
|
||||
|
||||
typedef NRangeCoder::CBitDecoder<kNumMoveBits> CMyBitDecoder;
|
||||
|
||||
class CDecoder:
|
||||
public ICompressCoder,
|
||||
public ICompressSetDecoderProperties,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
CLZOutWindow _outWindowStream;
|
||||
NRangeCoder::CDecoder _rangeDecoder;
|
||||
|
||||
CMyBitDecoder _mainChoiceDecoders[kNumStates][NLength::kNumPosStatesMax];
|
||||
CMyBitDecoder _matchChoiceDecoders[kNumStates];
|
||||
CMyBitDecoder _matchRepChoiceDecoders[kNumStates];
|
||||
CMyBitDecoder _matchRep1ChoiceDecoders[kNumStates];
|
||||
CMyBitDecoder _matchRep2ChoiceDecoders[kNumStates];
|
||||
CMyBitDecoder _matchRepShortChoiceDecoders[kNumStates][NLength::kNumPosStatesMax];
|
||||
|
||||
NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumPosSlotBits> _posSlotDecoder[kNumLenToPosStates];
|
||||
|
||||
NRangeCoder::CReverseBitTreeDecoder2<kNumMoveBits> _posDecoders[kNumPosModels];
|
||||
NRangeCoder::CReverseBitTreeDecoder<kNumMoveBits, kNumAlignBits> _posAlignDecoder;
|
||||
|
||||
NLength::CDecoder _lenDecoder;
|
||||
NLength::CDecoder _repMatchLenDecoder;
|
||||
|
||||
NLiteral::CDecoder _literalDecoder;
|
||||
|
||||
UINT32 _dictionarySize;
|
||||
UINT32 _dictionarySizeCheck;
|
||||
|
||||
UINT32 _posStateMask;
|
||||
|
||||
public:
|
||||
|
||||
MY_UNKNOWN_IMP1(ICompressSetDecoderProperties)
|
||||
|
||||
CDecoder();
|
||||
HRESULT Create();
|
||||
|
||||
|
||||
HRESULT Init(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream);
|
||||
/*
|
||||
void ReleaseStreams()
|
||||
{
|
||||
_outWindowStream.ReleaseStream();
|
||||
_rangeDecoder.ReleaseStream();
|
||||
}
|
||||
*/
|
||||
|
||||
class CDecoderFlusher
|
||||
{
|
||||
CDecoder *_decoder;
|
||||
public:
|
||||
bool NeedFlush;
|
||||
CDecoderFlusher(CDecoder *decoder):
|
||||
_decoder(decoder), NeedFlush(true) {}
|
||||
~CDecoderFlusher()
|
||||
{
|
||||
if (NeedFlush)
|
||||
_decoder->Flush();
|
||||
// _decoder->ReleaseStreams();
|
||||
}
|
||||
};
|
||||
|
||||
HRESULT Flush()
|
||||
{ return _outWindowStream.Flush(); }
|
||||
|
||||
// ICompressCoder interface
|
||||
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(SetDecoderProperties)(ISequentialInStream *inStream);
|
||||
|
||||
HRESULT SetDictionarySize(UINT32 dictionarySize);
|
||||
HRESULT SetLiteralProperties(UINT32 numLiteralPosStateBits,
|
||||
UINT32 numLiteralContextBits);
|
||||
HRESULT SetPosBitsProperties(UINT32 numPosStateBits);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
1274
7zip/Compress/LZMA/LZMAEncoder.cpp
Executable file
1274
7zip/Compress/LZMA/LZMAEncoder.cpp
Executable file
File diff suppressed because it is too large
Load Diff
294
7zip/Compress/LZMA/LZMAEncoder.h
Executable file
294
7zip/Compress/LZMA/LZMAEncoder.h
Executable file
@@ -0,0 +1,294 @@
|
||||
// LZMA/Encoder.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __LZMA_ENCODER_H
|
||||
#define __LZMA_ENCODER_H
|
||||
|
||||
#include "../../ICoder.h"
|
||||
#include "../../../Common/MyCom.h"
|
||||
#include "../LZ/IMatchFinder.h"
|
||||
|
||||
#include "LZMA.h"
|
||||
#include "LZMALen.h"
|
||||
#include "LZMALiteral.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NLZMA {
|
||||
|
||||
class CMatchFinderException
|
||||
{
|
||||
public:
|
||||
HRESULT ErrorCode;
|
||||
CMatchFinderException(HRESULT errorCode): ErrorCode(errorCode) {}
|
||||
};
|
||||
|
||||
struct COptimal
|
||||
{
|
||||
CState State;
|
||||
|
||||
bool Prev1IsChar;
|
||||
bool Prev2;
|
||||
|
||||
UINT32 PosPrev2;
|
||||
UINT32 BackPrev2;
|
||||
|
||||
UINT32 Price;
|
||||
UINT32 PosPrev; // posNext;
|
||||
UINT32 BackPrev;
|
||||
UINT32 Backs[kNumRepDistances];
|
||||
void MakeAsChar() { BackPrev = UINT32(-1); Prev1IsChar = false; }
|
||||
void MakeAsShortRep() { BackPrev = 0; ; Prev1IsChar = false; }
|
||||
bool IsShortRep() { return (BackPrev == 0); }
|
||||
};
|
||||
|
||||
|
||||
extern BYTE g_FastPos[1024];
|
||||
inline UINT32 GetPosSlot(UINT32 pos)
|
||||
{
|
||||
if (pos < (1 << 10))
|
||||
return g_FastPos[pos];
|
||||
if (pos < (1 << 19))
|
||||
return g_FastPos[pos >> 9] + 18;
|
||||
return g_FastPos[pos >> 18] + 36;
|
||||
}
|
||||
|
||||
inline UINT32 GetPosSlot2(UINT32 pos)
|
||||
{
|
||||
if (pos < (1 << 16))
|
||||
return g_FastPos[pos >> 6] + 12;
|
||||
if (pos < (1 << 25))
|
||||
return g_FastPos[pos >> 15] + 30;
|
||||
return g_FastPos[pos >> 24] + 48;
|
||||
}
|
||||
|
||||
const UINT32 kIfinityPrice = 0xFFFFFFF;
|
||||
|
||||
typedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder;
|
||||
|
||||
const UINT32 kNumOpts = 1 << 12;
|
||||
|
||||
class CEncoder :
|
||||
public ICompressCoder,
|
||||
// public IInitMatchFinder,
|
||||
public ICompressSetCoderProperties,
|
||||
public ICompressWriteCoderProperties,
|
||||
public CBaseCoder,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
COptimal _optimum[kNumOpts];
|
||||
public:
|
||||
CMyComPtr<IMatchFinder> _matchFinder; // test it
|
||||
NRangeCoder::CEncoder _rangeEncoder;
|
||||
private:
|
||||
|
||||
CMyBitEncoder _mainChoiceEncoders[kNumStates][NLength::kNumPosStatesEncodingMax];
|
||||
CMyBitEncoder _matchChoiceEncoders[kNumStates];
|
||||
CMyBitEncoder _matchRepChoiceEncoders[kNumStates];
|
||||
CMyBitEncoder _matchRep1ChoiceEncoders[kNumStates];
|
||||
CMyBitEncoder _matchRep2ChoiceEncoders[kNumStates];
|
||||
CMyBitEncoder _matchRepShortChoiceEncoders[kNumStates][NLength::kNumPosStatesEncodingMax];
|
||||
|
||||
NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates];
|
||||
|
||||
NRangeCoder::CReverseBitTreeEncoder2<kNumMoveBits> _posEncoders[kNumPosModels];
|
||||
NRangeCoder::CReverseBitTreeEncoder2<kNumMoveBits> _posAlignEncoder;
|
||||
|
||||
NLength::CPriceTableEncoder _lenEncoder;
|
||||
NLength::CPriceTableEncoder _repMatchLenEncoder;
|
||||
|
||||
NLiteral::CEncoder _literalEncoder;
|
||||
|
||||
UINT32 _matchDistances[kMatchMaxLen + 1];
|
||||
|
||||
bool _fastMode;
|
||||
bool _maxMode;
|
||||
UINT32 _numFastBytes;
|
||||
UINT32 _longestMatchLength;
|
||||
|
||||
UINT32 _additionalOffset;
|
||||
|
||||
UINT32 _optimumEndIndex;
|
||||
UINT32 _optimumCurrentIndex;
|
||||
|
||||
bool _longestMatchWasFound;
|
||||
|
||||
UINT32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax];
|
||||
|
||||
UINT32 _distancesPrices[kNumLenToPosStates][kNumFullDistances];
|
||||
|
||||
UINT32 _alignPrices[kAlignTableSize];
|
||||
UINT32 _alignPriceCount;
|
||||
|
||||
UINT32 _distTableSize;
|
||||
|
||||
UINT32 _posStateBits;
|
||||
UINT32 _posStateMask;
|
||||
UINT32 _numLiteralPosStateBits;
|
||||
UINT32 _numLiteralContextBits;
|
||||
|
||||
UINT32 _dictionarySize;
|
||||
|
||||
UINT32 _dictionarySizePrev;
|
||||
UINT32 _numFastBytesPrev;
|
||||
|
||||
UINT64 lastPosSlotFillingPos;
|
||||
UINT64 nowPos64;
|
||||
bool _finished;
|
||||
ISequentialInStream *_inStream;
|
||||
|
||||
int _matchFinderIndex;
|
||||
#ifdef COMPRESS_MF_MT
|
||||
bool _multiThread;
|
||||
#endif
|
||||
|
||||
bool _writeEndMark;
|
||||
|
||||
UINT32 ReadMatchDistances()
|
||||
{
|
||||
UINT32 len = _matchFinder->GetLongestMatch(_matchDistances);
|
||||
if (len == _numFastBytes)
|
||||
len += _matchFinder->GetMatchLen(len, _matchDistances[len],
|
||||
kMatchMaxLen - len);
|
||||
_additionalOffset++;
|
||||
HRESULT result = _matchFinder->MovePos();
|
||||
if (result != S_OK)
|
||||
throw CMatchFinderException(result);
|
||||
return len;
|
||||
}
|
||||
|
||||
void MovePos(UINT32 num);
|
||||
UINT32 GetRepLen1Price(CState state, UINT32 posState) const
|
||||
{
|
||||
return _matchRepChoiceEncoders[state.Index].GetPrice(0) +
|
||||
_matchRepShortChoiceEncoders[state.Index][posState].GetPrice(0);
|
||||
}
|
||||
UINT32 GetRepPrice(UINT32 repIndex, UINT32 len, CState state, UINT32 posState) const
|
||||
{
|
||||
UINT32 price = _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState);
|
||||
if(repIndex == 0)
|
||||
{
|
||||
price += _matchRepChoiceEncoders[state.Index].GetPrice(0);
|
||||
price += _matchRepShortChoiceEncoders[state.Index][posState].GetPrice(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
price += _matchRepChoiceEncoders[state.Index].GetPrice(1);
|
||||
if (repIndex == 1)
|
||||
price += _matchRep1ChoiceEncoders[state.Index].GetPrice(0);
|
||||
else
|
||||
{
|
||||
price += _matchRep1ChoiceEncoders[state.Index].GetPrice(1);
|
||||
price += _matchRep2ChoiceEncoders[state.Index].GetPrice(repIndex - 2);
|
||||
}
|
||||
}
|
||||
return price;
|
||||
}
|
||||
/*
|
||||
UINT32 GetPosLen2Price(UINT32 pos, UINT32 posState) const
|
||||
{
|
||||
if (pos >= kNumFullDistances)
|
||||
return kIfinityPrice;
|
||||
return _distancesPrices[0][pos] + _lenEncoder.GetPrice(0, posState);
|
||||
}
|
||||
UINT32 GetPosLen3Price(UINT32 pos, UINT32 len, UINT32 posState) const
|
||||
{
|
||||
UINT32 price;
|
||||
UINT32 lenToPosState = GetLenToPosState(len);
|
||||
if (pos < kNumFullDistances)
|
||||
price = _distancesPrices[lenToPosState][pos];
|
||||
else
|
||||
price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] +
|
||||
_alignPrices[pos & kAlignMask];
|
||||
return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);
|
||||
}
|
||||
*/
|
||||
UINT32 GetPosLenPrice(UINT32 pos, UINT32 len, UINT32 posState) const
|
||||
{
|
||||
if (len == 2 && pos >= 0x80)
|
||||
return kIfinityPrice;
|
||||
UINT32 price;
|
||||
UINT32 lenToPosState = GetLenToPosState(len);
|
||||
if (pos < kNumFullDistances)
|
||||
price = _distancesPrices[lenToPosState][pos];
|
||||
else
|
||||
price = _posSlotPrices[lenToPosState][GetPosSlot2(pos)] +
|
||||
_alignPrices[pos & kAlignMask];
|
||||
return price + _lenEncoder.GetPrice(len - kMatchMinLen, posState);
|
||||
}
|
||||
|
||||
UINT32 Backward(UINT32 &backRes, UINT32 cur);
|
||||
UINT32 GetOptimum(UINT32 &backRes, UINT32 position);
|
||||
UINT32 GetOptimumFast(UINT32 &backRes, UINT32 position);
|
||||
|
||||
void FillPosSlotPrices();
|
||||
void FillDistancesPrices();
|
||||
void FillAlignPrices();
|
||||
|
||||
void ReleaseStreams()
|
||||
{
|
||||
_matchFinder->ReleaseStream();
|
||||
// _rangeEncoder.ReleaseStream();
|
||||
}
|
||||
|
||||
HRESULT Flush();
|
||||
class CCoderReleaser
|
||||
{
|
||||
CEncoder *_coder;
|
||||
public:
|
||||
CCoderReleaser(CEncoder *coder): _coder(coder) {}
|
||||
~CCoderReleaser()
|
||||
{
|
||||
_coder->ReleaseStreams();
|
||||
}
|
||||
};
|
||||
friend class CCoderReleaser;
|
||||
|
||||
void WriteEndMarker(UINT32 posState);
|
||||
|
||||
public:
|
||||
CEncoder();
|
||||
void SetWriteEndMarkerMode(bool writeEndMarker)
|
||||
{ _writeEndMark= writeEndMarker; }
|
||||
|
||||
HRESULT Create();
|
||||
|
||||
MY_UNKNOWN_IMP2(
|
||||
ICompressSetCoderProperties,
|
||||
ICompressWriteCoderProperties
|
||||
)
|
||||
|
||||
STDMETHOD(Init)(
|
||||
ISequentialOutStream *outStream);
|
||||
|
||||
// ICompressCoder interface
|
||||
HRESULT SetStreams(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UINT64 *inSize, const UINT64 *outSize);
|
||||
HRESULT CodeOneBlock(UINT64 *inSize, UINT64 *outSize, INT32 *finished);
|
||||
|
||||
HRESULT CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
// ICompressCoder interface
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UINT64 *inSize, const UINT64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
// IInitMatchFinder interface
|
||||
STDMETHOD(InitMatchFinder)(IMatchFinder *matchFinder);
|
||||
|
||||
// ICompressSetCoderProperties2
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UINT32 numProperties);
|
||||
|
||||
// ICompressWriteCoderProperties
|
||||
STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
74
7zip/Compress/LZMA/LZMALen.cpp
Executable file
74
7zip/Compress/LZMA/LZMALen.cpp
Executable file
@@ -0,0 +1,74 @@
|
||||
// LZMALen.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "LZMALen.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NLZMA {
|
||||
namespace NLength {
|
||||
|
||||
void CEncoder::Init()
|
||||
{
|
||||
_choice.Init();
|
||||
for (UINT32 posState = 0; posState < _numPosStates; posState++)
|
||||
{
|
||||
_lowCoder[posState].Init();
|
||||
_midCoder[posState].Init();
|
||||
}
|
||||
_choice2.Init();
|
||||
_highCoder.Init();
|
||||
}
|
||||
|
||||
void CEncoder::Encode(NRangeCoder::CEncoder *rangeEncoder, UINT32 symbol, UINT32 posState)
|
||||
{
|
||||
if(symbol < kNumLowSymbols)
|
||||
{
|
||||
_choice.Encode(rangeEncoder, 0);
|
||||
_lowCoder[posState].Encode(rangeEncoder, symbol);
|
||||
}
|
||||
else
|
||||
{
|
||||
symbol -= kNumLowSymbols;
|
||||
_choice.Encode(rangeEncoder, 1);
|
||||
if(symbol < kNumMidSymbols)
|
||||
{
|
||||
_choice2.Encode(rangeEncoder, 0);
|
||||
_midCoder[posState].Encode(rangeEncoder, symbol);
|
||||
}
|
||||
else
|
||||
{
|
||||
_choice2.Encode(rangeEncoder, 1);
|
||||
_highCoder.Encode(rangeEncoder, symbol - kNumMidSymbols);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UINT32 CEncoder::GetPrice(UINT32 symbol, UINT32 posState) const
|
||||
{
|
||||
UINT32 price = 0;
|
||||
if(symbol < kNumLowSymbols)
|
||||
{
|
||||
price += _choice.GetPrice(0);
|
||||
price += _lowCoder[posState].GetPrice(symbol);
|
||||
}
|
||||
else
|
||||
{
|
||||
symbol -= kNumLowSymbols;
|
||||
price += _choice.GetPrice(1);
|
||||
if(symbol < kNumMidSymbols)
|
||||
{
|
||||
price += _choice2.GetPrice(0);
|
||||
price += _midCoder[posState].GetPrice(symbol);
|
||||
}
|
||||
else
|
||||
{
|
||||
price += _choice2.GetPrice(1);
|
||||
price += _highCoder.GetPrice(symbol - kNumMidSymbols);
|
||||
}
|
||||
}
|
||||
return price;
|
||||
}
|
||||
|
||||
}}}
|
||||
|
||||
114
7zip/Compress/LZMA/LZMALen.h
Executable file
114
7zip/Compress/LZMA/LZMALen.h
Executable file
@@ -0,0 +1,114 @@
|
||||
// LenCoder.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __LENCODER_H
|
||||
#define __LENCODER_H
|
||||
|
||||
#include "../RangeCoder/RangeCoderBitTree.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NLZMA {
|
||||
namespace NLength {
|
||||
|
||||
const int kNumMoveBits = 5;
|
||||
|
||||
const int kNumPosStatesBitsMax = 4;
|
||||
const UINT32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax);
|
||||
|
||||
const int kNumPosStatesBitsEncodingMax = 4;
|
||||
const UINT32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);
|
||||
|
||||
const int kNumLenBits = 3;
|
||||
const UINT32 kNumLowSymbols = 1 << kNumLenBits;
|
||||
const int kNumMidBits = 3;
|
||||
const UINT32 kNumMidSymbols = 1 << kNumMidBits;
|
||||
|
||||
const int kNumHighBits = 8;
|
||||
|
||||
const UINT32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits);
|
||||
|
||||
class CEncoder
|
||||
{
|
||||
NRangeCoder::CBitEncoder<kNumMoveBits> _choice;
|
||||
NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLenBits> _lowCoder[kNumPosStatesEncodingMax];
|
||||
NRangeCoder::CBitEncoder<kNumMoveBits> _choice2;
|
||||
NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesEncodingMax];
|
||||
NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits> _highCoder;
|
||||
protected:
|
||||
UINT32 _numPosStates;
|
||||
public:
|
||||
void Create(UINT32 numPosStates)
|
||||
{ _numPosStates = numPosStates; }
|
||||
void Init();
|
||||
void Encode(NRangeCoder::CEncoder *rangeEncoder, UINT32 symbol, UINT32 posState);
|
||||
UINT32 GetPrice(UINT32 symbol, UINT32 posState) const;
|
||||
};
|
||||
|
||||
const UINT32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;
|
||||
|
||||
class CPriceTableEncoder: public CEncoder
|
||||
{
|
||||
UINT32 _prices[kNumSymbolsTotal][kNumPosStatesEncodingMax];
|
||||
UINT32 _tableSize;
|
||||
UINT32 _counters[kNumPosStatesEncodingMax];
|
||||
public:
|
||||
void SetTableSize(UINT32 tableSize)
|
||||
{ _tableSize = tableSize; }
|
||||
UINT32 GetPrice(UINT32 symbol, UINT32 posState) const
|
||||
{ return _prices[symbol][posState]; }
|
||||
void UpdateTable(UINT32 posState)
|
||||
{
|
||||
for (UINT32 len = 0; len < _tableSize; len++)
|
||||
_prices[len][posState] = CEncoder::GetPrice(len , posState);
|
||||
_counters[posState] = _tableSize;
|
||||
}
|
||||
void UpdateTables()
|
||||
{
|
||||
for (UINT32 posState = 0; posState < _numPosStates; posState++)
|
||||
UpdateTable(posState);
|
||||
}
|
||||
void Encode(NRangeCoder::CEncoder *rangeEncoder, UINT32 symbol, UINT32 posState)
|
||||
{
|
||||
CEncoder::Encode(rangeEncoder, symbol, posState);
|
||||
if (--_counters[posState] == 0)
|
||||
UpdateTable(posState);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CDecoder
|
||||
{
|
||||
NRangeCoder::CBitDecoder<kNumMoveBits> _choice;
|
||||
NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumLenBits> _lowCoder[kNumPosStatesMax];
|
||||
NRangeCoder::CBitDecoder<kNumMoveBits> _choice2;
|
||||
NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesMax];
|
||||
NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumHighBits> _highCoder;
|
||||
UINT32 _numPosStates;
|
||||
public:
|
||||
void Create(UINT32 numPosStates)
|
||||
{ _numPosStates = numPosStates; }
|
||||
void Init()
|
||||
{
|
||||
_choice.Init();
|
||||
for (UINT32 posState = 0; posState < _numPosStates; posState++)
|
||||
{
|
||||
_lowCoder[posState].Init();
|
||||
_midCoder[posState].Init();
|
||||
}
|
||||
_choice2.Init();
|
||||
_highCoder.Init();
|
||||
}
|
||||
UINT32 Decode(NRangeCoder::CDecoder *rangeDecoder, UINT32 posState)
|
||||
{
|
||||
if(_choice.Decode(rangeDecoder) == 0)
|
||||
return _lowCoder[posState].Decode(rangeDecoder);
|
||||
if(_choice2.Decode(rangeDecoder) == 0)
|
||||
return kNumLowSymbols + _midCoder[posState].Decode(rangeDecoder);
|
||||
return kNumLowSymbols + kNumMidSymbols + _highCoder.Decode(rangeDecoder);
|
||||
}
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
69
7zip/Compress/LZMA/LZMALiteral.cpp
Executable file
69
7zip/Compress/LZMA/LZMALiteral.cpp
Executable file
@@ -0,0 +1,69 @@
|
||||
// LZMALiteral.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "LZMALiteral.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NLZMA {
|
||||
namespace NLiteral {
|
||||
|
||||
void CEncoder2::Init()
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int j = 1; j < (1 << 8); j++)
|
||||
_encoders[i][j].Init();
|
||||
}
|
||||
|
||||
void CEncoder2::Encode(NRangeCoder::CEncoder *rangeEncoder,
|
||||
bool matchMode, BYTE matchByte, BYTE symbol)
|
||||
{
|
||||
UINT32 context = 1;
|
||||
bool same = true;
|
||||
for (int i = 7; i >= 0; i--)
|
||||
{
|
||||
UINT32 bit = (symbol >> i) & 1;
|
||||
UINT state;
|
||||
if (matchMode && same)
|
||||
{
|
||||
UINT32 matchBit = (matchByte >> i) & 1;
|
||||
state = 1 + matchBit;
|
||||
same = (matchBit == bit);
|
||||
}
|
||||
else
|
||||
state = 0;
|
||||
_encoders[state][context].Encode(rangeEncoder, bit);
|
||||
context = (context << 1) | bit;
|
||||
}
|
||||
}
|
||||
|
||||
UINT32 CEncoder2::GetPrice(bool matchMode, BYTE matchByte, BYTE symbol) const
|
||||
{
|
||||
UINT32 price = 0;
|
||||
UINT32 context = 1;
|
||||
int i = 7;
|
||||
if (matchMode)
|
||||
{
|
||||
for (; i >= 0; i--)
|
||||
{
|
||||
UINT32 matchBit = (matchByte >> i) & 1;
|
||||
UINT32 bit = (symbol >> i) & 1;
|
||||
price += _encoders[1 + matchBit][context].GetPrice(bit);
|
||||
context = (context << 1) | bit;
|
||||
if (matchBit != bit)
|
||||
{
|
||||
i--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (; i >= 0; i--)
|
||||
{
|
||||
UINT32 bit = (symbol >> i) & 1;
|
||||
price += _encoders[0][context].GetPrice(bit);
|
||||
context = (context << 1) | bit;
|
||||
}
|
||||
return price;
|
||||
};
|
||||
|
||||
}}}
|
||||
166
7zip/Compress/LZMA/LZMALiteral.h
Executable file
166
7zip/Compress/LZMA/LZMALiteral.h
Executable file
@@ -0,0 +1,166 @@
|
||||
// LiteralCoder.h
|
||||
|
||||
// #pragma once
|
||||
|
||||
#ifndef __LITERALCODER_H
|
||||
#define __LITERALCODER_H
|
||||
|
||||
#include "../RangeCoder/RangeCoderBit.h"
|
||||
#include "../RangeCoder/RangeCoderOpt.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NLZMA {
|
||||
namespace NLiteral {
|
||||
|
||||
const int kNumMoveBits = 5;
|
||||
|
||||
class CEncoder2
|
||||
{
|
||||
NRangeCoder::CBitEncoder<kNumMoveBits> _encoders[3][1 << 8];
|
||||
public:
|
||||
void Init();
|
||||
void Encode(NRangeCoder::CEncoder *rangeEncoder, bool matchMode, BYTE matchByte, BYTE symbol);
|
||||
UINT32 GetPrice(bool matchMode, BYTE matchByte, BYTE symbol) const;
|
||||
};
|
||||
|
||||
class CDecoder2
|
||||
{
|
||||
NRangeCoder::CBitDecoder<kNumMoveBits> _decoders[3][1 << 8];
|
||||
public:
|
||||
void Init()
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
for (int j = 1; j < (1 << 8); j++)
|
||||
_decoders[i][j].Init();
|
||||
}
|
||||
|
||||
BYTE DecodeNormal(NRangeCoder::CDecoder *rangeDecoder)
|
||||
{
|
||||
UINT32 symbol = 1;
|
||||
RC_INIT_VAR
|
||||
do
|
||||
{
|
||||
// symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);
|
||||
RC_GETBIT(kNumMoveBits, _decoders[0][symbol].Probability, symbol)
|
||||
}
|
||||
while (symbol < 0x100);
|
||||
RC_FLUSH_VAR
|
||||
return symbol;
|
||||
}
|
||||
|
||||
BYTE DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, BYTE matchByte)
|
||||
{
|
||||
UINT32 symbol = 1;
|
||||
RC_INIT_VAR
|
||||
do
|
||||
{
|
||||
UINT32 matchBit = (matchByte >> 7) & 1;
|
||||
matchByte <<= 1;
|
||||
// UINT32 bit = _decoders[1 + matchBit][symbol].Decode(rangeDecoder);
|
||||
// symbol = (symbol << 1) | bit;
|
||||
UINT32 bit;
|
||||
RC_GETBIT2(kNumMoveBits, _decoders[1 + matchBit][symbol].Probability, symbol,
|
||||
bit = 0, bit = 1)
|
||||
if (matchBit != bit)
|
||||
{
|
||||
while (symbol < 0x100)
|
||||
{
|
||||
// symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder);
|
||||
RC_GETBIT(kNumMoveBits, _decoders[0][symbol].Probability, symbol)
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (symbol < 0x100);
|
||||
RC_FLUSH_VAR
|
||||
return symbol;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
const UINT32 kNumPrevByteBits = 1;
|
||||
const UINT32 kNumPrevByteStates = (1 << kNumPrevByteBits);
|
||||
|
||||
inline UINT32 GetLiteralState(BYTE prevByte)
|
||||
{ return (prevByte >> (8 - kNumPrevByteBits)); }
|
||||
*/
|
||||
|
||||
class CEncoder
|
||||
{
|
||||
CEncoder2 *_coders;
|
||||
UINT32 _numPrevBits;
|
||||
UINT32 _numPosBits;
|
||||
UINT32 _posMask;
|
||||
public:
|
||||
CEncoder(): _coders(0) {}
|
||||
~CEncoder() { Free(); }
|
||||
void Free()
|
||||
{
|
||||
delete []_coders;
|
||||
_coders = 0;
|
||||
}
|
||||
void Create(UINT32 numPosBits, UINT32 numPrevBits)
|
||||
{
|
||||
Free();
|
||||
_numPosBits = numPosBits;
|
||||
_posMask = (1 << numPosBits) - 1;
|
||||
_numPrevBits = numPrevBits;
|
||||
UINT32 numStates = 1 << (_numPrevBits + _numPosBits);
|
||||
_coders = new CEncoder2[numStates];
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
UINT32 numStates = 1 << (_numPrevBits + _numPosBits);
|
||||
for (UINT32 i = 0; i < numStates; i++)
|
||||
_coders[i].Init();
|
||||
}
|
||||
UINT32 GetState(UINT32 pos, BYTE prevByte) const
|
||||
{ return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }
|
||||
void Encode(NRangeCoder::CEncoder *rangeEncoder, UINT32 pos, BYTE prevByte,
|
||||
bool matchMode, BYTE matchByte, BYTE symbol)
|
||||
{ _coders[GetState(pos, prevByte)].Encode(rangeEncoder, matchMode,
|
||||
matchByte, symbol); }
|
||||
UINT32 GetPrice(UINT32 pos, BYTE prevByte, bool matchMode, BYTE matchByte, BYTE symbol) const
|
||||
{ return _coders[GetState(pos, prevByte)].GetPrice(matchMode, matchByte, symbol); }
|
||||
};
|
||||
|
||||
class CDecoder
|
||||
{
|
||||
CDecoder2 *_coders;
|
||||
UINT32 _numPrevBits;
|
||||
UINT32 _numPosBits;
|
||||
UINT32 _posMask;
|
||||
public:
|
||||
CDecoder(): _coders(0) {}
|
||||
~CDecoder() { Free(); }
|
||||
void Free()
|
||||
{
|
||||
delete []_coders;
|
||||
_coders = 0;
|
||||
}
|
||||
void Create(UINT32 numPosBits, UINT32 numPrevBits)
|
||||
{
|
||||
Free();
|
||||
_numPosBits = numPosBits;
|
||||
_posMask = (1 << numPosBits) - 1;
|
||||
_numPrevBits = numPrevBits;
|
||||
UINT32 numStates = 1 << (_numPrevBits + _numPosBits);
|
||||
_coders = new CDecoder2[numStates];
|
||||
}
|
||||
void Init()
|
||||
{
|
||||
UINT32 numStates = 1 << (_numPrevBits + _numPosBits);
|
||||
for (UINT32 i = 0; i < numStates; i++)
|
||||
_coders[i].Init();
|
||||
}
|
||||
UINT32 GetState(UINT32 pos, BYTE prevByte) const
|
||||
{ return ((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits)); }
|
||||
BYTE DecodeNormal(NRangeCoder::CDecoder *rangeDecoder, UINT32 pos, BYTE prevByte)
|
||||
{ return _coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder); }
|
||||
BYTE DecodeWithMatchByte(NRangeCoder::CDecoder *rangeDecoder, UINT32 pos, BYTE prevByte, BYTE matchByte)
|
||||
{ return _coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte); }
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
3
7zip/Compress/LZMA/StdAfx.cpp
Executable file
3
7zip/Compress/LZMA/StdAfx.cpp
Executable file
@@ -0,0 +1,3 @@
|
||||
// StdAfx.cpp
|
||||
|
||||
#include "stdafx.h"
|
||||
8
7zip/Compress/LZMA/StdAfx.h
Executable file
8
7zip/Compress/LZMA/StdAfx.h
Executable file
@@ -0,0 +1,8 @@
|
||||
// stdafx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#endif
|
||||
15
7zip/Compress/LZMA/resource.h
Executable file
15
7zip/Compress/LZMA/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/LZMA/resource.rc
Executable file
121
7zip/Compress/LZMA/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,12,0,0
|
||||
PRODUCTVERSION 3,12,0,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", "LZMA Codec\0"
|
||||
VALUE "FileVersion", "3, 12, 0, 0\0"
|
||||
VALUE "InternalName", "LZMA\0"
|
||||
VALUE "LegalCopyright", "Copyright (C) 1999-2003 Igor Pavlov\0"
|
||||
VALUE "LegalTrademarks", "\0"
|
||||
VALUE "OriginalFilename", "LZMA.dll\0"
|
||||
VALUE "PrivateBuild", "\0"
|
||||
VALUE "ProductName", "7-Zip\0"
|
||||
VALUE "ProductVersion", "3, 12, 0, 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