lzma_c: no need to rebuild for using in kpack/kerpack, cleanup

Removed samples, converted indentation to spaces, translated to english, added header for exporting functions.
Added is_kerpack argument to lzma_compress() to make it usable either for kpack and kerpack without rebuild
This commit is contained in:
2025-03-22 18:56:12 +03:00
parent 42e04486e7
commit 244e5c92f8
11 changed files with 1351 additions and 1677 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -6,15 +6,15 @@
typedef struct typedef struct
{ {
CState State; CState State;
bool Prev1IsChar; bool Prev1IsChar;
bool Prev2; bool Prev2;
unsigned PosPrev2; unsigned PosPrev2;
unsigned BackPrev2; unsigned BackPrev2;
unsigned Price; unsigned Price;
unsigned PosPrev; unsigned PosPrev;
unsigned BackPrev; unsigned BackPrev;
unsigned Backs[kNumRepDistances]; unsigned Backs[kNumRepDistances];
} COptimal; } COptimal;
#define COptimal_MakeAsChar(a) (a)->BackPrev=(unsigned)-1,(a)->Prev1IsChar=false #define COptimal_MakeAsChar(a) (a)->BackPrev=(unsigned)-1,(a)->Prev1IsChar=false
#define COptimal_MakeAsShortRep(a) (a)->BackPrev=0,(a)->Prev1IsChar=false #define COptimal_MakeAsShortRep(a) (a)->BackPrev=0,(a)->Prev1IsChar=false
@@ -26,27 +26,27 @@ typedef struct
typedef CMyBitEncoder CLiteralEncoder2[0x300]; typedef CMyBitEncoder CLiteralEncoder2[0x300];
typedef struct typedef struct
{ {
CLiteralEncoder2* _coders; CLiteralEncoder2* _coders;
int _numPrevBits; int _numPrevBits;
int _numPosBits; int _numPosBits;
unsigned _posMask; unsigned _posMask;
} CLiteralEncoder; } CLiteralEncoder;
typedef struct typedef struct
{ {
CMyBitEncoder _choice; CMyBitEncoder _choice;
CMyBitEncoder _choice2; CMyBitEncoder _choice2;
NRangeCoder_CBitTreeEncoder _lowCoder[kNumPosStatesEncodingMax]; NRangeCoder_CBitTreeEncoder _lowCoder[kNumPosStatesEncodingMax];
NRangeCoder_CBitTreeEncoder _midCoder[kNumPosStatesEncodingMax]; NRangeCoder_CBitTreeEncoder _midCoder[kNumPosStatesEncodingMax];
NRangeCoder_CBitTreeEncoder _highCoder; NRangeCoder_CBitTreeEncoder _highCoder;
} NLength_CEncoder; } NLength_CEncoder;
typedef struct typedef struct
{ {
NLength_CEncoder base; NLength_CEncoder base;
unsigned _prices[kNumSymbolsTotal][kNumPosStatesEncodingMax]; unsigned _prices[kNumSymbolsTotal][kNumPosStatesEncodingMax];
unsigned _tableSize; unsigned _tableSize;
unsigned _counters[kNumPosStatesEncodingMax]; unsigned _counters[kNumPosStatesEncodingMax];
} NLength_CPriceTableEncoder; } NLength_CPriceTableEncoder;
#define CPriceTableEncoder_Init(a,b) NLength_CEncoder_Init(&a.base,b) #define CPriceTableEncoder_Init(a,b) NLength_CEncoder_Init(&a.base,b)

View File

@@ -1,21 +1,11 @@
#include "MatchFinder.h" #include "MatchFinder.h"
/* memcpy must be inlined - we do not want to use RTL */
#include <memory.h> #include <memory.h>
/*#pragma function(memcpy)
void* __cdecl memcpy(void* _Dst, const void* _Src, size_t _Size)
{
unsigned long i;
for (i = 0; i < _Size; i++)
((char*)_Dst)[i] = ((char*)_Src)[i];
return _Dst;
}*/
//#pragma intrinsic(memcpy)
#define kMaxValForNormalize (((unsigned)1<<31)-1) #define kMaxValForNormalize (((unsigned)1<<31)-1)
/* settings for bt4: /* settings for bt4:
defined HASH_ARRAY_2 defined HASH_ARRAY_2
defined HASH_ARRAY_3 defined HASH_ARRAY_3
*/ */
//#define kHash2Size 0x400 //#define kHash2Size 0x400
@@ -57,56 +47,56 @@ static unsigned _streamPos;
static void LZInWindow_Create(unsigned keepSizeBefore,unsigned keepSizeAfter,unsigned keepSizeReserv,byte**mem) static void LZInWindow_Create(unsigned keepSizeBefore,unsigned keepSizeAfter,unsigned keepSizeReserv,byte**mem)
{ {
_keepSizeBefore = keepSizeBefore; _keepSizeBefore = keepSizeBefore;
_keepSizeAfter = keepSizeAfter; _keepSizeAfter = keepSizeAfter;
_keepSizeReserv = keepSizeReserv; _keepSizeReserv = keepSizeReserv;
_blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv; _blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;
_bufferBase = *mem; _bufferBase = *mem;
_blockSize = (_blockSize + 3) & ~3; _blockSize = (_blockSize + 3) & ~3;
*mem += _blockSize; *mem += _blockSize;
_pointerToLastSafePosition = _bufferBase + _blockSize - keepSizeAfter; _pointerToLastSafePosition = _bufferBase + _blockSize - keepSizeAfter;
} }
static void ReadBlock(void) static void ReadBlock(void)
{ {
if (_streamEndWasReached) if (_streamEndWasReached)
return; return;
for (;;) for (;;)
{ {
unsigned size; unsigned size;
size = (unsigned)(_bufferBase-_buffer) + _blockSize - _streamPos; size = (unsigned)(_bufferBase-_buffer) + _blockSize - _streamPos;
if (!size) return; if (!size) return;
if (size > pack_length - pack_pos) if (size > pack_length - pack_pos)
size = pack_length - pack_pos; size = pack_length - pack_pos;
memcpy(_buffer+_streamPos,curin,size); memcpy(_buffer+_streamPos,curin,size);
curin += size; curin += size;
pack_pos += size; pack_pos += size;
if (size == 0) if (size == 0)
{ {
byte* pointerToPosition; byte* pointerToPosition;
_posLimit = _streamPos; _posLimit = _streamPos;
pointerToPosition = _buffer + _posLimit; pointerToPosition = _buffer + _posLimit;
if (pointerToPosition > _pointerToLastSafePosition) if (pointerToPosition > _pointerToLastSafePosition)
_posLimit = _pointerToLastSafePosition - _buffer; _posLimit = _pointerToLastSafePosition - _buffer;
_streamEndWasReached = true; _streamEndWasReached = true;
return; return;
} }
_streamPos += size; _streamPos += size;
if (_streamPos >= _pos + _keepSizeAfter) if (_streamPos >= _pos + _keepSizeAfter)
{ {
_posLimit = _streamPos - _keepSizeAfter; _posLimit = _streamPos - _keepSizeAfter;
return; return;
} }
} }
} }
static void LZInWindow_Init(void) static void LZInWindow_Init(void)
{ {
_buffer = _bufferBase; _buffer = _bufferBase;
_pos = 0; _pos = 0;
_streamPos = 0; _streamPos = 0;
_streamEndWasReached = false; _streamEndWasReached = false;
ReadBlock(); ReadBlock();
} }
#else #else
#define LZInWindow_Create(a,b,c,d) /* nothing */ #define LZInWindow_Create(a,b,c,d) /* nothing */
@@ -118,24 +108,24 @@ const byte* GetPointerToCurrentPos(void) {return _buffer+_pos;}
#ifdef GENERIC_INPUT #ifdef GENERIC_INPUT
static void MoveBlock(void) static void MoveBlock(void)
{ {
unsigned offset,numBytes; unsigned offset,numBytes;
offset = _buffer-_bufferBase+_pos-_keepSizeBefore; offset = _buffer-_bufferBase+_pos-_keepSizeBefore;
numBytes = _buffer-_bufferBase+_streamPos-offset; numBytes = _buffer-_bufferBase+_streamPos-offset;
// copying backwards: safe to use memcpy instead of memmove // copying backwards: safe to use memcpy instead of memmove
memcpy(_bufferBase,_bufferBase+offset,numBytes); memcpy(_bufferBase,_bufferBase+offset,numBytes);
_buffer -= offset; _buffer -= offset;
} }
static void LZInWindow_MovePos(void) static void LZInWindow_MovePos(void)
{ {
_pos++; _pos++;
if (_pos > _posLimit) if (_pos > _posLimit)
{ {
const byte* pointerToPosition = _buffer+_pos; const byte* pointerToPosition = _buffer+_pos;
if (pointerToPosition > _pointerToLastSafePosition) if (pointerToPosition > _pointerToLastSafePosition)
MoveBlock(); MoveBlock();
ReadBlock(); ReadBlock();
} }
} }
#else #else
#define LZInWindow_MovePos() _pos++ #define LZInWindow_MovePos() _pos++
@@ -145,21 +135,21 @@ byte GetIndexByte(int index) {return _buffer[_pos+index];}
unsigned GetMatchLen(int index,unsigned distance,unsigned limit) unsigned GetMatchLen(int index,unsigned distance,unsigned limit)
{ {
const byte* pby; const byte* pby;
unsigned i; unsigned i;
#ifdef GENERIC_INPUT #ifdef GENERIC_INPUT
if (_streamEndWasReached) if (_streamEndWasReached)
if ((_pos+index)+limit > _streamPos) if ((_pos+index)+limit > _streamPos)
limit = _streamPos - (_pos+index); limit = _streamPos - (_pos+index);
#else #else
unsigned limit2 = pack_length - (pack_pos + index); unsigned limit2 = pack_length - (pack_pos + index);
if (limit > limit2) if (limit > limit2)
limit = limit2; limit = limit2;
#endif #endif
distance++; distance++;
pby = _buffer + _pos + index; pby = _buffer + _pos + index;
for (i=0;i<limit && pby[i]==pby[(int)(i-distance)];i++) ; for (i=0;i<limit && pby[i]==pby[(int)(i-distance)];i++) ;
return i; return i;
} }
unsigned GetNumAvailableBytes(void) {return _streamPos-_pos;} unsigned GetNumAvailableBytes(void) {return _streamPos-_pos;}
@@ -167,10 +157,10 @@ unsigned GetNumAvailableBytes(void) {return _streamPos-_pos;}
#ifdef GENERIC_INPUT #ifdef GENERIC_INPUT
void ReduceOffsets(int subValue) void ReduceOffsets(int subValue)
{ {
_buffer += subValue; _buffer += subValue;
_posLimit -= subValue; _posLimit -= subValue;
_pos -= subValue; _pos -= subValue;
_streamPos -= subValue; _streamPos -= subValue;
} }
#else #else
#define ReduceOffsets(a) /* nothing */ #define ReduceOffsets(a) /* nothing */
@@ -182,241 +172,241 @@ static unsigned crc_table[256];
void MatchFinder_Create(unsigned historySize,unsigned keepAddBufferBefore,unsigned matchMaxLen,unsigned keepAddBufferAfter,byte**mem) void MatchFinder_Create(unsigned historySize,unsigned keepAddBufferBefore,unsigned matchMaxLen,unsigned keepAddBufferAfter,byte**mem)
{ {
unsigned sizeReserv; unsigned sizeReserv;
sizeReserv = (historySize + keepAddBufferBefore + matchMaxLen + keepAddBufferAfter)/2+256; sizeReserv = (historySize + keepAddBufferBefore + matchMaxLen + keepAddBufferAfter)/2+256;
LZInWindow_Create(historySize+keepAddBufferBefore,matchMaxLen+keepAddBufferAfter,sizeReserv,mem); LZInWindow_Create(historySize+keepAddBufferBefore,matchMaxLen+keepAddBufferAfter,sizeReserv,mem);
_matchMaxLen = matchMaxLen; _matchMaxLen = matchMaxLen;
_cyclicBufferSize = historySize+1; _cyclicBufferSize = historySize+1;
_hash = (unsigned*)*mem; _hash = (unsigned*)*mem;
*mem += (kHashSizeSum + _cyclicBufferSize*2) * sizeof(unsigned); *mem += (kHashSizeSum + _cyclicBufferSize*2) * sizeof(unsigned);
_cutValue = 0xFF; _cutValue = 0xFF;
} }
void MatchFinder_Init(void) void MatchFinder_Init(void)
{ {
unsigned i,j,r; unsigned i,j,r;
LZInWindow_Init(); LZInWindow_Init();
for (i=0;i<kHashSizeSum;i++) for (i=0;i<kHashSizeSum;i++)
_hash[i] = 0; _hash[i] = 0;
_cyclicBufferPos = 0; _cyclicBufferPos = 0;
ReduceOffsets(-1); ReduceOffsets(-1);
for (i=0;i<256;i++) for (i=0;i<256;i++)
{ {
r = i; r = i;
for (j=0;j<8;j++) for (j=0;j<8;j++)
{ {
if (r & 1) if (r & 1)
r = (r>>1) ^ 0xEDB88320; r = (r>>1) ^ 0xEDB88320;
else else
r >>= 1; r >>= 1;
} }
crc_table[i] = r; crc_table[i] = r;
} }
} }
static unsigned Hash(const byte* ptr, unsigned* hash2Value) static unsigned Hash(const byte* ptr, unsigned* hash2Value)
{ {
unsigned temp; unsigned temp;
temp = crc_table[ptr[0]] ^ ptr[1]; temp = crc_table[ptr[0]] ^ ptr[1];
*hash2Value = *(word*)ptr; //ptr[0] + ((unsigned)ptr[1] << 8); *hash2Value = *(word*)ptr; //ptr[0] + ((unsigned)ptr[1] << 8);
return (temp ^ ((unsigned)ptr[2]<<8)) & (kHashSize - 1); return (temp ^ ((unsigned)ptr[2]<<8)) & (kHashSize - 1);
} }
unsigned GetLongestMatch(unsigned* distances) unsigned GetLongestMatch(unsigned* distances)
{ {
unsigned lenLimit,maxLen=0; unsigned lenLimit,maxLen=0;
unsigned matchMinPos; unsigned matchMinPos;
const byte* cur; const byte* cur;
unsigned hash2Value,hashValue; unsigned hash2Value,hashValue;
unsigned curMatch,curMatch2; unsigned curMatch,curMatch2;
unsigned *son,*ptr0,*ptr1; unsigned *son,*ptr0,*ptr1;
unsigned len0,len1,count; unsigned len0,len1,count;
if (_pos + _matchMaxLen <= _streamPos) if (_pos + _matchMaxLen <= _streamPos)
lenLimit = _matchMaxLen; lenLimit = _matchMaxLen;
else else
{ {
lenLimit = _streamPos - _pos; lenLimit = _streamPos - _pos;
if (lenLimit < kNumHashBytes) if (lenLimit < kNumHashBytes)
return 0; return 0;
} }
matchMinPos = (_pos>_cyclicBufferSize) ? (_pos-_cyclicBufferSize) : 0; matchMinPos = (_pos>_cyclicBufferSize) ? (_pos-_cyclicBufferSize) : 0;
cur = _buffer+_pos; cur = _buffer+_pos;
hashValue = Hash(cur,&hash2Value); hashValue = Hash(cur,&hash2Value);
curMatch = _hash[hashValue]; curMatch = _hash[hashValue];
curMatch2 = _hash[kHash2Offset + hash2Value]; curMatch2 = _hash[kHash2Offset + hash2Value];
_hash[kHash2Offset + hash2Value] = _pos; _hash[kHash2Offset + hash2Value] = _pos;
distances[2] = 0xFFFFFFFF; distances[2] = 0xFFFFFFFF;
if (curMatch2 > matchMinPos) if (curMatch2 > matchMinPos)
//if (_buffer[curMatch2] == cur[0]) //if (_buffer[curMatch2] == cur[0])
{ {
distances[2] = _pos - curMatch2 - 1; distances[2] = _pos - curMatch2 - 1;
maxLen = 2; maxLen = 2;
} }
_hash[hashValue] = _pos; _hash[hashValue] = _pos;
son = _hash + kHashSizeSum; son = _hash + kHashSizeSum;
ptr0 = son + (_cyclicBufferPos << 1) + 1; ptr0 = son + (_cyclicBufferPos << 1) + 1;
ptr1 = son + (_cyclicBufferPos << 1); ptr1 = son + (_cyclicBufferPos << 1);
distances[kNumHashBytes] = 0xFFFFFFFF; distances[kNumHashBytes] = 0xFFFFFFFF;
len0 = len1 = kNumHashDirectBytes; len0 = len1 = kNumHashDirectBytes;
count = _cutValue; count = _cutValue;
for (;;) for (;;)
{ {
const byte* pb; const byte* pb;
unsigned len,delta; unsigned len,delta;
unsigned cyclicPos; unsigned cyclicPos;
unsigned* pair; unsigned* pair;
if (curMatch <= matchMinPos || count--==0) if (curMatch <= matchMinPos || count--==0)
{ {
*ptr0 = *ptr1 = 0; *ptr0 = *ptr1 = 0;
break; break;
} }
pb = _buffer+curMatch; pb = _buffer+curMatch;
len = (len0<len1) ? len0 : len1; len = (len0<len1) ? len0 : len1;
do do
if (pb[len] != cur[len]) break; if (pb[len] != cur[len]) break;
while (++len != lenLimit); while (++len != lenLimit);
delta = _pos - curMatch; delta = _pos - curMatch;
while (maxLen < len) while (maxLen < len)
distances[++maxLen] = delta-1; distances[++maxLen] = delta-1;
cyclicPos = (delta <= _cyclicBufferPos) ? cyclicPos = (delta <= _cyclicBufferPos) ?
(_cyclicBufferPos - delta) : (_cyclicBufferPos - delta) :
(_cyclicBufferPos - delta + _cyclicBufferSize); (_cyclicBufferPos - delta + _cyclicBufferSize);
pair = son + (cyclicPos<<1); pair = son + (cyclicPos<<1);
if (len != lenLimit) if (len != lenLimit)
{ {
if (pb[len] < cur[len]) if (pb[len] < cur[len])
{ {
*ptr1 = curMatch; *ptr1 = curMatch;
ptr1 = pair+1; ptr1 = pair+1;
curMatch = *ptr1; curMatch = *ptr1;
len1 = len; len1 = len;
} }
else else
{ {
*ptr0 = curMatch; *ptr0 = curMatch;
ptr0 = pair; ptr0 = pair;
curMatch = *ptr0; curMatch = *ptr0;
len0 = len; len0 = len;
} }
} }
else else
{ {
*ptr1 = pair[0]; *ptr1 = pair[0];
*ptr0 = pair[1]; *ptr0 = pair[1];
break; break;
} }
} }
/*if (distances[4] < distances[3]) /*if (distances[4] < distances[3])
distances[3] = distances[4]; distances[3] = distances[4];
if (distances[3] < distances[2]) if (distances[3] < distances[2])
distances[2] = distances[3];*/ distances[2] = distances[3];*/
return maxLen; return maxLen;
} }
void DummyLongestMatch(void) void DummyLongestMatch(void)
{ {
unsigned lenLimit; unsigned lenLimit;
unsigned matchMinPos; unsigned matchMinPos;
const byte* cur; const byte* cur;
unsigned hash2Value,hashValue; unsigned hash2Value,hashValue;
unsigned curMatch; unsigned curMatch;
unsigned* son,*ptr0,*ptr1; unsigned* son,*ptr0,*ptr1;
unsigned len0,len1,count; unsigned len0,len1,count;
if (_pos + _matchMaxLen <= _streamPos) if (_pos + _matchMaxLen <= _streamPos)
lenLimit = _matchMaxLen; lenLimit = _matchMaxLen;
else else
{ {
lenLimit = _streamPos - _pos; lenLimit = _streamPos - _pos;
if (lenLimit < kNumHashBytes) if (lenLimit < kNumHashBytes)
return; return;
} }
matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0; matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
cur = _buffer+_pos; cur = _buffer+_pos;
hashValue = Hash(cur,&hash2Value); hashValue = Hash(cur,&hash2Value);
_hash[kHash2Offset + hash2Value] = _pos; _hash[kHash2Offset + hash2Value] = _pos;
curMatch = _hash[hashValue]; curMatch = _hash[hashValue];
_hash[hashValue] = _pos; _hash[hashValue] = _pos;
son = _hash+kHashSizeSum; son = _hash+kHashSizeSum;
ptr0 = son + (_cyclicBufferPos << 1) + 1; ptr0 = son + (_cyclicBufferPos << 1) + 1;
ptr1 = son + (_cyclicBufferPos << 1); ptr1 = son + (_cyclicBufferPos << 1);
len0 = len1 = kNumHashDirectBytes; len0 = len1 = kNumHashDirectBytes;
count = _cutValue; count = _cutValue;
for (;;) for (;;)
{ {
const byte* pb; const byte* pb;
unsigned len; unsigned len;
unsigned delta,cyclicPos; unsigned delta,cyclicPos;
unsigned* pair; unsigned* pair;
if (curMatch <= matchMinPos || count--==0) if (curMatch <= matchMinPos || count--==0)
break; break;
pb = _buffer+curMatch; pb = _buffer+curMatch;
len = (len0<len1) ? len0 : len1; len = (len0<len1) ? len0 : len1;
do do
if (pb[len] != cur[len]) break; if (pb[len] != cur[len]) break;
while (++len != lenLimit); while (++len != lenLimit);
delta = _pos - curMatch; delta = _pos - curMatch;
cyclicPos = (delta <= _cyclicBufferPos) ? cyclicPos = (delta <= _cyclicBufferPos) ?
(_cyclicBufferPos - delta) : (_cyclicBufferPos - delta) :
(_cyclicBufferPos - delta + _cyclicBufferSize); (_cyclicBufferPos - delta + _cyclicBufferSize);
pair = son + (cyclicPos << 1); pair = son + (cyclicPos << 1);
if (len != lenLimit) if (len != lenLimit)
{ {
if (pb[len] < cur[len]) if (pb[len] < cur[len])
{ {
*ptr1 = curMatch; *ptr1 = curMatch;
ptr1 = pair+1; ptr1 = pair+1;
curMatch = *ptr1; curMatch = *ptr1;
len1 = len; len1 = len;
} }
else else
{ {
*ptr0 = curMatch; *ptr0 = curMatch;
ptr0 = pair; ptr0 = pair;
curMatch = *ptr0; curMatch = *ptr0;
len0 = len; len0 = len;
} }
} }
else else
{ {
*ptr1 = pair[0]; *ptr1 = pair[0];
*ptr0 = pair[1]; *ptr0 = pair[1];
return; return;
} }
} }
*ptr0 = *ptr1 = 0; *ptr0 = *ptr1 = 0;
} }
#ifdef GENERIC_INPUT #ifdef GENERIC_INPUT
// for memory input size is always less than kMaxValForNormalize // for memory input size is always less than kMaxValForNormalize
static void Normalize(void) static void Normalize(void)
{ {
unsigned subValue; unsigned subValue;
unsigned* items; unsigned* items;
unsigned i,numItems; unsigned i,numItems;
subValue = _pos - _cyclicBufferSize; subValue = _pos - _cyclicBufferSize;
items = _hash; items = _hash;
numItems = (kHashSizeSum + _cyclicBufferSize*2); numItems = (kHashSizeSum + _cyclicBufferSize*2);
for (i=0;i<numItems;i++) for (i=0;i<numItems;i++)
{ {
unsigned value; unsigned value;
value = items[i]; value = items[i];
if (value <= subValue) if (value <= subValue)
value = 0; value = 0;
else else
value -= subValue; value -= subValue;
items[i] = value; items[i] = value;
} }
ReduceOffsets(subValue); ReduceOffsets(subValue);
} }
#endif #endif
void MatchFinder_MovePos(void) void MatchFinder_MovePos(void)
{ {
if (++_cyclicBufferPos == _cyclicBufferSize) if (++_cyclicBufferPos == _cyclicBufferSize)
_cyclicBufferPos = 0; _cyclicBufferPos = 0;
LZInWindow_MovePos(); LZInWindow_MovePos();
#ifdef GENERIC_INPUT #ifdef GENERIC_INPUT
if (_pos == kMaxValForNormalize) if (_pos == kMaxValForNormalize)
Normalize(); Normalize();
#endif #endif
} }

View File

@@ -10,182 +10,182 @@ static unsigned PriceTable[kBitModelTotal >> kNumMoveReducingBits];
void RangeEncoder_Init(void) void RangeEncoder_Init(void)
{ {
int i; int i;
unsigned start,end,j; unsigned start,end,j;
low = 0; low = 0;
range = 0xFFFFFFFF; range = 0xFFFFFFFF;
_cacheSize = 1; _cacheSize = 1;
_cache = 0; _cache = 0;
/* init price table */ /* init price table */
#define kNumBits (kNumBitModelTotalBits - kNumMoveReducingBits) #define kNumBits (kNumBitModelTotalBits - kNumMoveReducingBits)
for (i=kNumBits;i--;) for (i=kNumBits;i--;)
{ {
start = 1 << (kNumBits - i - 1); start = 1 << (kNumBits - i - 1);
end = 1 << (kNumBits - i); end = 1 << (kNumBits - i);
for (j=start;j<end;j++) for (j=start;j<end;j++)
PriceTable[j] = (i<<kNumBitPriceShiftBits) + PriceTable[j] = (i<<kNumBitPriceShiftBits) +
(((end-j)<<kNumBitPriceShiftBits) >> (kNumBits - i - 1)); (((end-j)<<kNumBitPriceShiftBits) >> (kNumBits - i - 1));
} }
#undef kNumBits #undef kNumBits
} }
void RangeEncoder_ShiftLow(void) void RangeEncoder_ShiftLow(void)
{ {
if ((unsigned)low < 0xFF000000U || (int)(low>>32)) if ((unsigned)low < 0xFF000000U || (int)(low>>32))
{ {
byte temp = _cache; byte temp = _cache;
do do
{ {
*curout++ = (byte)(temp + (byte)(low>>32)); *curout++ = (byte)(temp + (byte)(low>>32));
temp = 0xFF; temp = 0xFF;
} while (--_cacheSize); } while (--_cacheSize);
_cache = (byte)((unsigned)low>>24); _cache = (byte)((unsigned)low>>24);
} }
_cacheSize++; _cacheSize++;
low = (unsigned)low << 8; low = (unsigned)low << 8;
} }
void RangeEncoder_FlushData(void) void RangeEncoder_FlushData(void)
{ {
int i; int i;
for (i=0;i<5;i++) for (i=0;i<5;i++)
RangeEncoder_ShiftLow(); RangeEncoder_ShiftLow();
} }
void RangeEncoder_EncodeDirectBits(unsigned value,int numTotalBits) void RangeEncoder_EncodeDirectBits(unsigned value,int numTotalBits)
{ {
int i; int i;
for (i=numTotalBits;i--;) for (i=numTotalBits;i--;)
{ {
range >>= 1; range >>= 1;
if (((value >> i) & 1) == 1) if (((value >> i) & 1) == 1)
low += range; low += range;
if (range < kTopValue) if (range < kTopValue)
{ {
range <<= 8; range <<= 8;
RangeEncoder_ShiftLow(); RangeEncoder_ShiftLow();
} }
} }
} }
void CMyBitEncoder_Encode(CMyBitEncoder* e,unsigned symbol) void CMyBitEncoder_Encode(CMyBitEncoder* e,unsigned symbol)
{ {
unsigned newBound; unsigned newBound;
newBound = (range >> kNumBitModelTotalBits) * *e; newBound = (range >> kNumBitModelTotalBits) * *e;
if (symbol == 0) if (symbol == 0)
{ {
range = newBound; range = newBound;
*e += (kBitModelTotal - *e) >> kNumMoveBits; *e += (kBitModelTotal - *e) >> kNumMoveBits;
} }
else else
{ {
low += newBound; low += newBound;
range -= newBound; range -= newBound;
*e -= *e >> kNumMoveBits; *e -= *e >> kNumMoveBits;
} }
if (range < kTopValue) if (range < kTopValue)
{ {
range <<= 8; range <<= 8;
RangeEncoder_ShiftLow(); RangeEncoder_ShiftLow();
} }
} }
unsigned CMyBitEncoder_GetPrice(CMyBitEncoder* e, unsigned symbol) unsigned CMyBitEncoder_GetPrice(CMyBitEncoder* e, unsigned symbol)
{ {
return PriceTable[(((*e-symbol)^((-(int)symbol))) & (kBitModelTotal-1)) >> kNumMoveReducingBits]; return PriceTable[(((*e-symbol)^((-(int)symbol))) & (kBitModelTotal-1)) >> kNumMoveReducingBits];
} }
unsigned CMyBitEncoder_GetPrice0(CMyBitEncoder* e) unsigned CMyBitEncoder_GetPrice0(CMyBitEncoder* e)
{ {
return PriceTable[*e >> kNumMoveReducingBits]; return PriceTable[*e >> kNumMoveReducingBits];
} }
unsigned CMyBitEncoder_GetPrice1(CMyBitEncoder* e) unsigned CMyBitEncoder_GetPrice1(CMyBitEncoder* e)
{ {
return PriceTable[(kBitModelTotal - *e) >> kNumMoveReducingBits]; return PriceTable[(kBitModelTotal - *e) >> kNumMoveReducingBits];
} }
void CBitTreeEncoder_Init(NRangeCoder_CBitTreeEncoder*e,int numBitLevels) void CBitTreeEncoder_Init(NRangeCoder_CBitTreeEncoder*e,int numBitLevels)
{ {
unsigned i; unsigned i;
e->numBitLevels = numBitLevels; e->numBitLevels = numBitLevels;
for (i=1;i<((unsigned)1<<numBitLevels);i++) for (i=1;i<((unsigned)1<<numBitLevels);i++)
CMyBitEncoder_Init(e->Models[i]); CMyBitEncoder_Init(e->Models[i]);
} }
void CBitTreeEncoder_Encode(NRangeCoder_CBitTreeEncoder*e,unsigned symbol) void CBitTreeEncoder_Encode(NRangeCoder_CBitTreeEncoder*e,unsigned symbol)
{ {
unsigned modelIndex = 1; unsigned modelIndex = 1;
int bitIndex; int bitIndex;
unsigned bit; unsigned bit;
for (bitIndex = e->numBitLevels; bitIndex--;) for (bitIndex = e->numBitLevels; bitIndex--;)
{ {
bit = (symbol >> bitIndex) & 1; bit = (symbol >> bitIndex) & 1;
CMyBitEncoder_Encode(&e->Models[modelIndex],bit); CMyBitEncoder_Encode(&e->Models[modelIndex],bit);
modelIndex = (modelIndex << 1) | bit; modelIndex = (modelIndex << 1) | bit;
} }
} }
void CBitTreeEncoder_ReverseEncode(NRangeCoder_CBitTreeEncoder*e,unsigned symbol) void CBitTreeEncoder_ReverseEncode(NRangeCoder_CBitTreeEncoder*e,unsigned symbol)
{ {
unsigned modelIndex = 1; unsigned modelIndex = 1;
int i; int i;
unsigned bit; unsigned bit;
for (i=0;i<e->numBitLevels;i++) for (i=0;i<e->numBitLevels;i++)
{ {
bit = symbol & 1; bit = symbol & 1;
CMyBitEncoder_Encode(&e->Models[modelIndex],bit); CMyBitEncoder_Encode(&e->Models[modelIndex],bit);
modelIndex = (modelIndex << 1) | bit; modelIndex = (modelIndex << 1) | bit;
symbol >>= 1; symbol >>= 1;
} }
} }
unsigned CBitTreeEncoder_GetPrice(NRangeCoder_CBitTreeEncoder*e,unsigned symbol) unsigned CBitTreeEncoder_GetPrice(NRangeCoder_CBitTreeEncoder*e,unsigned symbol)
{ {
unsigned price = 0; unsigned price = 0;
symbol |= (1 << e->numBitLevels); symbol |= (1 << e->numBitLevels);
while (symbol != 1) while (symbol != 1)
{ {
price += CMyBitEncoder_GetPrice(&e->Models[symbol>>1],symbol&1); price += CMyBitEncoder_GetPrice(&e->Models[symbol>>1],symbol&1);
symbol >>= 1; symbol >>= 1;
} }
return price; return price;
} }
unsigned CBitTreeEncoder_ReverseGetPrice(NRangeCoder_CBitTreeEncoder*e,unsigned symbol) unsigned CBitTreeEncoder_ReverseGetPrice(NRangeCoder_CBitTreeEncoder*e,unsigned symbol)
{ {
unsigned price=0; unsigned price=0;
unsigned modelIndex=1; unsigned modelIndex=1;
int i; int i;
unsigned bit; unsigned bit;
for (i=e->numBitLevels;i;i--) for (i=e->numBitLevels;i;i--)
{ {
bit = symbol&1; bit = symbol&1;
symbol >>= 1; symbol >>= 1;
price += CMyBitEncoder_GetPrice(&e->Models[modelIndex],bit); price += CMyBitEncoder_GetPrice(&e->Models[modelIndex],bit);
modelIndex = (modelIndex<<1)|bit; modelIndex = (modelIndex<<1)|bit;
} }
return price; return price;
} }
unsigned ReverseBitTreeGetPrice(CMyBitEncoder*Models,unsigned NumBitLevels,unsigned symbol) unsigned ReverseBitTreeGetPrice(CMyBitEncoder*Models,unsigned NumBitLevels,unsigned symbol)
{ {
unsigned price=0; unsigned price=0;
unsigned modelIndex=1; unsigned modelIndex=1;
unsigned bit; unsigned bit;
int i; int i;
for (i=NumBitLevels;i;i--) for (i=NumBitLevels;i;i--)
{ {
bit = symbol & 1; bit = symbol & 1;
symbol >>= 1; symbol >>= 1;
price += CMyBitEncoder_GetPrice(Models+modelIndex,bit); price += CMyBitEncoder_GetPrice(Models+modelIndex,bit);
modelIndex = (modelIndex<<1)|bit; modelIndex = (modelIndex<<1)|bit;
} }
return price; return price;
} }
void ReverseBitTreeEncode(CMyBitEncoder*Models,int NumBitLevels,unsigned symbol) void ReverseBitTreeEncode(CMyBitEncoder*Models,int NumBitLevels,unsigned symbol)
{ {
unsigned modelIndex = 1; unsigned modelIndex = 1;
int i; int i;
unsigned bit; unsigned bit;
for (i=0;i<NumBitLevels;i++) for (i=0;i<NumBitLevels;i++)
{ {
bit = symbol & 1; bit = symbol & 1;
CMyBitEncoder_Encode(Models+modelIndex,bit); CMyBitEncoder_Encode(Models+modelIndex,bit);
modelIndex = (modelIndex<<1)|bit; modelIndex = (modelIndex<<1)|bit;
symbol >>= 1; symbol >>= 1;
} }
} }

