PhysicsFS 2.0.3 imported.
This commit is contained in:
parent
bcc0937726
commit
993311d151
459 changed files with 87785 additions and 0 deletions
19
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/ARM.cpp
Normal file
19
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/ARM.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
// 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);
|
||||
}
|
10
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/ARM.h
Normal file
10
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/ARM.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
// ARM.h
|
||||
|
||||
#ifndef __ARM_H
|
||||
#define __ARM_H
|
||||
|
||||
#include "BranchCoder.h"
|
||||
|
||||
MyClassA(BC_ARM, 0x05, 1)
|
||||
|
||||
#endif
|
20
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/ARMThumb.cpp
Normal file
20
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/ARMThumb.cpp
Normal file
|
@ -0,0 +1,20 @@
|
|||
// 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);
|
||||
}
|
10
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/ARMThumb.h
Normal file
10
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/ARMThumb.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
// ARMThumb.h
|
||||
|
||||
#ifndef __ARMTHUMB_H
|
||||
#define __ARMTHUMB_H
|
||||
|
||||
#include "BranchCoder.h"
|
||||
|
||||
MyClassA(BC_ARMThumb, 0x07, 1)
|
||||
|
||||
#endif
|
|
@ -0,0 +1,18 @@
|
|||
// BranchRegister.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../Common/RegisterCodec.h"
|
||||
|
||||
#include "x86_2.h"
|
||||
static void *CreateCodec() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CDecoder()); }
|
||||
#ifndef EXTRACT_ONLY
|
||||
static void *CreateCodecOut() { return (void *)(ICompressCoder2 *)(new NCompress::NBcj2::CEncoder()); }
|
||||
#else
|
||||
#define CreateCodecOut 0
|
||||
#endif
|
||||
|
||||
static CCodecInfo g_CodecInfo =
|
||||
{ CreateCodec, CreateCodecOut, 0x0303011B, L"BCJ2", 4, false };
|
||||
|
||||
REGISTER_CODEC(BCJ2)
|
|
@ -0,0 +1,18 @@
|
|||
// BranchRegister.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../Common/RegisterCodec.h"
|
||||
|
||||
#include "x86.h"
|
||||
static void *CreateCodec() { return (void *)(ICompressFilter *)(new CBCJ_x86_Decoder()); }
|
||||
#ifndef EXTRACT_ONLY
|
||||
static void *CreateCodecOut() { return (void *)(ICompressFilter *)(new CBCJ_x86_Encoder()); }
|
||||
#else
|
||||
#define CreateCodecOut 0
|
||||
#endif
|
||||
|
||||
static CCodecInfo g_CodecInfo =
|
||||
{ CreateCodec, CreateCodecOut, 0x03030103, L"BCJ", 1, true };
|
||||
|
||||
REGISTER_CODEC(BCJ)
|
|
@ -0,0 +1,18 @@
|
|||
// BranchCoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "BranchCoder.h"
|
||||
|
||||
STDMETHODIMP CBranchConverter::Init()
|
||||
{
|
||||
_bufferPos = 0;
|
||||
SubInit();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP_(UInt32) CBranchConverter::Filter(Byte *data, UInt32 size)
|
||||
{
|
||||
UInt32 processedSize = SubFilter(data, size);
|
||||
_bufferPos += processedSize;
|
||||
return processedSize;
|
||||
}
|
45
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/BranchCoder.h
Normal file
45
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/BranchCoder.h
Normal file
|
@ -0,0 +1,45 @@
|
|||
// BranchCoder.h
|
||||
|
||||
#ifndef __BRANCH_CODER_H
|
||||
#define __BRANCH_CODER_H
|
||||
|
||||
#include "Common/MyCom.h"
|
||||
#include "Common/Types.h"
|
||||
|
||||
#include "../../ICoder.h"
|
||||
|
||||
class CBranchConverter:
|
||||
public ICompressFilter,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
protected:
|
||||
UInt32 _bufferPos;
|
||||
virtual void SubInit() {}
|
||||
virtual UInt32 SubFilter(Byte *data, UInt32 size) = 0;
|
||||
public:
|
||||
MY_UNKNOWN_IMP;
|
||||
STDMETHOD(Init)();
|
||||
STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
|
||||
};
|
||||
|
||||
#define MyClassEncoderA(Name) class C ## Name: public CBranchConverter \
|
||||
{ public: UInt32 SubFilter(Byte *data, UInt32 size); };
|
||||
|
||||
#define MyClassDecoderA(Name) class C ## Name: public CBranchConverter \
|
||||
{ public: UInt32 SubFilter(Byte *data, UInt32 size); };
|
||||
|
||||
#define MyClassEncoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \
|
||||
{ public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};
|
||||
|
||||
#define MyClassDecoderB(Name, ADD_ITEMS, ADD_INIT) class C ## Name: public CBranchConverter, public ADD_ITEMS \
|
||||
{ public: UInt32 SubFilter(Byte *data, UInt32 size); ADD_INIT};
|
||||
|
||||
#define MyClassA(Name, id, subId) \
|
||||
MyClassEncoderA(Name ## _Encoder) \
|
||||
MyClassDecoderA(Name ## _Decoder)
|
||||
|
||||
#define MyClassB(Name, id, subId, ADD_ITEMS, ADD_INIT) \
|
||||
MyClassEncoderB(Name ## _Encoder, ADD_ITEMS, ADD_INIT) \
|
||||
MyClassDecoderB(Name ## _Decoder, ADD_ITEMS, ADD_INIT)
|
||||
|
||||
#endif
|
|
@ -0,0 +1,34 @@
|
|||
// BranchRegister.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../Common/RegisterCodec.h"
|
||||
|
||||
#include "PPC.h"
|
||||
#include "IA64.h"
|
||||
#include "ARM.h"
|
||||
#include "ARMThumb.h"
|
||||
#include "SPARC.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_IA64)
|
||||
CREATE_CODEC(BC_ARM)
|
||||
CREATE_CODEC(BC_ARMThumb)
|
||||
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")
|
||||
};
|
||||
|
||||
REGISTER_CODECS(Branch)
|
19
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/IA64.cpp
Normal file
19
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/IA64.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
// 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);
|
||||
}
|
10
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/IA64.h
Normal file
10
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/IA64.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
// IA64.h
|
||||
|
||||
#ifndef __IA64_H
|
||||
#define __IA64_H
|
||||
|
||||
#include "BranchCoder.h"
|
||||
|
||||
MyClassA(BC_IA64, 0x04, 1)
|
||||
|
||||
#endif
|
19
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/PPC.cpp
Normal file
19
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/PPC.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
// 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);
|
||||
}
|
10
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/PPC.h
Normal file
10
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/PPC.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
// PPC.h
|
||||
|
||||
#ifndef __PPC_H
|
||||
#define __PPC_H
|
||||
|
||||
#include "BranchCoder.h"
|
||||
|
||||
MyClassA(BC_PPC_B, 0x02, 5)
|
||||
|
||||
#endif
|
19
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/SPARC.cpp
Normal file
19
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/SPARC.cpp
Normal file
|
@ -0,0 +1,19 @@
|
|||
// 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);
|
||||
}
|
10
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/SPARC.h
Normal file
10
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/SPARC.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
// SPARC.h
|
||||
|
||||
#ifndef __SPARC_H
|
||||
#define __SPARC_H
|
||||
|
||||
#include "BranchCoder.h"
|
||||
|
||||
MyClassA(BC_SPARC, 0x08, 5)
|
||||
|
||||
#endif
|
|
@ -0,0 +1,3 @@
|
|||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
8
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/StdAfx.h
Normal file
8
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/StdAfx.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include "../../../Common/MyWindows.h"
|
||||
|
||||
#endif
|
14
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/x86.cpp
Normal file
14
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/x86.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
// x86.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "x86.h"
|
||||
|
||||
UInt32 CBCJ_x86_Encoder::SubFilter(Byte *data, UInt32 size)
|
||||
{
|
||||
return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 1);
|
||||
}
|
||||
|
||||
UInt32 CBCJ_x86_Decoder::SubFilter(Byte *data, UInt32 size)
|
||||
{
|
||||
return (UInt32)::x86_Convert(data, size, _bufferPos, &_prevMask, 0);
|
||||
}
|
21
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/x86.h
Normal file
21
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/x86.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
// x86.h
|
||||
|
||||
#ifndef __X86_H
|
||||
#define __X86_H
|
||||
|
||||
#include "BranchCoder.h"
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Compress/Branch/BranchX86.h"
|
||||
}
|
||||
|
||||
struct CBranch86
|
||||
{
|
||||
UInt32 _prevMask;
|
||||
void x86Init() { x86_Convert_Init(_prevMask); }
|
||||
};
|
||||
|
||||
MyClassB(BCJ_x86, 0x01, 3, CBranch86 ,
|
||||
virtual void SubInit() { x86Init(); })
|
||||
|
||||
#endif
|
392
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/x86_2.cpp
Normal file
392
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/x86_2.cpp
Normal file
|
@ -0,0 +1,392 @@
|
|||
// x86_2.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
#include "x86_2.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
}
|
||||
|
||||
namespace NCompress {
|
||||
namespace NBcj2 {
|
||||
|
||||
inline bool IsJcc(Byte b0, Byte b1) { return (b0 == 0x0F && (b1 & 0xF0) == 0x80); }
|
||||
inline bool IsJ(Byte b0, Byte b1) { return ((b1 & 0xFE) == 0xE8 || IsJcc(b0, b1)); }
|
||||
inline unsigned GetIndex(Byte b0, Byte b1) { return ((b1 == 0xE8) ? b0 : ((b1 == 0xE9) ? 256 : 257)); }
|
||||
|
||||
#ifndef EXTRACT_ONLY
|
||||
|
||||
static const int kBufferSize = 1 << 17;
|
||||
|
||||
static bool inline Test86MSByte(Byte b)
|
||||
{
|
||||
return (b == 0 || b == 0xFF);
|
||||
}
|
||||
|
||||
bool CEncoder::Create()
|
||||
{
|
||||
if (!_mainStream.Create(1 << 16))
|
||||
return false;
|
||||
if (!_callStream.Create(1 << 20))
|
||||
return false;
|
||||
if (!_jumpStream.Create(1 << 20))
|
||||
return false;
|
||||
if (!_rangeEncoder.Create(1 << 20))
|
||||
return false;
|
||||
if (_buffer == 0)
|
||||
{
|
||||
_buffer = (Byte *)MidAlloc(kBufferSize);
|
||||
if (_buffer == 0)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
CEncoder::~CEncoder()
|
||||
{
|
||||
::MidFree(_buffer);
|
||||
}
|
||||
|
||||
HRESULT CEncoder::Flush()
|
||||
{
|
||||
RINOK(_mainStream.Flush());
|
||||
RINOK(_callStream.Flush());
|
||||
RINOK(_jumpStream.Flush());
|
||||
_rangeEncoder.FlushData();
|
||||
return _rangeEncoder.FlushStream();
|
||||
}
|
||||
|
||||
const UInt32 kDefaultLimit = (1 << 24);
|
||||
|
||||
HRESULT CEncoder::CodeReal(ISequentialInStream **inStreams,
|
||||
const UInt64 **inSizes,
|
||||
UInt32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UInt64 ** /* outSizes */,
|
||||
UInt32 numOutStreams,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (numInStreams != 1 || numOutStreams != 4)
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (!Create())
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
bool sizeIsDefined = false;
|
||||
UInt64 inSize = 0;
|
||||
if (inSizes != NULL)
|
||||
if (inSizes[0] != NULL)
|
||||
{
|
||||
inSize = *inSizes[0];
|
||||
if (inSize <= kDefaultLimit)
|
||||
sizeIsDefined = true;
|
||||
}
|
||||
|
||||
ISequentialInStream *inStream = inStreams[0];
|
||||
|
||||
_mainStream.SetStream(outStreams[0]);
|
||||
_mainStream.Init();
|
||||
_callStream.SetStream(outStreams[1]);
|
||||
_callStream.Init();
|
||||
_jumpStream.SetStream(outStreams[2]);
|
||||
_jumpStream.Init();
|
||||
_rangeEncoder.SetStream(outStreams[3]);
|
||||
_rangeEncoder.Init();
|
||||
for (int i = 0; i < 256 + 2; i++)
|
||||
_statusEncoder[i].Init();
|
||||
CCoderReleaser releaser(this);
|
||||
|
||||
CMyComPtr<ICompressGetSubStreamSize> getSubStreamSize;
|
||||
{
|
||||
inStream->QueryInterface(IID_ICompressGetSubStreamSize, (void **)&getSubStreamSize);
|
||||
}
|
||||
|
||||
UInt32 nowPos = 0;
|
||||
UInt64 nowPos64 = 0;
|
||||
UInt32 bufferPos = 0;
|
||||
|
||||
Byte prevByte = 0;
|
||||
|
||||
UInt64 subStreamIndex = 0;
|
||||
UInt64 subStreamStartPos = 0;
|
||||
UInt64 subStreamEndPos = 0;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
UInt32 processedSize = 0;
|
||||
for (;;)
|
||||
{
|
||||
UInt32 size = kBufferSize - (bufferPos + processedSize);
|
||||
UInt32 processedSizeLoc;
|
||||
if (size == 0)
|
||||
break;
|
||||
RINOK(inStream->Read(_buffer + bufferPos + processedSize, size, &processedSizeLoc));
|
||||
if (processedSizeLoc == 0)
|
||||
break;
|
||||
processedSize += processedSizeLoc;
|
||||
}
|
||||
UInt32 endPos = bufferPos + processedSize;
|
||||
|
||||
if (endPos < 5)
|
||||
{
|
||||
// change it
|
||||
for (bufferPos = 0; bufferPos < endPos; bufferPos++)
|
||||
{
|
||||
Byte b = _buffer[bufferPos];
|
||||
_mainStream.WriteByte(b);
|
||||
UInt32 index;
|
||||
if (b == 0xE8)
|
||||
index = prevByte;
|
||||
else if (b == 0xE9)
|
||||
index = 256;
|
||||
else if (IsJcc(prevByte, b))
|
||||
index = 257;
|
||||
else
|
||||
{
|
||||
prevByte = b;
|
||||
continue;
|
||||
}
|
||||
_statusEncoder[index].Encode(&_rangeEncoder, 0);
|
||||
prevByte = b;
|
||||
}
|
||||
return Flush();
|
||||
}
|
||||
|
||||
bufferPos = 0;
|
||||
|
||||
UInt32 limit = endPos - 5;
|
||||
while(bufferPos <= limit)
|
||||
{
|
||||
Byte b = _buffer[bufferPos];
|
||||
_mainStream.WriteByte(b);
|
||||
if (!IsJ(prevByte, b))
|
||||
{
|
||||
bufferPos++;
|
||||
prevByte = b;
|
||||
continue;
|
||||
}
|
||||
Byte nextByte = _buffer[bufferPos + 4];
|
||||
UInt32 src =
|
||||
(UInt32(nextByte) << 24) |
|
||||
(UInt32(_buffer[bufferPos + 3]) << 16) |
|
||||
(UInt32(_buffer[bufferPos + 2]) << 8) |
|
||||
(_buffer[bufferPos + 1]);
|
||||
UInt32 dest = (nowPos + bufferPos + 5) + src;
|
||||
// if (Test86MSByte(nextByte))
|
||||
bool convert;
|
||||
if (getSubStreamSize != NULL)
|
||||
{
|
||||
UInt64 currentPos = (nowPos64 + bufferPos);
|
||||
while (subStreamEndPos < currentPos)
|
||||
{
|
||||
UInt64 subStreamSize;
|
||||
HRESULT result = getSubStreamSize->GetSubStreamSize(subStreamIndex, &subStreamSize);
|
||||
if (result == S_OK)
|
||||
{
|
||||
subStreamStartPos = subStreamEndPos;
|
||||
subStreamEndPos += subStreamSize;
|
||||
subStreamIndex++;
|
||||
}
|
||||
else if (result == S_FALSE || result == E_NOTIMPL)
|
||||
{
|
||||
getSubStreamSize.Release();
|
||||
subStreamStartPos = 0;
|
||||
subStreamEndPos = subStreamStartPos - 1;
|
||||
}
|
||||
else
|
||||
return result;
|
||||
}
|
||||
if (getSubStreamSize == NULL)
|
||||
{
|
||||
if (sizeIsDefined)
|
||||
convert = (dest < inSize);
|
||||
else
|
||||
convert = Test86MSByte(nextByte);
|
||||
}
|
||||
else if (subStreamEndPos - subStreamStartPos > kDefaultLimit)
|
||||
convert = Test86MSByte(nextByte);
|
||||
else
|
||||
{
|
||||
UInt64 dest64 = (currentPos + 5) + Int64(Int32(src));
|
||||
convert = (dest64 >= subStreamStartPos && dest64 < subStreamEndPos);
|
||||
}
|
||||
}
|
||||
else if (sizeIsDefined)
|
||||
convert = (dest < inSize);
|
||||
else
|
||||
convert = Test86MSByte(nextByte);
|
||||
unsigned index = GetIndex(prevByte, b);
|
||||
if (convert)
|
||||
{
|
||||
_statusEncoder[index].Encode(&_rangeEncoder, 1);
|
||||
bufferPos += 5;
|
||||
COutBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;
|
||||
for (int i = 24; i >= 0; i -= 8)
|
||||
s.WriteByte((Byte)(dest >> i));
|
||||
prevByte = nextByte;
|
||||
}
|
||||
else
|
||||
{
|
||||
_statusEncoder[index].Encode(&_rangeEncoder, 0);
|
||||
bufferPos++;
|
||||
prevByte = b;
|
||||
}
|
||||
}
|
||||
nowPos += bufferPos;
|
||||
nowPos64 += bufferPos;
|
||||
|
||||
if (progress != NULL)
|
||||
{
|
||||
/*
|
||||
const UInt64 compressedSize =
|
||||
_mainStream.GetProcessedSize() +
|
||||
_callStream.GetProcessedSize() +
|
||||
_jumpStream.GetProcessedSize() +
|
||||
_rangeEncoder.GetProcessedSize();
|
||||
*/
|
||||
RINOK(progress->SetRatioInfo(&nowPos64, NULL));
|
||||
}
|
||||
|
||||
UInt32 i = 0;
|
||||
while(bufferPos < endPos)
|
||||
_buffer[i++] = _buffer[bufferPos++];
|
||||
bufferPos = i;
|
||||
}
|
||||
}
|
||||
|
||||
STDMETHODIMP CEncoder::Code(ISequentialInStream **inStreams,
|
||||
const UInt64 **inSizes,
|
||||
UInt32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UInt64 **outSizes,
|
||||
UInt32 numOutStreams,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
try
|
||||
{
|
||||
return CodeReal(inStreams, inSizes, numInStreams,
|
||||
outStreams, outSizes,numOutStreams, progress);
|
||||
}
|
||||
catch(const COutBufferException &e) { return e.ErrorCode; }
|
||||
catch(...) { return S_FALSE; }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
HRESULT CDecoder::CodeReal(ISequentialInStream **inStreams,
|
||||
const UInt64 ** /* inSizes */,
|
||||
UInt32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UInt64 ** /* outSizes */,
|
||||
UInt32 numOutStreams,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (numInStreams != 4 || numOutStreams != 1)
|
||||
return E_INVALIDARG;
|
||||
|
||||
if (!_mainInStream.Create(1 << 16))
|
||||
return E_OUTOFMEMORY;
|
||||
if (!_callStream.Create(1 << 20))
|
||||
return E_OUTOFMEMORY;
|
||||
if (!_jumpStream.Create(1 << 16))
|
||||
return E_OUTOFMEMORY;
|
||||
if (!_rangeDecoder.Create(1 << 20))
|
||||
return E_OUTOFMEMORY;
|
||||
if (!_outStream.Create(1 << 16))
|
||||
return E_OUTOFMEMORY;
|
||||
|
||||
_mainInStream.SetStream(inStreams[0]);
|
||||
_callStream.SetStream(inStreams[1]);
|
||||
_jumpStream.SetStream(inStreams[2]);
|
||||
_rangeDecoder.SetStream(inStreams[3]);
|
||||
_outStream.SetStream(outStreams[0]);
|
||||
|
||||
_mainInStream.Init();
|
||||
_callStream.Init();
|
||||
_jumpStream.Init();
|
||||
_rangeDecoder.Init();
|
||||
_outStream.Init();
|
||||
|
||||
for (int i = 0; i < 256 + 2; i++)
|
||||
_statusDecoder[i].Init();
|
||||
|
||||
CCoderReleaser releaser(this);
|
||||
|
||||
Byte prevByte = 0;
|
||||
UInt32 processedBytes = 0;
|
||||
for (;;)
|
||||
{
|
||||
if (processedBytes >= (1 << 20) && progress != NULL)
|
||||
{
|
||||
/*
|
||||
const UInt64 compressedSize =
|
||||
_mainInStream.GetProcessedSize() +
|
||||
_callStream.GetProcessedSize() +
|
||||
_jumpStream.GetProcessedSize() +
|
||||
_rangeDecoder.GetProcessedSize();
|
||||
*/
|
||||
const UInt64 nowPos64 = _outStream.GetProcessedSize();
|
||||
RINOK(progress->SetRatioInfo(NULL, &nowPos64));
|
||||
processedBytes = 0;
|
||||
}
|
||||
UInt32 i;
|
||||
Byte b = 0;
|
||||
const UInt32 kBurstSize = (1 << 18);
|
||||
for (i = 0; i < kBurstSize; i++)
|
||||
{
|
||||
if (!_mainInStream.ReadByte(b))
|
||||
return Flush();
|
||||
_outStream.WriteByte(b);
|
||||
if (IsJ(prevByte, b))
|
||||
break;
|
||||
prevByte = b;
|
||||
}
|
||||
processedBytes += i;
|
||||
if (i == kBurstSize)
|
||||
continue;
|
||||
unsigned index = GetIndex(prevByte, b);
|
||||
if (_statusDecoder[index].Decode(&_rangeDecoder) == 1)
|
||||
{
|
||||
UInt32 src = 0;
|
||||
CInBuffer &s = (b == 0xE8) ? _callStream : _jumpStream;
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
Byte b0;
|
||||
if(!s.ReadByte(b0))
|
||||
return S_FALSE;
|
||||
src <<= 8;
|
||||
src |= ((UInt32)b0);
|
||||
}
|
||||
UInt32 dest = src - (UInt32(_outStream.GetProcessedSize()) + 4) ;
|
||||
_outStream.WriteByte((Byte)(dest));
|
||||
_outStream.WriteByte((Byte)(dest >> 8));
|
||||
_outStream.WriteByte((Byte)(dest >> 16));
|
||||
_outStream.WriteByte((Byte)(dest >> 24));
|
||||
prevByte = (Byte)(dest >> 24);
|
||||
processedBytes += 4;
|
||||
}
|
||||
else
|
||||
prevByte = b;
|
||||
}
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::Code(ISequentialInStream **inStreams,
|
||||
const UInt64 **inSizes,
|
||||
UInt32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UInt64 **outSizes,
|
||||
UInt32 numOutStreams,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
try
|
||||
{
|
||||
return CodeReal(inStreams, inSizes, numInStreams,
|
||||
outStreams, outSizes,numOutStreams, progress);
|
||||
}
|
||||
catch(const CInBufferException &e) { return e.ErrorCode; }
|
||||
catch(const COutBufferException &e) { return e.ErrorCode; }
|
||||
catch(...) { return S_FALSE; }
|
||||
}
|
||||
|
||||
}}
|
123
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/x86_2.h
Normal file
123
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Branch/x86_2.h
Normal file
|
@ -0,0 +1,123 @@
|
|||
// x86_2.h
|
||||
|
||||
#ifndef __BRANCH_X86_2_H
|
||||
#define __BRANCH_X86_2_H
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
#include "../RangeCoder/RangeCoderBit.h"
|
||||
#include "../../ICoder.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NBcj2 {
|
||||
|
||||
const int kNumMoveBits = 5;
|
||||
|
||||
#ifndef EXTRACT_ONLY
|
||||
|
||||
class CEncoder:
|
||||
public ICompressCoder2,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
Byte *_buffer;
|
||||
public:
|
||||
CEncoder(): _buffer(0) {};
|
||||
~CEncoder();
|
||||
bool Create();
|
||||
|
||||
COutBuffer _mainStream;
|
||||
COutBuffer _callStream;
|
||||
COutBuffer _jumpStream;
|
||||
NCompress::NRangeCoder::CEncoder _rangeEncoder;
|
||||
NCompress::NRangeCoder::CBitEncoder<kNumMoveBits> _statusEncoder[256 + 2];
|
||||
|
||||
HRESULT Flush();
|
||||
void ReleaseStreams()
|
||||
{
|
||||
_mainStream.ReleaseStream();
|
||||
_callStream.ReleaseStream();
|
||||
_jumpStream.ReleaseStream();
|
||||
_rangeEncoder.ReleaseStream();
|
||||
}
|
||||
|
||||
class CCoderReleaser
|
||||
{
|
||||
CEncoder *_coder;
|
||||
public:
|
||||
CCoderReleaser(CEncoder *coder): _coder(coder) {}
|
||||
~CCoderReleaser() { _coder->ReleaseStreams(); }
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
MY_UNKNOWN_IMP
|
||||
|
||||
HRESULT CodeReal(ISequentialInStream **inStreams,
|
||||
const UInt64 **inSizes,
|
||||
UInt32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UInt64 **outSizes,
|
||||
UInt32 numOutStreams,
|
||||
ICompressProgressInfo *progress);
|
||||
STDMETHOD(Code)(ISequentialInStream **inStreams,
|
||||
const UInt64 **inSizes,
|
||||
UInt32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UInt64 **outSizes,
|
||||
UInt32 numOutStreams,
|
||||
ICompressProgressInfo *progress);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
class CDecoder:
|
||||
public ICompressCoder2,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
CInBuffer _mainInStream;
|
||||
CInBuffer _callStream;
|
||||
CInBuffer _jumpStream;
|
||||
NCompress::NRangeCoder::CDecoder _rangeDecoder;
|
||||
NCompress::NRangeCoder::CBitDecoder<kNumMoveBits> _statusDecoder[256 + 2];
|
||||
|
||||
COutBuffer _outStream;
|
||||
|
||||
void ReleaseStreams()
|
||||
{
|
||||
_mainInStream.ReleaseStream();
|
||||
_callStream.ReleaseStream();
|
||||
_jumpStream.ReleaseStream();
|
||||
_rangeDecoder.ReleaseStream();
|
||||
_outStream.ReleaseStream();
|
||||
}
|
||||
|
||||
HRESULT Flush() { return _outStream.Flush(); }
|
||||
class CCoderReleaser
|
||||
{
|
||||
CDecoder *_coder;
|
||||
public:
|
||||
CCoderReleaser(CDecoder *coder): _coder(coder) {}
|
||||
~CCoderReleaser() { _coder->ReleaseStreams(); }
|
||||
};
|
||||
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
HRESULT CodeReal(ISequentialInStream **inStreams,
|
||||
const UInt64 **inSizes,
|
||||
UInt32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UInt64 **outSizes,
|
||||
UInt32 numOutStreams,
|
||||
ICompressProgressInfo *progress);
|
||||
STDMETHOD(Code)(ISequentialInStream **inStreams,
|
||||
const UInt64 **inSizes,
|
||||
UInt32 numInStreams,
|
||||
ISequentialOutStream **outStreams,
|
||||
const UInt64 **outSizes,
|
||||
UInt32 numOutStreams,
|
||||
ICompressProgressInfo *progress);
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,38 @@
|
|||
// ByteSwap.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ByteSwap.h"
|
||||
|
||||
STDMETHODIMP CByteSwap2::Init() { return S_OK; }
|
||||
|
||||
STDMETHODIMP_(UInt32) CByteSwap2::Filter(Byte *data, UInt32 size)
|
||||
{
|
||||
const UInt32 kStep = 2;
|
||||
UInt32 i;
|
||||
for (i = 0; i + kStep <= size; i += kStep)
|
||||
{
|
||||
Byte b = data[i];
|
||||
data[i] = data[i + 1];
|
||||
data[i + 1] = b;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
STDMETHODIMP CByteSwap4::Init() { return S_OK; }
|
||||
|
||||
STDMETHODIMP_(UInt32) CByteSwap4::Filter(Byte *data, UInt32 size)
|
||||
{
|
||||
const UInt32 kStep = 4;
|
||||
UInt32 i;
|
||||
for (i = 0; i + kStep <= size; i += kStep)
|
||||
{
|
||||
Byte b0 = data[i];
|
||||
Byte b1 = data[i + 1];
|
||||
data[i] = data[i + 3];
|
||||
data[i + 1] = data[i + 2];
|
||||
data[i + 2] = b1;
|
||||
data[i + 3] = b0;
|
||||
}
|
||||
return i;
|
||||
}
|
37
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/ByteSwap/ByteSwap.h
Normal file
37
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/ByteSwap/ByteSwap.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
// ByteSwap.h
|
||||
|
||||
#ifndef __BYTESWAP_H
|
||||
#define __BYTESWAP_H
|
||||
|
||||
#include "../../ICoder.h"
|
||||
#include "Common/MyCom.h"
|
||||
|
||||
// {23170F69-40C1-278B-0203-020000000000}
|
||||
DEFINE_GUID(CLSID_CCompressConvertByteSwap2,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x02, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
// {23170F69-40C1-278B-0203-040000000000}
|
||||
DEFINE_GUID(CLSID_CCompressConvertByteSwap4,
|
||||
0x23170F69, 0x40C1, 0x278B, 0x02, 0x03, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
class CByteSwap2:
|
||||
public ICompressFilter,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
STDMETHOD(Init)();
|
||||
STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
|
||||
};
|
||||
|
||||
class CByteSwap4:
|
||||
public ICompressFilter,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
public:
|
||||
MY_UNKNOWN_IMP
|
||||
STDMETHOD(Init)();
|
||||
STDMETHOD_(UInt32, Filter)(Byte *data, UInt32 size);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,17 @@
|
|||
// ByteSwapRegister.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../Common/RegisterCodec.h"
|
||||
|
||||
#include "ByteSwap.h"
|
||||
static void *CreateCodec2() { return (void *)(ICompressFilter *)(new CByteSwap2); }
|
||||
static void *CreateCodec4() { return (void *)(ICompressFilter *)(new CByteSwap4); }
|
||||
|
||||
static CCodecInfo g_CodecsInfo[] =
|
||||
{
|
||||
{ CreateCodec2, CreateCodec4, 0x020302, L"Swap2", 1, true },
|
||||
{ CreateCodec4, CreateCodec4, 0x020304, L"Swap4", 1, true }
|
||||
};
|
||||
|
||||
REGISTER_CODECS(ByteSwap)
|
|
@ -0,0 +1,3 @@
|
|||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
|
@ -0,0 +1,8 @@
|
|||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include "../../../Common/MyWindows.h"
|
||||
|
||||
#endif
|
157
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/CodecExports.cpp
Normal file
157
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/CodecExports.cpp
Normal file
|
@ -0,0 +1,157 @@
|
|||
// CodecExports.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../Common/ComTry.h"
|
||||
#include "../../Windows/PropVariant.h"
|
||||
#include "../Common/RegisterCodec.h"
|
||||
#include "../ICoder.h"
|
||||
|
||||
extern unsigned int g_NumCodecs;
|
||||
extern const CCodecInfo *g_Codecs[];
|
||||
|
||||
static const UInt16 kDecodeId = 0x2790;
|
||||
|
||||
DEFINE_GUID(CLSID_CCodec,
|
||||
0x23170F69, 0x40C1, kDecodeId, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
static inline HRESULT SetPropString(const char *s, unsigned int size, PROPVARIANT *value)
|
||||
{
|
||||
if ((value->bstrVal = ::SysAllocStringByteLen(s, size)) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static inline HRESULT SetPropGUID(const GUID &guid, PROPVARIANT *value)
|
||||
{
|
||||
return SetPropString((const char *)&guid, sizeof(GUID), value);
|
||||
}
|
||||
|
||||
static HRESULT SetClassID(CMethodId id, bool encode, PROPVARIANT *value)
|
||||
{
|
||||
GUID clsId = CLSID_CCodec;
|
||||
for (int i = 0; i < sizeof(id); i++, id >>= 8)
|
||||
clsId.Data4[i] = (Byte)(id & 0xFF);
|
||||
if (encode)
|
||||
clsId.Data3++;
|
||||
return SetPropGUID(clsId, value);
|
||||
}
|
||||
|
||||
static HRESULT FindCodecClassId(const GUID *clsID, UInt32 isCoder2, bool isFilter, bool &encode, int &index)
|
||||
{
|
||||
index = -1;
|
||||
if (clsID->Data1 != CLSID_CCodec.Data1 ||
|
||||
clsID->Data2 != CLSID_CCodec.Data2 ||
|
||||
(clsID->Data3 & ~1) != kDecodeId)
|
||||
return S_OK;
|
||||
encode = (clsID->Data3 != kDecodeId);
|
||||
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++)
|
||||
{
|
||||
const CCodecInfo &codec = *g_Codecs[i];
|
||||
if (id != codec.Id || encode && !codec.CreateEncoder || !encode && !codec.CreateDecoder)
|
||||
continue;
|
||||
if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||
|
||||
codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)
|
||||
return E_NOINTERFACE;
|
||||
index = i;
|
||||
return S_OK;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDAPI CreateCoder2(bool encode, UInt32 index, const GUID *iid, void **outObject)
|
||||
{
|
||||
COM_TRY_BEGIN
|
||||
*outObject = 0;
|
||||
bool isCoder = (*iid == IID_ICompressCoder) != 0;
|
||||
bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;
|
||||
bool isFilter = (*iid == IID_ICompressFilter) != 0;
|
||||
const CCodecInfo &codec = *g_Codecs[index];
|
||||
if (!isFilter && codec.IsFilter || isFilter && !codec.IsFilter ||
|
||||
codec.NumInStreams != 1 && !isCoder2 || codec.NumInStreams == 1 && isCoder2)
|
||||
return E_NOINTERFACE;
|
||||
if (encode)
|
||||
{
|
||||
if (!codec.CreateEncoder)
|
||||
return CLASS_E_CLASSNOTAVAILABLE;
|
||||
*outObject = codec.CreateEncoder();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!codec.CreateDecoder)
|
||||
return CLASS_E_CLASSNOTAVAILABLE;
|
||||
*outObject = codec.CreateDecoder();
|
||||
}
|
||||
if (isCoder)
|
||||
((ICompressCoder *)*outObject)->AddRef();
|
||||
else if (isCoder2)
|
||||
((ICompressCoder2 *)*outObject)->AddRef();
|
||||
else
|
||||
((ICompressFilter *)*outObject)->AddRef();
|
||||
return S_OK;
|
||||
COM_TRY_END
|
||||
}
|
||||
|
||||
STDAPI CreateCoder(const GUID *clsid, const GUID *iid, void **outObject)
|
||||
{
|
||||
*outObject = 0;
|
||||
bool isCoder = (*iid == IID_ICompressCoder) != 0;
|
||||
bool isCoder2 = (*iid == IID_ICompressCoder2) != 0;
|
||||
bool isFilter = (*iid == IID_ICompressFilter) != 0;
|
||||
if (!isCoder && !isCoder2 && !isFilter)
|
||||
return E_NOINTERFACE;
|
||||
bool encode;
|
||||
int codecIndex;
|
||||
HRESULT res = FindCodecClassId(clsid, isCoder2, isFilter, encode, codecIndex);
|
||||
if (res != S_OK)
|
||||
return res;
|
||||
if (codecIndex < 0)
|
||||
return CLASS_E_CLASSNOTAVAILABLE;
|
||||
return CreateCoder2(encode, codecIndex, iid, outObject);
|
||||
}
|
||||
|
||||
STDAPI GetMethodProperty(UInt32 codecIndex, PROPID propID, PROPVARIANT *value)
|
||||
{
|
||||
::VariantClear((VARIANTARG *)value);
|
||||
const CCodecInfo &codec = *g_Codecs[codecIndex];
|
||||
switch(propID)
|
||||
{
|
||||
case NMethodPropID::kID:
|
||||
{
|
||||
value->uhVal.QuadPart = (UInt64)codec.Id;
|
||||
value->vt = VT_UI8;
|
||||
break;
|
||||
}
|
||||
case NMethodPropID::kName:
|
||||
if ((value->bstrVal = ::SysAllocString(codec.Name)) != 0)
|
||||
value->vt = VT_BSTR;
|
||||
break;
|
||||
case NMethodPropID::kDecoder:
|
||||
if (codec.CreateDecoder)
|
||||
return SetClassID(codec.Id, false, value);
|
||||
break;
|
||||
case NMethodPropID::kEncoder:
|
||||
if (codec.CreateEncoder)
|
||||
return SetClassID(codec.Id, true, value);
|
||||
break;
|
||||
case NMethodPropID::kInStreams:
|
||||
{
|
||||
if (codec.NumInStreams != 1)
|
||||
{
|
||||
value->vt = VT_UI4;
|
||||
value->ulVal = codec.NumInStreams;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDAPI GetNumberOfMethods(UINT32 *numCodecs)
|
||||
{
|
||||
*numCodecs = g_NumCodecs;
|
||||
return S_OK;
|
||||
}
|
62
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Copy/CopyCoder.cpp
Normal file
62
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Copy/CopyCoder.cpp
Normal file
|
@ -0,0 +1,62 @@
|
|||
// Compress/CopyCoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
}
|
||||
|
||||
#include "CopyCoder.h"
|
||||
#include "../../Common/StreamUtils.h"
|
||||
|
||||
namespace NCompress {
|
||||
|
||||
static const UInt32 kBufferSize = 1 << 17;
|
||||
|
||||
CCopyCoder::~CCopyCoder()
|
||||
{
|
||||
::MidFree(_buffer);
|
||||
}
|
||||
|
||||
STDMETHODIMP CCopyCoder::Code(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 * /* inSize */, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
if (_buffer == 0)
|
||||
{
|
||||
_buffer = (Byte *)::MidAlloc(kBufferSize);
|
||||
if (_buffer == 0)
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
TotalSize = 0;
|
||||
for (;;)
|
||||
{
|
||||
UInt32 realProcessedSize;
|
||||
UInt32 size = kBufferSize;
|
||||
if (outSize != 0)
|
||||
if (size > *outSize - TotalSize)
|
||||
size = (UInt32)(*outSize - TotalSize);
|
||||
RINOK(inStream->Read(_buffer, size, &realProcessedSize));
|
||||
if (realProcessedSize == 0)
|
||||
break;
|
||||
RINOK(WriteStream(outStream, _buffer, realProcessedSize, NULL));
|
||||
TotalSize += realProcessedSize;
|
||||
if (progress != NULL)
|
||||
{
|
||||
RINOK(progress->SetRatioInfo(&TotalSize, &TotalSize));
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CCopyCoder::GetInStreamProcessedSize(UInt64 *value)
|
||||
{
|
||||
*value = TotalSize;
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
33
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Copy/CopyCoder.h
Normal file
33
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Copy/CopyCoder.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
// Compress/CopyCoder.h
|
||||
|
||||
#ifndef __COMPRESS_COPYCODER_H
|
||||
#define __COMPRESS_COPYCODER_H
|
||||
|
||||
#include "../../ICoder.h"
|
||||
#include "../../../Common/MyCom.h"
|
||||
|
||||
namespace NCompress {
|
||||
|
||||
class CCopyCoder:
|
||||
public ICompressCoder,
|
||||
public ICompressGetInStreamProcessedSize,
|
||||
public CMyUnknownImp
|
||||
{
|
||||
Byte *_buffer;
|
||||
public:
|
||||
UInt64 TotalSize;
|
||||
CCopyCoder(): TotalSize(0) , _buffer(0) {};
|
||||
~CCopyCoder();
|
||||
|
||||
MY_UNKNOWN_IMP1(ICompressGetInStreamProcessedSize)
|
||||
|
||||
STDMETHOD(Code)(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *inSize, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress);
|
||||
STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,13 @@
|
|||
// LZMARegister.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../Common/RegisterCodec.h"
|
||||
|
||||
#include "CopyCoder.h"
|
||||
static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::CCopyCoder); }
|
||||
|
||||
static CCodecInfo g_CodecInfo =
|
||||
{ CreateCodec, CreateCodec, 0x00, L"Copy", 1, false };
|
||||
|
||||
REGISTER_CODEC(Copy)
|
3
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Copy/StdAfx.cpp
Normal file
3
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Copy/StdAfx.cpp
Normal file
|
@ -0,0 +1,3 @@
|
|||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
8
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Copy/StdAfx.h
Normal file
8
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/Copy/StdAfx.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include "../../../Common/MyWindows.h"
|
||||
|
||||
#endif
|
16
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZ/LZOutWindow.cpp
Normal file
16
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZ/LZOutWindow.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
// LZOutWindow.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "LZOutWindow.h"
|
||||
|
||||
void CLZOutWindow::Init(bool solid)
|
||||
{
|
||||
if(!solid)
|
||||
COutBuffer::Init();
|
||||
#ifdef _NO_EXCEPTIONS
|
||||
ErrorCode = S_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
65
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZ/LZOutWindow.h
Normal file
65
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZ/LZOutWindow.h
Normal file
|
@ -0,0 +1,65 @@
|
|||
// LZOutWindow.h
|
||||
|
||||
#ifndef __LZ_OUT_WINDOW_H
|
||||
#define __LZ_OUT_WINDOW_H
|
||||
|
||||
#include "../../IStream.h"
|
||||
#include "../../Common/OutBuffer.h"
|
||||
|
||||
#ifndef _NO_EXCEPTIONS
|
||||
typedef COutBufferException CLZOutWindowException;
|
||||
#endif
|
||||
|
||||
class CLZOutWindow: public COutBuffer
|
||||
{
|
||||
public:
|
||||
void Init(bool solid = false);
|
||||
|
||||
// distance >= 0, len > 0,
|
||||
bool CopyBlock(UInt32 distance, UInt32 len)
|
||||
{
|
||||
UInt32 pos = _pos - distance - 1;
|
||||
if (distance >= _pos)
|
||||
{
|
||||
if (!_overDict || distance >= _bufferSize)
|
||||
return false;
|
||||
pos += _bufferSize;
|
||||
}
|
||||
if (_limitPos - _pos > len && _bufferSize - pos > len)
|
||||
{
|
||||
const Byte *src = _buffer + pos;
|
||||
Byte *dest = _buffer + _pos;
|
||||
_pos += len;
|
||||
do
|
||||
*dest++ = *src++;
|
||||
while(--len != 0);
|
||||
}
|
||||
else do
|
||||
{
|
||||
if (pos == _bufferSize)
|
||||
pos = 0;
|
||||
_buffer[_pos++] = _buffer[pos++];
|
||||
if (_pos == _limitPos)
|
||||
FlushWithCheck();
|
||||
}
|
||||
while(--len != 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
void PutByte(Byte b)
|
||||
{
|
||||
_buffer[_pos++] = b;
|
||||
if (_pos == _limitPos)
|
||||
FlushWithCheck();
|
||||
}
|
||||
|
||||
Byte GetByte(UInt32 distance) const
|
||||
{
|
||||
UInt32 pos = _pos - distance - 1;
|
||||
if (pos >= _bufferSize)
|
||||
pos += _bufferSize;
|
||||
return _buffer[pos];
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
6
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZ/StdAfx.h
Normal file
6
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZ/StdAfx.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#endif
|
82
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA/LZMA.h
Normal file
82
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA/LZMA.h
Normal file
|
@ -0,0 +1,82 @@
|
|||
// 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
|
338
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA/LZMADecoder.cpp
Normal file
338
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA/LZMADecoder.cpp
Normal file
|
@ -0,0 +1,338 @@
|
|||
// LZMADecoder.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "LZMADecoder.h"
|
||||
#include "../../../Common/Defs.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NLZMA {
|
||||
|
||||
const int kLenIdFinished = -1;
|
||||
const int kLenIdNeedInit = -2;
|
||||
|
||||
void CDecoder::Init()
|
||||
{
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
HRESULT CDecoder::CodeSpec(UInt32 curSize)
|
||||
{
|
||||
if (_outSizeDefined)
|
||||
{
|
||||
const UInt64 rem = _outSize - _outWindowStream.GetProcessedSize();
|
||||
if (curSize > rem)
|
||||
curSize = (UInt32)rem;
|
||||
}
|
||||
|
||||
if (_remainLen == kLenIdFinished)
|
||||
return S_OK;
|
||||
if (_remainLen == kLenIdNeedInit)
|
||||
{
|
||||
_rangeDecoder.Init();
|
||||
Init();
|
||||
_remainLen = 0;
|
||||
}
|
||||
if (curSize == 0)
|
||||
return S_OK;
|
||||
|
||||
UInt32 rep0 = _reps[0];
|
||||
UInt32 rep1 = _reps[1];
|
||||
UInt32 rep2 = _reps[2];
|
||||
UInt32 rep3 = _reps[3];
|
||||
CState state = _state;
|
||||
Byte previousByte;
|
||||
|
||||
while(_remainLen > 0 && curSize > 0)
|
||||
{
|
||||
previousByte = _outWindowStream.GetByte(rep0);
|
||||
_outWindowStream.PutByte(previousByte);
|
||||
_remainLen--;
|
||||
curSize--;
|
||||
}
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#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;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::CodeReal(ISequentialInStream *inStream,
|
||||
ISequentialOutStream *outStream,
|
||||
const UInt64 *, const UInt64 *outSize,
|
||||
ICompressProgressInfo *progress)
|
||||
{
|
||||
SetInStream(inStream);
|
||||
_outWindowStream.SetStream(outStream);
|
||||
SetOutStreamSize(outSize);
|
||||
CDecoderFlusher flusher(this);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
UInt32 curSize = 1 << 18;
|
||||
RINOK(CodeSpec(curSize));
|
||||
if (_remainLen == kLenIdFinished)
|
||||
break;
|
||||
if (progress != NULL)
|
||||
{
|
||||
UInt64 inSize = _rangeDecoder.GetProcessedSize();
|
||||
UInt64 nowPos64 = _outWindowStream.GetProcessedSize();
|
||||
RINOK(progress->SetRatioInfo(&inSize, &nowPos64));
|
||||
}
|
||||
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; }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
STDMETHODIMP CDecoder::SetOutStreamSize(const UInt64 *outSize)
|
||||
{
|
||||
_outSizeDefined = (outSize != NULL);
|
||||
if (_outSizeDefined)
|
||||
_outSize = *outSize;
|
||||
_remainLen = kLenIdNeedInit;
|
||||
_outWindowStream.Init();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
#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
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}}
|
255
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA/LZMADecoder.h
Normal file
255
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA/LZMADecoder.h
Normal file
|
@ -0,0 +1,255 @@
|
|||
// LZMA/Decoder.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 "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,
|
||||
public ICompressGetInStreamProcessedSize,
|
||||
#ifndef NO_READ_FROM_CODER
|
||||
public ICompressSetInStream,
|
||||
public ICompressSetOutStreamSize,
|
||||
public ISequentialInStream,
|
||||
#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;
|
||||
bool _outSizeDefined;
|
||||
|
||||
void Init();
|
||||
HRESULT CodeSpec(UInt32 size);
|
||||
public:
|
||||
|
||||
#ifndef NO_READ_FROM_CODER
|
||||
MY_UNKNOWN_IMP5(
|
||||
ICompressSetDecoderProperties2,
|
||||
ICompressGetInStreamProcessedSize,
|
||||
ICompressSetInStream,
|
||||
ICompressSetOutStreamSize,
|
||||
ISequentialInStream)
|
||||
#else
|
||||
MY_UNKNOWN_IMP2(
|
||||
ICompressSetDecoderProperties2,
|
||||
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,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
|
||||
|
||||
STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
|
||||
|
||||
STDMETHOD(SetInStream)(ISequentialInStream *inStream);
|
||||
STDMETHOD(ReleaseInStream)();
|
||||
STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);
|
||||
|
||||
#ifndef NO_READ_FROM_CODER
|
||||
STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
|
||||
#endif
|
||||
|
||||
CDecoder(): _outSizeDefined(false) {}
|
||||
virtual ~CDecoder() {}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
1547
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp
Normal file
1547
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA/LZMAEncoder.cpp
Normal file
File diff suppressed because it is too large
Load diff
465
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA/LZMAEncoder.h
Normal file
465
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA/LZMAEncoder.h
Normal file
|
@ -0,0 +1,465 @@
|
|||
// LZMA/Encoder.h
|
||||
|
||||
#ifndef __LZMA_ENCODER_H
|
||||
#define __LZMA_ENCODER_H
|
||||
|
||||
#include "../../../Common/MyCom.h"
|
||||
#include "../../ICoder.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "../../../../C/Alloc.h"
|
||||
#include "../../../../C/Compress/Lz/MatchFinder.h"
|
||||
#ifdef COMPRESS_MF_MT
|
||||
#include "../../../../C/Compress/Lz/MatchFinderMt.h"
|
||||
#endif
|
||||
}
|
||||
|
||||
#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)
|
||||
{
|
||||
#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;
|
||||
};
|
||||
|
||||
const UInt32 kNumSpecSymbols = kNumLowSymbols + kNumMidSymbols;
|
||||
|
||||
class CPriceTableEncoder: public CEncoder
|
||||
{
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
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];
|
||||
|
||||
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);
|
||||
|
||||
public:
|
||||
CEncoder();
|
||||
void SetWriteEndMarkerMode(bool writeEndMarker)
|
||||
{ _writeEndMark= writeEndMarker; }
|
||||
|
||||
HRESULT Create();
|
||||
|
||||
MY_UNKNOWN_IMP3(
|
||||
ICompressSetOutStream,
|
||||
ICompressSetCoderProperties,
|
||||
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,
|
||||
ICompressProgressInfo *progress);
|
||||
|
||||
// ICompressSetCoderProperties2
|
||||
STDMETHOD(SetCoderProperties)(const PROPID *propIDs,
|
||||
const PROPVARIANT *properties, UInt32 numProperties);
|
||||
|
||||
// ICompressWriteCoderProperties
|
||||
STDMETHOD(WriteCoderProperties)(ISequentialOutStream *outStream);
|
||||
|
||||
STDMETHOD(SetOutStream)(ISequentialOutStream *outStream);
|
||||
STDMETHOD(ReleaseOutStream)();
|
||||
|
||||
virtual ~CEncoder();
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,19 @@
|
|||
// LZMARegister.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../Common/RegisterCodec.h"
|
||||
|
||||
#include "LZMADecoder.h"
|
||||
static void *CreateCodec() { return (void *)(ICompressCoder *)(new NCompress::NLZMA::CDecoder); }
|
||||
#ifndef EXTRACT_ONLY
|
||||
#include "LZMAEncoder.h"
|
||||
static void *CreateCodecOut() { return (void *)(ICompressCoder *)(new NCompress::NLZMA::CEncoder); }
|
||||
#else
|
||||
#define CreateCodecOut 0
|
||||
#endif
|
||||
|
||||
static CCodecInfo g_CodecInfo =
|
||||
{ CreateCodec, CreateCodecOut, 0x030101, L"LZMA", 1, false };
|
||||
|
||||
REGISTER_CODEC(LZMA)
|
3
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA/StdAfx.cpp
Normal file
3
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA/StdAfx.cpp
Normal file
|
@ -0,0 +1,3 @@
|
|||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
8
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA/StdAfx.h
Normal file
8
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA/StdAfx.h
Normal file
|
@ -0,0 +1,8 @@
|
|||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include "../../../Common/MyWindows.h"
|
||||
|
||||
#endif
|
504
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp
Normal file
504
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA_Alone/AloneLZMA.dsp
Normal file
|
@ -0,0 +1,504 @@
|
|||
# Microsoft Developer Studio Project File - Name="AloneLZMA" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=AloneLZMA - Win32 DebugU
|
||||
!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 "AloneLZMA.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 "AloneLZMA.mak" CFG="AloneLZMA - Win32 DebugU"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "AloneLZMA - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "AloneLZMA - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "AloneLZMA - Win32 ReleaseU" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "AloneLZMA - Win32 DebugU" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "AloneLZMA - 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 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /MT /W3 /GX /O2 /I "..\..\..\\" /D "NDEBUG" /D "_MBCS" /D "WIN32" /D "_CONSOLE" /D "COMPRESS_MF_MT" /D "BENCH_MT" /FAcs /Yu"StdAfx.h" /FD /c
|
||||
# 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 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 /subsystem:console /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 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 /subsystem:console /machine:I386 /out:"c:\UTIL\lzma.exe" /opt:NOWIN98
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "AloneLZMA - 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 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "_MBCS" /D "WIN32" /D "_CONSOLE" /D "COMPRESS_MF_MT" /D "BENCH_MT" /Yu"StdAfx.h" /FD /GZ /c
|
||||
# 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 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 /subsystem:console /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 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 /subsystem:console /debug /machine:I386 /out:"c:\UTIL\lzma.exe" /pdbtype:sept
|
||||
|
||||
!ELSEIF "$(CFG)" == "AloneLZMA - Win32 ReleaseU"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "ReleaseU"
|
||||
# PROP BASE Intermediate_Dir "ReleaseU"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "ReleaseU"
|
||||
# PROP Intermediate_Dir "ReleaseU"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /MD /W3 /GX /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "EXCLUDE_COM" /D "NO_REGISTRY" /D "FORMAT_7Z" /D "FORMAT_BZIP2" /D "FORMAT_ZIP" /D "FORMAT_TAR" /D "FORMAT_GZIP" /D "COMPRESS_LZMA" /D "COMPRESS_BCJ_X86" /D "COMPRESS_BCJ2" /D "COMPRESS_COPY" /D "COMPRESS_MF_PAT" /D "COMPRESS_MF_BT" /D "COMPRESS_PPMD" /D "COMPRESS_DEFLATE" /D "COMPRESS_IMPLODE" /D "COMPRESS_BZIP2" /D "CRYPTO_ZIP" /Yu"StdAfx.h" /FD /c
|
||||
# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\..\..\\" /D "NDEBUG" /D "UNICODE" /D "_UNICODE" /D "WIN32" /D "_CONSOLE" /D "COMPRESS_MF_MT" /D "BENCH_MT" /Yu"StdAfx.h" /FD /c
|
||||
# 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 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 /subsystem:console /machine:I386 /out:"c:\UTIL\7za2.exe" /opt:NOWIN98
|
||||
# SUBTRACT BASE LINK32 /pdb:none
|
||||
# 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 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 /subsystem:console /machine:I386 /out:"c:\UTIL\lzma.exe" /opt:NOWIN98
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
|
||||
!ELSEIF "$(CFG)" == "AloneLZMA - Win32 DebugU"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "DebugU"
|
||||
# PROP BASE Intermediate_Dir "DebugU"
|
||||
# PROP BASE Ignore_Export_Lib 0
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "DebugU"
|
||||
# PROP Intermediate_Dir "DebugU"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "EXCLUDE_COM" /D "NO_REGISTRY" /D "FORMAT_7Z" /D "FORMAT_BZIP2" /D "FORMAT_ZIP" /D "FORMAT_TAR" /D "FORMAT_GZIP" /D "COMPRESS_LZMA" /D "COMPRESS_BCJ_X86" /D "COMPRESS_BCJ2" /D "COMPRESS_COPY" /D "COMPRESS_MF_PAT" /D "COMPRESS_MF_BT" /D "COMPRESS_PPMD" /D "COMPRESS_DEFLATE" /D "COMPRESS_IMPLODE" /D "COMPRESS_BZIP2" /D "CRYPTO_ZIP" /D "_MBCS" /Yu"StdAfx.h" /FD /GZ /c
|
||||
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "..\..\..\\" /D "_DEBUG" /D "_UNICODE" /D "UNICODE" /D "WIN32" /D "_CONSOLE" /D "COMPRESS_MF_MT" /D "BENCH_MT" /Yu"StdAfx.h" /FD /GZ /c
|
||||
# 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 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 /subsystem:console /debug /machine:I386 /out:"c:\UTIL\7za2.exe" /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 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 /subsystem:console /debug /machine:I386 /out:"c:\UTIL\lzma.exe" /pdbtype:sept
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "AloneLZMA - Win32 Release"
|
||||
# Name "AloneLZMA - Win32 Debug"
|
||||
# Name "AloneLZMA - Win32 ReleaseU"
|
||||
# Name "AloneLZMA - Win32 DebugU"
|
||||
# Begin Group "Spec"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# 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 "Compress"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Group "LZMA"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZMA\LZMA.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZMA\LZMADecoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZMA\LZMADecoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZMA\LZMAEncoder.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\LZMA\LZMAEncoder.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 "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
|
||||
# End Group
|
||||
# Begin Group "Windows"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Windows\FileIO.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Windows\FileIO.h
|
||||
# End Source File
|
||||
# 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\System.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Windows\System.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Windows\Thread.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Common"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\CommandLineParser.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\CommandLineParser.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\CRC.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\Defs.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Windows\Defs.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\IntToString.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\IntToString.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\MyCom.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\MyString.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\MyString.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\MyVector.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\MyVector.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\MyWindows.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\NewHandler.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\NewHandler.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\StringConvert.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\StringConvert.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\StringToInt.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\StringToInt.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\Common\Types.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "7zip Common"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\FileStreams.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\Common\FileStreams.h
|
||||
# End Source File
|
||||
# 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 "C"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Group "C-Lz"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Compress\Lz\MatchFinder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Compress\Lz\MatchFinderMt.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
|
||||
# End Group
|
||||
# Begin Group "LZMA_C"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Compress\Lzma\LzmaDecode.c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Compress\Lzma\LzmaDecode.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Compress\Lzma\LzmaTypes.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Branch"
|
||||
|
||||
# PROP Default_Filter ""
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Compress\Branch\BranchTypes.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\Compress\Branch\BranchX86.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\..\C\7zCrc.c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# 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\Types.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\ICoder.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LzmaAlone.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LzmaBench.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LzmaBench.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LzmaBenchCon.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LzmaBenchCon.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LzmaRam.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LzmaRam.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LzmaRamDecode.c
|
||||
# SUBTRACT CPP /YX /Yc /Yu
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\LzmaRamDecode.h
|
||||
# End Source File
|
||||
# End Target
|
||||
# End Project
|
|
@ -0,0 +1,29 @@
|
|||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "AloneLZMA"=.\AloneLZMA.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
554
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp
Normal file
554
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaAlone.cpp
Normal file
|
@ -0,0 +1,554 @@
|
|||
// LzmaAlone.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "../../../Common/MyWindows.h"
|
||||
#include "../../../Common/MyInitGuid.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(_WIN32) || defined(OS2) || defined(MSDOS)
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#define MY_SET_BINARY_MODE(file) _setmode(_fileno(file), O_BINARY)
|
||||
#else
|
||||
#define MY_SET_BINARY_MODE(file)
|
||||
#endif
|
||||
|
||||
#include "../../../Common/CommandLineParser.h"
|
||||
#include "../../../Common/StringConvert.h"
|
||||
#include "../../../Common/StringToInt.h"
|
||||
|
||||
#include "../../Common/FileStreams.h"
|
||||
#include "../../Common/StreamUtils.h"
|
||||
|
||||
#include "../LZMA/LZMADecoder.h"
|
||||
#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"
|
||||
}
|
||||
|
||||
using namespace NCommandLineParser;
|
||||
|
||||
#ifdef _WIN32
|
||||
bool g_IsNT = false;
|
||||
static inline bool IsItWindowsNT()
|
||||
{
|
||||
OSVERSIONINFO versionInfo;
|
||||
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
|
||||
if (!::GetVersionEx(&versionInfo))
|
||||
return false;
|
||||
return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
|
||||
}
|
||||
#endif
|
||||
|
||||
static const char *kCantAllocate = "Can not allocate memory";
|
||||
static const char *kReadError = "Read error";
|
||||
static const char *kWriteError = "Write error";
|
||||
|
||||
namespace NKey {
|
||||
enum Enum
|
||||
{
|
||||
kHelp1 = 0,
|
||||
kHelp2,
|
||||
kMode,
|
||||
kDictionary,
|
||||
kFastBytes,
|
||||
kMatchFinderCycles,
|
||||
kLitContext,
|
||||
kLitPos,
|
||||
kPosBits,
|
||||
kMatchFinder,
|
||||
kMultiThread,
|
||||
kEOS,
|
||||
kStdIn,
|
||||
kStdOut,
|
||||
kFilter86
|
||||
};
|
||||
}
|
||||
|
||||
static const CSwitchForm kSwitchForms[] =
|
||||
{
|
||||
{ L"?", NSwitchType::kSimple, false },
|
||||
{ L"H", NSwitchType::kSimple, false },
|
||||
{ L"A", NSwitchType::kUnLimitedPostString, false, 1 },
|
||||
{ L"D", NSwitchType::kUnLimitedPostString, false, 1 },
|
||||
{ L"FB", NSwitchType::kUnLimitedPostString, false, 1 },
|
||||
{ L"MC", NSwitchType::kUnLimitedPostString, false, 1 },
|
||||
{ L"LC", NSwitchType::kUnLimitedPostString, false, 1 },
|
||||
{ L"LP", NSwitchType::kUnLimitedPostString, false, 1 },
|
||||
{ L"PB", NSwitchType::kUnLimitedPostString, false, 1 },
|
||||
{ L"MF", NSwitchType::kUnLimitedPostString, false, 1 },
|
||||
{ L"MT", NSwitchType::kUnLimitedPostString, false, 0 },
|
||||
{ L"EOS", NSwitchType::kSimple, false },
|
||||
{ L"SI", NSwitchType::kSimple, false },
|
||||
{ L"SO", NSwitchType::kSimple, false },
|
||||
{ L"F86", NSwitchType::kPostChar, false, 0, 0, L"+" }
|
||||
};
|
||||
|
||||
static const int kNumSwitches = sizeof(kSwitchForms) / sizeof(kSwitchForms[0]);
|
||||
|
||||
static void PrintHelp()
|
||||
{
|
||||
fprintf(stderr, "\nUsage: LZMA <e|d> inputFile outputFile [<switches>...]\n"
|
||||
" e: encode file\n"
|
||||
" d: decode file\n"
|
||||
" 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"
|
||||
" -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"
|
||||
" -lp{N}: set number of literal pos bits - [0, 4], default: 0\n"
|
||||
" -pb{N}: set number of pos bits - [0, 4], default: 2\n"
|
||||
" -mf{MF_ID}: set Match Finder: [bt2, bt3, bt4, hc4], default: bt4\n"
|
||||
" -mt{N}: set number of CPU threads\n"
|
||||
" -eos: write End Of Stream marker\n"
|
||||
" -si: read data from stdin\n"
|
||||
" -so: write data to stdout\n"
|
||||
);
|
||||
}
|
||||
|
||||
static void PrintHelpAndExit(const char *s)
|
||||
{
|
||||
fprintf(stderr, "\nError: %s\n\n", s);
|
||||
PrintHelp();
|
||||
throw -1;
|
||||
}
|
||||
|
||||
static void IncorrectCommand()
|
||||
{
|
||||
PrintHelpAndExit("Incorrect command");
|
||||
}
|
||||
|
||||
static void WriteArgumentsToStringList(int numArguments, const char *arguments[],
|
||||
UStringVector &strings)
|
||||
{
|
||||
for(int i = 1; i < numArguments; i++)
|
||||
strings.Add(MultiByteToUnicodeString(arguments[i]));
|
||||
}
|
||||
|
||||
static bool GetNumber(const wchar_t *s, UInt32 &value)
|
||||
{
|
||||
value = 0;
|
||||
if (MyStringLen(s) == 0)
|
||||
return false;
|
||||
const wchar_t *end;
|
||||
UInt64 res = ConvertStringToUInt64(s, &end);
|
||||
if (*end != L'\0')
|
||||
return false;
|
||||
if (res > 0xFFFFFFFF)
|
||||
return false;
|
||||
value = UInt32(res);
|
||||
return true;
|
||||
}
|
||||
|
||||
int main2(int n, const char *args[])
|
||||
{
|
||||
#ifdef _WIN32
|
||||
g_IsNT = IsItWindowsNT();
|
||||
#endif
|
||||
|
||||
fprintf(stderr, "\nLZMA " MY_VERSION_COPYRIGHT_DATE "\n");
|
||||
|
||||
if (n == 1)
|
||||
{
|
||||
PrintHelp();
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool unsupportedTypes = (sizeof(Byte) != 1 || sizeof(UInt32) < 4 || sizeof(UInt64) < 4);
|
||||
if (unsupportedTypes)
|
||||
{
|
||||
fprintf(stderr, "Unsupported base types. Edit Common/Types.h and recompile");
|
||||
return 1;
|
||||
}
|
||||
|
||||
UStringVector commandStrings;
|
||||
WriteArgumentsToStringList(n, args, commandStrings);
|
||||
CParser parser(kNumSwitches);
|
||||
try
|
||||
{
|
||||
parser.ParseStrings(kSwitchForms, commandStrings);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
IncorrectCommand();
|
||||
}
|
||||
|
||||
if(parser[NKey::kHelp1].ThereIs || parser[NKey::kHelp2].ThereIs)
|
||||
{
|
||||
PrintHelp();
|
||||
return 0;
|
||||
}
|
||||
const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;
|
||||
|
||||
int paramIndex = 0;
|
||||
if (paramIndex >= nonSwitchStrings.Size())
|
||||
IncorrectCommand();
|
||||
const UString &command = nonSwitchStrings[paramIndex++];
|
||||
|
||||
bool dictionaryIsDefined = false;
|
||||
UInt32 dictionary = (UInt32)-1;
|
||||
if(parser[NKey::kDictionary].ThereIs)
|
||||
{
|
||||
UInt32 dicLog;
|
||||
if (!GetNumber(parser[NKey::kDictionary].PostStrings[0], dicLog))
|
||||
IncorrectCommand();
|
||||
dictionary = 1 << dicLog;
|
||||
dictionaryIsDefined = true;
|
||||
}
|
||||
UString mf = L"BT4";
|
||||
if (parser[NKey::kMatchFinder].ThereIs)
|
||||
mf = parser[NKey::kMatchFinder].PostStrings[0];
|
||||
|
||||
UInt32 numThreads = (UInt32)-1;
|
||||
|
||||
#ifdef COMPRESS_MF_MT
|
||||
if (parser[NKey::kMultiThread].ThereIs)
|
||||
{
|
||||
UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();
|
||||
const UString &s = parser[NKey::kMultiThread].PostStrings[0];
|
||||
if (s.IsEmpty())
|
||||
numThreads = numCPUs;
|
||||
else
|
||||
if (!GetNumber(s, numThreads))
|
||||
IncorrectCommand();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (command.CompareNoCase(L"b") == 0)
|
||||
{
|
||||
const UInt32 kNumDefaultItereations = 1;
|
||||
UInt32 numIterations = kNumDefaultItereations;
|
||||
{
|
||||
if (paramIndex < nonSwitchStrings.Size())
|
||||
if (!GetNumber(nonSwitchStrings[paramIndex++], numIterations))
|
||||
numIterations = kNumDefaultItereations;
|
||||
}
|
||||
return LzmaBenchCon(stderr, numIterations, numThreads, dictionary);
|
||||
}
|
||||
|
||||
if (numThreads == (UInt32)-1)
|
||||
numThreads = 1;
|
||||
|
||||
bool encodeMode = false;
|
||||
if (command.CompareNoCase(L"e") == 0)
|
||||
encodeMode = true;
|
||||
else if (command.CompareNoCase(L"d") == 0)
|
||||
encodeMode = false;
|
||||
else
|
||||
IncorrectCommand();
|
||||
|
||||
bool stdInMode = parser[NKey::kStdIn].ThereIs;
|
||||
bool stdOutMode = parser[NKey::kStdOut].ThereIs;
|
||||
|
||||
CMyComPtr<ISequentialInStream> inStream;
|
||||
CInFileStream *inStreamSpec = 0;
|
||||
if (stdInMode)
|
||||
{
|
||||
inStream = new CStdInFileStream;
|
||||
MY_SET_BINARY_MODE(stdin);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (paramIndex >= nonSwitchStrings.Size())
|
||||
IncorrectCommand();
|
||||
const UString &inputName = nonSwitchStrings[paramIndex++];
|
||||
inStreamSpec = new CInFileStream;
|
||||
inStream = inStreamSpec;
|
||||
if (!inStreamSpec->Open(GetSystemString(inputName)))
|
||||
{
|
||||
fprintf(stderr, "\nError: can not open input file %s\n",
|
||||
(const char *)GetOemString(inputName));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
CMyComPtr<ISequentialOutStream> outStream;
|
||||
COutFileStream *outStreamSpec = NULL;
|
||||
if (stdOutMode)
|
||||
{
|
||||
outStream = new CStdOutFileStream;
|
||||
MY_SET_BINARY_MODE(stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (paramIndex >= nonSwitchStrings.Size())
|
||||
IncorrectCommand();
|
||||
const UString &outputName = nonSwitchStrings[paramIndex++];
|
||||
outStreamSpec = new COutFileStream;
|
||||
outStream = outStreamSpec;
|
||||
if (!outStreamSpec->Create(GetSystemString(outputName), true))
|
||||
{
|
||||
fprintf(stderr, "\nError: can not open output file %s\n",
|
||||
(const char *)GetOemString(outputName));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (parser[NKey::kFilter86].ThereIs)
|
||||
{
|
||||
// -f86 switch is for x86 filtered mode: BCJ + LZMA.
|
||||
if (parser[NKey::kEOS].ThereIs || stdInMode)
|
||||
throw "Can not use stdin in this mode";
|
||||
UInt64 fileSize;
|
||||
inStreamSpec->File.GetLength(fileSize);
|
||||
if (fileSize > 0xF0000000)
|
||||
throw "File is too big";
|
||||
UInt32 inSize = (UInt32)fileSize;
|
||||
Byte *inBuffer = 0;
|
||||
if (inSize != 0)
|
||||
{
|
||||
inBuffer = (Byte *)MyAlloc((size_t)inSize);
|
||||
if (inBuffer == 0)
|
||||
throw kCantAllocate;
|
||||
}
|
||||
|
||||
UInt32 processedSize;
|
||||
if (ReadStream(inStream, inBuffer, (UInt32)inSize, &processedSize) != S_OK)
|
||||
throw "Can not read";
|
||||
if ((UInt32)inSize != processedSize)
|
||||
throw "Read size error";
|
||||
|
||||
Byte *outBuffer = 0;
|
||||
size_t outSizeProcessed;
|
||||
if (encodeMode)
|
||||
{
|
||||
// we allocate 105% of original size for output buffer
|
||||
size_t outSize = (size_t)fileSize / 20 * 21 + (1 << 16);
|
||||
if (outSize != 0)
|
||||
{
|
||||
outBuffer = (Byte *)MyAlloc((size_t)outSize);
|
||||
if (outBuffer == 0)
|
||||
throw kCantAllocate;
|
||||
}
|
||||
if (!dictionaryIsDefined)
|
||||
dictionary = 1 << 23;
|
||||
int res = LzmaRamEncode(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed,
|
||||
dictionary, parser[NKey::kFilter86].PostCharIndex == 0 ? SZ_FILTER_YES : SZ_FILTER_AUTO);
|
||||
if (res != 0)
|
||||
{
|
||||
fprintf(stderr, "\nEncoder error = %d\n", (int)res);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t outSize;
|
||||
if (LzmaRamGetUncompressedSize(inBuffer, inSize, &outSize) != 0)
|
||||
throw "data error";
|
||||
if (outSize != 0)
|
||||
{
|
||||
outBuffer = (Byte *)MyAlloc(outSize);
|
||||
if (outBuffer == 0)
|
||||
throw kCantAllocate;
|
||||
}
|
||||
int res = LzmaRamDecompress(inBuffer, inSize, outBuffer, outSize, &outSizeProcessed, malloc, free);
|
||||
if (res != 0)
|
||||
throw "LzmaDecoder error";
|
||||
}
|
||||
if (WriteStream(outStream, outBuffer, (UInt32)outSizeProcessed, &processedSize) != S_OK)
|
||||
throw kWriteError;
|
||||
MyFree(outBuffer);
|
||||
MyFree(inBuffer);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
UInt64 fileSize;
|
||||
if (encodeMode)
|
||||
{
|
||||
NCompress::NLZMA::CEncoder *encoderSpec = new NCompress::NLZMA::CEncoder;
|
||||
CMyComPtr<ICompressCoder> encoder = encoderSpec;
|
||||
|
||||
if (!dictionaryIsDefined)
|
||||
dictionary = 1 << 23;
|
||||
|
||||
UInt32 posStateBits = 2;
|
||||
UInt32 litContextBits = 3; // for normal files
|
||||
// UInt32 litContextBits = 0; // for 32-bit data
|
||||
UInt32 litPosBits = 0;
|
||||
// UInt32 litPosBits = 2; // for 32-bit data
|
||||
UInt32 algorithm = 1;
|
||||
UInt32 numFastBytes = 128;
|
||||
UInt32 matchFinderCycles = 16 + numFastBytes / 2;
|
||||
bool matchFinderCyclesDefined = false;
|
||||
|
||||
bool eos = parser[NKey::kEOS].ThereIs || stdInMode;
|
||||
|
||||
if(parser[NKey::kMode].ThereIs)
|
||||
if (!GetNumber(parser[NKey::kMode].PostStrings[0], algorithm))
|
||||
IncorrectCommand();
|
||||
|
||||
if(parser[NKey::kFastBytes].ThereIs)
|
||||
if (!GetNumber(parser[NKey::kFastBytes].PostStrings[0], numFastBytes))
|
||||
IncorrectCommand();
|
||||
matchFinderCyclesDefined = parser[NKey::kMatchFinderCycles].ThereIs;
|
||||
if (matchFinderCyclesDefined)
|
||||
if (!GetNumber(parser[NKey::kMatchFinderCycles].PostStrings[0], matchFinderCycles))
|
||||
IncorrectCommand();
|
||||
if(parser[NKey::kLitContext].ThereIs)
|
||||
if (!GetNumber(parser[NKey::kLitContext].PostStrings[0], litContextBits))
|
||||
IncorrectCommand();
|
||||
if(parser[NKey::kLitPos].ThereIs)
|
||||
if (!GetNumber(parser[NKey::kLitPos].PostStrings[0], litPosBits))
|
||||
IncorrectCommand();
|
||||
if(parser[NKey::kPosBits].ThereIs)
|
||||
if (!GetNumber(parser[NKey::kPosBits].PostStrings[0], posStateBits))
|
||||
IncorrectCommand();
|
||||
|
||||
PROPID propIDs[] =
|
||||
{
|
||||
NCoderPropID::kDictionarySize,
|
||||
NCoderPropID::kPosStateBits,
|
||||
NCoderPropID::kLitContextBits,
|
||||
NCoderPropID::kLitPosBits,
|
||||
NCoderPropID::kAlgorithm,
|
||||
NCoderPropID::kNumFastBytes,
|
||||
NCoderPropID::kMatchFinder,
|
||||
NCoderPropID::kEndMarker,
|
||||
NCoderPropID::kNumThreads,
|
||||
NCoderPropID::kMatchFinderCycles,
|
||||
};
|
||||
const int kNumPropsMax = sizeof(propIDs) / sizeof(propIDs[0]);
|
||||
|
||||
PROPVARIANT properties[kNumPropsMax];
|
||||
for (int p = 0; p < 6; p++)
|
||||
properties[p].vt = VT_UI4;
|
||||
|
||||
properties[0].ulVal = (UInt32)dictionary;
|
||||
properties[1].ulVal = (UInt32)posStateBits;
|
||||
properties[2].ulVal = (UInt32)litContextBits;
|
||||
properties[3].ulVal = (UInt32)litPosBits;
|
||||
properties[4].ulVal = (UInt32)algorithm;
|
||||
properties[5].ulVal = (UInt32)numFastBytes;
|
||||
|
||||
properties[6].vt = VT_BSTR;
|
||||
properties[6].bstrVal = (BSTR)(const wchar_t *)mf;
|
||||
|
||||
properties[7].vt = VT_BOOL;
|
||||
properties[7].boolVal = eos ? VARIANT_TRUE : VARIANT_FALSE;
|
||||
|
||||
properties[8].vt = VT_UI4;
|
||||
properties[8].ulVal = (UInt32)numThreads;
|
||||
|
||||
// it must be last in property list
|
||||
properties[9].vt = VT_UI4;
|
||||
properties[9].ulVal = (UInt32)matchFinderCycles;
|
||||
|
||||
int numProps = kNumPropsMax;
|
||||
if (!matchFinderCyclesDefined)
|
||||
numProps--;
|
||||
|
||||
if (encoderSpec->SetCoderProperties(propIDs, properties, numProps) != S_OK)
|
||||
IncorrectCommand();
|
||||
encoderSpec->WriteCoderProperties(outStream);
|
||||
|
||||
if (eos || stdInMode)
|
||||
fileSize = (UInt64)(Int64)-1;
|
||||
else
|
||||
inStreamSpec->File.GetLength(fileSize);
|
||||
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
Byte b = Byte(fileSize >> (8 * i));
|
||||
if (outStream->Write(&b, 1, 0) != S_OK)
|
||||
{
|
||||
fprintf(stderr, kWriteError);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
HRESULT result = encoder->Code(inStream, outStream, 0, 0, 0);
|
||||
if (result == E_OUTOFMEMORY)
|
||||
{
|
||||
fprintf(stderr, "\nError: Can not allocate memory\n");
|
||||
return 1;
|
||||
}
|
||||
else if (result != S_OK)
|
||||
{
|
||||
fprintf(stderr, "\nEncoder error = %X\n", (unsigned int)result);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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)
|
||||
{
|
||||
fprintf(stderr, kReadError);
|
||||
return 1;
|
||||
}
|
||||
if (decoderSpec->SetDecoderProperties2(properties, 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)
|
||||
{
|
||||
fprintf(stderr, "Decoder error");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (outStreamSpec != NULL)
|
||||
{
|
||||
if (outStreamSpec->Close() != S_OK)
|
||||
{
|
||||
fprintf(stderr, "File closing error");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int n, const char *args[])
|
||||
{
|
||||
try { return main2(n, args); }
|
||||
catch(const char *s)
|
||||
{
|
||||
fprintf(stderr, "\nError: %s\n", s);
|
||||
return 1;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
fprintf(stderr, "\nError\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
1024
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp
Normal file
1024
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaBench.cpp
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,48 @@
|
|||
// LzmaBench.h
|
||||
|
||||
#ifndef __LZMABENCH_H
|
||||
#define __LZMABENCH_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../../../Common/Types.h"
|
||||
#ifdef EXTERNAL_LZMA
|
||||
#include "../../UI/Common/LoadCodecs.h"
|
||||
#endif
|
||||
|
||||
struct CBenchInfo
|
||||
{
|
||||
UInt64 GlobalTime;
|
||||
UInt64 GlobalFreq;
|
||||
UInt64 UserTime;
|
||||
UInt64 UserFreq;
|
||||
UInt64 UnpackSize;
|
||||
UInt64 PackSize;
|
||||
UInt32 NumIterations;
|
||||
CBenchInfo(): NumIterations(0) {}
|
||||
};
|
||||
|
||||
struct IBenchCallback
|
||||
{
|
||||
virtual HRESULT SetEncodeResult(const CBenchInfo &info, bool final) = 0;
|
||||
virtual HRESULT SetDecodeResult(const CBenchInfo &info, bool final) = 0;
|
||||
};
|
||||
|
||||
UInt64 GetUsage(const CBenchInfo &benchOnfo);
|
||||
UInt64 GetRatingPerUsage(const CBenchInfo &info, UInt64 rating);
|
||||
UInt64 GetCompressRating(UInt32 dictionarySize, UInt64 elapsedTime, UInt64 freq, UInt64 size);
|
||||
UInt64 GetDecompressRating(UInt64 elapsedTime, UInt64 freq, UInt64 outSize, UInt64 inSize, UInt32 numIterations);
|
||||
|
||||
HRESULT LzmaBench(
|
||||
#ifdef EXTERNAL_LZMA
|
||||
CCodecs *codecs,
|
||||
#endif
|
||||
UInt32 numThreads, UInt32 dictionarySize, IBenchCallback *callback);
|
||||
|
||||
const int kBenchMinDicLogSize = 18;
|
||||
|
||||
UInt64 GetBenchMemoryUsage(UInt32 numThreads, UInt32 dictionary);
|
||||
|
||||
bool CrcInternalTest();
|
||||
HRESULT CrcBench(UInt32 numThreads, UInt32 bufferSize, UInt64 &speed);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,311 @@
|
|||
// LzmaBenchCon.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "LzmaBench.h"
|
||||
#include "LzmaBenchCon.h"
|
||||
#include "../../../Common/IntToString.h"
|
||||
|
||||
#if defined(BENCH_MT) || defined(_WIN32)
|
||||
#include "../../../Windows/System.h"
|
||||
#endif
|
||||
|
||||
#ifdef BREAK_HANDLER
|
||||
#include "../../UI/Console/ConsoleClose.h"
|
||||
#endif
|
||||
#include "../../../Common/MyCom.h"
|
||||
|
||||
struct CTotalBenchRes
|
||||
{
|
||||
UInt64 NumIterations;
|
||||
UInt64 Rating;
|
||||
UInt64 Usage;
|
||||
UInt64 RPU;
|
||||
void Init() { NumIterations = 0; Rating = 0; Usage = 0; RPU = 0; }
|
||||
void Normalize()
|
||||
{
|
||||
if (NumIterations == 0)
|
||||
return;
|
||||
Rating /= NumIterations;
|
||||
Usage /= NumIterations;
|
||||
RPU /= NumIterations;
|
||||
NumIterations = 1;
|
||||
}
|
||||
void SetMid(const CTotalBenchRes &r1, const CTotalBenchRes &r2)
|
||||
{
|
||||
Rating = (r1.Rating + r2.Rating) / 2;
|
||||
Usage = (r1.Usage + r2.Usage) / 2;
|
||||
RPU = (r1.RPU + r2.RPU) / 2;
|
||||
NumIterations = (r1.NumIterations + r2.NumIterations) / 2;
|
||||
}
|
||||
};
|
||||
|
||||
struct CBenchCallback: public IBenchCallback
|
||||
{
|
||||
CTotalBenchRes EncodeRes;
|
||||
CTotalBenchRes DecodeRes;
|
||||
FILE *f;
|
||||
void Init() { EncodeRes.Init(); DecodeRes.Init(); }
|
||||
void Normalize() { EncodeRes.Normalize(); DecodeRes.Normalize(); }
|
||||
UInt32 dictionarySize;
|
||||
HRESULT SetEncodeResult(const CBenchInfo &info, bool final);
|
||||
HRESULT SetDecodeResult(const CBenchInfo &info, bool final);
|
||||
};
|
||||
|
||||
static void NormalizeVals(UInt64 &v1, UInt64 &v2)
|
||||
{
|
||||
while (v1 > 1000000)
|
||||
{
|
||||
v1 >>= 1;
|
||||
v2 >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
static UInt64 MyMultDiv64(UInt64 value, UInt64 elapsedTime, UInt64 freq)
|
||||
{
|
||||
UInt64 elTime = elapsedTime;
|
||||
NormalizeVals(freq, elTime);
|
||||
if (elTime == 0)
|
||||
elTime = 1;
|
||||
return value * freq / elTime;
|
||||
}
|
||||
|
||||
static void PrintNumber(FILE *f, UInt64 value, int size)
|
||||
{
|
||||
char s[32];
|
||||
ConvertUInt64ToString(value, s);
|
||||
fprintf(f, " ");
|
||||
for (int len = (int)strlen(s); len < size; len++)
|
||||
fprintf(f, " ");
|
||||
fprintf(f, "%s", s);
|
||||
}
|
||||
|
||||
static void PrintRating(FILE *f, UInt64 rating)
|
||||
{
|
||||
PrintNumber(f, rating / 1000000, 6);
|
||||
}
|
||||
|
||||
static void PrintResults(FILE *f, UInt64 usage, UInt64 rpu, UInt64 rating)
|
||||
{
|
||||
PrintNumber(f, (usage + 5000) / 10000, 5);
|
||||
PrintRating(f, rpu);
|
||||
PrintRating(f, rating);
|
||||
}
|
||||
|
||||
|
||||
static void PrintResults(FILE *f, const CBenchInfo &info, UInt64 rating, CTotalBenchRes &res)
|
||||
{
|
||||
UInt64 speed = MyMultDiv64(info.UnpackSize, info.GlobalTime, info.GlobalFreq);
|
||||
PrintNumber(f, speed / 1024, 7);
|
||||
UInt64 usage = GetUsage(info);
|
||||
UInt64 rpu = GetRatingPerUsage(info, rating);
|
||||
PrintResults(f, usage, rpu, rating);
|
||||
res.NumIterations++;
|
||||
res.RPU += rpu;
|
||||
res.Rating += rating;
|
||||
res.Usage += usage;
|
||||
}
|
||||
|
||||
static void PrintTotals(FILE *f, const CTotalBenchRes &res)
|
||||
{
|
||||
fprintf(f, " ");
|
||||
PrintResults(f, res.Usage, res.RPU, res.Rating);
|
||||
}
|
||||
|
||||
|
||||
HRESULT CBenchCallback::SetEncodeResult(const CBenchInfo &info, bool final)
|
||||
{
|
||||
#ifdef BREAK_HANDLER
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
#endif
|
||||
|
||||
if (final)
|
||||
{
|
||||
UInt64 rating = GetCompressRating(dictionarySize, info.GlobalTime, info.GlobalFreq, info.UnpackSize);
|
||||
PrintResults(f, info, rating, EncodeRes);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static const char *kSep = " | ";
|
||||
|
||||
|
||||
HRESULT CBenchCallback::SetDecodeResult(const CBenchInfo &info, bool final)
|
||||
{
|
||||
#ifdef BREAK_HANDLER
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
#endif
|
||||
if (final)
|
||||
{
|
||||
UInt64 rating = GetDecompressRating(info.GlobalTime, info.GlobalFreq, info.UnpackSize, info.PackSize, info.NumIterations);
|
||||
fprintf(f, kSep);
|
||||
CBenchInfo info2 = info;
|
||||
info2.UnpackSize *= info2.NumIterations;
|
||||
info2.PackSize *= info2.NumIterations;
|
||||
info2.NumIterations = 1;
|
||||
PrintResults(f, info2, rating, DecodeRes);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static void PrintRequirements(FILE *f, const char *sizeString, UInt64 size, const char *threadsString, UInt32 numThreads)
|
||||
{
|
||||
fprintf(f, "\nRAM %s ", sizeString);
|
||||
PrintNumber(f, (size >> 20), 5);
|
||||
fprintf(f, " MB, # %s %3d", threadsString, (unsigned int)numThreads);
|
||||
}
|
||||
|
||||
HRESULT LzmaBenchCon(
|
||||
#ifdef EXTERNAL_LZMA
|
||||
CCodecs *codecs,
|
||||
#endif
|
||||
FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)
|
||||
{
|
||||
if (!CrcInternalTest())
|
||||
return S_FALSE;
|
||||
#ifdef BENCH_MT
|
||||
UInt64 ramSize = NWindows::NSystem::GetRamSize(); //
|
||||
UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();
|
||||
PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs);
|
||||
if (numThreads == (UInt32)-1)
|
||||
numThreads = numCPUs;
|
||||
if (numThreads > 1)
|
||||
numThreads &= ~1;
|
||||
if (dictionary == (UInt32)-1)
|
||||
{
|
||||
int dicSizeLog;
|
||||
for (dicSizeLog = 25; dicSizeLog > kBenchMinDicLogSize; dicSizeLog--)
|
||||
if (GetBenchMemoryUsage(numThreads, ((UInt32)1 << dicSizeLog)) + (8 << 20) <= ramSize)
|
||||
break;
|
||||
dictionary = (1 << dicSizeLog);
|
||||
}
|
||||
#else
|
||||
if (dictionary == (UInt32)-1)
|
||||
dictionary = (1 << 22);
|
||||
numThreads = 1;
|
||||
#endif
|
||||
|
||||
PrintRequirements(f, "usage:", GetBenchMemoryUsage(numThreads, dictionary), "Benchmark threads: ", numThreads);
|
||||
|
||||
CBenchCallback callback;
|
||||
callback.Init();
|
||||
callback.f = f;
|
||||
|
||||
fprintf(f, "\n\nDict Compressing | Decompressing\n ");
|
||||
int j;
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
fprintf(f, " Speed Usage R/U Rating");
|
||||
if (j == 0)
|
||||
fprintf(f, kSep);
|
||||
}
|
||||
fprintf(f, "\n ");
|
||||
for (j = 0; j < 2; j++)
|
||||
{
|
||||
fprintf(f, " KB/s %% MIPS MIPS");
|
||||
if (j == 0)
|
||||
fprintf(f, kSep);
|
||||
}
|
||||
fprintf(f, "\n\n");
|
||||
for (UInt32 i = 0; i < numIterations; i++)
|
||||
{
|
||||
const int kStartDicLog = 22;
|
||||
int pow = (dictionary < ((UInt32)1 << kStartDicLog)) ? kBenchMinDicLogSize : kStartDicLog;
|
||||
while (((UInt32)1 << pow) > dictionary)
|
||||
pow--;
|
||||
for (; ((UInt32)1 << pow) <= dictionary; pow++)
|
||||
{
|
||||
fprintf(f, "%2d:", pow);
|
||||
callback.dictionarySize = (UInt32)1 << pow;
|
||||
HRESULT res = LzmaBench(
|
||||
#ifdef EXTERNAL_LZMA
|
||||
codecs,
|
||||
#endif
|
||||
numThreads, callback.dictionarySize, &callback);
|
||||
fprintf(f, "\n");
|
||||
RINOK(res);
|
||||
}
|
||||
}
|
||||
callback.Normalize();
|
||||
fprintf(f, "----------------------------------------------------------------\nAvr:");
|
||||
PrintTotals(f, callback.EncodeRes);
|
||||
fprintf(f, " ");
|
||||
PrintTotals(f, callback.DecodeRes);
|
||||
fprintf(f, "\nTot:");
|
||||
CTotalBenchRes midRes;
|
||||
midRes.SetMid(callback.EncodeRes, callback.DecodeRes);
|
||||
PrintTotals(f, midRes);
|
||||
fprintf(f, "\n");
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
struct CTempValues
|
||||
{
|
||||
UInt64 *Values;
|
||||
CTempValues(UInt32 num) { Values = new UInt64[num]; }
|
||||
~CTempValues() { delete []Values; }
|
||||
};
|
||||
|
||||
HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary)
|
||||
{
|
||||
if (!CrcInternalTest())
|
||||
return S_FALSE;
|
||||
|
||||
#ifdef BENCH_MT
|
||||
UInt64 ramSize = NWindows::NSystem::GetRamSize();
|
||||
UInt32 numCPUs = NWindows::NSystem::GetNumberOfProcessors();
|
||||
PrintRequirements(f, "size: ", ramSize, "CPU hardware threads:", numCPUs);
|
||||
if (numThreads == (UInt32)-1)
|
||||
numThreads = numCPUs;
|
||||
#else
|
||||
numThreads = 1;
|
||||
#endif
|
||||
if (dictionary == (UInt32)-1)
|
||||
dictionary = (1 << 24);
|
||||
|
||||
CTempValues speedTotals(numThreads);
|
||||
fprintf(f, "\n\nSize");
|
||||
for (UInt32 ti = 0; ti < numThreads; ti++)
|
||||
{
|
||||
fprintf(f, " %5d", ti + 1);
|
||||
speedTotals.Values[ti] = 0;
|
||||
}
|
||||
fprintf(f, "\n\n");
|
||||
|
||||
UInt64 numSteps = 0;
|
||||
for (UInt32 i = 0; i < numIterations; i++)
|
||||
{
|
||||
for (int pow = 10; pow < 32; pow++)
|
||||
{
|
||||
UInt32 bufSize = (UInt32)1 << pow;
|
||||
if (bufSize > dictionary)
|
||||
break;
|
||||
fprintf(f, "%2d: ", pow);
|
||||
UInt64 speed;
|
||||
for (UInt32 ti = 0; ti < numThreads; ti++)
|
||||
{
|
||||
#ifdef BREAK_HANDLER
|
||||
if (NConsoleClose::TestBreakSignal())
|
||||
return E_ABORT;
|
||||
#endif
|
||||
RINOK(CrcBench(ti + 1, bufSize, speed));
|
||||
PrintNumber(f, (speed >> 20), 5);
|
||||
speedTotals.Values[ti] += speed;
|
||||
}
|
||||
fprintf(f, "\n");
|
||||
numSteps++;
|
||||
}
|
||||
}
|
||||
if (numSteps != 0)
|
||||
{
|
||||
fprintf(f, "\nAvg:");
|
||||
for (UInt32 ti = 0; ti < numThreads; ti++)
|
||||
PrintNumber(f, ((speedTotals.Values[ti] / numSteps) >> 20), 5);
|
||||
fprintf(f, "\n");
|
||||
}
|
||||
return S_OK;
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
// LzmaBenchCon.h
|
||||
|
||||
#ifndef __LZMABENCHCON_H
|
||||
#define __LZMABENCHCON_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../../../Common/Types.h"
|
||||
#ifdef EXTERNAL_LZMA
|
||||
#include "../../UI/Common/LoadCodecs.h"
|
||||
#endif
|
||||
HRESULT LzmaBenchCon(
|
||||
#ifdef EXTERNAL_LZMA
|
||||
CCodecs *codecs,
|
||||
#endif
|
||||
FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);
|
||||
|
||||
HRESULT CrcBenchCon(FILE *f, UInt32 numIterations, UInt32 numThreads, UInt32 dictionary);
|
||||
|
||||
#endif
|
||||
|
226
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp
Normal file
226
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRam.cpp
Normal file
|
@ -0,0 +1,226 @@
|
|||
// 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
|
||||
}
|
46
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRam.h
Normal file
46
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA_Alone/LzmaRam.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
// 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
|
|
@ -0,0 +1,78 @@
|
|||
/* 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;
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/* 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
|
|
@ -0,0 +1,3 @@
|
|||
// StdAfx.cpp
|
||||
|
||||
#include "StdAfx.h"
|
|
@ -0,0 +1,8 @@
|
|||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#include "../../../Common/MyWindows.h"
|
||||
|
||||
#endif
|
136
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA_Alone/makefile
Normal file
136
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA_Alone/makefile
Normal file
|
@ -0,0 +1,136 @@
|
|||
PROG = lzma.exe
|
||||
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 \
|
||||
$O\LZMAEncoder.obj \
|
||||
|
||||
COMMON_OBJS = \
|
||||
$O\CommandLineParser.obj \
|
||||
$O\CRC.obj \
|
||||
$O\IntToString.obj \
|
||||
$O\MyString.obj \
|
||||
$O\StringConvert.obj \
|
||||
$O\StringToInt.obj \
|
||||
$O\MyVector.obj
|
||||
|
||||
WIN_OBJS = \
|
||||
$O\System.obj
|
||||
|
||||
7ZIP_COMMON_OBJS = \
|
||||
$O\InBuffer.obj \
|
||||
$O\OutBuffer.obj \
|
||||
$O\StreamUtils.obj \
|
||||
|
||||
LZ_OBJS = \
|
||||
$O\LZOutWindow.obj \
|
||||
|
||||
C_OBJS = \
|
||||
$O\Alloc.obj \
|
||||
$O\7zCrc.obj \
|
||||
$O\Threads.obj \
|
||||
|
||||
C_LZ_OBJS = \
|
||||
$O\MatchFinder.obj \
|
||||
$O\MatchFinderMt.obj \
|
||||
|
||||
OBJS = \
|
||||
$(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 \
|
||||
$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)
|
||||
|
||||
|
||||
$(LZMA_OBJS): $(*B).cpp
|
||||
$(COMPL)
|
||||
$(LZMA_OPT_OBJS): ../LZMA/$(*B).cpp
|
||||
$(COMPL_O2)
|
||||
$(COMMON_OBJS): ../../../Common/$(*B).cpp
|
||||
$(COMPL)
|
||||
$(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
|
||||
$(COMPL_O2)
|
139
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA_Alone/makefile.gcc
Normal file
139
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/LZMA_Alone/makefile.gcc
Normal file
|
@ -0,0 +1,139 @@
|
|||
PROG = lzma
|
||||
CXX = g++ -O2 -Wall
|
||||
CXX_C = gcc -O2 -Wall
|
||||
LIB = -lm
|
||||
RM = rm -f
|
||||
CFLAGS = -c
|
||||
|
||||
ifdef SystemDrive
|
||||
IS_MINGW = 1
|
||||
endif
|
||||
|
||||
ifdef IS_MINGW
|
||||
FILE_IO =FileIO
|
||||
FILE_IO_2 =Windows/$(FILE_IO)
|
||||
LIB2 = -luuid
|
||||
else
|
||||
FILE_IO =C_FileIO
|
||||
FILE_IO_2 =Common/$(FILE_IO)
|
||||
endif
|
||||
|
||||
OBJS = \
|
||||
LzmaAlone.o \
|
||||
LzmaBench.o \
|
||||
LzmaBenchCon.o \
|
||||
LzmaRam.o \
|
||||
LZMADecoder.o \
|
||||
LZMAEncoder.o \
|
||||
LZOutWindow.o \
|
||||
RangeCoderBit.o \
|
||||
InBuffer.o \
|
||||
OutBuffer.o \
|
||||
FileStreams.o \
|
||||
StreamUtils.o \
|
||||
$(FILE_IO).o \
|
||||
CommandLineParser.o \
|
||||
CRC.o \
|
||||
IntToString.o \
|
||||
MyString.o \
|
||||
StringConvert.o \
|
||||
StringToInt.o \
|
||||
MyVector.o \
|
||||
7zCrc.o \
|
||||
Alloc.o \
|
||||
BranchX86.o \
|
||||
MatchFinder.o \
|
||||
LzmaDecode.o \
|
||||
LzmaRamDecode.o \
|
||||
|
||||
|
||||
all: $(PROG)
|
||||
|
||||
$(PROG): $(OBJS)
|
||||
$(CXX) -o $(PROG) $(LDFLAGS) $(OBJS) $(LIB) $(LIB2)
|
||||
|
||||
LzmaAlone.o: LzmaAlone.cpp
|
||||
$(CXX) $(CFLAGS) LzmaAlone.cpp
|
||||
|
||||
LzmaBench.o: LzmaBench.cpp
|
||||
$(CXX) $(CFLAGS) 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
|
||||
|
||||
OutBuffer.o: ../../Common/OutBuffer.cpp
|
||||
$(CXX) $(CFLAGS) ../../Common/OutBuffer.cpp
|
||||
|
||||
FileStreams.o: ../../Common/FileStreams.cpp
|
||||
$(CXX) $(CFLAGS) ../../Common/FileStreams.cpp
|
||||
|
||||
StreamUtils.o: ../../Common/StreamUtils.cpp
|
||||
$(CXX) $(CFLAGS) ../../Common/StreamUtils.cpp
|
||||
|
||||
$(FILE_IO).o: ../../../$(FILE_IO_2).cpp
|
||||
$(CXX) $(CFLAGS) ../../../$(FILE_IO_2).cpp
|
||||
|
||||
|
||||
CommandLineParser.o: ../../../Common/CommandLineParser.cpp
|
||||
$(CXX) $(CFLAGS) ../../../Common/CommandLineParser.cpp
|
||||
|
||||
CRC.o: ../../../Common/CRC.cpp
|
||||
$(CXX) $(CFLAGS) ../../../Common/CRC.cpp
|
||||
|
||||
MyWindows.o: ../../../Common/MyWindows.cpp
|
||||
$(CXX) $(CFLAGS) ../../../Common/MyWindows.cpp
|
||||
|
||||
IntToString.o: ../../../Common/IntToString.cpp
|
||||
$(CXX) $(CFLAGS) ../../../Common/IntToString.cpp
|
||||
|
||||
MyString.o: ../../../Common/MyString.cpp
|
||||
$(CXX) $(CFLAGS) ../../../Common/MyString.cpp
|
||||
|
||||
StringConvert.o: ../../../Common/StringConvert.cpp
|
||||
$(CXX) $(CFLAGS) ../../../Common/StringConvert.cpp
|
||||
|
||||
StringToInt.o: ../../../Common/StringToInt.cpp
|
||||
$(CXX) $(CFLAGS) ../../../Common/StringToInt.cpp
|
||||
|
||||
MyVector.o: ../../../Common/MyVector.cpp
|
||||
$(CXX) $(CFLAGS) ../../../Common/MyVector.cpp
|
||||
|
||||
7zCrc.o: ../../../../C/7zCrc.c
|
||||
$(CXX_C) $(CFLAGS) ../../../../C/7zCrc.c
|
||||
|
||||
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
|
||||
|
||||
MatchFinder.o: ../../../../C/Compress/Lz/MatchFinder.c
|
||||
$(CXX_C) $(CFLAGS) ../../../../C/Compress/Lz/MatchFinder.c
|
||||
|
||||
LzmaDecode.o: ../../../../C/Compress/Lzma/LzmaDecode.c
|
||||
$(CXX_C) $(CFLAGS) ../../../../C/Compress/Lzma/LzmaDecode.c
|
||||
|
||||
LzmaRamDecode.o: LzmaRamDecode.c
|
||||
$(CXX_C) $(CFLAGS) LzmaRamDecode.c
|
||||
|
||||
clean:
|
||||
-$(RM) $(PROG) $(OBJS)
|
||||
|
205
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/RangeCoder/RangeCoder.h
Normal file
205
lib/physfs-2.0.3/lzma/CPP/7zip/Compress/RangeCoder/RangeCoder.h
Normal file
|
@ -0,0 +1,205 @@
|
|||
// Compress/RangeCoder/RangeCoder.h
|
||||
|
||||
#ifndef __COMPRESS_RANGECODER_H
|
||||
#define __COMPRESS_RANGECODER_H
|
||||
|
||||
#include "../../Common/InBuffer.h"
|
||||
#include "../../Common/OutBuffer.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NRangeCoder {
|
||||
|
||||
const int kNumTopBits = 24;
|
||||
const UInt32 kTopValue = (1 << kNumTopBits);
|
||||
|
||||
class CEncoder
|
||||
{
|
||||
UInt32 _cacheSize;
|
||||
Byte _cache;
|
||||
public:
|
||||
UInt64 Low;
|
||||
UInt32 Range;
|
||||
COutBuffer Stream;
|
||||
bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }
|
||||
|
||||
void SetStream(ISequentialOutStream *stream) { Stream.SetStream(stream); }
|
||||
void Init()
|
||||
{
|
||||
Stream.Init();
|
||||
Low = 0;
|
||||
Range = 0xFFFFFFFF;
|
||||
_cacheSize = 1;
|
||||
_cache = 0;
|
||||
}
|
||||
|
||||
void FlushData()
|
||||
{
|
||||
// Low += 1;
|
||||
for(int i = 0; i < 5; i++)
|
||||
ShiftLow();
|
||||
}
|
||||
|
||||
HRESULT FlushStream() { return Stream.Flush(); }
|
||||
|
||||
void ReleaseStream() { Stream.ReleaseStream(); }
|
||||
|
||||
void Encode(UInt32 start, UInt32 size, UInt32 total)
|
||||
{
|
||||
Low += start * (Range /= total);
|
||||
Range *= size;
|
||||
while (Range < kTopValue)
|
||||
{
|
||||
Range <<= 8;
|
||||
ShiftLow();
|
||||
}
|
||||
}
|
||||
|
||||
void ShiftLow()
|
||||
{
|
||||
if ((UInt32)Low < (UInt32)0xFF000000 || (int)(Low >> 32) != 0)
|
||||
{
|
||||
Byte temp = _cache;
|
||||
do
|
||||
{
|
||||
Stream.WriteByte((Byte)(temp + (Byte)(Low >> 32)));
|
||||
temp = 0xFF;
|
||||
}
|
||||
while(--_cacheSize != 0);
|
||||
_cache = (Byte)((UInt32)Low >> 24);
|
||||
}
|
||||
_cacheSize++;
|
||||
Low = (UInt32)Low << 8;
|
||||
}
|
||||
|
||||
void EncodeDirectBits(UInt32 value, int numTotalBits)
|
||||
{
|
||||
for (int i = numTotalBits - 1; i >= 0; i--)
|
||||
{
|
||||
Range >>= 1;
|
||||
if (((value >> i) & 1) == 1)
|
||||
Low += Range;
|
||||
if (Range < kTopValue)
|
||||
{
|
||||
Range <<= 8;
|
||||
ShiftLow();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EncodeBit(UInt32 size0, UInt32 numTotalBits, UInt32 symbol)
|
||||
{
|
||||
UInt32 newBound = (Range >> numTotalBits) * size0;
|
||||
if (symbol == 0)
|
||||
Range = newBound;
|
||||
else
|
||||
{
|
||||
Low += newBound;
|
||||
Range -= newBound;
|
||||
}
|
||||
while (Range < kTopValue)
|
||||
{
|
||||
Range <<= 8;
|
||||
ShiftLow();
|
||||
}
|
||||
}
|
||||
|
||||
UInt64 GetProcessedSize() { return Stream.GetProcessedSize() + _cacheSize + 4; }
|
||||
};
|
||||
|
||||
class CDecoder
|
||||
{
|
||||
public:
|
||||
CInBuffer Stream;
|
||||
UInt32 Range;
|
||||
UInt32 Code;
|
||||
bool Create(UInt32 bufferSize) { return Stream.Create(bufferSize); }
|
||||
|
||||
void Normalize()
|
||||
{
|
||||
while (Range < kTopValue)
|
||||
{
|
||||
Code = (Code << 8) | Stream.ReadByte();
|
||||
Range <<= 8;
|
||||
}
|
||||
}
|
||||
|
||||
void SetStream(ISequentialInStream *stream) { Stream.SetStream(stream); }
|
||||
void Init()
|
||||
{
|
||||
Stream.Init();
|
||||
Code = 0;
|
||||
Range = 0xFFFFFFFF;
|
||||
for(int i = 0; i < 5; i++)
|
||||
Code = (Code << 8) | Stream.ReadByte();
|
||||
}
|
||||
|
||||
void ReleaseStream() { Stream.ReleaseStream(); }
|
||||
|
||||
UInt32 GetThreshold(UInt32 total)
|
||||
{
|
||||
return (Code) / ( Range /= total);
|
||||
}
|
||||
|
||||
void Decode(UInt32 start, UInt32 size)
|
||||
{
|
||||
Code -= start * Range;
|
||||
Range *= size;
|
||||
Normalize();
|
||||
}
|
||||
|
||||
UInt32 DecodeDirectBits(int numTotalBits)
|
||||
{
|
||||
UInt32 range = Range;
|
||||
UInt32 code = Code;
|
||||
UInt32 result = 0;
|
||||
for (int i = numTotalBits; i != 0; i--)
|
||||
{
|
||||
range >>= 1;
|
||||
/*
|
||||
result <<= 1;
|
||||
if (code >= range)
|
||||
{
|
||||
code -= range;
|
||||
result |= 1;
|
||||
}
|
||||
*/
|
||||
UInt32 t = (code - range) >> 31;
|
||||
code -= range & (t - 1);
|
||||
result = (result << 1) | (1 - t);
|
||||
|
||||
if (range < kTopValue)
|
||||
{
|
||||
code = (code << 8) | Stream.ReadByte();
|
||||
range <<= 8;
|
||||
}
|
||||
}
|
||||
Range = range;
|
||||
Code = code;
|
||||
return result;
|
||||
}
|
||||
|
||||
UInt32 DecodeBit(UInt32 size0, UInt32 numTotalBits)
|
||||
{
|
||||
UInt32 newBound = (Range >> numTotalBits) * size0;
|
||||
UInt32 symbol;
|
||||
if (Code < newBound)
|
||||
{
|
||||
symbol = 0;
|
||||
Range = newBound;
|
||||
}
|
||||
else
|
||||
{
|
||||
symbol = 1;
|
||||
Code -= newBound;
|
||||
Range -= newBound;
|
||||
}
|
||||
Normalize();
|
||||
return symbol;
|
||||
}
|
||||
|
||||
UInt64 GetProcessedSize() {return Stream.GetProcessedSize(); }
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,80 @@
|
|||
// Compress/RangeCoder/RangeCoderBit.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "RangeCoderBit.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NRangeCoder {
|
||||
|
||||
UInt32 CPriceTables::ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
|
||||
static CPriceTables g_PriceTables;
|
||||
|
||||
CPriceTables::CPriceTables() { Init(); }
|
||||
|
||||
void CPriceTables::Init()
|
||||
{
|
||||
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++)
|
||||
{
|
||||
const int kCyclesBits = 5;
|
||||
const UInt32 kCycles = (1 << kCyclesBits);
|
||||
|
||||
UInt32 range = UInt32(-1);
|
||||
UInt32 bitCount = 0;
|
||||
for (UInt32 j = 0; j < kCycles; j++)
|
||||
{
|
||||
range >>= (kNumBitModelTotalBits - kNumMoveReducingBits);
|
||||
range *= i;
|
||||
while(range < (1 << 31))
|
||||
{
|
||||
range <<= 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;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
}}
|
|
@ -0,0 +1,120 @@
|
|||
// Compress/RangeCoder/RangeCoderBit.h
|
||||
|
||||
#ifndef __COMPRESS_RANGECODER_BIT_H
|
||||
#define __COMPRESS_RANGECODER_BIT_H
|
||||
|
||||
#include "RangeCoder.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NRangeCoder {
|
||||
|
||||
const int kNumBitModelTotalBits = 11;
|
||||
const UInt32 kBitModelTotal = (1 << kNumBitModelTotalBits);
|
||||
|
||||
const int kNumMoveReducingBits = 2;
|
||||
|
||||
const int kNumBitPriceShiftBits = 6;
|
||||
const UInt32 kBitPrice = 1 << kNumBitPriceShiftBits;
|
||||
|
||||
class CPriceTables
|
||||
{
|
||||
public:
|
||||
static UInt32 ProbPrices[kBitModelTotal >> kNumMoveReducingBits];
|
||||
static void Init();
|
||||
CPriceTables();
|
||||
};
|
||||
|
||||
template <int numMoveBits>
|
||||
class CBitModel
|
||||
{
|
||||
public:
|
||||
UInt32 Prob;
|
||||
void UpdateModel(UInt32 symbol)
|
||||
{
|
||||
/*
|
||||
Prob -= (Prob + ((symbol - 1) & ((1 << numMoveBits) - 1))) >> numMoveBits;
|
||||
Prob += (1 - symbol) << (kNumBitModelTotalBits - numMoveBits);
|
||||
*/
|
||||
if (symbol == 0)
|
||||
Prob += (kBitModelTotal - Prob) >> numMoveBits;
|
||||
else
|
||||
Prob -= (Prob) >> numMoveBits;
|
||||
}
|
||||
public:
|
||||
void Init() { Prob = kBitModelTotal / 2; }
|
||||
};
|
||||
|
||||
template <int numMoveBits>
|
||||
class CBitEncoder: public CBitModel<numMoveBits>
|
||||
{
|
||||
public:
|
||||
void Encode(CEncoder *encoder, UInt32 symbol)
|
||||
{
|
||||
/*
|
||||
encoder->EncodeBit(this->Prob, kNumBitModelTotalBits, symbol);
|
||||
this->UpdateModel(symbol);
|
||||
*/
|
||||
UInt32 newBound = (encoder->Range >> kNumBitModelTotalBits) * this->Prob;
|
||||
if (symbol == 0)
|
||||
{
|
||||
encoder->Range = newBound;
|
||||
this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;
|
||||
}
|
||||
else
|
||||
{
|
||||
encoder->Low += newBound;
|
||||
encoder->Range -= newBound;
|
||||
this->Prob -= (this->Prob) >> numMoveBits;
|
||||
}
|
||||
if (encoder->Range < kTopValue)
|
||||
{
|
||||
encoder->Range <<= 8;
|
||||
encoder->ShiftLow();
|
||||
}
|
||||
}
|
||||
UInt32 GetPrice(UInt32 symbol) const
|
||||
{
|
||||
return CPriceTables::ProbPrices[
|
||||
(((this->Prob - symbol) ^ ((-(int)symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];
|
||||
}
|
||||
UInt32 GetPrice0() const { return CPriceTables::ProbPrices[this->Prob >> kNumMoveReducingBits]; }
|
||||
UInt32 GetPrice1() const { return CPriceTables::ProbPrices[(kBitModelTotal - this->Prob) >> kNumMoveReducingBits]; }
|
||||
};
|
||||
|
||||
|
||||
template <int numMoveBits>
|
||||
class CBitDecoder: public CBitModel<numMoveBits>
|
||||
{
|
||||
public:
|
||||
UInt32 Decode(CDecoder *decoder)
|
||||
{
|
||||
UInt32 newBound = (decoder->Range >> kNumBitModelTotalBits) * this->Prob;
|
||||
if (decoder->Code < newBound)
|
||||
{
|
||||
decoder->Range = newBound;
|
||||
this->Prob += (kBitModelTotal - this->Prob) >> numMoveBits;
|
||||
if (decoder->Range < kTopValue)
|
||||
{
|
||||
decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();
|
||||
decoder->Range <<= 8;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
decoder->Range -= newBound;
|
||||
decoder->Code -= newBound;
|
||||
this->Prob -= (this->Prob) >> numMoveBits;
|
||||
if (decoder->Range < kTopValue)
|
||||
{
|
||||
decoder->Code = (decoder->Code << 8) | decoder->Stream.ReadByte();
|
||||
decoder->Range <<= 8;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,161 @@
|
|||
// Compress/RangeCoder/RangeCoderBitTree.h
|
||||
|
||||
#ifndef __COMPRESS_RANGECODER_BIT_TREE_H
|
||||
#define __COMPRESS_RANGECODER_BIT_TREE_H
|
||||
|
||||
#include "RangeCoderBit.h"
|
||||
#include "RangeCoderOpt.h"
|
||||
|
||||
namespace NCompress {
|
||||
namespace NRangeCoder {
|
||||
|
||||
template <int numMoveBits, int NumBitLevels>
|
||||
class CBitTreeEncoder
|
||||
{
|
||||
CBitEncoder<numMoveBits> Models[1 << NumBitLevels];
|
||||
public:
|
||||
void Init()
|
||||
{
|
||||
for(UInt32 i = 1; i < (1 << NumBitLevels); i++)
|
||||
Models[i].Init();
|
||||
}
|
||||
void Encode(CEncoder *rangeEncoder, UInt32 symbol)
|
||||
{
|
||||
UInt32 modelIndex = 1;
|
||||
for (int bitIndex = NumBitLevels; bitIndex != 0 ;)
|
||||
{
|
||||
bitIndex--;
|
||||
UInt32 bit = (symbol >> bitIndex) & 1;
|
||||
Models[modelIndex].Encode(rangeEncoder, bit);
|
||||
modelIndex = (modelIndex << 1) | bit;
|
||||
}
|
||||
};
|
||||
void ReverseEncode(CEncoder *rangeEncoder, UInt32 symbol)
|
||||
{
|
||||
UInt32 modelIndex = 1;
|
||||
for (int i = 0; i < NumBitLevels; i++)
|
||||
{
|
||||
UInt32 bit = symbol & 1;
|
||||
Models[modelIndex].Encode(rangeEncoder, bit);
|
||||
modelIndex = (modelIndex << 1) | bit;
|
||||
symbol >>= 1;
|
||||
}
|
||||
}
|
||||
UInt32 GetPrice(UInt32 symbol) const
|
||||
{
|
||||
symbol |= (1 << NumBitLevels);
|
||||
UInt32 price = 0;
|
||||
while (symbol != 1)
|
||||
{
|
||||
price += Models[symbol >> 1].GetPrice(symbol & 1);
|
||||
symbol >>= 1;
|
||||
}
|
||||
return price;
|
||||
}
|
||||
UInt32 ReverseGetPrice(UInt32 symbol) const
|
||||
{
|
||||
UInt32 price = 0;
|
||||
UInt32 modelIndex = 1;
|
||||
for (int i = NumBitLevels; i != 0; i--)
|
||||
{
|
||||
UInt32 bit = symbol & 1;
|
||||
symbol >>= 1;
|
||||
price += Models[modelIndex].GetPrice(bit);
|
||||
modelIndex = (modelIndex << 1) | bit;
|
||||
}
|
||||
return price;
|
||||
}
|
||||
};
|
||||
|
||||
template <int numMoveBits, int NumBitLevels>
|
||||
class CBitTreeDecoder
|
||||
{
|
||||
CBitDecoder<numMoveBits> Models[1 << NumBitLevels];
|
||||
public:
|
||||
void Init()
|
||||
{
|
||||
for(UInt32 i = 1; i < (1 << NumBitLevels); i++)
|
||||
Models[i].Init();
|
||||
}
|
||||
UInt32 Decode(CDecoder *rangeDecoder)
|
||||
{
|
||||
UInt32 modelIndex = 1;
|
||||
RC_INIT_VAR
|
||||
for(int bitIndex = NumBitLevels; bitIndex != 0; bitIndex--)
|
||||
{
|
||||
// modelIndex = (modelIndex << 1) + Models[modelIndex].Decode(rangeDecoder);
|
||||
RC_GETBIT(numMoveBits, Models[modelIndex].Prob, modelIndex)
|
||||
}
|
||||
RC_FLUSH_VAR
|
||||
return modelIndex - (1 << NumBitLevels);
|
||||
};
|
||||
UInt32 ReverseDecode(CDecoder *rangeDecoder)
|
||||
{
|
||||
UInt32 modelIndex = 1;
|
||||
UInt32 symbol = 0;
|
||||
RC_INIT_VAR
|
||||
for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
|
||||
{
|
||||
// UInt32 bit = Models[modelIndex].Decode(rangeDecoder);
|
||||
// modelIndex <<= 1;
|
||||
// modelIndex += bit;
|
||||
// symbol |= (bit << bitIndex);
|
||||
RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))
|
||||
}
|
||||
RC_FLUSH_VAR
|
||||
return symbol;
|
||||
}
|
||||
};
|
||||
|
||||
template <int numMoveBits>
|
||||
void ReverseBitTreeEncode(CBitEncoder<numMoveBits> *Models,
|
||||
CEncoder *rangeEncoder, int NumBitLevels, UInt32 symbol)
|
||||
{
|
||||
UInt32 modelIndex = 1;
|
||||
for (int i = 0; i < NumBitLevels; i++)
|
||||
{
|
||||
UInt32 bit = symbol & 1;
|
||||
Models[modelIndex].Encode(rangeEncoder, bit);
|
||||
modelIndex = (modelIndex << 1) | bit;
|
||||
symbol >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
template <int numMoveBits>
|
||||
UInt32 ReverseBitTreeGetPrice(CBitEncoder<numMoveBits> *Models,
|
||||
UInt32 NumBitLevels, UInt32 symbol)
|
||||
{
|
||||
UInt32 price = 0;
|
||||
UInt32 modelIndex = 1;
|
||||
for (int i = NumBitLevels; i != 0; i--)
|
||||
{
|
||||
UInt32 bit = symbol & 1;
|
||||
symbol >>= 1;
|
||||
price += Models[modelIndex].GetPrice(bit);
|
||||
modelIndex = (modelIndex << 1) | bit;
|
||||
}
|
||||
return price;
|
||||
}
|
||||
|
||||
template <int numMoveBits>
|
||||
UInt32 ReverseBitTreeDecode(CBitDecoder<numMoveBits> *Models,
|
||||
CDecoder *rangeDecoder, int NumBitLevels)
|
||||
{
|
||||
UInt32 modelIndex = 1;
|
||||
UInt32 symbol = 0;
|
||||
RC_INIT_VAR
|
||||
for(int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
|
||||
{
|
||||
// UInt32 bit = Models[modelIndex].Decode(rangeDecoder);
|
||||
// modelIndex <<= 1;
|
||||
// modelIndex += bit;
|
||||
// symbol |= (bit << bitIndex);
|
||||
RC_GETBIT2(numMoveBits, Models[modelIndex].Prob, modelIndex, ; , symbol |= (1 << bitIndex))
|
||||
}
|
||||
RC_FLUSH_VAR
|
||||
return symbol;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
|
@ -0,0 +1,31 @@
|
|||
// Compress/RangeCoder/RangeCoderOpt.h
|
||||
|
||||
#ifndef __COMPRESS_RANGECODER_OPT_H
|
||||
#define __COMPRESS_RANGECODER_OPT_H
|
||||
|
||||
#define RC_INIT_VAR \
|
||||
UInt32 range = rangeDecoder->Range; \
|
||||
UInt32 code = rangeDecoder->Code;
|
||||
|
||||
#define RC_FLUSH_VAR \
|
||||
rangeDecoder->Range = range; \
|
||||
rangeDecoder->Code = code;
|
||||
|
||||
#define RC_NORMALIZE \
|
||||
if (range < NCompress::NRangeCoder::kTopValue) \
|
||||
{ code = (code << 8) | rangeDecoder->Stream.ReadByte(); range <<= 8; }
|
||||
|
||||
#define RC_GETBIT2(numMoveBits, prob, mi, A0, A1) \
|
||||
{ UInt32 bound = (range >> NCompress::NRangeCoder::kNumBitModelTotalBits) * prob; \
|
||||
if (code < bound) \
|
||||
{ A0; range = bound; \
|
||||
prob += (NCompress::NRangeCoder::kBitModelTotal - prob) >> numMoveBits; \
|
||||
mi <<= 1; } \
|
||||
else \
|
||||
{ A1; range -= bound; code -= bound; prob -= (prob) >> numMoveBits; \
|
||||
mi = (mi + mi) + 1; }} \
|
||||
RC_NORMALIZE
|
||||
|
||||
#define RC_GETBIT(numMoveBits, prob, mi) RC_GETBIT2(numMoveBits, prob, mi, ; , ;)
|
||||
|
||||
#endif
|
|
@ -0,0 +1,6 @@
|
|||
// StdAfx.h
|
||||
|
||||
#ifndef __STDAFX_H
|
||||
#define __STDAFX_H
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue