diff options
author | Igor Pavlov <ipavlov@users.sourceforge.net> | 2008-05-05 04:00:00 +0400 |
---|---|---|
committer | Kornel LesiĆski <kornel@geekhood.net> | 2016-05-28 02:15:55 +0300 |
commit | 3901bf0ab88106a5b031cba7bc18d60cdebf7eef (patch) | |
tree | 808a2489abed822223b118b64e0553db80af6087 /CPP/7zip/Compress | |
parent | bd1fa36322ac27f5715433b388742893d6524516 (diff) |
4.58 beta
Diffstat (limited to 'CPP/7zip/Compress')
84 files changed, 572 insertions, 6471 deletions
diff --git a/CPP/7zip/Compress/Arj/ArjDecoder1.cpp b/CPP/7zip/Compress/Arj/ArjDecoder1.cpp index dda3721a..df859971 100755 --- a/CPP/7zip/Compress/Arj/ArjDecoder1.cpp +++ b/CPP/7zip/Compress/Arj/ArjDecoder1.cpp @@ -237,7 +237,7 @@ UInt32 CCoder::decode_p() } -STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream, +HRESULT CCoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo *progress) { @@ -297,7 +297,7 @@ STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream, UInt32 len = number - 256 + kMatchMinLen; UInt32 distance = decode_p(); if (distance >= pos) - throw "data error"; + return S_FALSE; m_OutWindowStream.CopyBlock(distance, len); pos += len; } diff --git a/CPP/7zip/Compress/Arj/ArjDecoder1.h b/CPP/7zip/Compress/Arj/ArjDecoder1.h index 434a0a41..b337ec72 100755 --- a/CPP/7zip/Compress/Arj/ArjDecoder1.h +++ b/CPP/7zip/Compress/Arj/ArjDecoder1.h @@ -86,13 +86,11 @@ class CCoder : UInt32 decode_c(); UInt32 decode_p(); -public: - - MY_UNKNOWN_IMP - - STDMETHOD(CodeReal)(ISequentialInStream *inStream, + HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); +public: + MY_UNKNOWN_IMP STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, diff --git a/CPP/7zip/Compress/Arj/ArjDecoder2.cpp b/CPP/7zip/Compress/Arj/ArjDecoder2.cpp index 24c101d1..a0eca445 100755 --- a/CPP/7zip/Compress/Arj/ArjDecoder2.cpp +++ b/CPP/7zip/Compress/Arj/ArjDecoder2.cpp @@ -12,7 +12,7 @@ static const UInt32 kHistorySize = 26624; // static const UInt32 kMatchMaxLen = 256; static const UInt32 kMatchMinLen = 3; -STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream, +HRESULT CCoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream, const UInt64 * /* inSize */, const UInt64 *outSize, ICompressProgressInfo * /* progress */) { @@ -71,7 +71,7 @@ STDMETHODIMP CCoder::CodeReal(ISequentialInStream *inStream, if (width != 0) distance += m_InBitStream.ReadBits(width); if (distance >= pos) - throw "data error"; + return S_FALSE; m_OutWindowStream.CopyBlock(distance, len); pos += len; } diff --git a/CPP/7zip/Compress/Arj/ArjDecoder2.h b/CPP/7zip/Compress/Arj/ArjDecoder2.h index 7a33f6bd..67a54eba 100755 --- a/CPP/7zip/Compress/Arj/ArjDecoder2.h +++ b/CPP/7zip/Compress/Arj/ArjDecoder2.h @@ -47,12 +47,11 @@ class CCoder : }; friend class CCoderReleaser; -public: - MY_UNKNOWN_IMP - - STDMETHOD(CodeReal)(ISequentialInStream *inStream, + HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); +public: + MY_UNKNOWN_IMP STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, diff --git a/CPP/7zip/Compress/BWT/BlockSort.cpp b/CPP/7zip/Compress/BWT/BlockSort.cpp deleted file mode 100755 index 283d8302..00000000 --- a/CPP/7zip/Compress/BWT/BlockSort.cpp +++ /dev/null @@ -1,486 +0,0 @@ -// BlockSort.cpp - -#include "StdAfx.h" - -#include "BlockSort.h" - -extern "C" -{ - #include "../../../../C/Sort.h" -} - -// use BLOCK_SORT_EXTERNAL_FLAGS if blockSize > 1M -// #define BLOCK_SORT_USE_HEAP_SORT - -#if _MSC_VER >= 1300 - #define NO_INLINE __declspec(noinline) __fastcall -#else -#ifdef _MSC_VER - #define NO_INLINE __fastcall -#else - #define NO_INLINE -#endif -#endif - -// Don't change it !! -static const int kNumHashBytes = 2; -static const UInt32 kNumHashValues = 1 << (kNumHashBytes * 8); - -static const int kNumRefBitsMax = 12; // must be < (kNumHashBytes * 8) = 16 - -#define BS_TEMP_SIZE kNumHashValues - -#ifdef BLOCK_SORT_EXTERNAL_FLAGS - -static const int kNumFlagsBits = 5; // 32 Flags in UInt32 word -static const UInt32 kNumFlagsInWord = (1 << kNumFlagsBits); -static const UInt32 kFlagsMask = kNumFlagsInWord - 1; -static const UInt32 kAllFlags = 0xFFFFFFFF; - -#else - -const int kNumBitsMax = 20; -const UInt32 kIndexMask = (1 << kNumBitsMax) - 1; -const int kNumExtraBits = 32 - kNumBitsMax; -const int kNumExtra0Bits = kNumExtraBits - 2; -const UInt32 kNumExtra0Mask = (1 << kNumExtra0Bits) - 1; - -#define SetFinishedGroupSize(p, size) \ - { *(p) |= ((((size) - 1) & kNumExtra0Mask) << kNumBitsMax); \ - if ((size) > (1 << kNumExtra0Bits)) { \ - *(p) |= 0x40000000; *((p) + 1) |= ((((size) - 1)>> kNumExtra0Bits) << kNumBitsMax); } } \ - -inline void SetGroupSize(UInt32 *p, UInt32 size) -{ - if (--size == 0) - return; - *p |= 0x80000000 | ((size & kNumExtra0Mask) << kNumBitsMax); - if (size >= (1 << kNumExtra0Bits)) - { - *p |= 0x40000000; - p[1] |= ((size >> kNumExtra0Bits) << kNumBitsMax); - } -} - -#endif - -// SortGroup - is recursive Range-Sort function with HeapSort optimization for small blocks -// "range" is not real range. It's only for optimization. -// returns: 1 - if there are groups, 0 - no more groups - -UInt32 NO_INLINE SortGroup(UInt32 BlockSize, UInt32 NumSortedBytes, UInt32 groupOffset, UInt32 groupSize, int NumRefBits, UInt32 *Indices - #ifndef BLOCK_SORT_USE_HEAP_SORT - , UInt32 left, UInt32 range - #endif - ) -{ - UInt32 *ind2 = Indices + groupOffset; - if (groupSize <= 1) - { - /* - #ifndef BLOCK_SORT_EXTERNAL_FLAGS - SetFinishedGroupSize(ind2, 1); - #endif - */ - return 0; - } - UInt32 *Groups = Indices + BlockSize + BS_TEMP_SIZE; - if (groupSize <= ((UInt32)1 << NumRefBits) - #ifndef BLOCK_SORT_USE_HEAP_SORT - && groupSize <= range - #endif - ) - { - UInt32 *temp = Indices + BlockSize; - UInt32 j; - { - UInt32 gPrev; - UInt32 gRes = 0; - { - UInt32 sp = ind2[0] + NumSortedBytes; - if (sp >= BlockSize) sp -= BlockSize; - gPrev = Groups[sp]; - temp[0] = (gPrev << NumRefBits); - } - - for (j = 1; j < groupSize; j++) - { - UInt32 sp = ind2[j] + NumSortedBytes; - if (sp >= BlockSize) sp -= BlockSize; - UInt32 g = Groups[sp]; - temp[j] = (g << NumRefBits) | j; - gRes |= (gPrev ^ g); - } - if (gRes == 0) - { - #ifndef BLOCK_SORT_EXTERNAL_FLAGS - SetGroupSize(ind2, groupSize); - #endif - return 1; - } - } - - HeapSort(temp, groupSize); - const UInt32 mask = ((1 << NumRefBits) - 1); - UInt32 thereAreGroups = 0; - - UInt32 group = groupOffset; - UInt32 cg = (temp[0] >> NumRefBits); - temp[0] = ind2[temp[0] & mask]; - - #ifdef BLOCK_SORT_EXTERNAL_FLAGS - UInt32 *Flags = Groups + BlockSize; - #else - UInt32 prevGroupStart = 0; - #endif - - for (j = 1; j < groupSize; j++) - { - UInt32 val = temp[j]; - UInt32 cgCur = (val >> NumRefBits); - - if (cgCur != cg) - { - cg = cgCur; - group = groupOffset + j; - - #ifdef BLOCK_SORT_EXTERNAL_FLAGS - UInt32 t = group - 1; - Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); - #else - SetGroupSize(temp + prevGroupStart, j - prevGroupStart); - prevGroupStart = j; - #endif - } - else - thereAreGroups = 1; - UInt32 ind = ind2[val & mask]; - temp[j] = ind; - Groups[ind] = group; - } - - #ifndef BLOCK_SORT_EXTERNAL_FLAGS - SetGroupSize(temp + prevGroupStart, j - prevGroupStart); - #endif - - for (j = 0; j < groupSize; j++) - ind2[j] = temp[j]; - return thereAreGroups; - } - - // Check that all strings are in one group (cannot sort) - { - UInt32 sp = ind2[0] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize; - UInt32 group = Groups[sp]; - UInt32 j; - for (j = 1; j < groupSize; j++) - { - sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize; - if (Groups[sp] != group) - break; - } - if (j == groupSize) - { - #ifndef BLOCK_SORT_EXTERNAL_FLAGS - SetGroupSize(ind2, groupSize); - #endif - return 1; - } - } - - #ifndef BLOCK_SORT_USE_HEAP_SORT - //-------------------------------------- - // Range Sort - UInt32 i; - UInt32 mid; - for (;;) - { - if (range <= 1) - { - #ifndef BLOCK_SORT_EXTERNAL_FLAGS - SetGroupSize(ind2, groupSize); - #endif - return 1; - } - mid = left + ((range + 1) >> 1); - UInt32 j = groupSize; - i = 0; - do - { - UInt32 sp = ind2[i] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize; - if (Groups[sp] >= mid) - { - for (j--; j > i; j--) - { - sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize; - if (Groups[sp] < mid) - { - UInt32 temp = ind2[i]; ind2[i] = ind2[j]; ind2[j] = temp; - break; - } - } - if (i >= j) - break; - } - } - while(++i < j); - if (i == 0) - { - range = range - (mid - left); - left = mid; - } - else if (i == groupSize) - range = (mid - left); - else - break; - } - - #ifdef BLOCK_SORT_EXTERNAL_FLAGS - { - UInt32 t = (groupOffset + i - 1); - UInt32 *Flags = Groups + BlockSize; - Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); - } - #endif - - for (UInt32 j = i; j < groupSize; j++) - Groups[ind2[j]] = groupOffset + i; - - UInt32 res = SortGroup(BlockSize, NumSortedBytes, groupOffset, i, NumRefBits, Indices, left, mid - left); - return res | SortGroup(BlockSize, NumSortedBytes, groupOffset + i, groupSize - i, NumRefBits, Indices, mid, range - (mid - left)); - - #else - - //-------------------------------------- - // Heap Sort - - { - UInt32 j; - for (j = 0; j < groupSize; j++) - { - UInt32 sp = ind2[j] + NumSortedBytes; if (sp >= BlockSize) sp -= BlockSize; - ind2[j] = sp; - } - - HeapSortRef(ind2, Groups, groupSize); - - // Write Flags - UInt32 sp = ind2[0]; - UInt32 group = Groups[sp]; - - #ifdef BLOCK_SORT_EXTERNAL_FLAGS - UInt32 *Flags = Groups + BlockSize; - #else - UInt32 prevGroupStart = 0; - #endif - - for (j = 1; j < groupSize; j++) - { - sp = ind2[j]; - if (Groups[sp] != group) - { - group = Groups[sp]; - #ifdef BLOCK_SORT_EXTERNAL_FLAGS - UInt32 t = groupOffset + j - 1; - Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); - #else - SetGroupSize(ind2 + prevGroupStart, j - prevGroupStart); - prevGroupStart = j; - #endif - } - } - - #ifndef BLOCK_SORT_EXTERNAL_FLAGS - SetGroupSize(ind2 + prevGroupStart, j - prevGroupStart); - #endif - - // Write new Groups values and Check that there are groups - UInt32 thereAreGroups = 0; - for (j = 0; j < groupSize; j++) - { - UInt32 group = groupOffset + j; - #ifndef BLOCK_SORT_EXTERNAL_FLAGS - UInt32 subGroupSize = ((ind2[j] & ~0xC0000000) >> kNumBitsMax); - if ((ind2[j] & 0x40000000) != 0) - subGroupSize += ((ind2[j + 1] >> kNumBitsMax) << kNumExtra0Bits); - subGroupSize++; - for (;;) - { - UInt32 original = ind2[j]; - UInt32 sp = original & kIndexMask; - if (sp < NumSortedBytes) sp += BlockSize; sp -= NumSortedBytes; - ind2[j] = sp | (original & ~kIndexMask); - Groups[sp] = group; - if (--subGroupSize == 0) - break; - j++; - thereAreGroups = 1; - } - #else - for (;;) - { - UInt32 sp = ind2[j]; if (sp < NumSortedBytes) sp += BlockSize; sp -= NumSortedBytes; - ind2[j] = sp; - Groups[sp] = group; - if ((Flags[(groupOffset + j) >> kNumFlagsBits] & (1 << ((groupOffset + j) & kFlagsMask))) == 0) - break; - j++; - thereAreGroups = 1; - } - #endif - } - return thereAreGroups; - } - #endif -} - -// conditions: blockSize > 0 -UInt32 BlockSort(UInt32 *Indices, const Byte *data, UInt32 blockSize) -{ - UInt32 *counters = Indices + blockSize; - UInt32 i; - - // Radix-Sort for 2 bytes - for (i = 0; i < kNumHashValues; i++) - counters[i] = 0; - for (i = 0; i < blockSize - 1; i++) - counters[((UInt32)data[i] << 8) | data[i + 1]]++; - counters[((UInt32)data[i] << 8) | data[0]]++; - - UInt32 *Groups = counters + BS_TEMP_SIZE; - #ifdef BLOCK_SORT_EXTERNAL_FLAGS - UInt32 *Flags = Groups + blockSize; - { - UInt32 numWords = (blockSize + kFlagsMask) >> kNumFlagsBits; - for (i = 0; i < numWords; i++) - Flags[i] = kAllFlags; - } - #endif - - { - UInt32 sum = 0; - for (i = 0; i < kNumHashValues; i++) - { - UInt32 groupSize = counters[i]; - if (groupSize > 0) - { - #ifdef BLOCK_SORT_EXTERNAL_FLAGS - UInt32 t = sum + groupSize - 1; - Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); - #endif - sum += groupSize; - } - counters[i] = sum - groupSize; - } - - for (i = 0; i < blockSize - 1; i++) - Groups[i] = counters[((UInt32)data[i] << 8) | data[i + 1]]; - Groups[i] = counters[((UInt32)data[i] << 8) | data[0]]; - - for (i = 0; i < blockSize - 1; i++) - Indices[counters[((UInt32)data[i] << 8) | data[i + 1]]++] = i; - Indices[counters[((UInt32)data[i] << 8) | data[0]]++] = i; - - #ifndef BLOCK_SORT_EXTERNAL_FLAGS - UInt32 prev = 0; - for (i = 0; i < kNumHashValues; i++) - { - UInt32 prevGroupSize = counters[i] - prev; - if (prevGroupSize == 0) - continue; - SetGroupSize(Indices + prev, prevGroupSize); - prev = counters[i]; - } - #endif - } - - int NumRefBits; - for (NumRefBits = 0; ((blockSize - 1) >> NumRefBits) != 0; NumRefBits++); - NumRefBits = 32 - NumRefBits; - if (NumRefBits > kNumRefBitsMax) - NumRefBits = kNumRefBitsMax; - - for (UInt32 NumSortedBytes = kNumHashBytes; ; NumSortedBytes <<= 1) - { - #ifndef BLOCK_SORT_EXTERNAL_FLAGS - UInt32 finishedGroupSize = 0; - #endif - UInt32 newLimit = 0; - for (i = 0; i < blockSize;) - { - #ifdef BLOCK_SORT_EXTERNAL_FLAGS - - if ((Flags[i >> kNumFlagsBits] & (1 << (i & kFlagsMask))) == 0) - { - i++; - continue; - } - UInt32 groupSize; - for(groupSize = 1; - (Flags[(i + groupSize) >> kNumFlagsBits] & (1 << ((i + groupSize) & kFlagsMask))) != 0; - groupSize++); - - groupSize++; - - #else - - UInt32 groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax); - bool finishedGroup = ((Indices[i] & 0x80000000) == 0); - if ((Indices[i] & 0x40000000) != 0) - { - groupSize += ((Indices[i + 1] >> kNumBitsMax) << kNumExtra0Bits); - Indices[i + 1] &= kIndexMask; - } - Indices[i] &= kIndexMask; - groupSize++; - if (finishedGroup || groupSize == 1) - { - Indices[i - finishedGroupSize] &= kIndexMask; - if (finishedGroupSize > 1) - Indices[i - finishedGroupSize + 1] &= kIndexMask; - UInt32 newGroupSize = groupSize + finishedGroupSize; - SetFinishedGroupSize(Indices + i - finishedGroupSize, newGroupSize); - finishedGroupSize = newGroupSize; - i += groupSize; - continue; - } - finishedGroupSize = 0; - - #endif - - if (NumSortedBytes >= blockSize) - for (UInt32 j = 0; j < groupSize; j++) - { - UInt32 t = (i + j); - // Flags[t >> kNumFlagsBits] &= ~(1 << (t & kFlagsMask)); - Groups[Indices[t]] = t; - } - else - if (SortGroup(blockSize, NumSortedBytes, i, groupSize, NumRefBits, Indices - #ifndef BLOCK_SORT_USE_HEAP_SORT - , 0, blockSize - #endif - ) != 0) - newLimit = i + groupSize; - i += groupSize; - } - if (newLimit == 0) - break; - } - #ifndef BLOCK_SORT_EXTERNAL_FLAGS - for (i = 0; i < blockSize;) - { - UInt32 groupSize = ((Indices[i] & ~0xC0000000) >> kNumBitsMax); - if ((Indices[i] & 0x40000000) != 0) - { - groupSize += ((Indices[i + 1] >> kNumBitsMax) << kNumExtra0Bits); - Indices[i + 1] &= kIndexMask; - } - Indices[i] &= kIndexMask; - groupSize++; - i += groupSize; - } - #endif - return Groups[0]; -} - diff --git a/CPP/7zip/Compress/BWT/BlockSort.h b/CPP/7zip/Compress/BWT/BlockSort.h deleted file mode 100755 index def48a96..00000000 --- a/CPP/7zip/Compress/BWT/BlockSort.h +++ /dev/null @@ -1,21 +0,0 @@ -// BlockSort.h - -#ifndef __BLOCKSORT_H -#define __BLOCKSORT_H - -#include "Common/Types.h" - -// use BLOCK_SORT_EXTERNAL_FLAGS if blockSize can be > 1M -// #define BLOCK_SORT_EXTERNAL_FLAGS - -#ifdef BLOCK_SORT_EXTERNAL_FLAGS -#define BLOCK_SORT_EXTERNAL_SIZE(blockSize) ((((blockSize) + 31) >> 5)) -#else -#define BLOCK_SORT_EXTERNAL_SIZE(blockSize) 0 -#endif - -#define BLOCK_SORT_BUF_SIZE(blockSize) ((blockSize) * 2 + BLOCK_SORT_EXTERNAL_SIZE(blockSize) + (1 << 16)) - -UInt32 BlockSort(UInt32 *indices, const Byte *data, UInt32 blockSize); - -#endif diff --git a/CPP/7zip/Compress/BZip2/BZip2.dsp b/CPP/7zip/Compress/BZip2/BZip2.dsp deleted file mode 100755 index e26819a0..00000000 --- a/CPP/7zip/Compress/BZip2/BZip2.dsp +++ /dev/null @@ -1,316 +0,0 @@ -# Microsoft Developer Studio Project File - Name="BZip2" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=BZip2 - 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 "BZip2.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 "BZip2.mak" CFG="BZip2 - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "BZip2 - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "BZip2 - 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)" == "BZip2 - 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 "BZIP2_EXPORTS" /YX /FD /c -# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "BZ_NO_STDIO" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BZIP2_EXPORTS" /D "COMPRESS_BZIP2_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\BZip2.dll" /opt:NOWIN98 -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "BZip2 - 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 "BZIP2_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BZIP2_EXPORTS" /D "COMPRESS_BZIP2_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\BZip2.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "BZip2 - Win32 Release" -# Name "BZip2 - Win32 Debug" -# Begin Group "Spec" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Codec.def -# End Source File -# Begin Source File - -SOURCE=..\CodecExports.cpp -# End Source File -# Begin Source File - -SOURCE=..\DllExports.cpp -# End Source File -# Begin Source File - -SOURCE=.\resource.rc -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.cpp -# ADD CPP /Yc"StdAfx.h" -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.h -# End Source File -# End Group -# Begin Group "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 "Huffman" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Huffman\HuffmanDecoder.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Huffman\HuffmanEncode.c - -!IF "$(CFG)" == "BZip2 - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Huffman\HuffmanEncode.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Sort.c - -!IF "$(CFG)" == "BZip2 - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Sort.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\MSBFDecoder.h -# End Source File -# Begin Source File - -SOURCE=..\..\Common\MSBFEncoder.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 "BWT" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\BWT\BlockSort.cpp - -!IF "$(CFG)" == "BZip2 - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\BWT\BlockSort.h -# End Source File -# Begin Source File - -SOURCE=..\BWT\Mtf8.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 -# Begin Source File - -SOURCE=..\..\..\Windows\Thread.h -# End Source File -# End Group -# Begin Group "Ń" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\..\C\Alloc.c -# SUBTRACT CPP /YX /Yc /Yu -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Alloc.h -# End Source File -# End Group -# Begin Source File - -SOURCE=.\BZip2Const.h -# End Source File -# Begin Source File - -SOURCE=.\BZip2CRC.cpp -# End Source File -# Begin Source File - -SOURCE=.\BZip2CRC.h -# End Source File -# Begin Source File - -SOURCE=.\BZip2Decoder.cpp - -!IF "$(CFG)" == "BZip2 - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\BZip2Decoder.h -# End Source File -# Begin Source File - -SOURCE=.\BZip2Encoder.cpp - -!IF "$(CFG)" == "BZip2 - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "BZip2 - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\BZip2Encoder.h -# End Source File -# Begin Source File - -SOURCE=.\BZip2Register.cpp -# End Source File -# End Target -# End Project diff --git a/CPP/7zip/Compress/BZip2/BZip2.dsw b/CPP/7zip/Compress/BZip2/BZip2.dsw deleted file mode 100755 index 697e5095..00000000 --- a/CPP/7zip/Compress/BZip2/BZip2.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "BZip2"=.\BZip2.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp b/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp index 3f7dbc58..47ffa7c8 100755 --- a/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp +++ b/CPP/7zip/Compress/BZip2/BZip2Decoder.cpp @@ -432,10 +432,12 @@ CDecoder::~CDecoder() Free(); } -HRes CDecoder::Create() +#define RINOK_THREAD(x) { WRes __result_ = (x); if(__result_ != 0) return __result_; } + +HRESULT CDecoder::Create() { - RINOK(CanProcessEvent.CreateIfNotCreated()); - RINOK(CanStartWaitingEvent.CreateIfNotCreated()); + RINOK_THREAD(CanProcessEvent.CreateIfNotCreated()); + RINOK_THREAD(CanStartWaitingEvent.CreateIfNotCreated()); if (m_States != 0 && m_NumThreadsPrev == NumThreads) return S_OK; Free(); @@ -454,7 +456,7 @@ HRes CDecoder::Create() ti.Decoder = this; if (MtMode) { - HRes res = ti.Create(); + HRESULT res = ti.Create(); if (res != S_OK) { NumThreads = t; @@ -524,9 +526,12 @@ HRESULT CDecoder::DecodeFile(bool &isBZ, ICompressProgressInfo *progress) CState &s = m_States[t]; if (!s.Alloc()) return E_OUTOFMEMORY; - s.StreamWasFinishedEvent.Reset(); - s.WaitingWasStartedEvent.Reset(); - s.CanWriteEvent.Reset(); + if (MtMode) + { + RINOK(s.StreamWasFinishedEvent.Reset()); + RINOK(s.WaitingWasStartedEvent.Reset()); + RINOK(s.CanWriteEvent.Reset()); + } } #else if (!m_States[0].Alloc()) @@ -647,12 +652,13 @@ STDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value) static THREAD_FUNC_DECL MFThread(void *p) { ((CState *)p)->ThreadFunc(); return 0; } -HRes CState::Create() +HRESULT CState::Create() { - RINOK(StreamWasFinishedEvent.CreateIfNotCreated()); - RINOK(WaitingWasStartedEvent.CreateIfNotCreated()); - RINOK(CanWriteEvent.CreateIfNotCreated()); - return Thread.Create(MFThread, this); + RINOK_THREAD(StreamWasFinishedEvent.CreateIfNotCreated()); + RINOK_THREAD(WaitingWasStartedEvent.CreateIfNotCreated()); + RINOK_THREAD(CanWriteEvent.CreateIfNotCreated()); + RINOK_THREAD(Thread.Create(MFThread, this)); + return S_OK; } void CState::FinishStream() diff --git a/CPP/7zip/Compress/BZip2/BZip2Decoder.h b/CPP/7zip/Compress/BZip2/BZip2Decoder.h index 9c965b49..511302d5 100755 --- a/CPP/7zip/Compress/BZip2/BZip2Decoder.h +++ b/CPP/7zip/Compress/BZip2/BZip2Decoder.h @@ -17,13 +17,7 @@ #include "../../../Windows/Synchronization.h" #endif -#if _MSC_VER >= 1300 -#define NO_INLINE __declspec(noinline) __fastcall -#else -#ifdef _MSC_VER -#define NO_INLINE __fastcall -#endif -#endif +#define NO_INLINE MY_FAST_CALL namespace NCompress { namespace NBZip2 { @@ -50,7 +44,7 @@ struct CState Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size. - HRes Create(); + HRESULT Create(); void FinishStream(); void ThreadFunc(); @@ -126,7 +120,7 @@ public: UInt32 BlockSizeMax; CDecoder(); ~CDecoder(); - HRes Create(); + HRESULT Create(); void Free(); #else diff --git a/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp b/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp index ac5f78e1..2491ef17 100755 --- a/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp +++ b/CPP/7zip/Compress/BZip2/BZip2Encoder.cpp @@ -5,19 +5,15 @@ extern "C" { #include "../../../../C/Alloc.h" +#include "../../../../C/BwtSort.h" +#include "../../../../C/HuffEnc.h" } #include "BZip2Encoder.h" -#include "../BWT/BlockSort.h" #include "../BWT/Mtf8.h" #include "BZip2CRC.h" -extern "C" -{ - #include "../../../../C/Compress/Huffman/HuffmanEncode.h" -} - namespace NCompress { namespace NBZip2 { @@ -61,12 +57,15 @@ static THREAD_FUNC_DECL MFThread(void *threadCoderInfo) return ((CThreadInfo *)threadCoderInfo)->ThreadFunc(); } -HRes CThreadInfo::Create() +#define RINOK_THREAD(x) { WRes __result_ = (x); if(__result_ != 0) return __result_; } + +HRESULT CThreadInfo::Create() { - RINOK(StreamWasFinishedEvent.Create()); - RINOK(WaitingWasStartedEvent.Create()); - RINOK(CanWriteEvent.Create()); - return Thread.Create(MFThread, this); + RINOK_THREAD(StreamWasFinishedEvent.Create()); + RINOK_THREAD(WaitingWasStartedEvent.Create()); + RINOK_THREAD(CanWriteEvent.Create()); + RINOK_THREAD(Thread.Create(MFThread, this)); + return S_OK; } void CThreadInfo::FinishStream(bool needLeave) @@ -145,10 +144,10 @@ CEncoder::~CEncoder() Free(); } -HRes CEncoder::Create() +HRESULT CEncoder::Create() { - RINOK(CanProcessEvent.CreateIfNotCreated()); - RINOK(CanStartWaitingEvent.CreateIfNotCreated()); + RINOK_THREAD(CanProcessEvent.CreateIfNotCreated()); + RINOK_THREAD(CanStartWaitingEvent.CreateIfNotCreated()); if (ThreadsInfo != 0 && m_NumThreadsPrev == NumThreads) return S_OK; try @@ -167,7 +166,7 @@ HRes CEncoder::Create() ti.Encoder = this; if (MtMode) { - HRes res = ti.Create(); + HRESULT res = ti.Create(); if (res != S_OK) { NumThreads = t; @@ -733,9 +732,12 @@ HRESULT CEncoder::CodeReal(ISequentialInStream *inStream, { #ifdef COMPRESS_BZIP2_MT CThreadInfo &ti = ThreadsInfo[t]; - ti.StreamWasFinishedEvent.Reset(); - ti.WaitingWasStartedEvent.Reset(); - ti.CanWriteEvent.Reset(); + if (MtMode) + { + RINOK(ti.StreamWasFinishedEvent.Reset()); + RINOK(ti.WaitingWasStartedEvent.Reset()); + RINOK(ti.CanWriteEvent.Reset()); + } #else CThreadInfo &ti = ThreadsInfo; ti.Encoder = this; diff --git a/CPP/7zip/Compress/BZip2/BZip2Encoder.h b/CPP/7zip/Compress/BZip2/BZip2Encoder.h index 02d4cde3..98cd20d6 100755 --- a/CPP/7zip/Compress/BZip2/BZip2Encoder.h +++ b/CPP/7zip/Compress/BZip2/BZip2Encoder.h @@ -70,9 +70,9 @@ public: void SetPos(UInt32 bitPos) { m_Pos = bitPos / 8; - m_BitPos = 8 - (bitPos & 7); + m_BitPos = 8 - ((int)bitPos & 7); } - void SetCurState(UInt32 bitPos, Byte curByte) + void SetCurState(int bitPos, Byte curByte) { m_BitPos = 8 - bitPos; m_CurByte = curByte; @@ -103,7 +103,7 @@ private: UInt32 m_CRCs[1 << kNumPassesMax]; UInt32 m_NumCrcs; - int m_BlockIndex; + UInt32 m_BlockIndex; void WriteBits2(UInt32 value, UInt32 numBits); void WriteByte2(Byte b); @@ -128,7 +128,7 @@ public: UInt64 m_PackSize; Byte MtPad[1 << 8]; // It's pad for Multi-Threading. Must be >= Cache_Line_Size. - HRes Create(); + HRESULT Create(); void FinishStream(bool needLeave); DWORD ThreadFunc(); #endif @@ -189,7 +189,7 @@ public: void WriteCRC(UInt32 v); #ifdef COMPRESS_BZIP2_MT - HRes Create(); + HRESULT Create(); void Free(); #endif diff --git a/CPP/7zip/Compress/BZip2/makefile b/CPP/7zip/Compress/BZip2/makefile deleted file mode 100755 index 6e467583..00000000 --- a/CPP/7zip/Compress/BZip2/makefile +++ /dev/null @@ -1,58 +0,0 @@ -PROG = BZip2.dll -DEF_FILE = ../Codec.def -CFLAGS = $(CFLAGS) -I ../../../ -DCOMPRESS_BZIP2_MT -D_7ZIP_LARGE_PAGES -LIBS = $(LIBS) oleaut32.lib - -COMPRESS_OBJS = \ - $O\CodecExports.obj \ - $O\DllExports.obj \ - -BZIP2_OBJS = \ - $O\BZip2CRC.obj \ - $O\BZip2Register.obj \ - -BZIP2_OPT_OBJS = \ - $O\BZip2Decoder.obj \ - $O\BZip2Encoder.obj \ - -WIN_OBJS = \ - $O\Synchronization.obj - -7ZIP_COMMON_OBJS = \ - $O\InBuffer.obj \ - $O\OutBuffer.obj \ - -C_OBJS = \ - $O\Alloc.obj \ - $O\Sort.obj \ - -OBJS = \ - $O\StdAfx.obj \ - $(COMPRESS_OBJS) \ - $(BZIP2_OBJS) \ - $(BZIP2_OPT_OBJS) \ - $(WIN_OBJS) \ - $(7ZIP_COMMON_OBJS) \ - $O\BlockSort.obj \ - $(C_OBJS) \ - $O\HuffmanEncode.obj \ - $O\resource.res - -!include "../../../Build.mak" - -$(COMPRESS_OBJS): ../$(*B).cpp - $(COMPL) -$(BZIP2_OBJS): $(*B).cpp - $(COMPL) -$(BZIP2_OPT_OBJS): $(*B).cpp - $(COMPL_O2) -$(WIN_OBJS): ../../../Windows/$(*B).cpp - $(COMPL) -$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp - $(COMPL) -$O\BlockSort.obj: ../BWT/$(*B).cpp - $(COMPL_O2) -$(C_OBJS): ../../../../C/$(*B).c - $(COMPL_O2) -$O\HuffmanEncode.obj: ../../../../C/Compress/Huffman/$(*B).c - $(COMPL_O2) diff --git a/CPP/7zip/Compress/BZip2/resource.rc b/CPP/7zip/Compress/BZip2/resource.rc deleted file mode 100755 index c5bea782..00000000 --- a/CPP/7zip/Compress/BZip2/resource.rc +++ /dev/null @@ -1,3 +0,0 @@ -#include "../../MyVersionInfo.rc" - -MY_VERSION_INFO_DLL("BZip2 Codec", "BZip2") diff --git a/CPP/7zip/Compress/Branch/ARM.cpp b/CPP/7zip/Compress/Branch/ARM.cpp deleted file mode 100755 index 5870bc03..00000000 --- a/CPP/7zip/Compress/Branch/ARM.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// ARM.cpp - -#include "StdAfx.h" -#include "ARM.h" - -extern "C" -{ -#include "../../../../C/Compress/Branch/BranchARM.h" -} - -UInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size) -{ - return ::ARM_Convert(data, size, _bufferPos, 1); -} - -UInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size) -{ - return ::ARM_Convert(data, size, _bufferPos, 0); -} diff --git a/CPP/7zip/Compress/Branch/ARM.h b/CPP/7zip/Compress/Branch/ARM.h deleted file mode 100755 index 5561299b..00000000 --- a/CPP/7zip/Compress/Branch/ARM.h +++ /dev/null @@ -1,10 +0,0 @@ -// ARM.h - -#ifndef __ARM_H -#define __ARM_H - -#include "BranchCoder.h" - -MyClassA(BC_ARM, 0x05, 1) - -#endif diff --git a/CPP/7zip/Compress/Branch/ARMThumb.cpp b/CPP/7zip/Compress/Branch/ARMThumb.cpp deleted file mode 100755 index 7df641ac..00000000 --- a/CPP/7zip/Compress/Branch/ARMThumb.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// ARMThumb.cpp - -#include "StdAfx.h" - -#include "ARMThumb.h" - -extern "C" -{ -#include "../../../../C/Compress/Branch/BranchARMThumb.h" -} - -UInt32 CBC_ARMThumb_Encoder::SubFilter(Byte *data, UInt32 size) -{ - return ::ARMThumb_Convert(data, size, _bufferPos, 1); -} - -UInt32 CBC_ARMThumb_Decoder::SubFilter(Byte *data, UInt32 size) -{ - return ::ARMThumb_Convert(data, size, _bufferPos, 0); -} diff --git a/CPP/7zip/Compress/Branch/ARMThumb.h b/CPP/7zip/Compress/Branch/ARMThumb.h deleted file mode 100755 index 601e40bf..00000000 --- a/CPP/7zip/Compress/Branch/ARMThumb.h +++ /dev/null @@ -1,10 +0,0 @@ -// ARMThumb.h - -#ifndef __ARMTHUMB_H -#define __ARMTHUMB_H - -#include "BranchCoder.h" - -MyClassA(BC_ARMThumb, 0x07, 1) - -#endif diff --git a/CPP/7zip/Compress/Branch/Branch.dsp b/CPP/7zip/Compress/Branch/Branch.dsp deleted file mode 100755 index 795a534a..00000000 --- a/CPP/7zip/Compress/Branch/Branch.dsp +++ /dev/null @@ -1,433 +0,0 @@ -# Microsoft Developer Studio Project File - Name="Branch" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=Branch - 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 "Branch.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 "Branch.mak" CFG="Branch - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "Branch - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "Branch - 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)" == "Branch - 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 "BRANCH_EXPORTS" /YX /FD /c -# ADD CPP /nologo /Gz /MD /W3 /GX /O2 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BRANCH_EXPORTS" /FD /c -# SUBTRACT CPP /YX /Yc /Yu -# 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\Branch.dll" /opt:NOWIN98 -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "Branch - 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 "BRANCH_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 "BRANCH_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\Branch.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "Branch - Win32 Release" -# Name "Branch - Win32 Debug" -# Begin Group "Spec" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Codec.def -# End Source File -# Begin Source File - -SOURCE=..\CodecExports.cpp -# End Source File -# Begin Source File - -SOURCE=..\DllExports.cpp -# End Source File -# Begin Source File - -SOURCE=.\resource.rc -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.cpp -# ADD CPP /Yc"StdAfx.h" -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.h -# End Source File -# End Group -# Begin Group "Methods" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\ARM.cpp - -!IF "$(CFG)" == "Branch - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Branch - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\ARM.h -# End Source File -# Begin Source File - -SOURCE=.\ARMThumb.cpp - -!IF "$(CFG)" == "Branch - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Branch - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\ARMThumb.h -# End Source File -# Begin Source File - -SOURCE=.\BCJ2Register.cpp -# End Source File -# Begin Source File - -SOURCE=.\BCJRegister.cpp -# End Source File -# Begin Source File - -SOURCE=.\BranchCoder.cpp -# End Source File -# Begin Source File - -SOURCE=.\BranchCoder.h -# End Source File -# Begin Source File - -SOURCE=.\BranchRegister.cpp -# End Source File -# Begin Source File - -SOURCE=.\BranchTypes.h -# End Source File -# Begin Source File - -SOURCE=.\BranchX86.h -# End Source File -# Begin Source File - -SOURCE=.\IA64.cpp - -!IF "$(CFG)" == "Branch - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Branch - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\IA64.h -# End Source File -# Begin Source File - -SOURCE=.\PPC.cpp - -!IF "$(CFG)" == "Branch - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Branch - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\PPC.h -# End Source File -# Begin Source File - -SOURCE=.\SPARC.cpp -# End Source File -# Begin Source File - -SOURCE=.\SPARC.h -# End Source File -# Begin Source File - -SOURCE=.\x86.cpp - -!IF "$(CFG)" == "Branch - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Branch - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\x86.h -# End Source File -# Begin Source File - -SOURCE=.\x86_2.cpp - -!IF "$(CFG)" == "Branch - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Branch - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\x86_2.h -# End Source File -# End Group -# Begin Group "Stream" - -# 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.h -# End Source File -# End Group -# Begin Group "C" - -# PROP Default_Filter "" -# Begin Group "C Branch" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Branch\BranchARM.c - -!IF "$(CFG)" == "Branch - Win32 Release" - -!ELSEIF "$(CFG)" == "Branch - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Branch\BranchARM.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Branch\BranchARMThumb.c - -!IF "$(CFG)" == "Branch - Win32 Release" - -!ELSEIF "$(CFG)" == "Branch - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Branch\BranchARMThumb.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Branch\BranchIA64.c - -!IF "$(CFG)" == "Branch - Win32 Release" - -!ELSEIF "$(CFG)" == "Branch - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Branch\BranchIA64.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Branch\BranchPPC.c - -!IF "$(CFG)" == "Branch - Win32 Release" - -!ELSEIF "$(CFG)" == "Branch - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Branch\BranchPPC.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Branch\BranchSPARC.c - -!IF "$(CFG)" == "Branch - Win32 Release" - -!ELSEIF "$(CFG)" == "Branch - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Branch\BranchSPARC.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Branch\BranchTypes.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c - -!IF "$(CFG)" == "Branch - Win32 Release" - -!ELSEIF "$(CFG)" == "Branch - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h -# End Source File -# End Group -# Begin Source File - -SOURCE=..\..\..\..\C\Alloc.c - -!IF "$(CFG)" == "Branch - Win32 Release" - -!ELSEIF "$(CFG)" == "Branch - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Alloc.h -# End Source File -# End Group -# End Target -# End Project diff --git a/CPP/7zip/Compress/Branch/Branch.dsw b/CPP/7zip/Compress/Branch/Branch.dsw deleted file mode 100755 index 841c85a3..00000000 --- a/CPP/7zip/Compress/Branch/Branch.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "Branch"=.\Branch.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/CPP/7zip/Compress/Branch/BranchMisc.cpp b/CPP/7zip/Compress/Branch/BranchMisc.cpp new file mode 100755 index 00000000..ff4eafbe --- /dev/null +++ b/CPP/7zip/Compress/Branch/BranchMisc.cpp @@ -0,0 +1,39 @@ +// BranchMisc.cpp + +#include "StdAfx.h" +#include "BranchMisc.h" + +extern "C" +{ +#include "../../../../C/Bra.h" +} + +UInt32 CBC_ARM_Encoder::SubFilter(Byte *data, UInt32 size) + { return (UInt32)::ARM_Convert(data, size, _bufferPos, 1); } + +UInt32 CBC_ARM_Decoder::SubFilter(Byte *data, UInt32 size) + { return (UInt32)::ARM_Convert(data, size, _bufferPos, 0); } + +UInt32 CBC_ARMT_Encoder::SubFilter(Byte *data, UInt32 size) + { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 1); } + +UInt32 CBC_ARMT_Decoder::SubFilter(Byte *data, UInt32 size) + { return (UInt32)::ARMT_Convert(data, size, _bufferPos, 0); } + +UInt32 CBC_PPC_Encoder::SubFilter(Byte *data, UInt32 size) + { return (UInt32)::PPC_Convert(data, size, _bufferPos, 1); } + +UInt32 CBC_PPC_Decoder::SubFilter(Byte *data, UInt32 size) + { return (UInt32)::PPC_Convert(data, size, _bufferPos, 0); } + +UInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size) + { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 1); } + +UInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size) + { return (UInt32)::SPARC_Convert(data, size, _bufferPos, 0); } + +UInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size) + { return (UInt32)::IA64_Convert(data, size, _bufferPos, 1); } + +UInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size) + { return (UInt32)::IA64_Convert(data, size, _bufferPos, 0); } diff --git a/CPP/7zip/Compress/Branch/BranchMisc.h b/CPP/7zip/Compress/Branch/BranchMisc.h new file mode 100755 index 00000000..219eec1c --- /dev/null +++ b/CPP/7zip/Compress/Branch/BranchMisc.h @@ -0,0 +1,14 @@ +// BranchMisc.h + +#ifndef __BRANCHMISC_H +#define __BRANCHMISC_H + +#include "BranchCoder.h" + +MyClassA(BC_ARM, 0x05, 1) +MyClassA(BC_ARMT, 0x07, 1) +MyClassA(BC_PPC, 0x02, 5) +MyClassA(BC_SPARC, 0x08, 5) +MyClassA(BC_IA64, 0x04, 1) + +#endif diff --git a/CPP/7zip/Compress/Branch/BranchRegister.cpp b/CPP/7zip/Compress/Branch/BranchRegister.cpp index 2ccdcc64..69fbe5d3 100755 --- a/CPP/7zip/Compress/Branch/BranchRegister.cpp +++ b/CPP/7zip/Compress/Branch/BranchRegister.cpp @@ -4,31 +4,27 @@ #include "../../Common/RegisterCodec.h" -#include "PPC.h" -#include "IA64.h" -#include "ARM.h" -#include "ARMThumb.h" -#include "SPARC.h" +#include "BranchMisc.h" #define CREATE_CODEC(x) \ static void *CreateCodec ## x() { return (void *)(ICompressFilter *)(new C ## x ## _Decoder); } \ static void *CreateCodec ## x ## Out() { return (void *)(ICompressFilter *)(new C ## x ## _Encoder); } -CREATE_CODEC(BC_PPC_B) +CREATE_CODEC(BC_PPC) CREATE_CODEC(BC_IA64) CREATE_CODEC(BC_ARM) -CREATE_CODEC(BC_ARMThumb) +CREATE_CODEC(BC_ARMT) CREATE_CODEC(BC_SPARC) #define METHOD_ITEM(x, id1, id2, name) { CreateCodec ## x, CreateCodec ## x ## Out, 0x03030000 + (id1 * 256) + id2, name, 1, true } static CCodecInfo g_CodecsInfo[] = { - METHOD_ITEM(BC_PPC_B, 0x02, 0x05, L"BC_PPC_B"), - METHOD_ITEM(BC_IA64, 0x04, 1, L"BC_IA64"), - METHOD_ITEM(BC_ARM, 0x05, 1, L"BC_ARM"), - METHOD_ITEM(BC_ARMThumb,0x07, 1, L"BC_ARMThumb"), - METHOD_ITEM(BC_SPARC, 0x08, 0x05, L"BC_SPARC") + METHOD_ITEM(BC_PPC, 0x02, 0x05, L"PPC"), + METHOD_ITEM(BC_IA64, 0x04, 1, L"IA64"), + METHOD_ITEM(BC_ARM, 0x05, 1, L"ARM"), + METHOD_ITEM(BC_ARMT, 0x07, 1, L"ARMT"), + METHOD_ITEM(BC_SPARC, 0x08, 0x05, L"SPARC") }; REGISTER_CODECS(Branch) diff --git a/CPP/7zip/Compress/Branch/IA64.cpp b/CPP/7zip/Compress/Branch/IA64.cpp deleted file mode 100755 index ae4766a3..00000000 --- a/CPP/7zip/Compress/Branch/IA64.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// IA64.cpp - -#include "StdAfx.h" -#include "IA64.h" - -extern "C" -{ -#include "../../../../C/Compress/Branch/BranchIA64.h" -} - -UInt32 CBC_IA64_Encoder::SubFilter(Byte *data, UInt32 size) -{ - return ::IA64_Convert(data, size, _bufferPos, 1); -} - -UInt32 CBC_IA64_Decoder::SubFilter(Byte *data, UInt32 size) -{ - return ::IA64_Convert(data, size, _bufferPos, 0); -} diff --git a/CPP/7zip/Compress/Branch/IA64.h b/CPP/7zip/Compress/Branch/IA64.h deleted file mode 100755 index 7fe715ed..00000000 --- a/CPP/7zip/Compress/Branch/IA64.h +++ /dev/null @@ -1,10 +0,0 @@ -// IA64.h - -#ifndef __IA64_H -#define __IA64_H - -#include "BranchCoder.h" - -MyClassA(BC_IA64, 0x04, 1) - -#endif diff --git a/CPP/7zip/Compress/Branch/PPC.cpp b/CPP/7zip/Compress/Branch/PPC.cpp deleted file mode 100755 index ecd4b3d8..00000000 --- a/CPP/7zip/Compress/Branch/PPC.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// PPC.cpp - -#include "StdAfx.h" -#include "PPC.h" - -extern "C" -{ -#include "../../../../C/Compress/Branch/BranchPPC.h" -} - -UInt32 CBC_PPC_B_Encoder::SubFilter(Byte *data, UInt32 size) -{ - return ::PPC_B_Convert(data, size, _bufferPos, 1); -} - -UInt32 CBC_PPC_B_Decoder::SubFilter(Byte *data, UInt32 size) -{ - return ::PPC_B_Convert(data, size, _bufferPos, 0); -} diff --git a/CPP/7zip/Compress/Branch/PPC.h b/CPP/7zip/Compress/Branch/PPC.h deleted file mode 100755 index a0e33444..00000000 --- a/CPP/7zip/Compress/Branch/PPC.h +++ /dev/null @@ -1,10 +0,0 @@ -// PPC.h - -#ifndef __PPC_H -#define __PPC_H - -#include "BranchCoder.h" - -MyClassA(BC_PPC_B, 0x02, 5) - -#endif diff --git a/CPP/7zip/Compress/Branch/SPARC.cpp b/CPP/7zip/Compress/Branch/SPARC.cpp deleted file mode 100755 index 5678eb31..00000000 --- a/CPP/7zip/Compress/Branch/SPARC.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// SPARC.cpp - -#include "StdAfx.h" -#include "SPARC.h" - -extern "C" -{ -#include "../../../../C/Compress/Branch/BranchSPARC.h" -} - -UInt32 CBC_SPARC_Encoder::SubFilter(Byte *data, UInt32 size) -{ - return ::SPARC_Convert(data, size, _bufferPos, 1); -} - -UInt32 CBC_SPARC_Decoder::SubFilter(Byte *data, UInt32 size) -{ - return ::SPARC_Convert(data, size, _bufferPos, 0); -} diff --git a/CPP/7zip/Compress/Branch/SPARC.h b/CPP/7zip/Compress/Branch/SPARC.h deleted file mode 100755 index e0a682ef..00000000 --- a/CPP/7zip/Compress/Branch/SPARC.h +++ /dev/null @@ -1,10 +0,0 @@ -// SPARC.h - -#ifndef __SPARC_H -#define __SPARC_H - -#include "BranchCoder.h" - -MyClassA(BC_SPARC, 0x08, 5) - -#endif diff --git a/CPP/7zip/Compress/Branch/makefile b/CPP/7zip/Compress/Branch/makefile deleted file mode 100755 index 73ae75b2..00000000 --- a/CPP/7zip/Compress/Branch/makefile +++ /dev/null @@ -1,63 +0,0 @@ -PROG = Branch.dll -DEF_FILE = ../Codec.def -CFLAGS = $(CFLAGS) -I ../../../ -LIBS = $(LIBS) oleaut32.lib - -COMPRESS_OBJS = \ - $O\CodecExports.obj \ - $O\DllExports.obj \ - -BRANCH_OPT_OBJS = \ - $O\ARM.obj \ - $O\ARMThumb.obj \ - $O\BranchCoder.obj \ - $O\IA64.obj \ - $O\PPC.obj \ - $O\SPARC.obj \ - $O\x86.obj \ - $O\x86_2.obj \ - $O\BranchRegister.obj \ - $O\BCJRegister.obj \ - $O\BCJ2Register.obj \ - -C_OBJS = \ - $O\Alloc.obj \ - -C_BRANCH_OBJS = \ - $O\BranchARM.obj \ - $O\BranchARMThumb.obj \ - $O\BranchIA64.obj \ - $O\BranchPPC.obj \ - $O\BranchSPARC.obj \ - $O\BranchX86.obj \ - -7ZIP_COMMON_OBJS = \ - $O\InBuffer.obj \ - $O\OutBuffer.obj \ - - -OBJS = \ - $O\StdAfx.obj \ - $(COMPRESS_OBJS) \ - $(BRANCH_OPT_OBJS) \ - $(7ZIP_COMMON_OBJS) \ - $O\RangeCoderBit.obj \ - $(C_OBJS) \ - $(C_BRANCH_OBJS) \ - $O\resource.res - - -!include "../../../Build.mak" - -$(COMPRESS_OBJS): ../$(*B).cpp - $(COMPL) -$(BRANCH_OPT_OBJS): $(*B).cpp - $(COMPL_O2) -$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp - $(COMPL) -$O\RangeCoderBit.obj: ../RangeCoder/$(*B).cpp - $(COMPL) -$(C_OBJS): ../../../../C/$(*B).c - $(COMPL_O2) -$(C_BRANCH_OBJS): ../../../../C/Compress/Branch/$(*B).c - $(COMPL_O2) diff --git a/CPP/7zip/Compress/Branch/resource.rc b/CPP/7zip/Compress/Branch/resource.rc deleted file mode 100755 index 5476d4fa..00000000 --- a/CPP/7zip/Compress/Branch/resource.rc +++ /dev/null @@ -1,3 +0,0 @@ -#include "../../MyVersionInfo.rc" - -MY_VERSION_INFO_DLL("Branch Filter", "Branch") diff --git a/CPP/7zip/Compress/Branch/x86.h b/CPP/7zip/Compress/Branch/x86.h index 58176600..e898cb7e 100755 --- a/CPP/7zip/Compress/Branch/x86.h +++ b/CPP/7zip/Compress/Branch/x86.h @@ -6,7 +6,7 @@ #include "BranchCoder.h" extern "C" { -#include "../../../../C/Compress/Branch/BranchX86.h" +#include "../../../../C/Bra.h" } struct CBranch86 diff --git a/CPP/7zip/Compress/ByteSwap/ByteSwap.dsp b/CPP/7zip/Compress/ByteSwap/ByteSwap.dsp deleted file mode 100755 index 14c42981..00000000 --- a/CPP/7zip/Compress/ByteSwap/ByteSwap.dsp +++ /dev/null @@ -1,133 +0,0 @@ -# Microsoft Developer Studio Project File - Name="ByteSwap" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=ByteSwap - 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 "ByteSwap.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 "ByteSwap.mak" CFG="ByteSwap - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "ByteSwap - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "ByteSwap - 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)" == "ByteSwap - 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 "BYTESWAP_EXPORTS" /YX /FD /c -# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "BYTESWAP_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\Swap.dll" /opt:NOWIN98 -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "ByteSwap - 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 "BYTESWAP_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 "BYTESWAP_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\Swap.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "ByteSwap - Win32 Release" -# Name "ByteSwap - Win32 Debug" -# Begin Group "Spec" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Codec.def -# End Source File -# Begin Source File - -SOURCE=..\CodecExports.cpp -# End Source File -# Begin Source File - -SOURCE=..\DllExports.cpp -# End Source File -# Begin Source File - -SOURCE=.\resource.rc -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.cpp -# ADD CPP /Yc"StdAfx.h" -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.h -# End Source File -# End Group -# Begin Source File - -SOURCE=.\ByteSwap.cpp -# End Source File -# Begin Source File - -SOURCE=.\ByteSwap.h -# End Source File -# Begin Source File - -SOURCE=.\ByteSwapRegister.cpp -# End Source File -# End Target -# End Project diff --git a/CPP/7zip/Compress/ByteSwap/ByteSwap.dsw b/CPP/7zip/Compress/ByteSwap/ByteSwap.dsw deleted file mode 100755 index 413d7e6e..00000000 --- a/CPP/7zip/Compress/ByteSwap/ByteSwap.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "ByteSwap"=.\ByteSwap.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/CPP/7zip/Compress/ByteSwap/makefile b/CPP/7zip/Compress/ByteSwap/makefile deleted file mode 100755 index 80e8af78..00000000 --- a/CPP/7zip/Compress/ByteSwap/makefile +++ /dev/null @@ -1,25 +0,0 @@ -PROG = Swap.dll -DEF_FILE = ../Codec.def -CFLAGS = $(CFLAGS) -I ../../../ -LIBS = $(LIBS) oleaut32.lib - -COMPRESS_OBJS = \ - $O\CodecExports.obj \ - $O\DllExports.obj \ - -SWAP_OPT_OBJS = \ - $O\ByteSwap.obj \ - $O\ByteSwapRegister.obj \ - -OBJS = \ - $O\StdAfx.obj \ - $(COMPRESS_OBJS) \ - $(SWAP_OPT_OBJS) \ - $O\resource.res - -!include "../../../Build.mak" - -$(COMPRESS_OBJS): ../$(*B).cpp - $(COMPL) -$(SWAP_OPT_OBJS): $(*B).cpp - $(COMPL_O2) diff --git a/CPP/7zip/Compress/ByteSwap/resource.rc b/CPP/7zip/Compress/ByteSwap/resource.rc deleted file mode 100755 index 21c0c505..00000000 --- a/CPP/7zip/Compress/ByteSwap/resource.rc +++ /dev/null @@ -1,3 +0,0 @@ -#include "../../MyVersionInfo.rc" - -MY_VERSION_INFO_DLL("SWAP filter Codec", "SWAP") diff --git a/CPP/7zip/Compress/CodecExports.cpp b/CPP/7zip/Compress/CodecExports.cpp index a4a85b64..7500d923 100755 --- a/CPP/7zip/Compress/CodecExports.cpp +++ b/CPP/7zip/Compress/CodecExports.cpp @@ -48,7 +48,7 @@ static HRESULT FindCodecClassId(const GUID *clsID, UInt32 isCoder2, bool isFilte UInt64 id = 0; for (int j = 0; j < 8; j++) id |= ((UInt64)clsID->Data4[j]) << (8 * j); - for (UInt32 i = 0; i < g_NumCodecs; i++) + for (unsigned i = 0; i < g_NumCodecs; i++) { const CCodecInfo &codec = *g_Codecs[i]; if (id != codec.Id || encode && !codec.CreateEncoder || !encode && !codec.CreateDecoder) @@ -142,7 +142,7 @@ STDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value) if (codec.NumInStreams != 1) { value->vt = VT_UI4; - value->ulVal = codec.NumInStreams; + value->ulVal = (ULONG)codec.NumInStreams; } break; } diff --git a/CPP/7zip/Compress/Copy/Copy.dsp b/CPP/7zip/Compress/Copy/Copy.dsp deleted file mode 100755 index efbc5e31..00000000 --- a/CPP/7zip/Compress/Copy/Copy.dsp +++ /dev/null @@ -1,158 +0,0 @@ -# Microsoft Developer Studio Project File - Name="Copy" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=Copy - 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 "Copy.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 "Copy.mak" CFG="Copy - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "Copy - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "Copy - 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)" == "Copy - 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 "COPY_EXPORTS" /YX /FD /c -# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COPY_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 0x409 /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\Copy.dll" /opt:NOWIN98 -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "Copy - 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 "COPY_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "COPY_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 0x409 /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\Copy.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "Copy - Win32 Release" -# Name "Copy - Win32 Debug" -# Begin Group "Spec" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Codec.def -# End Source File -# Begin Source File - -SOURCE=..\CodecExports.cpp -# End Source File -# Begin Source File - -SOURCE=..\DllExports.cpp -# End Source File -# Begin Source File - -SOURCE=.\resource.rc -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.cpp -# ADD CPP /Yc"StdAfx.h" -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.h -# End Source File -# End Group -# Begin Group "7-Zip Common" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\Common\StreamUtils.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Common\StreamUtils.h -# End Source File -# End Group -# Begin Group "Ń" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\..\C\Alloc.c -# SUBTRACT CPP /YX /Yc /Yu -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Alloc.h -# End Source File -# End Group -# Begin Source File - -SOURCE=.\CopyCoder.cpp -# End Source File -# Begin Source File - -SOURCE=.\CopyCoder.h -# End Source File -# Begin Source File - -SOURCE=.\CopyRegister.cpp -# End Source File -# End Target -# End Project diff --git a/CPP/7zip/Compress/Copy/Copy.dsw b/CPP/7zip/Compress/Copy/Copy.dsw deleted file mode 100755 index 53ddf6cf..00000000 --- a/CPP/7zip/Compress/Copy/Copy.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "Copy"=".\Copy.dsp" - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/CPP/7zip/Compress/Copy/CopyCoder.cpp b/CPP/7zip/Compress/Copy/CopyCoder.cpp index 8e18db2b..d5285185 100755 --- a/CPP/7zip/Compress/Copy/CopyCoder.cpp +++ b/CPP/7zip/Compress/Copy/CopyCoder.cpp @@ -42,7 +42,7 @@ STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream, RINOK(inStream->Read(_buffer, size, &realProcessedSize)); if (realProcessedSize == 0) break; - RINOK(WriteStream(outStream, _buffer, realProcessedSize, NULL)); + RINOK(WriteStream(outStream, _buffer, realProcessedSize)); TotalSize += realProcessedSize; if (progress != NULL) { diff --git a/CPP/7zip/Compress/Copy/makefile b/CPP/7zip/Compress/Copy/makefile deleted file mode 100755 index 4588a341..00000000 --- a/CPP/7zip/Compress/Copy/makefile +++ /dev/null @@ -1,37 +0,0 @@ -PROG = Copy.dll -DEF_FILE = ../Codec.def -CFLAGS = $(CFLAGS) -I ../../../ -LIBS = $(LIBS) oleaut32.lib - -COMPRESS_OBJS = \ - $O\CodecExports.obj \ - $O\DllExports.obj \ - -COPY_OBJS = \ - $O\CopyCoder.obj \ - $O\CopyRegister.obj \ - -7ZIP_COMMON_OBJS = \ - $O\StreamUtils.obj \ - -C_OBJS = \ - $O\Alloc.obj \ - -OBJS = \ - $O\StdAfx.obj \ - $(COMPRESS_OBJS) \ - $(COPY_OBJS) \ - $(7ZIP_COMMON_OBJS) \ - $(C_OBJS) \ - $O\resource.res - -!include "../../../Build.mak" - -$(COMPRESS_OBJS): ../$(*B).cpp - $(COMPL) -$(COPY_OBJS): $(*B).cpp - $(COMPL) -$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp - $(COMPL) -$(C_OBJS): ../../../../C/$(*B).c - $(COMPL_O2) diff --git a/CPP/7zip/Compress/Copy/resource.rc b/CPP/7zip/Compress/Copy/resource.rc deleted file mode 100755 index 234c85bf..00000000 --- a/CPP/7zip/Compress/Copy/resource.rc +++ /dev/null @@ -1,3 +0,0 @@ -#include "../../MyVersionInfo.rc" - -MY_VERSION_INFO_DLL("Copy Codec", "Copy") diff --git a/CPP/7zip/Compress/Deflate/Deflate.dsp b/CPP/7zip/Compress/Deflate/Deflate.dsp deleted file mode 100755 index 11854458..00000000 --- a/CPP/7zip/Compress/Deflate/Deflate.dsp +++ /dev/null @@ -1,350 +0,0 @@ -# Microsoft Developer Studio Project File - Name="Deflate" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=Deflate - 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 "Deflate.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 "Deflate.mak" CFG="Deflate - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "Deflate - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "Deflate - 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)" == "Deflate - 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 "DEFLATE_EXPORTS" /YX /FD /c -# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DEFLATE_EXPORTS" /D "_ST_MODE" /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 0x409 /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\Deflate.dll" /opt:NOWIN98 -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "Deflate - 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 "DEFLATE_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /Gz /MDd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "DEFLATE_EXPORTS" /D "_ST_MODE" /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 0x409 /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\Deflate.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "Deflate - Win32 Release" -# Name "Deflate - Win32 Debug" -# Begin Group "Spec" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Codec.def -# End Source File -# Begin Source File - -SOURCE=..\CodecExports.cpp -# End Source File -# Begin Source File - -SOURCE=..\DllExports.cpp -# End Source File -# Begin Source File - -SOURCE=.\resource.rc -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.cpp -# ADD CPP /Yc"StdAfx.h" -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.h -# End Source File -# End Group -# Begin Group "Huffman" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Huffman\HuffmanDecoder.h -# End Source File -# End Group -# Begin Group "Interface" - -# PROP Default_Filter "" -# 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 -# Begin Source File - -SOURCE=..\..\Common\LSBFEncoder.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Common\LSBFEncoder.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 "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 "Windows" - -# PROP Default_Filter "" -# End Group -# Begin Group "LZ" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\LZ\LZOutWindow.cpp -# End Source File -# Begin Source File - -SOURCE=..\LZ\LZOutWindow.h -# End Source File -# End Group -# Begin Group "LZ_C" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\..\C\7zCrc.c - -!IF "$(CFG)" == "Deflate - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Deflate - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\7zCrc.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Alloc.c -# SUBTRACT CPP /YX /Yc /Yu -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Alloc.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Lz\LzHash.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.c - -!IF "$(CFG)" == "Deflate - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Deflate - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.h -# End Source File -# End Group -# Begin Group "C Huffman" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Huffman\HuffmanEncode.c - -!IF "$(CFG)" == "Deflate - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Deflate - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Huffman\HuffmanEncode.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Sort.c - -!IF "$(CFG)" == "Deflate - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Deflate - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Sort.h -# End Source File -# End Group -# Begin Source File - -SOURCE=.\Deflate64Register.cpp -# End Source File -# Begin Source File - -SOURCE=.\DeflateConst.h -# End Source File -# Begin Source File - -SOURCE=.\DeflateDecoder.cpp - -!IF "$(CFG)" == "Deflate - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Deflate - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\DeflateDecoder.h -# End Source File -# Begin Source File - -SOURCE=.\DeflateEncoder.cpp - -!IF "$(CFG)" == "Deflate - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "Deflate - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\DeflateEncoder.h -# End Source File -# Begin Source File - -SOURCE=.\DeflateNsisRegister.cpp -# End Source File -# Begin Source File - -SOURCE=.\DeflateRegister.cpp -# End Source File -# End Target -# End Project diff --git a/CPP/7zip/Compress/Deflate/Deflate.dsw b/CPP/7zip/Compress/Deflate/Deflate.dsw deleted file mode 100755 index f17203ed..00000000 --- a/CPP/7zip/Compress/Deflate/Deflate.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "Deflate"=.\Deflate.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/CPP/7zip/Compress/Deflate/DeflateEncoder.cpp b/CPP/7zip/Compress/Deflate/DeflateEncoder.cpp index 2c623750..44ff42b4 100755 --- a/CPP/7zip/Compress/Deflate/DeflateEncoder.cpp +++ b/CPP/7zip/Compress/Deflate/DeflateEncoder.cpp @@ -2,6 +2,8 @@ #include "StdAfx.h" +#include <stdio.h> + #include "DeflateEncoder.h" #include "Windows/Defs.h" @@ -9,8 +11,8 @@ extern "C" { #include "../../../../C/Alloc.h" +#include "../../../../C/HuffEnc.h" } -// #include "../LZ/BinTree/BinTree3Z.h" #if _MSC_VER >= 1300 #define NO_INLINE __declspec(noinline) @@ -18,11 +20,6 @@ extern "C" #define NO_INLINE #endif -extern "C" -{ - #include "../../../../C/Compress/Huffman/HuffmanEncode.h" -} - namespace NCompress { namespace NDeflate { namespace NEncoder { @@ -31,7 +28,7 @@ const int kNumDivPassesMax = 10; // [0, 16); ratio/speed/ram tradeoff; use big v const UInt32 kNumTables = (1 << kNumDivPassesMax); static UInt32 kFixedHuffmanCodeBlockSizeMax = (1 << 8); // [0, (1 << 32)); ratio/speed tradeoff; use big value for better compression ratio. -static UInt32 kDivideCodeBlockSizeMin = (1 << 6); // [1, (1 << 32)); ratio/speed tradeoff; use small value for better compression ratio. +static UInt32 kDivideCodeBlockSizeMin = (1 << 7); // [1, (1 << 32)); ratio/speed tradeoff; use small value for better compression ratio. static UInt32 kDivideBlockSizeMin = (1 << 6); // [1, (1 << 32)); ratio/speed tradeoff; use small value for better compression ratio. static const UInt32 kMaxUncompressedBlockSize = ((1 << 16) - 1) * 1; // [1, (1 << 32)) @@ -40,11 +37,11 @@ static const UInt32 kMatchArrayLimit = kMatchArraySize - kMatchMaxLen * 4 * size static const UInt32 kBlockUncompressedSizeThreshold = kMaxUncompressedBlockSize - kMatchMaxLen - kNumOpts; -static const int kMaxCodeBitLength = 12; +static const int kMaxCodeBitLength = 11; static const int kMaxLevelBitLength = 7; -static Byte kNoLiteralStatPrice = 12; -static Byte kNoLenStatPrice = 12; +static Byte kNoLiteralStatPrice = 11; +static Byte kNoLenStatPrice = 11; static Byte kNoPosStatPrice = 6; static Byte g_LenSlots[kNumLenSymbolsMax]; @@ -85,19 +82,9 @@ inline UInt32 GetPosSlot(UInt32 pos) return g_FastPos[pos >> 8] + 16; } -void *SzAlloc(size_t size) -{ - if (size == 0) - return 0; - return malloc(size); -} - -void SzFree(void *address) -{ - free(address); -} - -ISzAlloc g_Alloc = { SzAlloc, SzFree }; +static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); } +static void SzFree(void *p, void *address) { p = p; MyFree(address); } +static ISzAlloc g_Alloc = { SzAlloc, SzFree }; CCoder::CCoder(bool deflate64Mode): m_Deflate64Mode(deflate64Mode), @@ -591,10 +578,10 @@ NO_INLINE void CCoder::LevelTableCode(const Byte *levels, int numLevels, const B } } -NO_INLINE void CCoder::MakeTables() +NO_INLINE void CCoder::MakeTables(unsigned maxHuffLen) { - Huffman_Generate(mainFreqs, mainCodes, m_NewLevels.litLenLevels, kFixedMainTableSize, kMaxCodeBitLength); - Huffman_Generate(distFreqs, distCodes, m_NewLevels.distLevels, kDistTableSize64, kMaxCodeBitLength); + Huffman_Generate(mainFreqs, mainCodes, m_NewLevels.litLenLevels, kFixedMainTableSize, maxHuffLen); + Huffman_Generate(distFreqs, distCodes, m_NewLevels.distLevels, kDistTableSize64, maxHuffLen); } NO_INLINE UInt32 Huffman_GetPrice(const UInt32 *freqs, const Byte *lens, UInt32 num) @@ -632,7 +619,7 @@ NO_INLINE void CCoder::TryBlock() if (m_OptimumCurrentIndex == m_OptimumEndIndex) { if (m_Pos >= kMatchArrayLimit || BlockSizeRes >= blockSize || !m_SecondPass && - ((Inline_MatchFinder_GetNumAvailableBytes(&_lzInWindow) == 0) || m_ValueIndex >= m_ValueBlockSize)) + ((Inline_MatchFinder_GetNumAvailableBytes(&_lzInWindow) == 0) || m_ValueIndex >= m_ValueBlockSize)) break; } UInt32 pos; @@ -773,7 +760,11 @@ NO_INLINE UInt32 CCoder::TryDynBlock(int tableIndex, UInt32 numPasses) { m_Pos = posTemp; TryBlock(); - MakeTables(); + unsigned numHuffBits = + (m_ValueIndex > 18000 ? 12 : + (m_ValueIndex > 7000 ? 11 : + (m_ValueIndex > 2000 ? 10 : 9))); + MakeTables(numHuffBits); SetPrices(m_NewLevels); } @@ -893,11 +884,12 @@ void CCoder::CodeBlock(int tableIndex, bool finalBlock) WriteBits(NBlockType::kFixedHuffman, kBlockTypeFieldSize); TryFixedBlock(tableIndex); int i; + const int kMaxStaticHuffLen = 9; for (i = 0; i < kFixedMainTableSize; i++) - mainFreqs[i] = (UInt32)1 << (kNumHuffmanBits - m_NewLevels.litLenLevels[i]); + mainFreqs[i] = (UInt32)1 << (kMaxStaticHuffLen - m_NewLevels.litLenLevels[i]); for (i = 0; i < kFixedDistTableSize; i++) - distFreqs[i] = (UInt32)1 << (kNumHuffmanBits - m_NewLevels.distLevels[i]); - MakeTables(); + distFreqs[i] = (UInt32)1 << (kMaxStaticHuffLen - m_NewLevels.distLevels[i]); + MakeTables(kMaxStaticHuffLen); } else { @@ -921,9 +913,13 @@ void CCoder::CodeBlock(int tableIndex, bool finalBlock) } } -HRes Read(void *object, void *data, UInt32 size, UInt32 *processedSize) +SRes Read(void *object, void *data, size_t *size) { - return (HRes)((CSeqInStream *)object)->RealStream->Read(data, size, processedSize); + const UInt32 kStepSize = (UInt32)1 << 31; + UInt32 curSize = ((*size < kStepSize) ? (UInt32)*size : kStepSize); + HRESULT res = ((CSeqInStream *)object)->RealStream->Read(data, curSize, &curSize); + *size = curSize; + return (SRes)res; } HRESULT CCoder::CodeReal(ISequentialInStream *inStream, @@ -935,7 +931,7 @@ HRESULT CCoder::CodeReal(ISequentialInStream *inStream, RINOK(Create()); - m_ValueBlockSize = (1 << 13) + (1 << 12) * m_NumDivPasses; + m_ValueBlockSize = (7 << 10) + (1 << 12) * m_NumDivPasses; UInt64 nowPos = 0; diff --git a/CPP/7zip/Compress/Deflate/DeflateEncoder.h b/CPP/7zip/Compress/Deflate/DeflateEncoder.h index a7b2bb5b..4cdfa707 100755 --- a/CPP/7zip/Compress/Deflate/DeflateEncoder.h +++ b/CPP/7zip/Compress/Deflate/DeflateEncoder.h @@ -12,7 +12,7 @@ extern "C" { - #include "../../../../C/Compress/Lz/MatchFinder.h" + #include "../../../../C/LzFind.h" } namespace NCompress { @@ -132,7 +132,7 @@ public: void WriteBits(UInt32 value, int numBits); void LevelTableCode(const Byte *levels, int numLevels, const Byte *lens, const UInt32 *codes); - void MakeTables(); + void MakeTables(unsigned maxHuffLen); UInt32 GetLzBlockPrice() const; void TryBlock(); UInt32 TryDynBlock(int tableIndex, UInt32 numPasses); diff --git a/CPP/7zip/Compress/Deflate/makefile b/CPP/7zip/Compress/Deflate/makefile deleted file mode 100755 index 302d2888..00000000 --- a/CPP/7zip/Compress/Deflate/makefile +++ /dev/null @@ -1,63 +0,0 @@ -PROG = Deflate.dll -DEF_FILE = ../Codec.def -CFLAGS = $(CFLAGS) -I ../../../ -LIBS = $(LIBS) oleaut32.lib - -COMPRESS_OBJS = \ - $O\CodecExports.obj \ - $O\DllExports.obj \ - -DEFLATE_OPT_OBJS = \ - $O\DeflateDecoder.obj \ - $O\DeflateEncoder.obj \ - $O\DeflateRegister.obj \ - $O\Deflate64Register.obj \ - $O\DeflateNsisRegister.obj \ - -7ZIP_COMMON_OBJS = \ - $O\InBuffer.obj \ - $O\OutBuffer.obj \ - $O\LSBFDecoder.obj \ - $O\LSBFEncoder.obj \ - -LZ_OBJS = \ - $O\LZOutWindow.obj \ - -C_OBJS = \ - $O\Alloc.obj \ - $O\7zCrc.obj \ - $O\Sort.obj \ - -C_LZ_OBJS = \ - $O\MatchFinder.obj \ - -!include "../../Crc2.mak" - -OBJS = \ - $O\StdAfx.obj \ - $(COMPRESS_OBJS) \ - $(DEFLATE_OPT_OBJS) \ - $(7ZIP_COMMON_OBJS) \ - $(LZ_OBJS) \ - $(C_OBJS) \ - $(C_LZ_OBJS) \ - $O\HuffmanEncode.obj \ - $O\resource.res - -!include "../../../Build.mak" - -$(COMPRESS_OBJS): ../$(*B).cpp - $(COMPL) -$(DEFLATE_OPT_OBJS): $(*B).cpp - $(COMPL_O2) -$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp - $(COMPL) -$(LZ_OBJS): ../LZ/$(*B).cpp - $(COMPL) -$(C_OBJS): ../../../../C/$(*B).c - $(COMPL_O2) -$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c - $(COMPL_O2) -$O\HuffmanEncode.obj: ../../../../C/Compress/Huffman/$(*B).c - $(COMPL_O2) -!include "../../Crc.mak" diff --git a/CPP/7zip/Compress/Deflate/resource.rc b/CPP/7zip/Compress/Deflate/resource.rc deleted file mode 100755 index 910bc281..00000000 --- a/CPP/7zip/Compress/Deflate/resource.rc +++ /dev/null @@ -1,3 +0,0 @@ -#include "../../MyVersionInfo.rc" - -MY_VERSION_INFO_DLL("Deflate Codec", "Deflate") diff --git a/CPP/7zip/Compress/Huffman/HuffmanDecoder.h b/CPP/7zip/Compress/Huffman/HuffmanDecoder.h index 57115197..df67e8c9 100755 --- a/CPP/7zip/Compress/Huffman/HuffmanDecoder.h +++ b/CPP/7zip/Compress/Huffman/HuffmanDecoder.h @@ -22,7 +22,8 @@ public: bool SetCodeLengths(const Byte *codeLengths) { - int lenCounts[kNumBitsMax + 1], tmpPositions[kNumBitsMax + 1]; + int lenCounts[kNumBitsMax + 1]; + UInt32 tmpPositions[kNumBitsMax + 1]; int i; for(i = 1; i <= kNumBitsMax; i++) lenCounts[i] = 0; diff --git a/CPP/7zip/Compress/LZMA/LZMA.dsp b/CPP/7zip/Compress/LZMA/LZMA.dsp deleted file mode 100755 index 2e699d43..00000000 --- a/CPP/7zip/Compress/LZMA/LZMA.dsp +++ /dev/null @@ -1,367 +0,0 @@ -# Microsoft Developer Studio Project File - Name="LZMA" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=LZMA - Win32 Debug -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "LZMA.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "LZMA.mak" CFG="LZMA - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "LZMA - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "LZMA - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -MTL=midl.exe -RSC=rc.exe - -!IF "$(CFG)" == "LZMA - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMA_EXPORTS" /YX /FD /c -# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "../../../" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMA_EXPORTS" /D "COMPRESS_MF_MT" /D "_7ZIP_LARGE_PAGES" /Yu"StdAfx.h" /FD /c -# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x419 /d "NDEBUG" -# ADD RSC /l 0x419 /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"C:\Program Files\7-zip\Codecs\LZMA.dll" /opt:NOWIN98 -# SUBTRACT LINK32 /pdb:none /debug - -!ELSEIF "$(CFG)" == "LZMA - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Ignore_Export_Lib 1 -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMA_EXPORTS" /YX /FD /GZ /c -# ADD CPP /nologo /Gz /MTd /W3 /Gm /GX /ZI /Od /I "../../../" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LZMA_EXPORTS" /D "COMPRESS_MF_MT" /D "_7ZIP_LARGE_PAGES" /Yu"StdAfx.h" /FD /GZ /c -# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 -# ADD BASE RSC /l 0x419 /d "_DEBUG" -# ADD RSC /l 0x419 /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LINK32=link.exe -# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept -# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"C:\Program Files\7-zip\Codecs\LZMA.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "LZMA - Win32 Release" -# Name "LZMA - Win32 Debug" -# Begin Group "Spec" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Codec.def -# End Source File -# Begin Source File - -SOURCE=..\CodecExports.cpp -# End Source File -# Begin Source File - -SOURCE=..\DllExports.cpp -# End Source File -# Begin Source File - -SOURCE=.\resource.rc -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.cpp -# ADD CPP /Yc"StdAfx.h" -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.h -# End Source File -# End Group -# Begin Group "7-zip Common" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\Common\InBuffer.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Common\InBuffer.h -# End Source File -# Begin Source File - -SOURCE=..\..\Common\OutBuffer.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Common\OutBuffer.h -# End Source File -# Begin Source File - -SOURCE=..\..\Common\StreamUtils.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Common\StreamUtils.h -# End Source File -# End Group -# Begin Group "RangeCoder" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\RangeCoder\RangeCoder.h -# End Source File -# Begin Source File - -SOURCE=..\RangeCoder\RangeCoderBit.cpp -# End Source File -# Begin Source File - -SOURCE=..\RangeCoder\RangeCoderBit.h -# End Source File -# Begin Source File - -SOURCE=..\RangeCoder\RangeCoderBitTree.h -# End Source File -# Begin Source File - -SOURCE=..\RangeCoder\RangeCoderOpt.h -# End Source File -# End Group -# Begin Group "Interface" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\ICoder.h -# End Source File -# Begin Source File - -SOURCE=..\..\IStream.h -# End Source File -# End Group -# Begin Group "LZ" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\LZ\LZOutWindow.cpp -# End Source File -# Begin Source File - -SOURCE=..\LZ\LZOutWindow.h -# End Source File -# End Group -# Begin Group "Common" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\Common\ComTry.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\Common\Defs.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\Common\Exception.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\Common\MyCom.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\Common\MyUnknown.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\Common\MyWindows.h -# End Source File -# End Group -# Begin Group "C" - -# PROP Default_Filter "" -# Begin Group "C_Lz" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Lz\LzHash.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.c - -!IF "$(CFG)" == "LZMA - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "LZMA - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.c - -!IF "$(CFG)" == "LZMA - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "LZMA - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.h -# End Source File -# End Group -# Begin Source File - -SOURCE=..\..\..\..\C\7zCrc.c - -!IF "$(CFG)" == "LZMA - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "LZMA - Win32 Debug" - -# SUBTRACT CPP /YX /Yc /Yu - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\7zCrc.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Alloc.c -# SUBTRACT CPP /YX /Yc /Yu -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Alloc.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\IStream.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Threads.c -# SUBTRACT CPP /YX /Yc /Yu -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Threads.h -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Types.h -# End Source File -# End Group -# Begin Source File - -SOURCE=.\LZMA.h -# End Source File -# Begin Source File - -SOURCE=.\LZMADecoder.cpp - -!IF "$(CFG)" == "LZMA - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "LZMA - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\LZMADecoder.h -# End Source File -# Begin Source File - -SOURCE=.\LZMAEncoder.cpp - -!IF "$(CFG)" == "LZMA - Win32 Release" - -# ADD CPP /O2 /FAs -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "LZMA - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\LZMAEncoder.h -# End Source File -# Begin Source File - -SOURCE=.\LZMARegister.cpp -# End Source File -# End Target -# End Project diff --git a/CPP/7zip/Compress/LZMA/LZMA.dsw b/CPP/7zip/Compress/LZMA/LZMA.dsw deleted file mode 100755 index f750e453..00000000 --- a/CPP/7zip/Compress/LZMA/LZMA.dsw +++ /dev/null @@ -1,29 +0,0 @@ -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> -{{{ -}}} - -############################################################################### - diff --git a/CPP/7zip/Compress/LZMA/LZMA.h b/CPP/7zip/Compress/LZMA/LZMA.h deleted file mode 100755 index 7bc4c438..00000000 --- a/CPP/7zip/Compress/LZMA/LZMA.h +++ /dev/null @@ -1,82 +0,0 @@ -// LZMA.h - -#ifndef __LZMA_H -#define __LZMA_H - -namespace NCompress { -namespace NLZMA { - -const UInt32 kNumRepDistances = 4; - -const int 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]; } - bool IsCharState() const { return Index < 7; } -}; - -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; -} - -namespace NLength { - -const int kNumPosStatesBitsMax = 4; -const UInt32 kNumPosStatesMax = (1 << kNumPosStatesBitsMax); - -const int kNumPosStatesBitsEncodingMax = 4; -const UInt32 kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax); - -const int kNumLowBits = 3; -const int kNumMidBits = 3; -const int kNumHighBits = 8; -const UInt32 kNumLowSymbols = 1 << kNumLowBits; -const UInt32 kNumMidSymbols = 1 << kNumMidBits; -const UInt32 kNumSymbolsTotal = kNumLowSymbols + kNumMidSymbols + (1 << kNumHighBits); - -} - -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 int kNumLitPosStatesBitsEncodingMax = 4; -const int kNumLitContextBitsMax = 8; - -const int kNumMoveBits = 5; - -}} - -#endif diff --git a/CPP/7zip/Compress/LZMA/LZMADecoder.cpp b/CPP/7zip/Compress/LZMA/LZMADecoder.cpp index 1b73855c..1df7fe6c 100755 --- a/CPP/7zip/Compress/LZMA/LZMADecoder.cpp +++ b/CPP/7zip/Compress/LZMA/LZMADecoder.cpp @@ -4,333 +4,187 @@ #include "LZMADecoder.h" #include "../../../Common/Defs.h" +#include "../../Common/StreamUtils.h" + +extern "C" +{ + #include "../../../../C/Alloc.h" +} + +static HRESULT SResToHRESULT(SRes res) +{ + switch(res) + { + case SZ_OK: return S_OK; + case SZ_ERROR_MEM: return E_OUTOFMEMORY; + case SZ_ERROR_PARAM: return E_INVALIDARG; + // case SZ_ERROR_PROGRESS: return E_ABORT; + case SZ_ERROR_DATA: return S_FALSE; + } + return E_FAIL; +} namespace NCompress { namespace NLZMA { -const int kLenIdFinished = -1; -const int kLenIdNeedInit = -2; +static const UInt32 kInBufSize = 1 << 20; -void CDecoder::Init() +CDecoder::CDecoder(): _inBuf(0), _outSizeDefined(false) { - { - for(int i = 0; i < kNumStates; i++) - { - for (UInt32 j = 0; j <= _posStateMask; j++) - { - _isMatch[i][j].Init(); - _isRep0Long[i][j].Init(); - } - _isRep[i].Init(); - _isRepG0[i].Init(); - _isRepG1[i].Init(); - _isRepG2[i].Init(); - } - } - { - for (UInt32 i = 0; i < kNumLenToPosStates; i++) - _posSlotDecoder[i].Init(); - } - { - for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++) - _posDecoders[i].Init(); - } - _posAlignDecoder.Init(); - _lenDecoder.Init(_posStateMask + 1); - _repMatchLenDecoder.Init(_posStateMask + 1); - _literalDecoder.Init(); - - _state.Init(); - _reps[0] = _reps[1] = _reps[2] = _reps[3] = 0; + LzmaDec_Construct(&_state); } -HRESULT CDecoder::CodeSpec(UInt32 curSize) -{ - if (_outSizeDefined) - { - const UInt64 rem = _outSize - _outWindowStream.GetProcessedSize(); - if (curSize > rem) - curSize = (UInt32)rem; - } +static void *SzAlloc(void *p, size_t size) { p = p; return MyAlloc(size); } +static void SzFree(void *p, void *address) { p = p; MyFree(address); } +static ISzAlloc g_Alloc = { SzAlloc, SzFree }; - if (_remainLen == kLenIdFinished) - return S_OK; - if (_remainLen == kLenIdNeedInit) - { - _rangeDecoder.Init(); - Init(); - _remainLen = 0; - } - if (curSize == 0) - return S_OK; +CDecoder::~CDecoder() +{ + LzmaDec_Free(&_state, &g_Alloc); + MyFree(_inBuf); +} - UInt32 rep0 = _reps[0]; - UInt32 rep1 = _reps[1]; - UInt32 rep2 = _reps[2]; - UInt32 rep3 = _reps[3]; - CState state = _state; - Byte previousByte; +STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *prop, UInt32 size) +{ + RINOK(SResToHRESULT(LzmaDec_Allocate(&_state, prop, size, &g_Alloc))); - while(_remainLen > 0 && curSize > 0) + if (_inBuf == 0) { - previousByte = _outWindowStream.GetByte(rep0); - _outWindowStream.PutByte(previousByte); - _remainLen--; - curSize--; + _inBuf = (Byte *)MyAlloc(kInBufSize); + if (_inBuf == 0) + return E_OUTOFMEMORY; } - UInt64 nowPos64 = _outWindowStream.GetProcessedSize(); - if (nowPos64 == 0) - previousByte = 0; - else - previousByte = _outWindowStream.GetByte(0); - while(curSize > 0) - { - { - #ifdef _NO_EXCEPTIONS - if (_rangeDecoder.Stream.ErrorCode != S_OK) - return _rangeDecoder.Stream.ErrorCode; - #endif - if (_rangeDecoder.Stream.WasFinished()) - return S_FALSE; - UInt32 posState = UInt32(nowPos64) & _posStateMask; - if (_isMatch[state.Index][posState].Decode(&_rangeDecoder) == 0) - { - if(!state.IsCharState()) - previousByte = _literalDecoder.DecodeWithMatchByte(&_rangeDecoder, - (UInt32)nowPos64, previousByte, _outWindowStream.GetByte(rep0)); - else - previousByte = _literalDecoder.DecodeNormal(&_rangeDecoder, - (UInt32)nowPos64, previousByte); - _outWindowStream.PutByte(previousByte); - state.UpdateChar(); - curSize--; - nowPos64++; - } - else - { - UInt32 len; - if(_isRep[state.Index].Decode(&_rangeDecoder) == 1) - { - len = 0; - if(_isRepG0[state.Index].Decode(&_rangeDecoder) == 0) - { - if(_isRep0Long[state.Index][posState].Decode(&_rangeDecoder) == 0) - { - state.UpdateShortRep(); - len = 1; - } - } - else - { - UInt32 distance; - if(_isRepG1[state.Index].Decode(&_rangeDecoder) == 0) - distance = rep1; - else - { - if (_isRepG2[state.Index].Decode(&_rangeDecoder) == 0) - distance = rep2; - else - { - distance = rep3; - rep3 = rep2; - } - rep2 = rep1; - } - rep1 = rep0; - rep0 = distance; - } - if (len == 0) - { - len = _repMatchLenDecoder.Decode(&_rangeDecoder, posState) + kMatchMinLen; - state.UpdateRep(); - } - } - else - { - rep3 = rep2; - rep2 = rep1; - rep1 = rep0; - len = kMatchMinLen + _lenDecoder.Decode(&_rangeDecoder, posState); - state.UpdateMatch(); - UInt32 posSlot = _posSlotDecoder[GetLenToPosState(len)].Decode(&_rangeDecoder); - if (posSlot >= kStartPosModelIndex) - { - UInt32 numDirectBits = (posSlot >> 1) - 1; - rep0 = ((2 | (posSlot & 1)) << numDirectBits); + return S_OK; +} - if (posSlot < kEndPosModelIndex) - rep0 += NRangeCoder::ReverseBitTreeDecode(_posDecoders + - rep0 - posSlot - 1, &_rangeDecoder, numDirectBits); - else - { - rep0 += (_rangeDecoder.DecodeDirectBits( - numDirectBits - kNumAlignBits) << kNumAlignBits); - rep0 += _posAlignDecoder.ReverseDecode(&_rangeDecoder); - if (rep0 == 0xFFFFFFFF) - { - _remainLen = kLenIdFinished; - return S_OK; - } - } - } - else - rep0 = posSlot; - } - UInt32 locLen = len; - if (len > curSize) - locLen = (UInt32)curSize; - if (!_outWindowStream.CopyBlock(rep0, locLen)) - return S_FALSE; - previousByte = _outWindowStream.GetByte(0); - curSize -= locLen; - nowPos64 += locLen; - len -= locLen; - if (len != 0) - { - _remainLen = (Int32)len; - break; - } +STDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value) { *value = _inSizeProcessed; return S_OK; } +STDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream) { _inStream = inStream; return S_OK; } +STDMETHODIMP CDecoder::ReleaseInStream() { _inStream.Release(); return S_OK; } - #ifdef _NO_EXCEPTIONS - if (_outWindowStream.ErrorCode != S_OK) - return _outWindowStream.ErrorCode; - #endif - } - } - } - if (_rangeDecoder.Stream.WasFinished()) - return S_FALSE; - _reps[0] = rep0; - _reps[1] = rep1; - _reps[2] = rep2; - _reps[3] = rep3; - _state = state; +STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize) +{ + _outSizeDefined = (outSize != NULL); + if (_outSizeDefined) + _outSize = *outSize; + LzmaDec_Init(&_state); + + _inPos = _inSize = 0; + _inSizeProcessed = _outSizeProcessed = 0; return S_OK; } -STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream, - ISequentialOutStream *outStream, - const UInt64 *, const UInt64 *outSize, - ICompressProgressInfo *progress) +STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, + ISequentialOutStream *outStream, const UInt64 * /* inSize */, + const UInt64 *outSize, ICompressProgressInfo *progress) { - SetInStream(inStream); - _outWindowStream.SetStream(outStream); + if (_inBuf == 0) + return S_FALSE; SetOutStreamSize(outSize); - CDecoderFlusher flusher(this); for (;;) { - UInt32 curSize = 1 << 18; - RINOK(CodeSpec(curSize)); - if (_remainLen == kLenIdFinished) - break; - if (progress != NULL) + if (_inPos == _inSize) { - UInt64 inSize = _rangeDecoder.GetProcessedSize(); - UInt64 nowPos64 = _outWindowStream.GetProcessedSize(); - RINOK(progress->SetRatioInfo(&inSize, &nowPos64)); + _inPos = _inSize = 0; + RINOK(inStream->Read(_inBuf, kInBufSize, &_inSize)); } - if (_outSizeDefined) - if (_outWindowStream.GetProcessedSize() >= _outSize) - break; - } - flusher.NeedFlush = false; - return Flush(); -} - - -#ifdef _NO_EXCEPTIONS - -#define LZMA_TRY_BEGIN -#define LZMA_TRY_END - -#else -#define LZMA_TRY_BEGIN try { -#define LZMA_TRY_END } \ - catch(const CInBufferException &e) { return e.ErrorCode; } \ - catch(const CLZOutWindowException &e) { return e.ErrorCode; } \ - catch(...) { return S_FALSE; } + SizeT dicPos = _state.dicPos; + SizeT curSize = _state.dicBufSize - dicPos; + const UInt32 kStepSize = ((UInt32)1 << 22); + if (curSize > kStepSize) + curSize = (SizeT)kStepSize; + + ELzmaFinishMode finishMode = LZMA_FINISH_ANY; + if (_outSizeDefined) + { + const UInt64 rem = _outSize - _outSizeProcessed; + if (rem < curSize) + { + curSize = (SizeT)rem; + /* + // finishMode = LZMA_FINISH_END; + we can't use LZMA_FINISH_END here to allow partial decoding + */ + } + } -#endif + SizeT inSizeProcessed = _inSize - _inPos; + ELzmaStatus status; + SRes res = LzmaDec_DecodeToDic(&_state, dicPos + curSize, _inBuf + _inPos, &inSizeProcessed, finishMode, &status); + _inPos += (UInt32)inSizeProcessed; + _inSizeProcessed += inSizeProcessed; + SizeT outSizeProcessed = _state.dicPos - dicPos; + _outSizeProcessed += outSizeProcessed; -STDMETHODIMP CDecoder::Code(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, - ICompressProgressInfo *progress) -{ - LZMA_TRY_BEGIN - return CodeReal(inStream, outStream, inSize, outSize, progress); - LZMA_TRY_END -} - -STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *properties, UInt32 size) -{ - if (size < 5) - return E_INVALIDARG; - int lc = properties[0] % 9; - Byte remainder = (Byte)(properties[0] / 9); - int lp = remainder % 5; - int pb = remainder / 5; - if (pb > NLength::kNumPosStatesBitsMax) - return E_INVALIDARG; - _posStateMask = (1 << pb) - 1; - UInt32 dictionarySize = 0; - for (int i = 0; i < 4; i++) - dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8); - if (!_outWindowStream.Create(dictionarySize)) - return E_OUTOFMEMORY; - if (!_literalDecoder.Create(lp, lc)) - return E_OUTOFMEMORY; - if (!_rangeDecoder.Create(1 << 20)) - return E_OUTOFMEMORY; - return S_OK; -} + bool finished = (inSizeProcessed == 0 && outSizeProcessed == 0); + bool stopDecoding = (_outSizeDefined && _outSizeProcessed >= _outSize); -STDMETHODIMP CDecoder::GetInStreamProcessedSize(UInt64 *value) -{ - *value = _rangeDecoder.GetProcessedSize(); - return S_OK; -} - -STDMETHODIMP CDecoder::SetInStream(ISequentialInStream *inStream) -{ - _rangeDecoder.SetStream(inStream); - return S_OK; -} - -STDMETHODIMP CDecoder::ReleaseInStream() -{ - _rangeDecoder.ReleaseStream(); - return S_OK; -} + if (res != 0 || _state.dicPos == _state.dicBufSize || finished || stopDecoding) + { + HRESULT res2 = WriteStream(outStream, _state.dic, _state.dicPos); + if (res != 0) + return S_FALSE; + RINOK(res2); + if (stopDecoding) + return S_OK; + if (finished) + return (status == LZMA_STATUS_FINISHED_WITH_MARK ? S_OK : S_FALSE); + } + if (_state.dicPos == _state.dicBufSize) + _state.dicPos = 0; -STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize) -{ - _outSizeDefined = (outSize != NULL); - if (_outSizeDefined) - _outSize = *outSize; - _remainLen = kLenIdNeedInit; - _outWindowStream.Init(); - return S_OK; + if (progress != NULL) + { + RINOK(progress->SetRatioInfo(&_inSizeProcessed, &_outSizeProcessed)); + } + } } #ifndef NO_READ_FROM_CODER STDMETHODIMP CDecoder::Read(void *data, UInt32 size, UInt32 *processedSize) { - LZMA_TRY_BEGIN if (processedSize) *processedSize = 0; - const UInt64 startPos = _outWindowStream.GetProcessedSize(); - _outWindowStream.SetMemStream((Byte *)data); - RINOK(CodeSpec(size)); - if (processedSize) - *processedSize = (UInt32)(_outWindowStream.GetProcessedSize() - startPos); - return Flush(); - LZMA_TRY_END + do + { + if (_inPos == _inSize) + { + _inPos = _inSize = 0; + RINOK(_inStream->Read(_inBuf, kInBufSize, &_inSize)); + } + { + SizeT inProcessed = _inSize - _inPos; + + if (_outSizeDefined) + { + const UInt64 rem = _outSize - _outSizeProcessed; + if (rem < size) + size = (UInt32)rem; + } + + SizeT outProcessed = size; + ELzmaStatus status; + SRes res = LzmaDec_DecodeToBuf(&_state, (Byte *)data, &outProcessed, + _inBuf + _inPos, &inProcessed, LZMA_FINISH_ANY, &status); + _inPos += (UInt32)inProcessed; + _inSizeProcessed += inProcessed; + _outSizeProcessed += outProcessed; + size -= (UInt32)outProcessed; + data = (Byte *)data + outProcessed; + if (processedSize) + *processedSize += (UInt32)outProcessed; + RINOK(SResToHRESULT(res)); + if (inProcessed == 0 && outProcessed == 0) + return S_OK; + } + } + while (size != 0); + return S_OK; } #endif diff --git a/CPP/7zip/Compress/LZMA/LZMADecoder.h b/CPP/7zip/Compress/LZMA/LZMADecoder.h index bc44a5a9..be5df30d 100755 --- a/CPP/7zip/Compress/LZMA/LZMADecoder.h +++ b/CPP/7zip/Compress/LZMA/LZMADecoder.h @@ -1,151 +1,19 @@ -// LZMA/Decoder.h +// LZMADecoder.h #ifndef __LZMA_DECODER_H #define __LZMA_DECODER_H #include "../../../Common/MyCom.h" #include "../../ICoder.h" -#include "../LZ/LZOutWindow.h" -#include "../RangeCoder/RangeCoderBitTree.h" extern "C" { - #include "../../../../C/Alloc.h" + #include "../../../../C/LzmaDec.h" } -#include "LZMA.h" - namespace NCompress { namespace NLZMA { -typedef NRangeCoder::CBitDecoder<kNumMoveBits> CMyBitDecoder; - -class CLiteralDecoder2 -{ - CMyBitDecoder _decoders[0x300]; -public: - void Init() - { - for (int i = 0; i < 0x300; i++) - _decoders[i].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[symbol].Prob, symbol) - } - while (symbol < 0x100); - RC_FLUSH_VAR - return (Byte)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[0x100 + (matchBit << 8) + symbol].Prob, symbol, - bit = 0, bit = 1) - if (matchBit != bit) - { - while (symbol < 0x100) - { - // symbol = (symbol << 1) | _decoders[0][symbol].Decode(rangeDecoder); - RC_GETBIT(kNumMoveBits, _decoders[symbol].Prob, symbol) - } - break; - } - } - while (symbol < 0x100); - RC_FLUSH_VAR - return (Byte)symbol; - } -}; - -class CLiteralDecoder -{ - CLiteralDecoder2 *_coders; - int _numPrevBits; - int _numPosBits; - UInt32 _posMask; -public: - CLiteralDecoder(): _coders(0) {} - ~CLiteralDecoder() { Free(); } - void Free() - { - MyFree(_coders); - _coders = 0; - } - bool Create(int numPosBits, int numPrevBits) - { - if (_coders == 0 || (numPosBits + numPrevBits) != - (_numPrevBits + _numPosBits) ) - { - Free(); - UInt32 numStates = 1 << (numPosBits + numPrevBits); - _coders = (CLiteralDecoder2 *)MyAlloc(numStates * sizeof(CLiteralDecoder2)); - } - _numPosBits = numPosBits; - _posMask = (1 << numPosBits) - 1; - _numPrevBits = numPrevBits; - return (_coders != 0); - } - 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); } -}; - -namespace NLength { - -class CDecoder -{ - CMyBitDecoder _choice; - CMyBitDecoder _choice2; - NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumLowBits> _lowCoder[kNumPosStatesMax]; - NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesMax]; - NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumHighBits> _highCoder; -public: - void Init(UInt32 numPosStates) - { - _choice.Init(); - _choice2.Init(); - for (UInt32 posState = 0; posState < numPosStates; posState++) - { - _lowCoder[posState].Init(); - _midCoder[posState].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); - } -}; - -} - class CDecoder: public ICompressCoder, public ICompressSetDecoderProperties2, @@ -157,38 +25,15 @@ class CDecoder: #endif public CMyUnknownImp { - CLZOutWindow _outWindowStream; - NRangeCoder::CDecoder _rangeDecoder; - - CMyBitDecoder _isMatch[kNumStates][NLength::kNumPosStatesMax]; - CMyBitDecoder _isRep[kNumStates]; - CMyBitDecoder _isRepG0[kNumStates]; - CMyBitDecoder _isRepG1[kNumStates]; - CMyBitDecoder _isRepG2[kNumStates]; - CMyBitDecoder _isRep0Long[kNumStates][NLength::kNumPosStatesMax]; - - NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumPosSlotBits> _posSlotDecoder[kNumLenToPosStates]; - - CMyBitDecoder _posDecoders[kNumFullDistances - kEndPosModelIndex]; - NRangeCoder::CBitTreeDecoder<kNumMoveBits, kNumAlignBits> _posAlignDecoder; - - NLength::CDecoder _lenDecoder; - NLength::CDecoder _repMatchLenDecoder; - - CLiteralDecoder _literalDecoder; - - UInt32 _posStateMask; - - /////////////////// - // State - UInt32 _reps[4]; - CState _state; - Int32 _remainLen; // -1 means end of stream. // -2 means need Init - UInt64 _outSize; + CMyComPtr<ISequentialInStream> _inStream; + Byte *_inBuf; + UInt32 _inPos; + UInt32 _inSize; + CLzmaDec _state; bool _outSizeDefined; - - void Init(); - HRESULT CodeSpec(UInt32 size); + UInt64 _outSize; + UInt64 _inSizeProcessed; + UInt64 _outSizeProcessed; public: #ifndef NO_READ_FROM_CODER @@ -204,34 +49,8 @@ public: ICompressGetInStreamProcessedSize) #endif - void ReleaseStreams() - { - _outWindowStream.ReleaseStream(); - ReleaseInStream(); - } - - 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(); } - - 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, + ISequentialOutStream *outStream, const UInt64 *_inSize, const UInt64 *outSize, ICompressProgressInfo *progress); STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size); @@ -246,8 +65,9 @@ public: STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); #endif - CDecoder(): _outSizeDefined(false) {} - virtual ~CDecoder() {} + CDecoder(); + virtual ~CDecoder(); + }; }} diff --git a/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp b/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp index 021099d8..25faa730 100755 --- a/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp +++ b/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp @@ -16,255 +16,71 @@ #endif #endif -#include "../../../Common/Defs.h" -#include "../../Common/StreamUtils.h" - #include "LZMAEncoder.h" -// extern "C" { #include "../../../../C/7zCrc.h" } - -// #define SHOW_STAT - - -namespace NCompress { -namespace NLZMA { - -// struct CCrcInit { CCrcInit() { InitCrcTable(); } } g_CrcInit; - -const int kDefaultDictionaryLogSize = 22; -const UInt32 kNumFastBytesDefault = 0x20; - -#ifndef LZMA_LOG_BSR -Byte g_FastPos[1 << kNumLogBits]; - -class CFastPosInit -{ -public: - CFastPosInit() { Init(); } - void Init() - { - const Byte kFastSlots = kNumLogBits * 2; - int c = 2; - g_FastPos[0] = 0; - g_FastPos[1] = 1; - - for (Byte slotFast = 2; slotFast < kFastSlots; slotFast++) - { - UInt32 k = (1 << ((slotFast >> 1) - 1)); - for (UInt32 j = 0; j < k; j++, c++) - g_FastPos[c] = slotFast; - } - } -} g_FastPosInit; -#endif +#include "../../Common/StreamUtils.h" -void CLiteralEncoder2::Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol) -{ - UInt32 context = 1; - int i = 8; - do - { - i--; - UInt32 bit = (symbol >> i) & 1; - _encoders[context].Encode(rangeEncoder, bit); - context = (context << 1) | bit; - } - while(i != 0); +extern "C" +{ +#include "../../../../C/Alloc.h" } -void CLiteralEncoder2::EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, - Byte matchByte, Byte symbol) +static HRESULT SResToHRESULT(SRes res) { - UInt32 context = 1; - int i = 8; - do + switch(res) { - i--; - UInt32 bit = (symbol >> i) & 1; - UInt32 matchBit = (matchByte >> i) & 1; - _encoders[0x100 + (matchBit << 8) + context].Encode(rangeEncoder, bit); - context = (context << 1) | bit; - if (matchBit != bit) - { - while(i != 0) - { - i--; - UInt32 bit = (symbol >> i) & 1; - _encoders[context].Encode(rangeEncoder, bit); - context = (context << 1) | bit; - } - break; - } + case SZ_OK: return S_OK; + case SZ_ERROR_MEM: return E_OUTOFMEMORY; + case SZ_ERROR_PARAM: return E_INVALIDARG; + // case SZ_ERROR_THREAD: return E_FAIL; } - while(i != 0); + return E_FAIL; } -UInt32 CLiteralEncoder2::GetPrice(bool matchMode, Byte matchByte, Byte symbol) const -{ - UInt32 price = 0; - UInt32 context = 1; - int i = 8; - if (matchMode) - { - do - { - i--; - UInt32 matchBit = (matchByte >> i) & 1; - UInt32 bit = (symbol >> i) & 1; - price += _encoders[0x100 + (matchBit << 8) + context].GetPrice(bit); - context = (context << 1) | bit; - if (matchBit != bit) - break; - } - while (i != 0); - } - while(i != 0) - { - i--; - UInt32 bit = (symbol >> i) & 1; - price += _encoders[context].GetPrice(bit); - context = (context << 1) | bit; - } - return price; -}; - +namespace NCompress { +namespace NLZMA { -namespace NLength { +static const UInt32 kStreamStepSize = (UInt32)1 << 31; -void CEncoder::Init(UInt32 numPosStates) +static SRes MyRead(void *object, void *data, size_t *size) { - _choice.Init(); - _choice2.Init(); - for (UInt32 posState = 0; posState < numPosStates; posState++) - { - _lowCoder[posState].Init(); - _midCoder[posState].Init(); - } - _highCoder.Init(); + UInt32 curSize = ((*size < kStreamStepSize) ? (UInt32)*size : kStreamStepSize); + HRESULT res = ((CSeqInStream *)object)->RealStream->Read(data, curSize, &curSize); + *size = curSize; + return (SRes)res; } -void CEncoder::Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState) +static size_t MyWrite(void *object, const void *data, size_t size) { - if(symbol < kNumLowSymbols) - { - _choice.Encode(rangeEncoder, 0); - _lowCoder[posState].Encode(rangeEncoder, symbol); - } - else - { - _choice.Encode(rangeEncoder, 1); - if(symbol < kNumLowSymbols + kNumMidSymbols) - { - _choice2.Encode(rangeEncoder, 0); - _midCoder[posState].Encode(rangeEncoder, symbol - kNumLowSymbols); - } - else - { - _choice2.Encode(rangeEncoder, 1); - _highCoder.Encode(rangeEncoder, symbol - kNumLowSymbols - kNumMidSymbols); - } - } + CSeqOutStream *p = (CSeqOutStream *)object; + p->Res = WriteStream(p->RealStream, data, size); + if (p->Res != 0) + return 0; + return size; } -void CEncoder::SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const -{ - UInt32 a0 = _choice.GetPrice0(); - UInt32 a1 = _choice.GetPrice1(); - UInt32 b0 = a1 + _choice2.GetPrice0(); - UInt32 b1 = a1 + _choice2.GetPrice1(); - UInt32 i = 0; - for (i = 0; i < kNumLowSymbols; i++) - { - if (i >= numSymbols) - return; - prices[i] = a0 + _lowCoder[posState].GetPrice(i); - } - for (; i < kNumLowSymbols + kNumMidSymbols; i++) - { - if (i >= numSymbols) - return; - prices[i] = b0 + _midCoder[posState].GetPrice(i - kNumLowSymbols); - } - for (; i < numSymbols; i++) - prices[i] = b1 + _highCoder.GetPrice(i - kNumLowSymbols - kNumMidSymbols); -} +static void *SzBigAlloc(void *, size_t size) { return BigAlloc(size); } +static void SzBigFree(void *, void *address) { BigFree(address); } +static ISzAlloc g_BigAlloc = { SzBigAlloc, SzBigFree }; -} +static void *SzAlloc(void *, size_t size) { return MyAlloc(size); } +static void SzFree(void *, void *address) { MyFree(address); } +static ISzAlloc g_Alloc = { SzAlloc, SzFree }; -CEncoder::CEncoder(): - _numFastBytes(kNumFastBytesDefault), - _distTableSize(kDefaultDictionaryLogSize * 2), - _posStateBits(2), - _posStateMask(4 - 1), - _numLiteralPosStateBits(0), - _numLiteralContextBits(3), - _dictionarySize(1 << kDefaultDictionaryLogSize), - _matchFinderCycles(0), - #ifdef COMPRESS_MF_MT - _multiThread(false), - #endif - _writeEndMark(false) +CEncoder::CEncoder() { - MatchFinder_Construct(&_matchFinderBase); - // _maxMode = false; - _fastMode = false; - #ifdef COMPRESS_MF_MT - MatchFinderMt_Construct(&_matchFinderMt); - _matchFinderMt.MatchFinder = &_matchFinderBase; - #endif + _seqInStream.SeqInStream.Read = MyRead; + _seqOutStream.SeqOutStream.Write = MyWrite; + _encoder = 0; + _encoder = LzmaEnc_Create(&g_Alloc); + if (_encoder == 0) + throw 1; } - -static void *SzAlloc(size_t size) { return BigAlloc(size); } -static void SzFree(void *address) { BigFree(address); } -ISzAlloc g_Alloc = { SzAlloc, SzFree }; - CEncoder::~CEncoder() { - #ifdef COMPRESS_MF_MT - MatchFinderMt_Destruct(&_matchFinderMt, &g_Alloc); - #endif - MatchFinder_Free(&_matchFinderBase, &g_Alloc); -} - -static const UInt32 kBigHashDicLimit = (UInt32)1 << 24; - -HRESULT CEncoder::Create() -{ - if (!_rangeEncoder.Create(1 << 20)) - return E_OUTOFMEMORY; - bool btMode = (_matchFinderBase.btMode != 0); - #ifdef COMPRESS_MF_MT - _mtMode = (_multiThread && !_fastMode && btMode); - #endif - - if (!_literalEncoder.Create(_numLiteralPosStateBits, _numLiteralContextBits)) - return E_OUTOFMEMORY; - - _matchFinderBase.bigHash = (_dictionarySize > kBigHashDicLimit); - - UInt32 numCycles = 16 + (_numFastBytes >> 1); - if (!btMode) - numCycles >>= 1; - if (_matchFinderCycles != 0) - numCycles = _matchFinderCycles; - _matchFinderBase.cutValue = numCycles; - #ifdef COMPRESS_MF_MT - if (_mtMode) - { - RINOK(MatchFinderMt_Create(&_matchFinderMt, _dictionarySize, kNumOpts, _numFastBytes, kMatchMaxLen, &g_Alloc)); - _matchFinderObj = &_matchFinderMt; - MatchFinderMt_CreateVTable(&_matchFinderMt, &_matchFinder); - } - else - #endif - { - if (!MatchFinder_Create(&_matchFinderBase, _dictionarySize, kNumOpts, _numFastBytes, kMatchMaxLen, &g_Alloc)) - return E_OUTOFMEMORY; - _matchFinderObj = &_matchFinderBase; - MatchFinder_CreateVTable(&_matchFinderBase, &_matchFinder); - } - return S_OK; + if (_encoder != 0) + LzmaEnc_Destroy(_encoder, &g_Alloc, &g_BigAlloc); } inline wchar_t GetUpperChar(wchar_t c) @@ -274,7 +90,7 @@ inline wchar_t GetUpperChar(wchar_t c) return c; } -static int ParseMatchFinder(const wchar_t *s, int *btMode, UInt32 *numHashBytes /* , int *skipModeBits */) +static int ParseMatchFinder(const wchar_t *s, int *btMode, int *numHashBytes) { wchar_t c = GetUpperChar(*s++); if (c == L'H') @@ -299,1249 +115,113 @@ static int ParseMatchFinder(const wchar_t *s, int *btMode, UInt32 *numHashBytes if (numHashBytesLoc < 2 || numHashBytesLoc > 4) return 0; c = GetUpperChar(*s++); - /* - int skipModeBitsLoc = 0; - if (c == L'D') - { - skipModeBitsLoc = 2; - c = GetUpperChar(*s++); - } - */ if (c != L'\0') return 0; *btMode = 1; *numHashBytes = numHashBytesLoc; - // *skipModeBits = skipModeBitsLoc; return 1; } STDMETHODIMP CEncoder::SetCoderProperties(const PROPID *propIDs, const PROPVARIANT *properties, UInt32 numProperties) { + CLzmaEncProps props; + LzmaEncProps_Init(&props); + for (UInt32 i = 0; i < numProperties; i++) { const PROPVARIANT &prop = properties[i]; - switch(propIDs[i]) + switch (propIDs[i]) { case NCoderPropID::kNumFastBytes: - { - if (prop.vt != VT_UI4) - return E_INVALIDARG; - UInt32 numFastBytes = prop.ulVal; - if(numFastBytes < 5 || numFastBytes > kMatchMaxLen) - return E_INVALIDARG; - _numFastBytes = numFastBytes; - break; - } + if (prop.vt != VT_UI4) return E_INVALIDARG; props.fb = prop.ulVal; break; case NCoderPropID::kMatchFinderCycles: - { - if (prop.vt != VT_UI4) - return E_INVALIDARG; - _matchFinderCycles = prop.ulVal; - break; - } + if (prop.vt != VT_UI4) return E_INVALIDARG; props.mc = prop.ulVal; break; case NCoderPropID::kAlgorithm: - { - if (prop.vt != VT_UI4) - return E_INVALIDARG; - UInt32 maximize = prop.ulVal; - _fastMode = (maximize == 0); - // _maxMode = (maximize >= 2); - break; - } - case NCoderPropID::kMatchFinder: - { - if (prop.vt != VT_BSTR) - return E_INVALIDARG; - if (!ParseMatchFinder(prop.bstrVal, &_matchFinderBase.btMode, &_matchFinderBase.numHashBytes /* , &_matchFinderBase.skipModeBits */)) - return E_INVALIDARG; - break; - } - case NCoderPropID::kMultiThread: - { - if (prop.vt != VT_BOOL) - return E_INVALIDARG; - #ifdef COMPRESS_MF_MT - Bool newMultiThread = (prop.boolVal == VARIANT_TRUE); - if (newMultiThread != _multiThread) - { - ReleaseMatchFinder(); - _multiThread = newMultiThread; - } - #endif - break; - } - case NCoderPropID::kNumThreads: - { - if (prop.vt != VT_UI4) - return E_INVALIDARG; - #ifdef COMPRESS_MF_MT - Bool newMultiThread = (prop.ulVal > 1) ? True : False; - if (newMultiThread != _multiThread) - { - ReleaseMatchFinder(); - _multiThread = newMultiThread; - } - #endif - break; - } + if (prop.vt != VT_UI4) return E_INVALIDARG; props.algo = prop.ulVal; break; case NCoderPropID::kDictionarySize: - { - const int kDicLogSizeMaxCompress = 30; // must be <= ((kNumLogBits - 1) * 2) + 7 = 31; - if (prop.vt != VT_UI4) - return E_INVALIDARG; - UInt32 dictionarySize = prop.ulVal; - if (dictionarySize < UInt32(1 << kDicLogSizeMin) || - dictionarySize > UInt32(1 << kDicLogSizeMaxCompress)) - return E_INVALIDARG; - _dictionarySize = dictionarySize; - UInt32 dicLogSize; - for(dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++) - if (dictionarySize <= (UInt32(1) << dicLogSize)) - break; - _distTableSize = dicLogSize * 2; - break; - } + if (prop.vt != VT_UI4) return E_INVALIDARG; props.dictSize = prop.ulVal; break; case NCoderPropID::kPosStateBits: - { - if (prop.vt != VT_UI4) - return E_INVALIDARG; - UInt32 value = prop.ulVal; - if (value > (UInt32)NLength::kNumPosStatesBitsEncodingMax) - return E_INVALIDARG; - _posStateBits = value; - _posStateMask = (1 << _posStateBits) - 1; - break; - } + if (prop.vt != VT_UI4) return E_INVALIDARG; props.pb = prop.ulVal; break; case NCoderPropID::kLitPosBits: - { - if (prop.vt != VT_UI4) - return E_INVALIDARG; - UInt32 value = prop.ulVal; - if (value > (UInt32)kNumLitPosStatesBitsEncodingMax) - return E_INVALIDARG; - _numLiteralPosStateBits = value; - break; - } + if (prop.vt != VT_UI4) return E_INVALIDARG; props.lp = prop.ulVal; break; case NCoderPropID::kLitContextBits: - { - if (prop.vt != VT_UI4) - return E_INVALIDARG; - UInt32 value = prop.ulVal; - if (value > (UInt32)kNumLitContextBitsMax) - return E_INVALIDARG; - _numLiteralContextBits = value; - break; - } + if (prop.vt != VT_UI4) return E_INVALIDARG; props.lc = prop.ulVal; break; + case NCoderPropID::kNumThreads: + if (prop.vt != VT_UI4) return E_INVALIDARG; props.numThreads = prop.ulVal; break; + case NCoderPropID::kMultiThread: + if (prop.vt != VT_BOOL) return E_INVALIDARG; props.numThreads = ((prop.boolVal == VARIANT_TRUE) ? 2 : 1); break; case NCoderPropID::kEndMarker: - { - if (prop.vt != VT_BOOL) - return E_INVALIDARG; - SetWriteEndMarkerMode(prop.boolVal == VARIANT_TRUE); - break; - } + if (prop.vt != VT_BOOL) return E_INVALIDARG; props.writeEndMark = (prop.boolVal == VARIANT_TRUE); break; + case NCoderPropID::kMatchFinder: + if (prop.vt != VT_BSTR) return E_INVALIDARG; + if (!ParseMatchFinder(prop.bstrVal, &props.btMode, &props.numHashBytes /* , &_matchFinderBase.skipModeBits */)) + return E_INVALIDARG; break; default: return E_INVALIDARG; } } - return S_OK; + return SResToHRESULT(LzmaEnc_SetProps(_encoder, &props)); } STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream) { - const UInt32 kPropSize = 5; - Byte properties[kPropSize]; - properties[0] = (Byte)((_posStateBits * 5 + _numLiteralPosStateBits) * 9 + _numLiteralContextBits); - for (int i = 0; i < 4; i++) - properties[1 + i] = Byte(_dictionarySize >> (8 * i)); - return WriteStream(outStream, properties, kPropSize, NULL); + Byte props[LZMA_PROPS_SIZE]; + size_t size = LZMA_PROPS_SIZE; + RINOK(LzmaEnc_WriteProperties(_encoder, props, &size)); + return WriteStream(outStream, props, size); } STDMETHODIMP CEncoder::SetOutStream(ISequentialOutStream *outStream) { - _rangeEncoder.SetStream(outStream); + _seqOutStream.RealStream = outStream; + _seqOutStream.Res = S_OK; return S_OK; } STDMETHODIMP CEncoder::ReleaseOutStream() { - _rangeEncoder.ReleaseStream(); + _seqOutStream.RealStream.Release(); return S_OK; } -HRESULT CEncoder::Init() +typedef struct _CCompressProgressImp { - CBaseState::Init(); - - _rangeEncoder.Init(); + ICompressProgress p; + ICompressProgressInfo *Progress; + HRESULT Res; +} CCompressProgressImp; - for(int i = 0; i < kNumStates; i++) - { - for (UInt32 j = 0; j <= _posStateMask; j++) - { - _isMatch[i][j].Init(); - _isRep0Long[i][j].Init(); - } - _isRep[i].Init(); - _isRepG0[i].Init(); - _isRepG1[i].Init(); - _isRepG2[i].Init(); - } - - _literalEncoder.Init(); - - { - for(UInt32 i = 0; i < kNumLenToPosStates; i++) - _posSlotEncoder[i].Init(); - } - { - for(UInt32 i = 0; i < kNumFullDistances - kEndPosModelIndex; i++) - _posEncoders[i].Init(); - } +#define PROGRESS_UNKNOWN_VALUE ((UInt64)(Int64)-1) - _lenEncoder.Init(1 << _posStateBits); - _repMatchLenEncoder.Init(1 << _posStateBits); +#define CONVERT_PR_VAL(x) (x == PROGRESS_UNKNOWN_VALUE ? NULL : &x) - _posAlignEncoder.Init(); - - _longestMatchWasFound = false; - _optimumEndIndex = 0; - _optimumCurrentIndex = 0; - _additionalOffset = 0; - - return S_OK; -} - -#ifdef SHOW_STAT -static int ttt = 0; -#endif - -void CEncoder::MovePos(UInt32 num) +SRes CompressProgress(void *pp, UInt64 inSize, UInt64 outSize) { - #ifdef SHOW_STAT - ttt += num; - printf("\n MovePos %d", num); - #endif - if (num != 0) - { - _additionalOffset += num; - _matchFinder.Skip(_matchFinderObj, num); - } -} - -UInt32 CEncoder::Backward(UInt32 &backRes, UInt32 cur) -{ - _optimumEndIndex = cur; - UInt32 posMem = _optimum[cur].PosPrev; - UInt32 backMem = _optimum[cur].BackPrev; - do - { - if (_optimum[cur].Prev1IsChar) - { - _optimum[posMem].MakeAsChar(); - _optimum[posMem].PosPrev = posMem - 1; - if (_optimum[cur].Prev2) - { - _optimum[posMem - 1].Prev1IsChar = false; - _optimum[posMem - 1].PosPrev = _optimum[cur].PosPrev2; - _optimum[posMem - 1].BackPrev = _optimum[cur].BackPrev2; - } - } - UInt32 posPrev = posMem; - UInt32 backCur = backMem; - - backMem = _optimum[posPrev].BackPrev; - posMem = _optimum[posPrev].PosPrev; - - _optimum[posPrev].BackPrev = backCur; - _optimum[posPrev].PosPrev = cur; - cur = posPrev; - } - while(cur != 0); - backRes = _optimum[0].BackPrev; - _optimumCurrentIndex = _optimum[0].PosPrev; - return _optimumCurrentIndex; -} - -/* -Out: - (lenRes == 1) && (backRes == 0xFFFFFFFF) means Literal -*/ - -UInt32 CEncoder::GetOptimum(UInt32 position, UInt32 &backRes) -{ - if(_optimumEndIndex != _optimumCurrentIndex) - { - const COptimal &optimum = _optimum[_optimumCurrentIndex]; - UInt32 lenRes = optimum.PosPrev - _optimumCurrentIndex; - backRes = optimum.BackPrev; - _optimumCurrentIndex = optimum.PosPrev; - return lenRes; - } - _optimumCurrentIndex = _optimumEndIndex = 0; - - UInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj); - - UInt32 lenMain, numDistancePairs; - if (!_longestMatchWasFound) - { - lenMain = ReadMatchDistances(numDistancePairs); - } - else - { - lenMain = _longestMatchLength; - numDistancePairs = _numDistancePairs; - _longestMatchWasFound = false; - } - - const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1; - if (numAvailableBytes < 2) - { - backRes = (UInt32)(-1); - return 1; - } - if (numAvailableBytes > kMatchMaxLen) - numAvailableBytes = kMatchMaxLen; - - UInt32 reps[kNumRepDistances]; - UInt32 repLens[kNumRepDistances]; - UInt32 repMaxIndex = 0; - UInt32 i; - for(i = 0; i < kNumRepDistances; i++) - { - reps[i] = _repDistances[i]; - const Byte *data2 = data - (reps[i] + 1); - if (data[0] != data2[0] || data[1] != data2[1]) - { - repLens[i] = 0; - continue; - } - UInt32 lenTest; - for (lenTest = 2; lenTest < numAvailableBytes && data[lenTest] == data2[lenTest]; lenTest++); - repLens[i] = lenTest; - if (lenTest > repLens[repMaxIndex]) - repMaxIndex = i; - } - if(repLens[repMaxIndex] >= _numFastBytes) - { - backRes = repMaxIndex; - UInt32 lenRes = repLens[repMaxIndex]; - MovePos(lenRes - 1); - return lenRes; - } - - UInt32 *matchDistances = _matchDistances; - if(lenMain >= _numFastBytes) - { - backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances; - MovePos(lenMain - 1); - return lenMain; - } - Byte currentByte = *data; - Byte matchByte = *(data - (reps[0] + 1)); - - if(lenMain < 2 && currentByte != matchByte && repLens[repMaxIndex] < 2) - { - backRes = (UInt32)-1; - return 1; - } - - _optimum[0].State = _state; - - UInt32 posState = (position & _posStateMask); - - _optimum[1].Price = _isMatch[_state.Index][posState].GetPrice0() + - _literalEncoder.GetSubCoder(position, _previousByte)->GetPrice(!_state.IsCharState(), matchByte, currentByte); - _optimum[1].MakeAsChar(); - - UInt32 matchPrice = _isMatch[_state.Index][posState].GetPrice1(); - UInt32 repMatchPrice = matchPrice + _isRep[_state.Index].GetPrice1(); - - if(matchByte == currentByte) - { - UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(_state, posState); - if(shortRepPrice < _optimum[1].Price) - { - _optimum[1].Price = shortRepPrice; - _optimum[1].MakeAsShortRep(); - } - } - UInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]); - - if(lenEnd < 2) - { - backRes = _optimum[1].BackPrev; - return 1; - } - - _optimum[1].PosPrev = 0; - for (i = 0; i < kNumRepDistances; i++) - _optimum[0].Backs[i] = reps[i]; - - UInt32 len = lenEnd; - do - _optimum[len--].Price = kIfinityPrice; - while (len >= 2); - - for(i = 0; i < kNumRepDistances; i++) - { - UInt32 repLen = repLens[i]; - if (repLen < 2) - continue; - UInt32 price = repMatchPrice + GetPureRepPrice(i, _state, posState); - do - { - UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(repLen - 2, posState); - COptimal &optimum = _optimum[repLen]; - if (curAndLenPrice < optimum.Price) - { - optimum.Price = curAndLenPrice; - optimum.PosPrev = 0; - optimum.BackPrev = i; - optimum.Prev1IsChar = false; - } - } - while(--repLen >= 2); - } - - UInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0(); - - len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2); - if (len <= lenMain) - { - UInt32 offs = 0; - while (len > matchDistances[offs]) - offs += 2; - for(; ; len++) - { - UInt32 distance = matchDistances[offs + 1]; - UInt32 curAndLenPrice = normalMatchPrice + GetPosLenPrice(distance, len, posState); - COptimal &optimum = _optimum[len]; - if (curAndLenPrice < optimum.Price) - { - optimum.Price = curAndLenPrice; - optimum.PosPrev = 0; - optimum.BackPrev = distance + kNumRepDistances; - optimum.Prev1IsChar = false; - } - if (len == matchDistances[offs]) - { - offs += 2; - if (offs == numDistancePairs) - break; - } - } - } - - UInt32 cur = 0; - - for (;;) - { - cur++; - if(cur == lenEnd) - { - return Backward(backRes, cur); - } - UInt32 numAvailableBytesFull = _matchFinder.GetNumAvailableBytes(_matchFinderObj); - UInt32 newLen, numDistancePairs; - newLen = ReadMatchDistances(numDistancePairs); - if(newLen >= _numFastBytes) - { - _numDistancePairs = numDistancePairs; - _longestMatchLength = newLen; - _longestMatchWasFound = true; - return Backward(backRes, cur); - } - position++; - COptimal &curOptimum = _optimum[cur]; - UInt32 posPrev = curOptimum.PosPrev; - CState state; - if (curOptimum.Prev1IsChar) - { - posPrev--; - if (curOptimum.Prev2) - { - state = _optimum[curOptimum.PosPrev2].State; - if (curOptimum.BackPrev2 < kNumRepDistances) - state.UpdateRep(); - else - state.UpdateMatch(); - } - else - state = _optimum[posPrev].State; - state.UpdateChar(); - } - else - state = _optimum[posPrev].State; - if (posPrev == cur - 1) - { - if (curOptimum.IsShortRep()) - state.UpdateShortRep(); - else - state.UpdateChar(); - } - else - { - UInt32 pos; - if (curOptimum.Prev1IsChar && curOptimum.Prev2) - { - posPrev = curOptimum.PosPrev2; - pos = curOptimum.BackPrev2; - state.UpdateRep(); - } - else - { - pos = curOptimum.BackPrev; - if (pos < kNumRepDistances) - state.UpdateRep(); - else - state.UpdateMatch(); - } - const COptimal &prevOptimum = _optimum[posPrev]; - if (pos < kNumRepDistances) - { - reps[0] = prevOptimum.Backs[pos]; - UInt32 i; - for(i = 1; i <= pos; i++) - reps[i] = prevOptimum.Backs[i - 1]; - for(; i < kNumRepDistances; i++) - reps[i] = prevOptimum.Backs[i]; - } - else - { - reps[0] = (pos - kNumRepDistances); - for(UInt32 i = 1; i < kNumRepDistances; i++) - reps[i] = prevOptimum.Backs[i - 1]; - } - } - curOptimum.State = state; - for(UInt32 i = 0; i < kNumRepDistances; i++) - curOptimum.Backs[i] = reps[i]; - UInt32 curPrice = curOptimum.Price; - const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1; - const Byte currentByte = *data; - const Byte matchByte = *(data - (reps[0] + 1)); - - UInt32 posState = (position & _posStateMask); - - UInt32 curAnd1Price = curPrice + - _isMatch[state.Index][posState].GetPrice0() + - _literalEncoder.GetSubCoder(position, *(data - 1))->GetPrice(!state.IsCharState(), matchByte, currentByte); - - COptimal &nextOptimum = _optimum[cur + 1]; - - bool nextIsChar = false; - if (curAnd1Price < nextOptimum.Price) - { - nextOptimum.Price = curAnd1Price; - nextOptimum.PosPrev = cur; - nextOptimum.MakeAsChar(); - nextIsChar = true; - } - - UInt32 matchPrice = curPrice + _isMatch[state.Index][posState].GetPrice1(); - UInt32 repMatchPrice = matchPrice + _isRep[state.Index].GetPrice1(); - - if(matchByte == currentByte && - !(nextOptimum.PosPrev < cur && nextOptimum.BackPrev == 0)) - { - UInt32 shortRepPrice = repMatchPrice + GetRepLen1Price(state, posState); - if(shortRepPrice <= nextOptimum.Price) - { - nextOptimum.Price = shortRepPrice; - nextOptimum.PosPrev = cur; - nextOptimum.MakeAsShortRep(); - nextIsChar = true; - } - } - /* - if(newLen == 2 && matchDistances[2] >= kDistLimit2) // test it maybe set 2000 ? - continue; - */ - - numAvailableBytesFull = MyMin(kNumOpts - 1 - cur, numAvailableBytesFull); - UInt32 numAvailableBytes = numAvailableBytesFull; - - if (numAvailableBytes < 2) - continue; - if (numAvailableBytes > _numFastBytes) - numAvailableBytes = _numFastBytes; - if (!nextIsChar && matchByte != currentByte) // speed optimization - { - // try Literal + rep0 - const Byte *data2 = data - (reps[0] + 1); - UInt32 limit = MyMin(numAvailableBytesFull, _numFastBytes + 1); - UInt32 temp; - for (temp = 1; temp < limit && data[temp] == data2[temp]; temp++); - UInt32 lenTest2 = temp - 1; - if (lenTest2 >= 2) - { - CState state2 = state; - state2.UpdateChar(); - UInt32 posStateNext = (position + 1) & _posStateMask; - UInt32 nextRepMatchPrice = curAnd1Price + - _isMatch[state2.Index][posStateNext].GetPrice1() + - _isRep[state2.Index].GetPrice1(); - // for (; lenTest2 >= 2; lenTest2--) - { - UInt32 offset = cur + 1 + lenTest2; - while(lenEnd < offset) - _optimum[++lenEnd].Price = kIfinityPrice; - UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice( - 0, lenTest2, state2, posStateNext); - COptimal &optimum = _optimum[offset]; - if (curAndLenPrice < optimum.Price) - { - optimum.Price = curAndLenPrice; - optimum.PosPrev = cur + 1; - optimum.BackPrev = 0; - optimum.Prev1IsChar = true; - optimum.Prev2 = false; - } - } - } - } - - UInt32 startLen = 2; // speed optimization - for(UInt32 repIndex = 0; repIndex < kNumRepDistances; repIndex++) - { - // UInt32 repLen = _matchFinder.GetMatchLen(0 - 1, reps[repIndex], newLen); // test it; - const Byte *data2 = data - (reps[repIndex] + 1); - if (data[0] != data2[0] || data[1] != data2[1]) - continue; - UInt32 lenTest; - for (lenTest = 2; lenTest < numAvailableBytes && data[lenTest] == data2[lenTest]; lenTest++); - while(lenEnd < cur + lenTest) - _optimum[++lenEnd].Price = kIfinityPrice; - UInt32 lenTestTemp = lenTest; - UInt32 price = repMatchPrice + GetPureRepPrice(repIndex, state, posState); - do - { - UInt32 curAndLenPrice = price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState); - COptimal &optimum = _optimum[cur + lenTest]; - if (curAndLenPrice < optimum.Price) - { - optimum.Price = curAndLenPrice; - optimum.PosPrev = cur; - optimum.BackPrev = repIndex; - optimum.Prev1IsChar = false; - } - } - while(--lenTest >= 2); - lenTest = lenTestTemp; - - if (repIndex == 0) - startLen = lenTest + 1; - - // if (_maxMode) - { - UInt32 lenTest2 = lenTest + 1; - UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes); - for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++); - lenTest2 -= lenTest + 1; - if (lenTest2 >= 2) - { - CState state2 = state; - state2.UpdateRep(); - UInt32 posStateNext = (position + lenTest) & _posStateMask; - UInt32 curAndLenCharPrice = - price + _repMatchLenEncoder.GetPrice(lenTest - 2, posState) + - _isMatch[state2.Index][posStateNext].GetPrice0() + - _literalEncoder.GetSubCoder(position + lenTest, data[lenTest - 1])->GetPrice( - true, data2[lenTest], data[lenTest]); - state2.UpdateChar(); - posStateNext = (position + lenTest + 1) & _posStateMask; - UInt32 nextRepMatchPrice = curAndLenCharPrice + - _isMatch[state2.Index][posStateNext].GetPrice1() + - _isRep[state2.Index].GetPrice1(); - - // for(; lenTest2 >= 2; lenTest2--) - { - UInt32 offset = cur + lenTest + 1 + lenTest2; - while(lenEnd < offset) - _optimum[++lenEnd].Price = kIfinityPrice; - UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice( - 0, lenTest2, state2, posStateNext); - COptimal &optimum = _optimum[offset]; - if (curAndLenPrice < optimum.Price) - { - optimum.Price = curAndLenPrice; - optimum.PosPrev = cur + lenTest + 1; - optimum.BackPrev = 0; - optimum.Prev1IsChar = true; - optimum.Prev2 = true; - optimum.PosPrev2 = cur; - optimum.BackPrev2 = repIndex; - } - } - } - } - } - - // for(UInt32 lenTest = 2; lenTest <= newLen; lenTest++) - if (newLen > numAvailableBytes) - { - newLen = numAvailableBytes; - for (numDistancePairs = 0; newLen > matchDistances[numDistancePairs]; numDistancePairs += 2); - matchDistances[numDistancePairs] = newLen; - numDistancePairs += 2; - } - if (newLen >= startLen) - { - UInt32 normalMatchPrice = matchPrice + _isRep[state.Index].GetPrice0(); - while(lenEnd < cur + newLen) - _optimum[++lenEnd].Price = kIfinityPrice; - - UInt32 offs = 0; - while(startLen > matchDistances[offs]) - offs += 2; - UInt32 curBack = matchDistances[offs + 1]; - UInt32 posSlot = GetPosSlot2(curBack); - for(UInt32 lenTest = /*2*/ startLen; ; lenTest++) - { - UInt32 curAndLenPrice = normalMatchPrice; - UInt32 lenToPosState = GetLenToPosState(lenTest); - if (curBack < kNumFullDistances) - curAndLenPrice += _distancesPrices[lenToPosState][curBack]; - else - curAndLenPrice += _posSlotPrices[lenToPosState][posSlot] + _alignPrices[curBack & kAlignMask]; - - curAndLenPrice += _lenEncoder.GetPrice(lenTest - kMatchMinLen, posState); - - COptimal &optimum = _optimum[cur + lenTest]; - if (curAndLenPrice < optimum.Price) - { - optimum.Price = curAndLenPrice; - optimum.PosPrev = cur; - optimum.BackPrev = curBack + kNumRepDistances; - optimum.Prev1IsChar = false; - } - - if (/*_maxMode && */lenTest == matchDistances[offs]) - { - // Try Match + Literal + Rep0 - const Byte *data2 = data - (curBack + 1); - UInt32 lenTest2 = lenTest + 1; - UInt32 limit = MyMin(numAvailableBytesFull, lenTest2 + _numFastBytes); - for (; lenTest2 < limit && data[lenTest2] == data2[lenTest2]; lenTest2++); - lenTest2 -= lenTest + 1; - if (lenTest2 >= 2) - { - CState state2 = state; - state2.UpdateMatch(); - UInt32 posStateNext = (position + lenTest) & _posStateMask; - UInt32 curAndLenCharPrice = curAndLenPrice + - _isMatch[state2.Index][posStateNext].GetPrice0() + - _literalEncoder.GetSubCoder(position + lenTest, data[lenTest - 1])->GetPrice( - true, data2[lenTest], data[lenTest]); - state2.UpdateChar(); - posStateNext = (posStateNext + 1) & _posStateMask; - UInt32 nextRepMatchPrice = curAndLenCharPrice + - _isMatch[state2.Index][posStateNext].GetPrice1() + - _isRep[state2.Index].GetPrice1(); - - // for(; lenTest2 >= 2; lenTest2--) - { - UInt32 offset = cur + lenTest + 1 + lenTest2; - while(lenEnd < offset) - _optimum[++lenEnd].Price = kIfinityPrice; - UInt32 curAndLenPrice = nextRepMatchPrice + GetRepPrice(0, lenTest2, state2, posStateNext); - COptimal &optimum = _optimum[offset]; - if (curAndLenPrice < optimum.Price) - { - optimum.Price = curAndLenPrice; - optimum.PosPrev = cur + lenTest + 1; - optimum.BackPrev = 0; - optimum.Prev1IsChar = true; - optimum.Prev2 = true; - optimum.PosPrev2 = cur; - optimum.BackPrev2 = curBack + kNumRepDistances; - } - } - } - offs += 2; - if (offs == numDistancePairs) - break; - curBack = matchDistances[offs + 1]; - if (curBack >= kNumFullDistances) - posSlot = GetPosSlot2(curBack); - } - } - } - } -} - -static inline bool ChangePair(UInt32 smallDist, UInt32 bigDist) -{ - return ((bigDist >> 7) > smallDist); -} - -UInt32 CEncoder::ReadMatchDistances(UInt32 &numDistancePairs) -{ - UInt32 lenRes = 0; - numDistancePairs = _matchFinder.GetMatches(_matchFinderObj, _matchDistances); - #ifdef SHOW_STAT - printf("\n i = %d numPairs = %d ", ttt, numDistancePairs / 2); - if (ttt >= 61994) - ttt = ttt; - - ttt++; - for (UInt32 i = 0; i < numDistancePairs; i += 2) - printf("%2d %6d | ", _matchDistances[i], _matchDistances[i + 1]); - #endif - if (numDistancePairs > 0) - { - lenRes = _matchDistances[numDistancePairs - 2]; - if (lenRes == _numFastBytes) - { - UInt32 numAvail = _matchFinder.GetNumAvailableBytes(_matchFinderObj) + 1; - const Byte *pby = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1; - UInt32 distance = _matchDistances[numDistancePairs - 1] + 1; - if (numAvail > kMatchMaxLen) - numAvail = kMatchMaxLen; - - const Byte *pby2 = pby - distance; - for (; lenRes < numAvail && pby[lenRes] == pby2[lenRes]; lenRes++); - } - } - _additionalOffset++; - return lenRes; -} - -UInt32 CEncoder::GetOptimumFast(UInt32 &backRes) -{ - UInt32 numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj); - UInt32 lenMain, numDistancePairs; - if (!_longestMatchWasFound) - { - lenMain = ReadMatchDistances(numDistancePairs); - } - else - { - lenMain = _longestMatchLength; - numDistancePairs = _numDistancePairs; - _longestMatchWasFound = false; - } - - const Byte *data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1; - if (numAvailableBytes > kMatchMaxLen) - numAvailableBytes = kMatchMaxLen; - if (numAvailableBytes < 2) - { - backRes = (UInt32)(-1); - return 1; - } - - UInt32 repLens[kNumRepDistances]; - UInt32 repMaxIndex = 0; - - for(UInt32 i = 0; i < kNumRepDistances; i++) - { - const Byte *data2 = data - (_repDistances[i] + 1); - if (data[0] != data2[0] || data[1] != data2[1]) - { - repLens[i] = 0; - continue; - } - UInt32 len; - for (len = 2; len < numAvailableBytes && data[len] == data2[len]; len++); - if(len >= _numFastBytes) - { - backRes = i; - MovePos(len - 1); - return len; - } - repLens[i] = len; - if (len > repLens[repMaxIndex]) - repMaxIndex = i; - } - UInt32 *matchDistances = _matchDistances; - if(lenMain >= _numFastBytes) - { - backRes = matchDistances[numDistancePairs - 1] + kNumRepDistances; - MovePos(lenMain - 1); - return lenMain; - } - - UInt32 backMain = 0; // for GCC - if (lenMain >= 2) - { - backMain = matchDistances[numDistancePairs - 1]; - while (numDistancePairs > 2 && lenMain == matchDistances[numDistancePairs - 4] + 1) - { - if (!ChangePair(matchDistances[numDistancePairs - 3], backMain)) - break; - numDistancePairs -= 2; - lenMain = matchDistances[numDistancePairs - 2]; - backMain = matchDistances[numDistancePairs - 1]; - } - if (lenMain == 2 && backMain >= 0x80) - lenMain = 1; - } - - if (repLens[repMaxIndex] >= 2) - { - if (repLens[repMaxIndex] + 1 >= lenMain || - repLens[repMaxIndex] + 2 >= lenMain && (backMain > (1 << 9)) || - repLens[repMaxIndex] + 3 >= lenMain && (backMain > (1 << 15))) - { - backRes = repMaxIndex; - UInt32 lenRes = repLens[repMaxIndex]; - MovePos(lenRes - 1); - return lenRes; - } - } - - if (lenMain >= 2 && numAvailableBytes > 2) - { - numAvailableBytes = _matchFinder.GetNumAvailableBytes(_matchFinderObj); - _longestMatchLength = ReadMatchDistances(_numDistancePairs); - if (_longestMatchLength >= 2) - { - UInt32 newDistance = matchDistances[_numDistancePairs - 1]; - if (_longestMatchLength >= lenMain && newDistance < backMain || - _longestMatchLength == lenMain + 1 && !ChangePair(backMain, newDistance) || - _longestMatchLength > lenMain + 1 || - _longestMatchLength + 1 >= lenMain && lenMain >= 3 && ChangePair(newDistance, backMain)) - { - _longestMatchWasFound = true; - backRes = UInt32(-1); - return 1; - } - } - data = _matchFinder.GetPointerToCurrentPos(_matchFinderObj) - 1; - for(UInt32 i = 0; i < kNumRepDistances; i++) - { - const Byte *data2 = data - (_repDistances[i] + 1); - if (data[1] != data2[1] || data[2] != data2[2]) - { - repLens[i] = 0; - continue; - } - UInt32 len; - for (len = 2; len < numAvailableBytes && data[len] == data2[len]; len++); - if (len + 1 >= lenMain) - { - _longestMatchWasFound = true; - backRes = UInt32(-1); - return 1; - } - } - backRes = backMain + kNumRepDistances; - MovePos(lenMain - 2); - return lenMain; - } - backRes = UInt32(-1); - return 1; -} - -HRESULT CEncoder::Flush(UInt32 nowPos) -{ - // ReleaseMFStream(); - if (_matchFinderBase.result != SZ_OK) - return _matchFinderBase.result; - WriteEndMarker(nowPos & _posStateMask); - _rangeEncoder.FlushData(); - return _rangeEncoder.FlushStream(); -} - -void CEncoder::WriteEndMarker(UInt32 posState) -{ - // This function for writing End Mark for stream version of LZMA. - // In current version this feature is not used. - if (!_writeEndMark) - return; - - _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1); - _isRep[_state.Index].Encode(&_rangeEncoder, 0); - _state.UpdateMatch(); - UInt32 len = kMatchMinLen; // kMatchMaxLen; - _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode); - UInt32 posSlot = (1 << kNumPosSlotBits) - 1; - UInt32 lenToPosState = GetLenToPosState(len); - _posSlotEncoder[lenToPosState].Encode(&_rangeEncoder, posSlot); - UInt32 footerBits = 30; - UInt32 posReduced = (UInt32(1) << footerBits) - 1; - _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits); - _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask); -} - -HRESULT CEncoder::CodeReal(ISequentialInStream *inStream, - ISequentialOutStream *outStream, - const UInt64 *inSize, const UInt64 *outSize, - ICompressProgressInfo *progress) -{ - // _needReleaseMFStream = false; - #ifdef COMPRESS_MF_MT - #ifdef USE_ALLOCA - alloca(0x300); - #endif - #endif - CCoderReleaser coderReleaser(this); - RINOK(SetStreams(inStream, outStream, inSize, outSize)); - for (;;) - { - UInt64 processedInSize; - UInt64 processedOutSize; - Int32 finished; - RINOK(CodeOneBlock(&processedInSize, &processedOutSize, &finished)); - if (finished != 0) - break; - if (progress != 0) - { - RINOK(progress->SetRatioInfo(&processedInSize, &processedOutSize)); - } - } - return S_OK; -} - -HRESULT CEncoder::SetStreams(ISequentialInStream *inStream, - ISequentialOutStream *outStream, - const UInt64 * /* inSize */, const UInt64 * /* outSize */) -{ - _inStream = inStream; - _finished = false; - RINOK(Create()); - RINOK(SetOutStream(outStream)); - RINOK(Init()); - - if (!_fastMode) - { - FillDistancesPrices(); - FillAlignPrices(); - } - - _lenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen); - _lenEncoder.UpdateTables(1 << _posStateBits); - _repMatchLenEncoder.SetTableSize(_numFastBytes + 1 - kMatchMinLen); - _repMatchLenEncoder.UpdateTables(1 << _posStateBits); - - nowPos64 = 0; - return S_OK; -} - -static HRes MyRead(void *object, void *data, UInt32 size, UInt32 *processedSize) -{ - return (HRes)((CSeqInStream *)object)->RealStream->Read(data, size, processedSize); -} - -HRESULT CEncoder::CodeOneBlock(UInt64 *inSize, UInt64 *outSize, Int32 *finished) -{ - if (_inStream != 0) - { - _seqInStream.RealStream = _inStream; - _seqInStream.SeqInStream.Read = MyRead; - _matchFinderBase.stream = &_seqInStream.SeqInStream; - _matchFinder.Init(_matchFinderObj); - _needReleaseMFStream = true; - _inStream = 0; - } - - - *finished = 1; - if (_finished) - return _matchFinderBase.result; - _finished = true; - - if (nowPos64 == 0) - { - if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0) - return Flush((UInt32)nowPos64); - UInt32 len, numDistancePairs; - len = ReadMatchDistances(numDistancePairs); - UInt32 posState = UInt32(nowPos64) & _posStateMask; - _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0); - _state.UpdateChar(); - Byte curByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _additionalOffset); - _literalEncoder.GetSubCoder(UInt32(nowPos64), _previousByte)->Encode(&_rangeEncoder, curByte); - _previousByte = curByte; - _additionalOffset--; - nowPos64++; - } - - UInt32 nowPos32 = (UInt32)nowPos64; - UInt32 progressPosValuePrev = nowPos32; - - if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0) - return Flush(nowPos32); - - for (;;) - { - #ifdef _NO_EXCEPTIONS - if (_rangeEncoder.Stream.ErrorCode != S_OK) - return _rangeEncoder.Stream.ErrorCode; - #endif - UInt32 pos, len; - - if (_fastMode) - len = GetOptimumFast(pos); - else - len = GetOptimum(nowPos32, pos); - - UInt32 posState = nowPos32 & _posStateMask; - if(len == 1 && pos == 0xFFFFFFFF) - { - _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 0); - Byte curByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _additionalOffset); - CLiteralEncoder2 *subCoder = _literalEncoder.GetSubCoder(nowPos32, _previousByte); - if(_state.IsCharState()) - subCoder->Encode(&_rangeEncoder, curByte); - else - { - Byte matchByte = _matchFinder.GetIndexByte(_matchFinderObj, 0 - _repDistances[0] - 1 - _additionalOffset); - subCoder->EncodeMatched(&_rangeEncoder, matchByte, curByte); - } - _state.UpdateChar(); - _previousByte = curByte; - } - else - { - _isMatch[_state.Index][posState].Encode(&_rangeEncoder, 1); - if(pos < kNumRepDistances) - { - _isRep[_state.Index].Encode(&_rangeEncoder, 1); - if(pos == 0) - { - _isRepG0[_state.Index].Encode(&_rangeEncoder, 0); - _isRep0Long[_state.Index][posState].Encode(&_rangeEncoder, ((len == 1) ? 0 : 1)); - } - else - { - UInt32 distance = _repDistances[pos]; - _isRepG0[_state.Index].Encode(&_rangeEncoder, 1); - if (pos == 1) - _isRepG1[_state.Index].Encode(&_rangeEncoder, 0); - else - { - _isRepG1[_state.Index].Encode(&_rangeEncoder, 1); - _isRepG2[_state.Index].Encode(&_rangeEncoder, pos - 2); - if (pos == 3) - _repDistances[3] = _repDistances[2]; - _repDistances[2] = _repDistances[1]; - } - _repDistances[1] = _repDistances[0]; - _repDistances[0] = distance; - } - if (len == 1) - _state.UpdateShortRep(); - else - { - _repMatchLenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode); - _state.UpdateRep(); - } - } - else - { - _isRep[_state.Index].Encode(&_rangeEncoder, 0); - _state.UpdateMatch(); - _lenEncoder.Encode(&_rangeEncoder, len - kMatchMinLen, posState, !_fastMode); - pos -= kNumRepDistances; - UInt32 posSlot = GetPosSlot(pos); - _posSlotEncoder[GetLenToPosState(len)].Encode(&_rangeEncoder, posSlot); - - if (posSlot >= kStartPosModelIndex) - { - UInt32 footerBits = ((posSlot >> 1) - 1); - UInt32 base = ((2 | (posSlot & 1)) << footerBits); - UInt32 posReduced = pos - base; - - if (posSlot < kEndPosModelIndex) - NRangeCoder::ReverseBitTreeEncode(_posEncoders + base - posSlot - 1, - &_rangeEncoder, footerBits, posReduced); - else - { - _rangeEncoder.EncodeDirectBits(posReduced >> kNumAlignBits, footerBits - kNumAlignBits); - _posAlignEncoder.ReverseEncode(&_rangeEncoder, posReduced & kAlignMask); - _alignPriceCount++; - } - } - _repDistances[3] = _repDistances[2]; - _repDistances[2] = _repDistances[1]; - _repDistances[1] = _repDistances[0]; - _repDistances[0] = pos; - _matchPriceCount++; - } - _previousByte = _matchFinder.GetIndexByte(_matchFinderObj, len - 1 - _additionalOffset); - } - _additionalOffset -= len; - nowPos32 += len; - if (_additionalOffset == 0) - { - if (!_fastMode) - { - if (_matchPriceCount >= (1 << 7)) - FillDistancesPrices(); - if (_alignPriceCount >= kAlignTableSize) - FillAlignPrices(); - } - if (_matchFinder.GetNumAvailableBytes(_matchFinderObj) == 0) - return Flush(nowPos32); - if (nowPos32 - progressPosValuePrev >= (1 << 14)) - { - nowPos64 += nowPos32 - progressPosValuePrev; - *inSize = nowPos64; - *outSize = _rangeEncoder.GetProcessedSize(); - _finished = false; - *finished = 0; - return _matchFinderBase.result; - } - } - } + CCompressProgressImp *p = (CCompressProgressImp *)pp; + p->Res = p->Progress->SetRatioInfo(CONVERT_PR_VAL(inSize), CONVERT_PR_VAL(outSize)); + return (SRes)p->Res; } STDMETHODIMP CEncoder::Code(ISequentialInStream *inStream, - ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, + ISequentialOutStream *outStream, const UInt64 * /* inSize */, + const UInt64 * /* outSize */, ICompressProgressInfo *progress) { - #ifndef _NO_EXCEPTIONS - try - { - #endif - return CodeReal(inStream, outStream, inSize, outSize, progress); - #ifndef _NO_EXCEPTIONS - } - catch(const COutBufferException &e) { return e.ErrorCode; } - catch(...) { return E_FAIL; } - #endif + CCompressProgressImp progressImp; + progressImp.p.Progress = CompressProgress; + progressImp.Progress = progress; + progressImp.Res = SZ_OK; + + _seqInStream.RealStream = inStream; + SetOutStream(outStream); + SRes res = LzmaEnc_Encode(_encoder, &_seqOutStream.SeqOutStream, &_seqInStream.SeqInStream, progress ? &progressImp.p : NULL, &g_Alloc, &g_BigAlloc); + ReleaseOutStream(); + if (res == SZ_ERROR_WRITE && _seqOutStream.Res != S_OK) + return _seqOutStream.Res; + if (res == SZ_ERROR_PROGRESS && progressImp.Res != S_OK) + return progressImp.Res; + return SResToHRESULT(res); } -void CEncoder::FillDistancesPrices() -{ - UInt32 tempPrices[kNumFullDistances]; - for (UInt32 i = kStartPosModelIndex; i < kNumFullDistances; i++) - { - UInt32 posSlot = GetPosSlot(i); - UInt32 footerBits = ((posSlot >> 1) - 1); - UInt32 base = ((2 | (posSlot & 1)) << footerBits); - tempPrices[i] = NRangeCoder::ReverseBitTreeGetPrice(_posEncoders + - base - posSlot - 1, footerBits, i - base); - } - - for (UInt32 lenToPosState = 0; lenToPosState < kNumLenToPosStates; lenToPosState++) - { - UInt32 posSlot; - NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> &encoder = _posSlotEncoder[lenToPosState]; - UInt32 *posSlotPrices = _posSlotPrices[lenToPosState]; - for (posSlot = 0; posSlot < _distTableSize; posSlot++) - posSlotPrices[posSlot] = encoder.GetPrice(posSlot); - for (posSlot = kEndPosModelIndex; posSlot < _distTableSize; posSlot++) - posSlotPrices[posSlot] += ((((posSlot >> 1) - 1) - kNumAlignBits) << NRangeCoder::kNumBitPriceShiftBits); - - UInt32 *distancesPrices = _distancesPrices[lenToPosState]; - UInt32 i; - for (i = 0; i < kStartPosModelIndex; i++) - distancesPrices[i] = posSlotPrices[i]; - for (; i < kNumFullDistances; i++) - distancesPrices[i] = posSlotPrices[GetPosSlot(i)] + tempPrices[i]; - } - _matchPriceCount = 0; -} - -void CEncoder::FillAlignPrices() -{ - for (UInt32 i = 0; i < kAlignTableSize; i++) - _alignPrices[i] = _posAlignEncoder.ReverseGetPrice(i); - _alignPriceCount = 0; -} - }} diff --git a/CPP/7zip/Compress/LZMA/LZMAEncoder.h b/CPP/7zip/Compress/LZMA/LZMAEncoder.h index da159795..711ac0b4 100755 --- a/CPP/7zip/Compress/LZMA/LZMAEncoder.h +++ b/CPP/7zip/Compress/LZMA/LZMAEncoder.h @@ -8,419 +8,39 @@ extern "C" { - #include "../../../../C/Alloc.h" - #include "../../../../C/Compress/Lz/MatchFinder.h" - #ifdef COMPRESS_MF_MT - #include "../../../../C/Compress/Lz/MatchFinderMt.h" - #endif + #include "../../../../C/LzmaEnc.h" } -#include "../RangeCoder/RangeCoderBitTree.h" - -#include "LZMA.h" - namespace NCompress { namespace NLZMA { -typedef NRangeCoder::CBitEncoder<kNumMoveBits> CMyBitEncoder; - -class CBaseState -{ -protected: - CState _state; - Byte _previousByte; - UInt32 _repDistances[kNumRepDistances]; - void Init() - { - _state.Init(); - _previousByte = 0; - for(UInt32 i = 0 ; i < kNumRepDistances; i++) - _repDistances[i] = 0; - } -}; - -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); } -}; - - -// #define LZMA_LOG_BRANCH - -#if _MSC_VER >= 1400 -// Must give gain in core 2. but slower ~2% on k8. -// #define LZMA_LOG_BSR -#endif - -#ifndef LZMA_LOG_BSR -static const int kNumLogBits = 13; // don't change it ! -extern Byte g_FastPos[]; -#endif -inline UInt32 GetPosSlot(UInt32 pos) +struct CSeqInStream { - #ifdef LZMA_LOG_BSR - if (pos < 2) - return pos; - unsigned long index; - _BitScanReverse(&index, pos); - return (index + index) + ((pos >> (index - 1)) & 1); - #else - if (pos < (1 << kNumLogBits)) - return g_FastPos[pos]; - if (pos < (1 << (kNumLogBits * 2 - 1))) - return g_FastPos[pos >> (kNumLogBits - 1)] + (kNumLogBits - 1) * 2; - return g_FastPos[pos >> (kNumLogBits - 1) * 2] + (kNumLogBits - 1) * 4; - #endif -} - -inline UInt32 GetPosSlot2(UInt32 pos) -{ - #ifdef LZMA_LOG_BSR - unsigned long index; - _BitScanReverse(&index, pos); - return (index + index) + ((pos >> (index - 1)) & 1); - #else - #ifdef LZMA_LOG_BRANCH - if (pos < (1 << (kNumLogBits + 6))) - return g_FastPos[pos >> 6] + 12; - if (pos < (1 << (kNumLogBits * 2 + 5))) - return g_FastPos[pos >> (kNumLogBits + 5)] + (kNumLogBits + 5) * 2; - return g_FastPos[pos >> (kNumLogBits * 2 + 4)] + (kNumLogBits * 2 + 4) * 2; - #else - // it's faster with VC6-32bit. - UInt32 s = 6 + ((kNumLogBits - 1) & (UInt32)((Int32)(((1 << (kNumLogBits + 6)) - 1) - pos) >> 31)); - return g_FastPos[pos >> s] + (s * 2); - #endif - #endif -} - -const UInt32 kIfinityPrice = 0xFFFFFFF; - -const UInt32 kNumOpts = 1 << 12; - - -class CLiteralEncoder2 -{ - CMyBitEncoder _encoders[0x300]; -public: - void Init() - { - for (int i = 0; i < 0x300; i++) - _encoders[i].Init(); - } - void Encode(NRangeCoder::CEncoder *rangeEncoder, Byte symbol); - void EncodeMatched(NRangeCoder::CEncoder *rangeEncoder, Byte matchByte, Byte symbol); - UInt32 GetPrice(bool matchMode, Byte matchByte, Byte symbol) const; -}; - -class CLiteralEncoder -{ - CLiteralEncoder2 *_coders; - int _numPrevBits; - int _numPosBits; - UInt32 _posMask; -public: - CLiteralEncoder(): _coders(0) {} - ~CLiteralEncoder() { Free(); } - void Free() - { - MyFree(_coders); - _coders = 0; - } - bool Create(int numPosBits, int numPrevBits) - { - if (_coders == 0 || (numPosBits + numPrevBits) != (_numPrevBits + _numPosBits)) - { - Free(); - UInt32 numStates = 1 << (numPosBits + numPrevBits); - _coders = (CLiteralEncoder2 *)MyAlloc(numStates * sizeof(CLiteralEncoder2)); - } - _numPosBits = numPosBits; - _posMask = (1 << numPosBits) - 1; - _numPrevBits = numPrevBits; - return (_coders != 0); - } - void Init() - { - UInt32 numStates = 1 << (_numPrevBits + _numPosBits); - for (UInt32 i = 0; i < numStates; i++) - _coders[i].Init(); - } - CLiteralEncoder2 *GetSubCoder(UInt32 pos, Byte prevByte) - { return &_coders[((pos & _posMask) << _numPrevBits) + (prevByte >> (8 - _numPrevBits))]; } -}; - -namespace NLength { - -class CEncoder -{ - CMyBitEncoder _choice; - CMyBitEncoder _choice2; - NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumLowBits> _lowCoder[kNumPosStatesEncodingMax]; - NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumMidBits> _midCoder[kNumPosStatesEncodingMax]; - NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumHighBits> _highCoder; -public: - void Init(UInt32 numPosStates); - void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState); - void SetPrices(UInt32 posState, UInt32 numSymbols, UInt32 *prices) const; + ISeqInStream SeqInStream; + ISequentialInStream *RealStream; }; -const UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols; - -class CPriceTableEncoder: public CEncoder +struct CSeqOutStream { - UInt32 _prices[kNumPosStatesEncodingMax][kNumSymbolsTotal]; - UInt32 _tableSize; - UInt32 _counters[kNumPosStatesEncodingMax]; -public: - void SetTableSize(UInt32 tableSize) { _tableSize = tableSize; } - UInt32 GetPrice(UInt32 symbol, UInt32 posState) const { return _prices[posState][symbol]; } - void UpdateTable(UInt32 posState) - { - SetPrices(posState, _tableSize, _prices[posState]); - _counters[posState] = _tableSize; - } - void UpdateTables(UInt32 numPosStates) - { - for (UInt32 posState = 0; posState < numPosStates; posState++) - UpdateTable(posState); - } - void Encode(NRangeCoder::CEncoder *rangeEncoder, UInt32 symbol, UInt32 posState, bool updatePrice) - { - CEncoder::Encode(rangeEncoder, symbol, posState); - if (updatePrice) - if (--_counters[posState] == 0) - UpdateTable(posState); - } + ISeqOutStream SeqOutStream; + CMyComPtr<ISequentialOutStream> RealStream; + HRESULT Res; }; -} - -typedef struct _CSeqInStream -{ - ISeqInStream SeqInStream; - CMyComPtr<ISequentialInStream> RealStream; -} CSeqInStream; - - class CEncoder : public ICompressCoder, public ICompressSetOutStream, public ICompressSetCoderProperties, public ICompressWriteCoderProperties, - public CBaseState, public CMyUnknownImp { - NRangeCoder::CEncoder _rangeEncoder; - - IMatchFinder _matchFinder; - void *_matchFinderObj; - - #ifdef COMPRESS_MF_MT - Bool _multiThread; - Bool _mtMode; - CMatchFinderMt _matchFinderMt; - #endif - - CMatchFinder _matchFinderBase; - #ifdef COMPRESS_MF_MT - Byte _pad1[kMtCacheLineDummy]; - #endif - - COptimal _optimum[kNumOpts]; - - CMyBitEncoder _isMatch[kNumStates][NLength::kNumPosStatesEncodingMax]; - CMyBitEncoder _isRep[kNumStates]; - CMyBitEncoder _isRepG0[kNumStates]; - CMyBitEncoder _isRepG1[kNumStates]; - CMyBitEncoder _isRepG2[kNumStates]; - CMyBitEncoder _isRep0Long[kNumStates][NLength::kNumPosStatesEncodingMax]; - - NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumPosSlotBits> _posSlotEncoder[kNumLenToPosStates]; - - CMyBitEncoder _posEncoders[kNumFullDistances - kEndPosModelIndex]; - NRangeCoder::CBitTreeEncoder<kNumMoveBits, kNumAlignBits> _posAlignEncoder; - - NLength::CPriceTableEncoder _lenEncoder; - NLength::CPriceTableEncoder _repMatchLenEncoder; - - CLiteralEncoder _literalEncoder; - - UInt32 _matchDistances[kMatchMaxLen * 2 + 2 + 1]; - - bool _fastMode; - // bool _maxMode; - UInt32 _numFastBytes; - UInt32 _longestMatchLength; - UInt32 _numDistancePairs; - - UInt32 _additionalOffset; - - UInt32 _optimumEndIndex; - UInt32 _optimumCurrentIndex; - - bool _longestMatchWasFound; - - UInt32 _posSlotPrices[kNumLenToPosStates][kDistTableSizeMax]; + CLzmaEncHandle _encoder; - UInt32 _distancesPrices[kNumLenToPosStates][kNumFullDistances]; - - UInt32 _alignPrices[kAlignTableSize]; - UInt32 _alignPriceCount; - - UInt32 _distTableSize; - - UInt32 _posStateBits; - UInt32 _posStateMask; - UInt32 _numLiteralPosStateBits; - UInt32 _numLiteralContextBits; - - UInt32 _dictionarySize; - - UInt32 _matchPriceCount; - UInt64 nowPos64; - bool _finished; - ISequentialInStream *_inStream; - CSeqInStream _seqInStream; - - UInt32 _matchFinderCycles; - // int _numSkip - - bool _writeEndMark; - - bool _needReleaseMFStream; - - void ReleaseMatchFinder() - { - _matchFinder.Init = 0; - _seqInStream.RealStream.Release(); - } - - void ReleaseMFStream() - { - if (_matchFinderObj && _needReleaseMFStream) - { - #ifdef COMPRESS_MF_MT - if (_mtMode) - MatchFinderMt_ReleaseStream(&_matchFinderMt); - #endif - _needReleaseMFStream = false; - } - _seqInStream.RealStream.Release(); - } - - UInt32 ReadMatchDistances(UInt32 &numDistancePairs); - - void MovePos(UInt32 num); - UInt32 GetRepLen1Price(CState state, UInt32 posState) const - { - return _isRepG0[state.Index].GetPrice0() + - _isRep0Long[state.Index][posState].GetPrice0(); - } - - UInt32 GetPureRepPrice(UInt32 repIndex, CState state, UInt32 posState) const - { - UInt32 price; - if(repIndex == 0) - { - price = _isRepG0[state.Index].GetPrice0(); - price += _isRep0Long[state.Index][posState].GetPrice1(); - } - else - { - price = _isRepG0[state.Index].GetPrice1(); - if (repIndex == 1) - price += _isRepG1[state.Index].GetPrice0(); - else - { - price += _isRepG1[state.Index].GetPrice1(); - price += _isRepG2[state.Index].GetPrice(repIndex - 2); - } - } - return price; - } - UInt32 GetRepPrice(UInt32 repIndex, UInt32 len, CState state, UInt32 posState) const - { - return _repMatchLenEncoder.GetPrice(len - kMatchMinLen, posState) + - GetPureRepPrice(repIndex, state, posState); - } - /* - 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 - { - 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 position, UInt32 &backRes); - UInt32 GetOptimumFast(UInt32 &backRes); - - void FillDistancesPrices(); - void FillAlignPrices(); - - void ReleaseStreams() - { - ReleaseMFStream(); - ReleaseOutStream(); - } - - HRESULT Flush(UInt32 nowPos); - class CCoderReleaser - { - CEncoder *_coder; - public: - CCoderReleaser(CEncoder *coder): _coder(coder) {} - ~CCoderReleaser() { _coder->ReleaseStreams(); } - }; - friend class CCoderReleaser; - - void WriteEndMarker(UInt32 posState); + CSeqOutStream _seqOutStream; public: CEncoder(); - void SetWriteEndMarkerMode(bool writeEndMarker) - { _writeEndMark= writeEndMarker; } - - HRESULT Create(); MY_UNKNOWN_IMP3( ICompressSetOutStream, @@ -428,20 +48,7 @@ public: ICompressWriteCoderProperties ) - HRESULT Init(); - - // 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, diff --git a/CPP/7zip/Compress/LZMA/makefile b/CPP/7zip/Compress/LZMA/makefile deleted file mode 100755 index 4a108b42..00000000 --- a/CPP/7zip/Compress/LZMA/makefile +++ /dev/null @@ -1,70 +0,0 @@ -PROG = LZMA.dll -DEF_FILE = ../Codec.def -CFLAGS = $(CFLAGS) -I ../../../ \ - -DCOMPRESS_MF_MT \ - -D_7ZIP_LARGE_PAGES \ - -LIBS = $(LIBS) oleaut32.lib - -COMPRESS_OBJS = \ - $O\CodecExports.obj \ - $O\DllExports.obj \ - -COMMON_OBJS = \ - $O\CRC.obj \ - -LZMA_OPT_OBJS = \ - $O\LZMADecoder.obj \ - $O\LZMAEncoder.obj \ - $O\LZMARegister.obj \ - -7ZIP_COMMON_OBJS = \ - $O\InBuffer.obj \ - $O\OutBuffer.obj \ - $O\StreamUtils.obj \ - -LZ_OBJS = \ - $O\LZOutWindow.obj \ - -C_OBJS = \ - $O\Threads.obj \ - $O\Alloc.obj \ - -C_LZ_OBJS = \ - $O\MatchFinder.obj \ - $O\MatchFinderMt.obj \ - -!include "../../Crc2.mak" - -OBJS = \ - $O\StdAfx.obj \ - $(COMPRESS_OBJS) \ - $(COMMON_OBJS) \ - $(LZMA_OPT_OBJS) \ - $(7ZIP_COMMON_OBJS) \ - $(LZ_OBJS) \ - $(C_OBJS) \ - $(C_LZ_OBJS) \ - $(CRC_OBJS) \ - $O\RangeCoderBit.obj \ - $O\resource.res - -!include "../../../Build.mak" - -$(COMPRESS_OBJS): ../$(*B).cpp - $(COMPL) -$(COMMON_OBJS): ../../../Common/$(*B).cpp - $(COMPL) -$(LZMA_OPT_OBJS): $(*B).cpp - $(COMPL_O2) -$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp - $(COMPL) -$(LZ_OBJS): ../LZ/$(*B).cpp - $(COMPL) -$O\RangeCoderBit.obj: ../RangeCoder/$(*B).cpp - $(COMPL) -$(C_OBJS): ../../../../C/$(*B).c - $(COMPL_O2) -$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c - $(COMPL_O2) -!include "../../Crc.mak" diff --git a/CPP/7zip/Compress/LZMA/resource.rc b/CPP/7zip/Compress/LZMA/resource.rc deleted file mode 100755 index 1b2b6abb..00000000 --- a/CPP/7zip/Compress/LZMA/resource.rc +++ /dev/null @@ -1,3 +0,0 @@ -#include "../../MyVersionInfo.rc" - -MY_VERSION_INFO_DLL("LZMA Codec", "LZMA") diff --git a/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp b/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp index 39fee934..a09c3069 100755 --- a/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp +++ b/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp @@ -371,134 +371,132 @@ SOURCE=..\..\Common\StreamUtils.h # Begin Group "C" # PROP Default_Filter "" -# Begin Group "C-Lz" +# Begin Group "LzmaUtil" # PROP Default_Filter "" # Begin Source File -SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.c +SOURCE=..\..\..\..\C\LzmaUtil\Lzma86Dec.c # SUBTRACT CPP /YX /Yc /Yu # End Source File # Begin Source File -SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.h +SOURCE=..\..\..\..\C\LzmaUtil\Lzma86Dec.h # End Source File # Begin Source File -SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.c +SOURCE=..\..\..\..\C\LzmaUtil\Lzma86Enc.c # SUBTRACT CPP /YX /Yc /Yu # End Source File # Begin Source File -SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.h +SOURCE=..\..\..\..\C\LzmaUtil\Lzma86Enc.h # End Source File +# End Group # Begin Source File -SOURCE=..\..\..\..\C\Threads.c +SOURCE=..\..\..\..\C\7zCrc.c # SUBTRACT CPP /YX /Yc /Yu # End Source File # Begin Source File -SOURCE=..\..\..\..\C\Threads.h +SOURCE=..\..\..\..\C\7zCrc.h # End Source File -# End Group -# Begin Group "LZMA_C" - -# PROP Default_Filter "" # Begin Source File -SOURCE=..\..\..\..\C\Compress\Lzma\LzmaDecode.c +SOURCE=..\..\..\..\C\Alloc.c # SUBTRACT CPP /YX /Yc /Yu # End Source File # Begin Source File -SOURCE=..\..\..\..\C\Compress\Lzma\LzmaDecode.h +SOURCE=..\..\..\..\C\Alloc.h # End Source File # Begin Source File -SOURCE=..\..\..\..\C\Compress\Lzma\LzmaTypes.h +SOURCE=..\..\..\..\C\Bra.h # End Source File -# End Group -# Begin Group "Branch" - -# PROP Default_Filter "" # Begin Source File -SOURCE=..\..\..\..\C\Compress\Branch\BranchTypes.h +SOURCE=..\..\..\..\C\Bra86.c +# SUBTRACT CPP /YX /Yc /Yu # End Source File # Begin Source File -SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c +SOURCE=..\..\..\..\C\LzFind.c # SUBTRACT CPP /YX /Yc /Yu # End Source File # Begin Source File -SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h +SOURCE=..\..\..\..\C\LzFind.h # End Source File -# End Group # Begin Source File -SOURCE=..\..\..\..\C\7zCrc.c +SOURCE=..\..\..\..\C\LzFindMt.c # SUBTRACT CPP /YX /Yc /Yu # End Source File # Begin Source File -SOURCE=..\..\..\..\C\7zCrc.h +SOURCE=..\..\..\..\C\LzFindMt.h # End Source File # Begin Source File -SOURCE=..\..\..\..\C\Alloc.c +SOURCE=..\..\..\..\C\LzHash.h +# End Source File +# Begin Source File + +SOURCE=..\..\..\..\C\LzmaDec.c # SUBTRACT CPP /YX /Yc /Yu # End Source File # Begin Source File -SOURCE=..\..\..\..\C\Alloc.h +SOURCE=..\..\..\..\C\LzmaDec.h # End Source File # Begin Source File -SOURCE=..\..\..\..\C\Types.h +SOURCE=..\..\..\..\C\LzmaEnc.c +# SUBTRACT CPP /YX /Yc /Yu # End Source File -# End Group # Begin Source File -SOURCE=..\..\ICoder.h +SOURCE=..\..\..\..\C\LzmaEnc.h # End Source File # Begin Source File -SOURCE=.\LzmaAlone.cpp +SOURCE=..\..\..\..\C\Threads.c +# SUBTRACT CPP /YX /Yc /Yu # End Source File # Begin Source File -SOURCE=.\LzmaBench.cpp +SOURCE=..\..\..\..\C\Threads.h # End Source File # Begin Source File -SOURCE=.\LzmaBench.h +SOURCE=..\..\..\..\C\Types.h # End Source File +# End Group # Begin Source File -SOURCE=.\LzmaBenchCon.cpp +SOURCE=..\..\ICoder.h # End Source File # Begin Source File -SOURCE=.\LzmaBenchCon.h +SOURCE=.\LzmaAlone.cpp # End Source File # Begin Source File -SOURCE=.\LzmaRam.cpp +SOURCE=.\LzmaBench.cpp # End Source File # Begin Source File -SOURCE=.\LzmaRam.h +SOURCE=.\LzmaBench.h # End Source File # Begin Source File -SOURCE=.\LzmaRamDecode.c -# SUBTRACT CPP /YX /Yc /Yu +SOURCE=.\LzmaBenchCon.cpp # End Source File # Begin Source File -SOURCE=.\LzmaRamDecode.h +SOURCE=.\LzmaBenchCon.h # End Source File # End Target # End Project diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp b/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp index 0e83f576..0d2800bd 100755 --- a/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp +++ b/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp @@ -26,15 +26,19 @@ #include "../LZMA/LZMAEncoder.h" #include "LzmaBenchCon.h" -#include "LzmaRam.h" #ifdef COMPRESS_MF_MT #include "../../../Windows/System.h" #endif +#include "../../MyVersion.h" + + extern "C" { -#include "LzmaRamDecode.h" + #include "../../../../C/Alloc.h" + #include "../../../../C/LzmaUtil/Lzma86Dec.h" + #include "../../../../C/LzmaUtil/Lzma86Enc.h" } using namespace NCommandLineParser; @@ -105,7 +109,7 @@ static void PrintHelp() " b: Benchmark\n" "<Switches>\n" " -a{N}: set compression mode - [0, 1], default: 1 (max)\n" - " -d{N}: set dictionary - [0,30], default: 23 (8MB)\n" + " -d{N}: set dictionary - [12, 30], default: 23 (8MB)\n" " -fb{N}: set number of fast bytes - [5, 273], default: 128\n" " -mc{N}: set number of cycles for match finder\n" " -lc{N}: set number of literal context bits - [0, 8], default: 3\n" @@ -159,7 +163,7 @@ int main2(int n, const char *args[]) g_IsNT = IsItWindowsNT(); #endif - fprintf(stderr, "\nLZMA 4.56 Copyright (c) 1999-2007 Igor Pavlov 2007-10-19\n"); + fprintf(stderr, "\nLZMA " MY_VERSION_COPYRIGHT_DATE "\n"); if (n == 1) { @@ -306,7 +310,7 @@ int main2(int n, const char *args[]) inStreamSpec->File.GetLength(fileSize); if (fileSize > 0xF0000000) throw "File is too big"; - UInt32 inSize = (UInt32)fileSize; + size_t inSize = (size_t)fileSize; Byte *inBuffer = 0; if (inSize != 0) { @@ -315,18 +319,15 @@ int main2(int n, const char *args[]) throw kCantAllocate; } - UInt32 processedSize; - if (ReadStream(inStream, inBuffer, (UInt32)inSize, &processedSize) != S_OK) + if (ReadStream_FAIL(inStream, inBuffer, inSize) != S_OK) throw "Can not read"; - if ((UInt32)inSize != processedSize) - throw "Read size error"; Byte *outBuffer = 0; - size_t outSizeProcessed; + size_t outSize; if (encodeMode) { // we allocate 105% of original size for output buffer - size_t outSize = (size_t)fileSize / 20 * 21 + (1 << 16); + outSize = (size_t)fileSize / 20 * 21 + (1 << 16); if (outSize != 0) { outBuffer = (Byte *)MyAlloc((size_t)outSize); @@ -335,8 +336,8 @@ int main2(int n, const char *args[]) } if (!dictionaryIsDefined) dictionary = 1 << 23; - int res = LzmaRamEncode(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, - dictionary, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO); + int res = Lzma86_Encode(outBuffer, &outSize, inBuffer, inSize, + 5, dictionary, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO); if (res != 0) { fprintf(stderr, "\nEncoder error = %d\n", (int)res); @@ -345,20 +346,25 @@ int main2(int n, const char *args[]) } else { - size_t outSize; - if (LzmaRamGetUncompressedSize(inBuffer, inSize, &outSize) != 0) + UInt64 outSize64; + if (Lzma86_GetUnpackSize(inBuffer, inSize, &outSize64) != 0) throw "data error"; + outSize = (size_t)outSize64; + if (outSize != outSize64) + throw "too big"; if (outSize != 0) { outBuffer = (Byte *)MyAlloc(outSize); if (outBuffer == 0) throw kCantAllocate; } - int res = LzmaRamDecompress(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, malloc, free); + int res = Lzma86_Decode(outBuffer, &outSize, inBuffer, &inSize); + if (inSize != (size_t)fileSize) + throw "incorrect processed size"; if (res != 0) throw "LzmaDecoder error"; } - if (WriteStream(outStream, outBuffer, (UInt32)outSizeProcessed, &processedSize) != S_OK) + if (WriteStream(outStream, outBuffer, outSize) != S_OK) throw kWriteError; MyFree(outBuffer); MyFree(inBuffer); @@ -486,40 +492,22 @@ int main2(int n, const char *args[]) NCompress::NLZMA::CDecoder *decoderSpec = new NCompress::NLZMA::CDecoder; CMyComPtr<ICompressCoder> decoder = decoderSpec; const UInt32 kPropertiesSize = 5; - Byte properties[kPropertiesSize]; - UInt32 processedSize; - if (ReadStream(inStream, properties, kPropertiesSize, &processedSize) != S_OK) - { - fprintf(stderr, kReadError); - return 1; - } - if (processedSize != kPropertiesSize) + Byte header[kPropertiesSize + 8]; + if (ReadStream_FALSE(inStream, header, kPropertiesSize + 8) != S_OK) { fprintf(stderr, kReadError); return 1; } - if (decoderSpec->SetDecoderProperties2(properties, kPropertiesSize) != S_OK) + if (decoderSpec->SetDecoderProperties2(header, kPropertiesSize) != S_OK) { fprintf(stderr, "SetDecoderProperties error"); return 1; } fileSize = 0; for (int i = 0; i < 8; i++) - { - Byte b; - if (inStream->Read(&b, 1, &processedSize) != S_OK) - { - fprintf(stderr, kReadError); - return 1; - } - if (processedSize != 1) - { - fprintf(stderr, kReadError); - return 1; - } - fileSize |= ((UInt64)b) << (8 * i); - } - if (decoder->Code(inStream, outStream, 0, &fileSize, 0) != S_OK) + fileSize |= ((UInt64)header[kPropertiesSize + i]) << (8 * i); + + if (decoder->Code(inStream, outStream, 0, (fileSize == (UInt64)(Int64)-1) ? 0 : &fileSize, 0) != S_OK) { fprintf(stderr, "Decoder error"); return 1; @@ -536,7 +524,7 @@ int main2(int n, const char *args[]) return 0; } -int main(int n, const char *args[]) +int MY_CDECL main(int n, const char *args[]) { try { return main2(n, args); } catch(const char *s) diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp b/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp index 4cd2d63e..cbb0aa86 100755 --- a/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp +++ b/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp @@ -438,17 +438,14 @@ static UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq) UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size) { UInt64 t = GetLogSize(dictionarySize) - (kBenchMinDicLogSize << kSubBits); - // UInt64 numCommandsForOne = 1000 + ((t * t * 7) >> (2 * kSubBits)); // AMD K8 - UInt64 numCommandsForOne = 870 + ((t * t * 5) >> (2 * kSubBits)); // Intel Core2 - + UInt64 numCommandsForOne = 870 + ((t * t * 5) >> (2 * kSubBits)); UInt64 numCommands = (UInt64)(size) * numCommandsForOne; return MyMultDiv64(numCommands, elapsedTime, freq); } UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations) { - // UInt64 numCommands = (inSize * 216 + outSize * 14) * numIterations; // AMD K8 - UInt64 numCommands = (inSize * 220 + outSize * 8) * numIterations; // Intel Core2 + UInt64 numCommands = (inSize * 200 + outSize * 4) * numIterations; return MyMultDiv64(numCommands, elapsedTime, freq); } @@ -796,10 +793,9 @@ HRESULT LzmaBench( { for (UInt32 j = 0; j < numSubDecoderThreads; j++) { - size_t allocaSize = ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF; HRESULT res = encoder.CreateDecoderThread(j, (i == 0 && j == 0) #ifdef USE_ALLOCA - , allocaSize + , ((i * numSubDecoderThreads + j) * 16 * 21) & 0x7FF #endif ); RINOK(res); diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp b/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp deleted file mode 100755 index b86d1ea9..00000000 --- a/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp +++ /dev/null @@ -1,226 +0,0 @@ -// LzmaRam.cpp - -#include "StdAfx.h" -#include "../../../Common/Types.h" -#include "../LZMA/LZMADecoder.h" -#include "../LZMA/LZMAEncoder.h" -#include "LzmaRam.h" - -extern "C" -{ - #include "../../../../C/Compress/Branch/BranchX86.h" -} - -class CInStreamRam: - public ISequentialInStream, - public CMyUnknownImp -{ - const Byte *Data; - size_t Size; - size_t Pos; -public: - MY_UNKNOWN_IMP - void Init(const Byte *data, size_t size) - { - Data = data; - Size = size; - Pos = 0; - } - STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); -}; - -STDMETHODIMP CInStreamRam::Read(void *data, UInt32 size, UInt32 *processedSize) -{ - if (size > (Size - Pos)) - size = (UInt32)(Size - Pos); - for (UInt32 i = 0; i < size; i++) - ((Byte *)data)[i] = Data[Pos + i]; - Pos += size; - if(processedSize != NULL) - *processedSize = size; - return S_OK; -} - -class COutStreamRam: - public ISequentialOutStream, - public CMyUnknownImp -{ - size_t Size; -public: - Byte *Data; - size_t Pos; - bool Overflow; - void Init(Byte *data, size_t size) - { - Data = data; - Size = size; - Pos = 0; - Overflow = false; - } - void SetPos(size_t pos) - { - Overflow = false; - Pos = pos; - } - MY_UNKNOWN_IMP - HRESULT WriteByte(Byte b) - { - if (Pos >= Size) - { - Overflow = true; - return E_FAIL; - } - Data[Pos++] = b; - return S_OK; - } - STDMETHOD(Write)(const void *data, UInt32 size, UInt32 *processedSize); -}; - -STDMETHODIMP COutStreamRam::Write(const void *data, UInt32 size, UInt32 *processedSize) -{ - UInt32 i; - for (i = 0; i < size && Pos < Size; i++) - Data[Pos++] = ((const Byte *)data)[i]; - if(processedSize != NULL) - *processedSize = i; - if (i != size) - { - Overflow = true; - return E_FAIL; - } - return S_OK; -} - -#define SZ_RAM_E_FAIL (1) -#define SZ_RAM_E_OUTOFMEMORY (2) -#define SZE_OUT_OVERFLOW (3) - -int LzmaRamEncode( - const Byte *inBuffer, size_t inSize, - Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, - UInt32 dictionarySize, ESzFilterMode filterMode) -{ - #ifndef _NO_EXCEPTIONS - try { - #endif - - *outSizeProcessed = 0; - const size_t kIdSize = 1; - const size_t kLzmaPropsSize = 5; - const size_t kMinDestSize = kIdSize + kLzmaPropsSize + 8; - if (outSize < kMinDestSize) - return SZE_OUT_OVERFLOW; - NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder; - CMyComPtr<ICompressCoder> encoder = encoderSpec; - - PROPID propIDs[] = - { - NCoderPropID::kAlgorithm, - NCoderPropID::kDictionarySize, - NCoderPropID::kNumFastBytes, - }; - const int kNumProps = sizeof(propIDs) / sizeof(propIDs[0]); - PROPVARIANT properties[kNumProps]; - properties[0].vt = VT_UI4; - properties[1].vt = VT_UI4; - properties[2].vt = VT_UI4; - properties[0].ulVal = (UInt32)2; - properties[1].ulVal = (UInt32)dictionarySize; - properties[2].ulVal = (UInt32)64; - - if (encoderSpec->SetCoderProperties(propIDs, properties, kNumProps) != S_OK) - return 1; - - COutStreamRam *outStreamSpec = new COutStreamRam; - if (outStreamSpec == 0) - return SZ_RAM_E_OUTOFMEMORY; - CMyComPtr<ISequentialOutStream> outStream = outStreamSpec; - CInStreamRam *inStreamSpec = new CInStreamRam; - if (inStreamSpec == 0) - return SZ_RAM_E_OUTOFMEMORY; - CMyComPtr<ISequentialInStream> inStream = inStreamSpec; - - outStreamSpec->Init(outBuffer, outSize); - if (outStreamSpec->WriteByte(0) != S_OK) - return SZE_OUT_OVERFLOW; - - if (encoderSpec->WriteCoderProperties(outStream) != S_OK) - return SZE_OUT_OVERFLOW; - if (outStreamSpec->Pos != kIdSize + kLzmaPropsSize) - return 1; - - int i; - for (i = 0; i < 8; i++) - { - UInt64 t = (UInt64)(inSize); - if (outStreamSpec->WriteByte((Byte)((t) >> (8 * i))) != S_OK) - return SZE_OUT_OVERFLOW; - } - - Byte *filteredStream = 0; - - bool useFilter = (filterMode != SZ_FILTER_NO); - if (useFilter) - { - if (inSize != 0) - { - filteredStream = (Byte *)MyAlloc(inSize); - if (filteredStream == 0) - return SZ_RAM_E_OUTOFMEMORY; - memmove(filteredStream, inBuffer, inSize); - } - UInt32 x86State; - x86_Convert_Init(x86State); - x86_Convert(filteredStream, (SizeT)inSize, 0, &x86State, 1); - } - - size_t minSize = 0; - int numPasses = (filterMode == SZ_FILTER_AUTO) ? 3 : 1; - bool bestIsFiltered = false; - int mainResult = 0; - size_t startPos = outStreamSpec->Pos; - for (i = 0; i < numPasses; i++) - { - if (numPasses > 1 && i == numPasses - 1 && !bestIsFiltered) - break; - outStreamSpec->SetPos(startPos); - bool curModeIsFiltered = false; - if (useFilter && i == 0) - curModeIsFiltered = true; - if (numPasses > 1 && i == numPasses - 1) - curModeIsFiltered = true; - - inStreamSpec->Init(curModeIsFiltered ? filteredStream : inBuffer, inSize); - - HRESULT lzmaResult = encoder->Code(inStream, outStream, 0, 0, 0); - - mainResult = 0; - if (lzmaResult == E_OUTOFMEMORY) - { - mainResult = SZ_RAM_E_OUTOFMEMORY; - break; - } - if (i == 0 || outStreamSpec->Pos <= minSize) - { - minSize = outStreamSpec->Pos; - bestIsFiltered = curModeIsFiltered; - } - if (outStreamSpec->Overflow) - mainResult = SZE_OUT_OVERFLOW; - else if (lzmaResult != S_OK) - { - mainResult = SZ_RAM_E_FAIL; - break; - } - } - *outSizeProcessed = outStreamSpec->Pos; - if (bestIsFiltered) - outBuffer[0] = 1; - if (useFilter) - MyFree(filteredStream); - return mainResult; - - #ifndef _NO_EXCEPTIONS - } catch(...) { return SZ_RAM_E_OUTOFMEMORY; } - #endif -} diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaRam.h b/CPP/7zip/Compress/LZMA_Alone/LzmaRam.h deleted file mode 100755 index 1244dc86..00000000 --- a/CPP/7zip/Compress/LZMA_Alone/LzmaRam.h +++ /dev/null @@ -1,46 +0,0 @@ -// LzmaRam.h - -#ifndef __LzmaRam_h -#define __LzmaRam_h - -#include <stdlib.h> -#include "../../../Common/Types.h" - -/* -LzmaRamEncode: BCJ + LZMA RAM->RAM compressing. -It uses .lzma format, but it writes one additional byte to .lzma file: - 0: - no filter - 1: - x86(BCJ) filter. - -To provide best compression ratio dictionarySize mustbe >= inSize - -LzmaRamEncode allocates Data with MyAlloc/BigAlloc functions. -RAM Requirements: - RamSize = dictionarySize * 9.5 + 6MB + FilterBlockSize - FilterBlockSize = 0, if useFilter == false - FilterBlockSize = inSize, if useFilter == true - - Return code: - 0 - OK - 1 - Unspecified Error - 2 - Memory allocating error - 3 - Output buffer OVERFLOW - -If you use SZ_FILTER_AUTO mode, then encoder will use 2 or 3 passes: - 2 passes when FILTER_NO provides better compression. - 3 passes when FILTER_YES provides better compression. -*/ - -enum ESzFilterMode -{ - SZ_FILTER_NO, - SZ_FILTER_YES, - SZ_FILTER_AUTO -}; - -int LzmaRamEncode( - const Byte *inBuffer, size_t inSize, - Byte *outBuffer, size_t outSize, size_t *outSizeProcessed, - UInt32 dictionarySize, ESzFilterMode filterMode); - -#endif diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c b/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c deleted file mode 100755 index 29f798be..00000000 --- a/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.c +++ /dev/null @@ -1,78 +0,0 @@ -/* LzmaRamDecode.c */ - -#include "LzmaRamDecode.h" -#ifdef _SZ_ONE_DIRECTORY -#include "LzmaDecode.h" -#include "BranchX86.h" -#else -#include "../../../../C/Compress/Lzma/LzmaDecode.h" -#include "../../../../C/Compress/Branch/BranchX86.h" -#endif - -#define LZMA_PROPS_SIZE 14 -#define LZMA_SIZE_OFFSET 6 - -int LzmaRamGetUncompressedSize( - const unsigned char *inBuffer, - size_t inSize, - size_t *outSize) -{ - unsigned int i; - if (inSize < LZMA_PROPS_SIZE) - return 1; - *outSize = 0; - for(i = 0; i < sizeof(size_t); i++) - *outSize += ((size_t)inBuffer[LZMA_SIZE_OFFSET + i]) << (8 * i); - for(; i < 8; i++) - if (inBuffer[LZMA_SIZE_OFFSET + i] != 0) - return 1; - return 0; -} - -#define SZE_DATA_ERROR (1) -#define SZE_OUTOFMEMORY (2) - -int LzmaRamDecompress( - const unsigned char *inBuffer, - size_t inSize, - unsigned char *outBuffer, - size_t outSize, - size_t *outSizeProcessed, - void * (*allocFunc)(size_t size), - void (*freeFunc)(void *)) -{ - CLzmaDecoderState state; /* it's about 24 bytes structure, if int is 32-bit */ - int result; - SizeT outSizeProcessedLoc; - SizeT inProcessed; - int useFilter; - - if (inSize < LZMA_PROPS_SIZE) - return 1; - useFilter = inBuffer[0]; - - *outSizeProcessed = 0; - if (useFilter > 1) - return 1; - - if (LzmaDecodeProperties(&state.Properties, inBuffer + 1, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK) - return 1; - state.Probs = (CProb *)allocFunc(LzmaGetNumProbs(&state.Properties) * sizeof(CProb)); - if (state.Probs == 0) - return SZE_OUTOFMEMORY; - - result = LzmaDecode(&state, - inBuffer + LZMA_PROPS_SIZE, (SizeT)inSize - LZMA_PROPS_SIZE, &inProcessed, - outBuffer, (SizeT)outSize, &outSizeProcessedLoc); - freeFunc(state.Probs); - if (result != LZMA_RESULT_OK) - return 1; - *outSizeProcessed = (size_t)outSizeProcessedLoc; - if (useFilter == 1) - { - UInt32 x86State; - x86_Convert_Init(x86State); - x86_Convert(outBuffer, (SizeT)outSizeProcessedLoc, 0, &x86State, 0); - } - return 0; -} diff --git a/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.h b/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.h deleted file mode 100755 index 7e641c55..00000000 --- a/CPP/7zip/Compress/LZMA_Alone/LzmaRamDecode.h +++ /dev/null @@ -1,55 +0,0 @@ -/* LzmaRamDecode.h */ - -#ifndef __LzmaRamDecode_h -#define __LzmaRamDecode_h - -#include <stdlib.h> - -/* -LzmaRamGetUncompressedSize: - In: - inBuffer - input data - inSize - input data size - Out: - outSize - uncompressed size - Return code: - 0 - OK - 1 - Error in headers -*/ - -int LzmaRamGetUncompressedSize( - const unsigned char *inBuffer, - size_t inSize, - size_t *outSize); - - -/* -LzmaRamDecompress: - In: - inBuffer - input data - inSize - input data size - outBuffer - output data - outSize - output size - allocFunc - alloc function (can be malloc) - freeFunc - free function (can be free) - Out: - outSizeProcessed - processed size - Return code: - 0 - OK - 1 - Error in headers / data stream - 2 - Memory allocating error - -Memory requirements depend from properties of LZMA stream. -With default lzma settings it's about 16 KB. -*/ - -int LzmaRamDecompress( - const unsigned char *inBuffer, - size_t inSize, - unsigned char *outBuffer, - size_t outSize, - size_t *outSizeProcessed, - void * (*allocFunc)(size_t size), - void (*freeFunc)(void *)); - -#endif diff --git a/CPP/7zip/Compress/LZMA_Alone/makefile b/CPP/7zip/Compress/LZMA_Alone/makefile index 16e76376..69196871 100755 --- a/CPP/7zip/Compress/LZMA_Alone/makefile +++ b/CPP/7zip/Compress/LZMA_Alone/makefile @@ -1,49 +1,13 @@ PROG = lzma.exe +LIBS = $(LIBS) user32.lib CFLAGS = $(CFLAGS) \ -DCOMPRESS_MF_MT \ -DBENCH_MT \ -LIBS = $(LIBS) oleaut32.lib user32.lib - -!IFDEF CPU -LIBS = $(LIBS) bufferoverflowU.lib -CFLAGS = $(CFLAGS) -GS- -Zc:forScope -W4 -Wp64 -DUNICODE -D_UNICODE -!ENDIF - -!IFNDEF O -!IFDEF CPU -O=$(CPU) -!ELSE -O=O -!ENDIF -!ENDIF - -!IFDEF MY_STATIC_LINK -!IFNDEF MY_SINGLE_THREAD -CFLAGS = $(CFLAGS) -MT -!ENDIF -!ELSE -CFLAGS = $(CFLAGS) -MD -!ENDIF - -CFLAGS = $(CFLAGS) -nologo -EHsc -c -Fo$O/ -CFLAGS_O1 = $(CFLAGS) -O1 -CFLAGS_O2 = $(CFLAGS) -O2 - -LFLAGS = $(LFLAGS) -nologo -OPT:NOWIN98 - -PROGPATH = $O\$(PROG) - -COMPL_O1 = $(CPP) $(CFLAGS_O1) $** -COMPL_O2 = $(CPP) $(CFLAGS_O2) $** -COMPL = $(CPP) $(CFLAGS_O1) $** - - LZMA_OBJS = \ $O\LzmaAlone.obj \ $O\LzmaBench.obj \ $O\LzmaBenchCon.obj \ - $O\LzmaRam.obj \ LZMA_OPT_OBJS = \ $O\LZMADecoder.obj \ @@ -66,44 +30,33 @@ WIN_OBJS = \ $O\OutBuffer.obj \ $O\StreamUtils.obj \ -LZ_OBJS = \ - $O\LZOutWindow.obj \ - C_OBJS = \ - $O\Alloc.obj \ $O\7zCrc.obj \ + $O\Alloc.obj \ + $O\Bra86.obj \ + $O\LzFind.obj \ + $O\LzFindMt.obj \ + $O\LzmaDec.obj \ + $O\LzmaEnc.obj \ $O\Threads.obj \ -C_LZ_OBJS = \ - $O\MatchFinder.obj \ - $O\MatchFinderMt.obj \ +C_LZMAUTIL_OBJS = \ + $O\Lzma86Dec.obj \ + $O\Lzma86Enc.obj \ OBJS = \ + $O\StdAfx.obj \ $(LZMA_OBJS) \ $(LZMA_OPT_OBJS) \ $(COMMON_OBJS) \ $(WIN_OBJS) \ $(7ZIP_COMMON_OBJS) \ - $(LZ_OBJS) \ $(C_OBJS) \ - $(C_LZ_OBJS) \ - $O\LzmaRamDecode.obj \ - $O\LzmaDecode.obj \ + $(C_LZMAUTIL_OBJS) \ $O\FileStreams.obj \ $O\FileIO.obj \ - $O\RangeCoderBit.obj \ - $O\BranchX86.obj \ - -all: $(PROGPATH) - -clean: - -del /Q $(PROGPATH) $O\*.exe $O\*.dll $O\*.obj $O\*.lib $O\*.exp $O\*.res $O\*.pch - -$O: - if not exist "$O" mkdir "$O" -$(PROGPATH): $O $(OBJS) - link $(LFLAGS) -out:$(PROGPATH) $(OBJS) $(LIBS) +!include "../../../Build.mak" $(LZMA_OBJS): $(*B).cpp @@ -116,21 +69,11 @@ $(WIN_OBJS): ../../../Windows/$(*B).cpp $(COMPL) $(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp $(COMPL) -$(LZ_OBJS): ../LZ/$(*B).cpp - $(COMPL) -$O\RangeCoderBit.obj: ../RangeCoder/$(*B).cpp - $(COMPL) -$O\LzmaRamDecode.obj: LzmaRamDecode.c - $(COMPL_O1) -$O\LzmaDecode.obj: ../../../../C/Compress/Lzma/LzmaDecode.c - $(COMPL_O2) -$O\BranchX86.obj: ../../../../C/Compress/Branch/BranchX86.c - $(COMPL_O2) $O\FileStreams.obj: ../../Common/FileStreams.cpp $(COMPL) $O\FileIO.obj: ../../../Windows/FileIO.cpp $(COMPL) $(C_OBJS): ../../../../C/$(*B).c $(COMPL_O2) -$(C_LZ_OBJS): ../../../../C/Compress/Lz/$(*B).c +$(C_LZMAUTIL_OBJS): ../../../../C/LzmaUtil/$(*B).c $(COMPL_O2) diff --git a/CPP/7zip/Compress/LZMA_Alone/makefile.gcc b/CPP/7zip/Compress/LZMA_Alone/makefile.gcc index 4fed05e6..b5a5f1d1 100755 --- a/CPP/7zip/Compress/LZMA_Alone/makefile.gcc +++ b/CPP/7zip/Compress/LZMA_Alone/makefile.gcc @@ -22,11 +22,8 @@ OBJS = \ LzmaAlone.o \ LzmaBench.o \ LzmaBenchCon.o \ - LzmaRam.o \ LZMADecoder.o \ LZMAEncoder.o \ - LZOutWindow.o \ - RangeCoderBit.o \ InBuffer.o \ OutBuffer.o \ FileStreams.o \ @@ -41,10 +38,12 @@ OBJS = \ MyVector.o \ 7zCrc.o \ Alloc.o \ - BranchX86.o \ - MatchFinder.o \ - LzmaDecode.o \ - LzmaRamDecode.o \ + Bra86.o \ + LzFind.o \ + LzmaDec.o \ + LzmaEnc.o \ + Lzma86Dec.o \ + Lzma86Enc.o \ all: $(PROG) @@ -61,21 +60,12 @@ LzmaBench.o: LzmaBench.cpp LzmaBenchCon.o: LzmaBenchCon.cpp $(CXX) $(CFLAGS) LzmaBenchCon.cpp -LzmaRam.o: LzmaRam.cpp - $(CXX) $(CFLAGS) LzmaRam.cpp - LZMADecoder.o: ../LZMA/LZMADecoder.cpp $(CXX) $(CFLAGS) ../LZMA/LZMADecoder.cpp LZMAEncoder.o: ../LZMA/LZMAEncoder.cpp $(CXX) $(CFLAGS) ../LZMA/LZMAEncoder.cpp -LZOutWindow.o: ../LZ/LZOutWindow.cpp - $(CXX) $(CFLAGS) ../LZ/LZOutWindow.cpp - -RangeCoderBit.o: ../RangeCoder/RangeCoderBit.cpp - $(CXX) $(CFLAGS) ../RangeCoder/RangeCoderBit.cpp - InBuffer.o: ../../Common/InBuffer.cpp $(CXX) $(CFLAGS) ../../Common/InBuffer.cpp @@ -122,17 +112,23 @@ MyVector.o: ../../../Common/MyVector.cpp Alloc.o: ../../../../C/Alloc.c $(CXX_C) $(CFLAGS) ../../../../C/Alloc.c -BranchX86.o: ../../../../C/Compress/Branch/BranchX86.c - $(CXX_C) $(CFLAGS) ../../../../C/Compress/Branch/BranchX86.c +Bra86.o: ../../../../C/Bra86.c + $(CXX_C) $(CFLAGS) ../../../../C/Bra86.c + +LzFind.o: ../../../../C/LzFind.c + $(CXX_C) $(CFLAGS) ../../../../C/LzFind.c + +LzmaDec.o: ../../../../C/LzmaDec.c + $(CXX_C) $(CFLAGS) ../../../../C/LzmaDec.c -MatchFinder.o: ../../../../C/Compress/Lz/MatchFinder.c - $(CXX_C) $(CFLAGS) ../../../../C/Compress/Lz/MatchFinder.c +LzmaEnc.o: ../../../../C/LzmaEnc.c + $(CXX_C) $(CFLAGS) ../../../../C/LzmaEnc.c -LzmaDecode.o: ../../../../C/Compress/Lzma/LzmaDecode.c - $(CXX_C) $(CFLAGS) ../../../../C/Compress/Lzma/LzmaDecode.c +Lzma86Dec.o: ../../../../C/LzmaUtil/Lzma86Dec.c + $(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Dec.c -LzmaRamDecode.o: LzmaRamDecode.c - $(CXX_C) $(CFLAGS) LzmaRamDecode.c +Lzma86Enc.o: ../../../../C/LzmaUtil/Lzma86Enc.c + $(CXX_C) $(CFLAGS) ../../../../C/LzmaUtil/Lzma86Enc.c clean: -$(RM) $(PROG) $(OBJS) diff --git a/CPP/7zip/Compress/Lzx/LzxDecoder.cpp b/CPP/7zip/Compress/Lzx/LzxDecoder.cpp index 5ed05b53..94ce6fc9 100755 --- a/CPP/7zip/Compress/Lzx/LzxDecoder.cpp +++ b/CPP/7zip/Compress/Lzx/LzxDecoder.cpp @@ -38,7 +38,7 @@ STDMETHODIMP CDecoder::Flush() return m_x86ConvertOutStreamSpec->Flush(); } -UInt32 CDecoder::ReadBits(UInt32 numBits) { return m_InBitStream.ReadBits(numBits); } +UInt32 CDecoder::ReadBits(int numBits) { return m_InBitStream.ReadBits(numBits); } #define RIF(x) { if (!(x)) return false; } @@ -63,12 +63,12 @@ bool CDecoder::ReadTable(Byte *lastLevels, Byte *newLevels, UInt32 numSymbols) UInt32 number = m_LevelDecoder.DecodeSymbol(&m_InBitStream); if (number == kLevelSymbolZeros) { - num = kLevelSymbolZerosStartValue + ReadBits(kLevelSymbolZerosNumBits); + num = kLevelSymbolZerosStartValue + (int)ReadBits(kLevelSymbolZerosNumBits); symbol = 0; } else if (number == kLevelSymbolZerosBig) { - num = kLevelSymbolZerosBigStartValue + ReadBits(kLevelSymbolZerosBigNumBits); + num = kLevelSymbolZerosBigStartValue + (int)ReadBits(kLevelSymbolZerosBigNumBits); symbol = 0; } else if (number == kLevelSymbolSame || number <= kNumHuffmanBits) @@ -77,7 +77,7 @@ bool CDecoder::ReadTable(Byte *lastLevels, Byte *newLevels, UInt32 numSymbols) num = 1; else { - num = kLevelSymbolSameStartValue + ReadBits(kLevelSymbolSameNumBits); + num = kLevelSymbolSameStartValue + (int)ReadBits(kLevelSymbolSameNumBits); number = m_LevelDecoder.DecodeSymbol(&m_InBitStream); if (number > kNumHuffmanBits) return false; @@ -262,7 +262,7 @@ HRESULT CDecoder::CodeSpec(UInt32 curSize) int numDirectBits; if (posSlot < kNumPowerPosSlots) { - numDirectBits = (posSlot >> 1) - 1; + numDirectBits = (int)(posSlot >> 1) - 1; distance = ((2 | (posSlot & 1)) << numDirectBits); } else @@ -297,7 +297,7 @@ HRESULT CDecoder::CodeSpec(UInt32 curSize) next -= locLen; if (len != 0) { - _remainLen = len; + _remainLen = (int)len; return S_OK; } } diff --git a/CPP/7zip/Compress/Lzx/LzxDecoder.h b/CPP/7zip/Compress/Lzx/LzxDecoder.h index 777067e0..4a577d38 100755 --- a/CPP/7zip/Compress/Lzx/LzxDecoder.h +++ b/CPP/7zip/Compress/Lzx/LzxDecoder.h @@ -63,7 +63,7 @@ public: void MovePos(UInt32 numBits) { - m_BitPos += numBits; + m_BitPos += (int)numBits; Normalize(); } @@ -76,8 +76,8 @@ public: UInt32 ReadBitsBig(int numBits) { - UInt32 numBits0 = numBits / 2; - UInt32 numBits1 = numBits - numBits0; + int numBits0 = numBits / 2; + int numBits1 = numBits - numBits0; UInt32 res = ReadBits(numBits0) << numBits1; return res + ReadBits(numBits1); } @@ -128,7 +128,7 @@ class CDecoder : bool _wimMode; - UInt32 ReadBits(UInt32 numBits); + UInt32 ReadBits(int numBits); bool ReadTable(Byte *lastLevels, Byte *newLevels, UInt32 numSymbols); bool ReadTables(); void ClearPrevLevels(); diff --git a/CPP/7zip/Compress/PPMD/PPMD.dsp b/CPP/7zip/Compress/PPMD/PPMD.dsp deleted file mode 100755 index c98d809d..00000000 --- a/CPP/7zip/Compress/PPMD/PPMD.dsp +++ /dev/null @@ -1,242 +0,0 @@ -# Microsoft Developer Studio Project File - Name="PPMD" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 - -CFG=PPMD - 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 "PPMD.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 "PPMD.mak" CFG="PPMD - Win32 Debug" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "PPMD - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") -!MESSAGE "PPMD - 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)" == "PPMD - 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 "PPMD_EXPORTS" /YX /FD /c -# ADD CPP /nologo /Gz /MD /W3 /GX /O1 /I "..\..\..\\" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "PPMD_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\PPMd.dll" /opt:NOWIN98 -# SUBTRACT LINK32 /pdb:none - -!ELSEIF "$(CFG)" == "PPMD - 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 "PPMD_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 "PPMD_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\PPMd.dll" /pdbtype:sept - -!ENDIF - -# Begin Target - -# Name "PPMD - Win32 Release" -# Name "PPMD - Win32 Debug" -# Begin Group "Spec" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\Codec.def -# End Source File -# Begin Source File - -SOURCE=..\CodecExports.cpp -# End Source File -# Begin Source File - -SOURCE=..\DllExports.cpp -# End Source File -# Begin Source File - -SOURCE=.\resource.rc -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.cpp -# ADD CPP /Yc -# End Source File -# Begin Source File - -SOURCE=.\StdAfx.h -# End Source File -# End Group -# Begin Group "PPMD" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\PPMDContext.h -# End Source File -# Begin Source File - -SOURCE=.\PPMDDecode.h -# End Source File -# Begin Source File - -SOURCE=.\PPMDDecoder.cpp - -!IF "$(CFG)" == "PPMD - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "PPMD - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\PPMDDecoder.h -# End Source File -# Begin Source File - -SOURCE=.\PPMDEncode.h -# End Source File -# Begin Source File - -SOURCE=.\PPMDEncoder.cpp - -!IF "$(CFG)" == "PPMD - Win32 Release" - -# ADD CPP /O2 -# SUBTRACT CPP /YX /Yc /Yu - -!ELSEIF "$(CFG)" == "PPMD - Win32 Debug" - -!ENDIF - -# End Source File -# Begin Source File - -SOURCE=.\PPMDEncoder.h -# End Source File -# Begin Source File - -SOURCE=.\PPMDRegister.cpp -# End Source File -# Begin Source File - -SOURCE=.\PPMDSubAlloc.h -# End Source File -# Begin Source File - -SOURCE=.\PPMDType.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\OutBuffer.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Common\OutBuffer.h -# End Source File -# Begin Source File - -SOURCE=..\..\Common\StreamUtils.cpp -# End Source File -# Begin Source File - -SOURCE=..\..\Common\StreamUtils.h -# End Source File -# End Group -# Begin Group "RangeCoder" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\RangeCoder\RangeCoder.h -# End Source File -# End Group -# Begin Group "Common" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\Common\Types.h -# End Source File -# End Group -# Begin Group "Ń" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=..\..\..\..\C\Alloc.c -# SUBTRACT CPP /YX /Yc /Yu -# End Source File -# Begin Source File - -SOURCE=..\..\..\..\C\Alloc.h -# End Source File -# End Group -# End Target -# End Project diff --git a/CPP/7zip/Compress/PPMD/PPMD.dsw b/CPP/7zip/Compress/PPMD/PPMD.dsw deleted file mode 100755 index 8032f3db..00000000 --- a/CPP/7zip/Compress/PPMD/PPMD.dsw +++ /dev/null @@ -1,29 +0,0 @@ -Microsoft Developer Studio Workspace File, Format Version 6.00 -# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! - -############################################################################### - -Project: "PPMD"=.\PPMD.dsp - Package Owner=<4> - -Package=<5> -{{{ -}}} - -Package=<4> -{{{ -}}} - -############################################################################### - -Global: - -Package=<5> -{{{ -}}} - -Package=<3> -{{{ -}}} - -############################################################################### - diff --git a/CPP/7zip/Compress/PPMD/PPMDEncoder.cpp b/CPP/7zip/Compress/PPMD/PPMDEncoder.cpp index fe99ea5a..cefd2478 100755 --- a/CPP/7zip/Compress/PPMD/PPMDEncoder.cpp +++ b/CPP/7zip/Compress/PPMD/PPMDEncoder.cpp @@ -81,7 +81,7 @@ STDMETHODIMP CEncoder::WriteCoderProperties(ISequentialOutStream *outStream) properties[0] = _order; for (int i = 0; i < 4; i++) properties[1 + i] = Byte(_usedMemorySize >> (8 * i)); - return WriteStream(outStream, properties, kPropSize, NULL); + return WriteStream(outStream, properties, kPropSize); } const UInt32 kUsedMemorySizeDefault = (1 << 24); diff --git a/CPP/7zip/Compress/PPMD/makefile b/CPP/7zip/Compress/PPMD/makefile deleted file mode 100755 index f146edb0..00000000 --- a/CPP/7zip/Compress/PPMD/makefile +++ /dev/null @@ -1,43 +0,0 @@ -PROG = PPMd.dll -DEF_FILE = ../Codec.def -CFLAGS = $(CFLAGS) -I ../../../ -D_7ZIP_LARGE_PAGES -LIBS = $(LIBS) oleaut32.lib - -COMPRESS_OBJS = \ - $O\CodecExports.obj \ - $O\DllExports.obj \ - -PPMD_OPT_OBJS = \ - $O\PPMDDecoder.obj \ - $O\PPMDEncoder.obj \ - $O\PPMDRegister.obj \ - -7ZIP_COMMON_OBJS = \ - $O\InBuffer.obj \ - $O\OutBuffer.obj \ - $O\StreamUtils.obj \ - -C_OBJS = \ - $O\Alloc.obj \ - -OBJS = \ - $O\StdAfx.obj \ - $(COMPRESS_OBJS) \ - $(PPMD_OPT_OBJS) \ - $(7ZIP_COMMON_OBJS) \ - $(C_OBJS) \ - $O\resource.res - - -!include "../../../Build.mak" - -$(COMPRESS_OBJS): ../$(*B).cpp - $(COMPL) -$(PPMD_OPT_OBJS): $(*B).cpp - $(COMPL_O2) -$(7ZIP_COMMON_OBJS): ../../Common/$(*B).cpp - $(COMPL) -$(C_OBJS): ../../../../C/$(*B).c - $(COMPL_O2) - - diff --git a/CPP/7zip/Compress/PPMD/resource.rc b/CPP/7zip/Compress/PPMD/resource.rc deleted file mode 100755 index fed98e19..00000000 --- a/CPP/7zip/Compress/PPMD/resource.rc +++ /dev/null @@ -1,3 +0,0 @@ -#include "../../MyVersionInfo.rc" - -MY_VERSION_INFO_DLL("PPMd Codec", "PPMd") diff --git a/CPP/7zip/Compress/RangeCoder/RangeCoder.h b/CPP/7zip/Compress/RangeCoder/RangeCoder.h index bbb2ba82..0a6b4064 100755 --- a/CPP/7zip/Compress/RangeCoder/RangeCoder.h +++ b/CPP/7zip/Compress/RangeCoder/RangeCoder.h @@ -71,13 +71,12 @@ public: Low = (UInt32)Low << 8; } - void EncodeDirectBits(UInt32 value, int numTotalBits) + void EncodeDirectBits(UInt32 value, int numBits) { - for (int i = numTotalBits - 1; i >= 0; i--) + for (numBits--; numBits >= 0; numBits--) { Range >>= 1; - if (((value >> i) & 1) == 1) - Low += Range; + Low += Range & (0 - ((value >> numBits) & 1)); if (Range < kTopValue) { Range <<= 8; diff --git a/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp b/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp index 8e4c4d3a..9a7c0a05 100755 --- a/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp +++ b/CPP/7zip/Compress/RangeCoder/RangeCoderBit.cpp @@ -7,74 +7,30 @@ namespace NCompress { namespace NRangeCoder { -UInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits]; -static CPriceTables g_PriceTables; - -CPriceTables::CPriceTables() { Init(); } +UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits]; -void CPriceTables::Init() +struct CPriceTables { CPriceTables() { - const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits); - for(int i = kNumBits - 1; i >= 0; i--) - { - UInt32 start = 1 << (kNumBits - i - 1); - UInt32 end = 1 << (kNumBits - i); - for (UInt32 j = start; j < end; j++) - ProbPrices[j] = (i << kNumBitPriceShiftBits) + - (((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1)); - } - - /* - // simplest: bad solution - for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++) - ProbPrices[i] = kBitPrice; - */ - - /* - const double kDummyMultMid = (1.0 / kBitPrice) / 2; - const double kDummyMultMid = 0; - // float solution - double ln2 = log(double(2)); - double lnAll = log(double(kBitModelTotal >> kNumMoveReducingBits)); - for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++) - ProbPrices[i] = UInt32((fabs(lnAll - log(double(i))) / ln2 + kDummyMultMid) * kBitPrice); - */ - - /* - // experimental, slow, solution: - for(UInt32 i = 1; i < (kBitModelTotal >> kNumMoveReducingBits) - 1; i++) + for (UInt32 i = (1 << kNumMoveReducingBits) / 2; i < kBitModelTotal; i += (1 << kNumMoveReducingBits)) { - const int kCyclesBits = 5; - const UInt32 kCycles = (1 << kCyclesBits); - - UInt32 range = UInt32(-1); + const int kCyclesBits = kNumBitPriceShiftBits; + UInt32 w = i; UInt32 bitCount = 0; - for (UInt32 j = 0; j < kCycles; j++) + for (int j = 0; j < kCyclesBits; j++) { - range >>= (kNumBitModelTotalBits - kNumMoveReducingBits); - range *= i; - while(range < (1 << 31)) + w = w * w; + bitCount <<= 1; + while (w >= ((UInt32)1 << 16)) { - range <<= 1; + w >>= 1; bitCount++; } } - bitCount <<= kNumBitPriceShiftBits; - range -= (1 << 31); - for (int k = kNumBitPriceShiftBits - 1; k >= 0; k--) - { - range <<= 1; - if (range > (1 << 31)) - { - bitCount += (1 << k); - range -= (1 << 31); - } - } - ProbPrices[i] = (bitCount - // + (1 << (kCyclesBits - 1)) - ) >> kCyclesBits; + ProbPrices[i >> kNumMoveReducingBits] = ((kNumBitModelTotalBits << kCyclesBits) - 15 - bitCount); } - */ } +}; + +static CPriceTables g_PriceTables; }} diff --git a/CPP/7zip/Compress/RangeCoder/RangeCoderBit.h b/CPP/7zip/Compress/RangeCoder/RangeCoderBit.h index 624f887c..0ac50dfe 100755 --- a/CPP/7zip/Compress/RangeCoder/RangeCoderBit.h +++ b/CPP/7zip/Compress/RangeCoder/RangeCoderBit.h @@ -11,18 +11,12 @@ namespace NRangeCoder { const int kNumBitModelTotalBits = 11; const UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits); -const int kNumMoveReducingBits = 2; +const int kNumMoveReducingBits = 4; -const int kNumBitPriceShiftBits = 6; +const int kNumBitPriceShiftBits = 4; const UInt32 kBitPrice = 1 << kNumBitPriceShiftBits; -class CPriceTables -{ -public: - static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits]; - static void Init(); - CPriceTables(); -}; +extern UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits]; template <int numMoveBits> class CBitModel @@ -74,11 +68,10 @@ public: } UInt32 GetPrice(UInt32 symbol) const { - return CPriceTables::ProbPrices[ - (((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits]; + return ProbPrices[(this->Prob ^ ((-(int)symbol)) & (kBitModelTotal - 1)) >> kNumMoveReducingBits]; } - UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; } - UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; } + UInt32 GetPrice0() const { return ProbPrices[this->Prob >> kNumMoveReducingBits]; } + UInt32 GetPrice1() const { return ProbPrices[(this->Prob ^ (kBitModelTotal - 1)) >> kNumMoveReducingBits]; } }; diff --git a/CPP/7zip/Compress/RangeCoder/RangeCoderBitTree.h b/CPP/7zip/Compress/RangeCoder/RangeCoderBitTree.h index 4f0c78b4..97dd9b38 100755 --- a/CPP/7zip/Compress/RangeCoder/RangeCoderBitTree.h +++ b/CPP/7zip/Compress/RangeCoder/RangeCoderBitTree.h @@ -16,7 +16,7 @@ class CBitTreeEncoder public: void Init() { - for(UInt32 i = 1; i < (1 << NumBitLevels); i++) + for(UInt32 i = 0; i < (1 << NumBitLevels); i++) Models[i].Init(); } void Encode(CEncoder *rangeEncoder, UInt32 symbol) @@ -74,7 +74,7 @@ class CBitTreeDecoder public: void Init() { - for(UInt32 i = 1; i < (1 << NumBitLevels); i++) + for(UInt32 i = 0; i < (1 << NumBitLevels); i++) Models[i].Init(); } UInt32 Decode(CDecoder *rangeDecoder) diff --git a/CPP/7zip/Compress/Rar/Rar29.dsp b/CPP/7zip/Compress/Rar/Rar29.dsp index c5ee2228..9eb36ac3 100755 --- a/CPP/7zip/Compress/Rar/Rar29.dsp +++ b/CPP/7zip/Compress/Rar/Rar29.dsp @@ -182,19 +182,19 @@ SOURCE=..\..\..\Common\CRC.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.cpp +SOURCE=..\..\..\Common\MyVector.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\NewHandler.h +SOURCE=..\..\..\Common\MyVector.h # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.cpp +SOURCE=..\..\..\Common\NewHandler.cpp # End Source File # Begin Source File -SOURCE=..\..\..\Common\Vector.h +SOURCE=..\..\..\Common\NewHandler.h # End Source File # End Group # Begin Group "Rar3" diff --git a/CPP/7zip/Compress/Rar/Rar2Decoder.cpp b/CPP/7zip/Compress/Rar/Rar2Decoder.cpp index 057a1a60..28d50213 100755 --- a/CPP/7zip/Compress/Rar/Rar2Decoder.cpp +++ b/CPP/7zip/Compress/Rar/Rar2Decoder.cpp @@ -69,16 +69,6 @@ Byte CFilter::Decode(int &channelDelta, Byte deltaByte) } } -class CException -{ -public: - enum ECauseType - { - kData - } Cause; - CException(ECauseType cause): Cause(cause) {} -}; - static const char *kNumberErrorMessage = "Number error"; static const UInt32 kHistorySize = 1 << 20; @@ -307,7 +297,7 @@ bool CDecoder::DecodeLz(Int32 pos) return true; } -STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream, +HRESULT CDecoder::CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress) { @@ -373,7 +363,7 @@ STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream, } } if (pos > unPackSize) - throw CException(CException::kData); + return S_FALSE; if (!ReadLastTables()) return S_FALSE; diff --git a/CPP/7zip/Compress/Rar/Rar2Decoder.h b/CPP/7zip/Compress/Rar/Rar2Decoder.h index 9567de0a..7906b1fc 100755 --- a/CPP/7zip/Compress/Rar/Rar2Decoder.h +++ b/CPP/7zip/Compress/Rar/Rar2Decoder.h @@ -147,6 +147,10 @@ class CDecoder : bool DecodeMm(UInt32 pos); bool DecodeLz(Int32 pos); + HRESULT CodeReal(ISequentialInStream *inStream, + ISequentialOutStream *outStream, const UInt64 *inSize, const UInt64 *outSize, + ICompressProgressInfo *progress); + public: CDecoder(); @@ -158,10 +162,6 @@ public: m_InBitStream.ReleaseStream(); } - 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); diff --git a/CPP/7zip/Compress/Rar/Rar3Decoder.cpp b/CPP/7zip/Compress/Rar/Rar3Decoder.cpp index e629f4df..5ba13646 100755 --- a/CPP/7zip/Compress/Rar/Rar3Decoder.cpp +++ b/CPP/7zip/Compress/Rar/Rar3Decoder.cpp @@ -58,11 +58,7 @@ CDecoder::~CDecoder() HRESULT CDecoder::WriteDataToStream(const Byte *data, UInt32 size) { - UInt32 processedSize; - HRESULT res = WriteStream(_outStream, data, size, &processedSize); - if (res == S_OK && processedSize != size) - res = E_FAIL; - return res; + return WriteStream(_outStream, data, size); } HRESULT CDecoder::WriteData(const Byte *data, UInt32 size) diff --git a/CPP/7zip/Compress/Rar/Rar3Vm.h b/CPP/7zip/Compress/Rar/Rar3Vm.h index d31fcd0a..8b2e01f1 100755 --- a/CPP/7zip/Compress/Rar/Rar3Vm.h +++ b/CPP/7zip/Compress/Rar/Rar3Vm.h @@ -11,9 +11,6 @@ #include "../../../../C/CpuArch.h" #define RARVM_STANDARD_FILTERS -#ifdef LITTLE_ENDIAN_UNALIGN -#define RARVM_LITTLE_ENDIAN_UNALIGN -#endif namespace NCompress { namespace NRar3 { @@ -37,27 +34,8 @@ public: namespace NVm { -inline UInt32 GetValue32(const void *addr) -{ - #ifdef RARVM_LITTLE_ENDIAN_UNALIGN - return *(const UInt32 *)addr; - #else - const Byte *b = (const Byte *)addr; - return UInt32((UInt32)b[0]|((UInt32)b[1]<<8)|((UInt32)b[2]<<16)|((UInt32)b[3]<<24)); - #endif -} - -inline void SetValue32(void *addr, UInt32 value) -{ - #ifdef RARVM_LITTLE_ENDIAN_UNALIGN - *(UInt32 *)addr = value; - #else - ((Byte *)addr)[0] = (Byte)value; - ((Byte *)addr)[1] = (Byte)(value >> 8); - ((Byte *)addr)[2] = (Byte)(value >> 16); - ((Byte *)addr)[3] = (Byte)(value >> 24); - #endif -} +inline UInt32 GetValue32(const void *addr) { return GetUi32(addr); } +inline void SetValue32(void *addr, UInt32 value) { SetUi32(addr, value); } UInt32 ReadEncodedUInt32(CMemBitDecoder &inp); @@ -147,14 +125,7 @@ class CVm if (byteMode) return(*(const Byte *)addr); else - { - #ifdef RARVM_LITTLE_ENDIAN_UNALIGN - return *(const UInt32 *)addr; - #else - const Byte *b = (const Byte *)addr; - return UInt32((UInt32)b[0]|((UInt32)b[1]<<8)|((UInt32)b[2]<<16)|((UInt32)b[3]<<24)); - #endif - } + return GetUi32(addr); } static void SetValue(bool byteMode, void *addr, UInt32 value) @@ -162,16 +133,7 @@ class CVm if (byteMode) *(Byte *)addr = (Byte)value; else - { - #ifdef RARVM_LITTLE_ENDIAN_UNALIGN - *(UInt32 *)addr = value; - #else - ((Byte *)addr)[0] = (Byte)value; - ((Byte *)addr)[1] = (Byte)(value >> 8); - ((Byte *)addr)[2] = (Byte)(value >> 16); - ((Byte *)addr)[3] = (Byte)(value >> 24); - #endif - } + SetUi32(addr, value); } UInt32 GetFixedGlobalValue32(UInt32 globalOffset) { return GetValue(false, &Mem[kGlobalOffset + globalOffset]); } diff --git a/CPP/7zip/Compress/Rar/makefile b/CPP/7zip/Compress/Rar/makefile index f55bf17e..27cedbd9 100755 --- a/CPP/7zip/Compress/Rar/makefile +++ b/CPP/7zip/Compress/Rar/makefile @@ -16,7 +16,7 @@ RAR29_OPT_OBJS = \ COMMON_OBJS = \ $O\CRC.obj \ - $O\Vector.obj \ + $O\MyVector.obj \ 7ZIP_COMMON_OBJS = \ $O\InBuffer.obj \ |