View File

@@ -2,8 +2,8 @@
typedef struct typedef struct
{ {
CMyBitEncoder Models[1<<8]; CMyBitEncoder Models[1<<8];
int numBitLevels; int numBitLevels;
} NRangeCoder_CBitTreeEncoder; } NRangeCoder_CBitTreeEncoder;
extern void CBitTreeEncoder_Init(NRangeCoder_CBitTreeEncoder*e,int numBitLevels); extern void CBitTreeEncoder_Init(NRangeCoder_CBitTreeEncoder*e,int numBitLevels);

View File

@@ -1,132 +0,0 @@
# Microsoft Developer Studio Project File - Name="lzmapack" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Static Library" 0x0104
CFG=lzmapack - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "lzmapack.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 "lzmapack.mak" CFG="lzmapack - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "lzmapack - Win32 Release" (based on "Win32 (x86) Static Library")
!MESSAGE "lzmapack - Win32 Debug" (based on "Win32 (x86) Static Library")
!MESSAGE
# Begin Project
# PROP AllowPerConfigDependencies 0
# PROP Scc_ProjName ""
# PROP Scc_LocalPath ""
CPP=cl.exe
RSC=rc.exe
!IF "$(CFG)" == "lzmapack - 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 ""
# PROP Intermediate_Dir "Release"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
# ADD CPP /nologo /W3 /GX /O1 /Ob1 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /Zl /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
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ELSEIF "$(CFG)" == "lzmapack - 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 ""
# PROP Intermediate_Dir "Debug"
# PROP Target_Dir ""
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /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
LIB32=link.exe -lib
# ADD BASE LIB32 /nologo
# ADD LIB32 /nologo
!ENDIF
# Begin Target
# Name "lzmapack - Win32 Release"
# Name "lzmapack - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\LZMAEncoder.c
# End Source File
# Begin Source File
SOURCE=.\MatchFinder.c
# End Source File
# Begin Source File
SOURCE=.\RangeCoder.c
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# Begin Source File
SOURCE=.\common.h
# End Source File
# Begin Source File
SOURCE=.\lzma.h
# End Source File
# Begin Source File
SOURCE=.\LZMAEncoder.h
# End Source File
# Begin Source File
SOURCE=.\MatchFinder.h
# End Source File
# Begin Source File
SOURCE=.\RangeCoder.h
# End Source File
# Begin Source File
SOURCE=.\RangeCoderBit.h
# End Source File
# Begin Source File
SOURCE=.\RangeCoderBitTree.h
# End Source File
# End Group
# End Target
# End Project

View File

@@ -1,44 +0,0 @@
Microsoft Developer Studio Workspace File, Format Version 6.00
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
###############################################################################
Project: "lzmapack"=.\lzmapack.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
}}}
###############################################################################
Project: "lzmatest"=.\lzmatest\lzmatest.dsp - Package Owner=<4>
Package=<5>
{{{
}}}
Package=<4>
{{{
Begin Project Dependency
Project_Dep_Name lzmapack
End Project Dependency
}}}
###############################################################################
Global:
Package=<5>
{{{
}}}
Package=<3>
{{{
}}}
###############################################################################

View File

@@ -1,102 +0,0 @@
# Microsoft Developer Studio Project File - Name="lzmatest" - Package Owner=<4>
# Microsoft Developer Studio Generated Build File, Format Version 6.00
# ** DO NOT EDIT **
# TARGTYPE "Win32 (x86) Console Application" 0x0103
CFG=lzmatest - Win32 Debug
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
!MESSAGE use the Export Makefile command and run
!MESSAGE
!MESSAGE NMAKE /f "lzmatest.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 "lzmatest.mak" CFG="lzmatest - Win32 Debug"
!MESSAGE
!MESSAGE Possible choices for configuration are:
!MESSAGE
!MESSAGE "lzmatest - Win32 Release" (based on "Win32 (x86) Console Application")
!MESSAGE "lzmatest - Win32 Debug" (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)" == "lzmatest - 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 /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /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 ..\lzmapack.lib /nologo /subsystem:console /machine:I386
!ELSEIF "$(CFG)" == "lzmatest - 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 /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /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 ..\lzmapack.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
!ENDIF
# Begin Target
# Name "lzmatest - Win32 Release"
# Name "lzmatest - Win32 Debug"
# Begin Group "Source Files"
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
# Begin Source File
SOURCE=.\main.cpp
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter "h;hpp;hxx;hm;inl"
# End Group
# Begin Group "Resource Files"
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
# End Group
# End Target
# End Project

View File

@@ -1,31 +0,0 @@
#include <stdio.h>
#include <windows.h>
extern "C" __stdcall lzma_set_dict_size(unsigned logdictsize);
extern "C" __stdcall lzma_compress(
const void* source,
void* destination,
unsigned length,
void* workmem);
int main()
{
FILE* f;
f = fopen("test.in","rb");
fseek(f,0,SEEK_END);
unsigned inlen = ftell(f);
fseek(f,0,SEEK_SET);
void* in = VirtualAlloc(NULL,inlen,MEM_COMMIT,PAGE_READWRITE);
void* out = VirtualAlloc(NULL,inlen,MEM_COMMIT,PAGE_READWRITE);
fread(in,1,inlen,f);
fclose(f);
unsigned logdictsize,dictsize;
for (logdictsize=0,dictsize=1;dictsize<inlen && logdictsize<=28;logdictsize++,dictsize<<=1) ;
lzma_set_dict_size(logdictsize);
void* work = VirtualAlloc(NULL,dictsize*19/2+0x509000,MEM_COMMIT,PAGE_READWRITE);
unsigned outlen = lzma_compress(in,out,inlen,work);
printf("%d -> %d\n",inlen,outlen);
f = fopen("test.out","wb");
fwrite(out,1,outlen,f);
fclose(f);
return 0;
}

View File

@@ -1,44 +1,33 @@
<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> C <20><><EFBFBD><EFBFBD>, diamond'<27><>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> This directory contains a simplified version of the LZMA packer rewritten in C by me, diamond.
LZMA-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> LZMA SDK 4.32 <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> copyright (c) 1999-2005 The original LZMA SDK 4.32 is copyright (c) 1999-2005
Igor Pavlov, <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> http://www.7-zip.org/sdk.html, Igor Pavlov, can be obtained from the page http://www.7-zip.org/sdk.html,
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> C++,C# <EFBFBD> Java <EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> in particular, it contains versions of the source code in C++, C# and Java for packing and
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD> LZMA-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> ANSI-C, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 7z. unpacking, the LZMA unpacking code in ANSI-C, a description of the 7z format.
<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> This version is not thread-safe (!), supports only bt4 match-finder,
bt4 match-finder, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD> <20><><EFBFBD> some packing parameters are fixed (however, this can be easily modified if necessary),
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>), <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> only data compression in RAM is supported. (These restrictions are not in the original LZMA SDK.)
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. (<28><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> LZMA
SDK.) <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> VC++, <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> ANSI C <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> VC-<2D><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> #pragma intrinsic(memcpy), <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> memcpy <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD> - <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> C run-time library. (<28><><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> MtApPack, <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RTL <20> <20> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD> Windows, <20> <20><><EFBFBD> Kolibri.)
<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> LZMA SDK, <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> This library, like the original LZMA SDK, can be used in other
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>) GNU LGPL <EFBFBD><EFBFBD><EFBFBD> programs under one of the licenses (your choice) GNU LGPL or
GNU CPL. (<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> SDK <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GNU CPL. (The original SDK also allows the original library to be used without restrictions,
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> provided that the object files are used without modifying the code; this version does not.)
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>, <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.)
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: <20> C++-<2D><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>: Two functions are exported: in C++ the declaration looks like this:
extern "C" __stdcall void lzma_set_dict_size(unsigned logdictsize); extern "C" __stdcall void lzma_set_dict_size(unsigned logdictsize);
extern "C" __stdcall unsigned lzma_compress( extern "C" __stdcall unsigned lzma_compress(
const void* source, const void* source,
void* destination, void* destination,
unsigned length, unsigned length,
void* workmem); void* workmem, int is_kerpack)
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, Before packing, the dictionary size of the first of these functions, taking the base 2 logarithm of this value,
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 2 <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (i.e. dictsize == (1<<logdictsize)). The maximum buffer size is 256Mb,
(<28>.<2E>. dictsize == (1<<logdictsize)). <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> 256Mb, so the logdictsize parameter should not exceed 28. If the buffer size is larger than the input data size,
<EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> logdictsize <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 28. <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> the result does not depend on the buffer size, i.e. for data of 12345 bytes,
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, the results of compression with a 16384-byte buffer and with a 1 megabyte buffer are the same.
<EFBFBD>.<2E>. <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 12345 <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> 16384 <20><><EFBFBD><EFBFBD> <20> Packing is performed by calling the second of these functions;
<EFBFBD><EFBFBD> 1 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. source is a pointer to the input data, destination is a pointer to the buffer for packed data,
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>. source - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> length is the length of the input data, workmem is a pointer to temporary memory
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, destination - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, used by the packer; at least 0x509000+dictsize*19/2 bytes must be allocated.
length - <20><><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, workmem - <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, For packed data, 0x10 + length*9/8 bytes is enough in the worst case.
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>; <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD> 0x509000+dictsize*19/2
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0x10 + length*9/8 <20><><EFBFBD><EFBFBD>.