53 # pragma GCC diagnostic ignored "-Wunused-function" 56 #if defined (__clang__) 57 # pragma clang diagnostic ignored "-Wunused-function" 64 #define LZ4_COMMONDEFS_ONLY 71 #define DICTIONARY_LOGSIZE 16 72 #define MAXD (1<<DICTIONARY_LOGSIZE) 73 #define MAXD_MASK (MAXD - 1) 75 #define HASH_LOG (DICTIONARY_LOGSIZE-1) 76 #define HASHTABLESIZE (1 << HASH_LOG) 77 #define HASH_MASK (HASHTABLESIZE - 1) 79 #define OPTIMAL_ML (int)((ML_MASK-1)+MINMATCH) 105 #define HASH_FUNCTION(i) (((i) * 2654435761U) >> ((MINMATCH*8)-HASH_LOG)) 107 #define DELTANEXTU16(p) chainTable[(U16)(p)] 121 hc4->
base = start - 64
KB;
135 const U32 target = (
U32)(ip - base);
141 size_t delta = idx - HashTable[h];
153 const BYTE* ip,
const BYTE*
const iLimit,
154 const BYTE** matchpos,
155 const int maxNbAttempts)
165 int nbAttempts=maxNbAttempts;
172 while ((matchIndex>=lowLimit) && (nbAttempts))
175 if (matchIndex >= dictLimit)
177 match = base + matchIndex;
178 if (*(match+ml) == *(ip+ml)
182 if (mlt > ml) { ml = mlt; *matchpos =
match; }
187 match = dictBase + matchIndex;
191 const BYTE* vLimit = ip + (dictLimit - matchIndex);
192 if (vLimit > iLimit) vLimit = iLimit;
194 if ((ip+mlt == vLimit) && (vLimit < iLimit))
195 mlt +=
LZ4_count(ip+mlt, base+dictLimit, iLimit);
196 if (mlt > ml) { ml = mlt; *matchpos = base + matchIndex; }
208 const BYTE*
const ip,
209 const BYTE*
const iLowLimit,
210 const BYTE*
const iHighLimit,
212 const BYTE** matchpos,
213 const BYTE** startpos,
214 const int maxNbAttempts)
220 const BYTE*
const lowPrefixPtr = base + dictLimit;
224 int nbAttempts = maxNbAttempts;
225 int delta = (int)(ip-iLowLimit);
232 while ((matchIndex>=lowLimit) && (nbAttempts))
235 if (matchIndex >= dictLimit)
237 const BYTE* matchPtr = base + matchIndex;
238 if (*(iLowLimit + longest) == *(matchPtr - delta + longest))
244 while ((ip+back>iLowLimit)
245 && (matchPtr+back > lowPrefixPtr)
246 && (ip[back-1] == matchPtr[back-1]))
254 *matchpos = matchPtr+back;
261 const BYTE* matchPtr = dictBase + matchIndex;
266 const BYTE* vLimit = ip + (dictLimit - matchIndex);
267 if (vLimit > iHighLimit) vLimit = iHighLimit;
269 if ((ip+mlt == vLimit) && (vLimit < iHighLimit))
270 mlt +=
LZ4_count(ip+mlt, base+dictLimit, iHighLimit);
271 while ((ip+back > iLowLimit) && (matchIndex+back > lowLimit) && (ip[back-1] == matchPtr[back-1])) back--;
273 if ((
int)mlt > longest) { longest = (int)mlt; *matchpos = base + matchIndex + back; *startpos = ip+back; }
285 #define LZ4HC_DEBUG 0 287 static unsigned debug = 0;
303 if (debug) printf(
"literal : %u -- match : %u -- offset : %u\n", (
U32)(*ip - *anchor), (
U32)matchLength, (
U32)(*ip-match));
307 length = (int)(*ip - *anchor);
309 if ((limitedOutputBuffer) && ((*op + (length>>8) + length + (2 + 1 +
LASTLITERALS)) > oend))
return 1;
321 length = (int)(matchLength-
MINMATCH);
322 if ((limitedOutputBuffer) && (*op + (length>>8) + (1 +
LASTLITERALS) > oend))
return 1;
323 if (length>=(
int)
ML_MASK) { *token+=
ML_MASK; length-=
ML_MASK;
for(; length > 509 ; length-=510) { *(*op)++ = 255; *(*op)++ = 255; }
if (length > 254) { length-=255; *(*op)++ = 255; } *(*op)++ = (
BYTE)length; }
324 else *token += (
BYTE)(length);
345 const BYTE* ip = (
const BYTE*) source;
346 const BYTE* anchor = ip;
354 unsigned maxNbAttempts;
355 int ml, ml2, ml3, ml0;
368 maxNbAttempts = 1 << (compressionLevel-1);
377 if (!ml) { ip++;
continue; }
397 if (start2 < ip + ml0)
406 if ((start2 - ip) < 3)
425 if (ip+new_ml > start2 + ml2 -
MINMATCH) new_ml = (int)(start2 - ip) + ml2 -
MINMATCH;
426 correction = new_ml - (int)(start2 - ip);
429 start2 += correction;
436 if (start2 + ml2 < mflimit)
443 if (start2 < ip+ml) ml = (int)(start2 - ip);
451 if (start3 < ip+ml+3)
453 if (start3 >= (ip+ml))
457 int correction = (int)(ip+ml - start2);
458 start2 += correction;
492 if ((start2 - ip) < (int)
ML_MASK)
496 if (ip + ml > start2 + ml2 -
MINMATCH) ml = (int)(start2 - ip) + ml2 -
MINMATCH;
497 correction = ml - (int)(start2 - ip);
500 start2 += correction;
507 ml = (int)(start2 - ip);
525 int lastRun = (int)(iend - anchor);
526 if ((limit) && (((
char*)op - dest) + lastRun + 1 + ((lastRun+255-
RUN_MASK)/255) > (
U32)maxOutputSize))
return 0;
529 memcpy(op, anchor, iend - anchor);
534 return (
int) (((
char*)op)-
dest);
542 if (((
size_t)(state)&(
sizeof(
void*)-1)) != 0)
return 0;
577 if (dictSize > 64
KB)
579 dictionary += dictSize - 64
KB;
583 if (dictSize >= 4)
LZ4HC_Insert (ctxPtr, (
const BYTE*)dictionary +(dictSize-3));
584 ctxPtr->
end = (
const BYTE*)dictionary + dictSize;
593 if (ctxPtr->
end >= ctxPtr->
base + 4)
600 ctxPtr->
end = newBlock;
613 if ((
size_t)(ctxPtr->
end - ctxPtr->
base) > 2
GB)
616 if (dictSize > 64
KB) dictSize = 64
KB;
622 if ((
const BYTE*)source != ctxPtr->
end)
627 const BYTE* sourceEnd = (
const BYTE*) source + inputSize;
630 if ((sourceEnd > dictBegin) && ((
const BYTE*)source < dictEnd))
632 if (sourceEnd > dictEnd) sourceEnd = dictEnd;
655 int prefixSize = (int)(streamPtr->
end - (streamPtr->
base + streamPtr->
dictLimit));
656 if (dictSize > 64
KB) dictSize = 64
KB;
657 if (dictSize < 4) dictSize = 0;
658 if (dictSize > prefixSize) dictSize = prefixSize;
659 memmove(safeBuffer, streamPtr->
end - dictSize, dictSize);
662 streamPtr->
end = (
const BYTE*)safeBuffer + dictSize;
663 streamPtr->
base = streamPtr->
end - endIndex;
664 streamPtr->
dictLimit = endIndex - dictSize;
665 streamPtr->
lowLimit = endIndex - dictSize;
684 int LZ4_compressHC2_limitedOutput_withStateHC (
void*
state,
const char* src,
char*
dst,
int srcSize,
int maxDstSize,
int cLevel) {
return LZ4_compress_HC_extStateHC(state, src, dst, srcSize, maxDstSize, cLevel); }
695 if ((((
size_t)state) & (
sizeof(
void*)-1)) != 0)
return 1;
int LZ4_freeHC(void *LZ4HC_Data)
static int LZ4_compressHC_continue_generic(LZ4HC_Data_Structure *ctxPtr, const char *source, char *dest, int inputSize, int maxOutputSize, limitedOutput_directive limit)
int LZ4_loadDictHC(LZ4_streamHC_t *LZ4_streamHCPtr, const char *dictionary, int dictSize)
int LZ4_compressHC2_withStateHC(void *state, const char *src, char *dst, int srcSize, int cLevel)
int LZ4_compressHC(const char *src, char *dst, int srcSize)
static U32 LZ4HC_hashPtr(const void *ptr)
int LZ4_compressHC_withStateHC(void *state, const char *src, char *dst, int srcSize)
int LZ4_freeStreamHC(LZ4_streamHC_t *LZ4_streamHCPtr)
FORCE_INLINE void LZ4HC_Insert(LZ4HC_Data_Structure *hc4, const BYTE *ip)
def match(kptsFrom, kptsTo, scoresFrom, scoresTo, descriptorsFrom, descriptorsTo, imageWidth, imageHeight)
void LZ4_resetStreamHC(LZ4_streamHC_t *LZ4_streamHCPtr, int compressionLevel)
int LZ4_compressHC2_limitedOutput_continue(void *LZ4HC_Data, const char *source, char *dest, int inputSize, int maxOutputSize, int compressionLevel)
LZ4_streamHC_t * LZ4_createStreamHC(void)
int LZ4_compressHC_limitedOutput_continue(LZ4_streamHC_t *ctx, const char *src, char *dst, int srcSize, int maxDstSize)
const char char int int compressionLevel
int LZ4_compressHC_limitedOutput(const char *src, char *dst, int srcSize, int maxDstSize)
int LZ4_compress_HC(const char *src, char *dst, int srcSize, int maxDstSize, int compressionLevel)
static int LZ4HC_compress_generic(void *ctxvoid, const char *source, char *dest, int inputSize, int maxOutputSize, int compressionLevel, limitedOutput_directive limit)
int LZ4_compressHC2_limitedOutput_withStateHC(void *state, const char *src, char *dst, int srcSize, int maxDstSize, int cLevel)
int LZ4_resetStreamStateHC(void *state, char *inputBuffer)
static void LZ4HC_init(LZ4HC_Data_Structure *hc4, const BYTE *start)
static void LZ4HC_setExternalDict(LZ4HC_Data_Structure *ctxPtr, const BYTE *newBlock)
int LZ4_sizeofStateHC(void)
void * LZ4_createHC(char *inputBuffer)
static void LZ4_writeLE16(void *memPtr, U16 value)
int LZ4_compressHC_continue(LZ4_streamHC_t *ctx, const char *src, char *dst, int srcSize)
static void LZ4_wildCopy(void *dstPtr, const void *srcPtr, void *dstEnd)
static U32 LZ4_read32(const void *memPtr)
#define LZ4_STATIC_ASSERT(c)
RecoveryProgressState state
int LZ4_compress_HC_extStateHC(void *state, const char *src, char *dst, int srcSize, int maxDstSize, int compressionLevel)
const char char int int maxOutputSize
int LZ4_compressHC2_limitedOutput(const char *src, char *dst, int srcSize, int maxDstSize, int cLevel)
int LZ4_compressHC2(const char *src, char *dst, int srcSize, int cLevel)
int LZ4_compress_HC_continue(LZ4_streamHC_t *LZ4_streamHCPtr, const char *source, char *dest, int inputSize, int maxOutputSize)
int LZ4_sizeofStreamStateHC(void)
int LZ4_compressBound(int isize)
int LZ4_compressHC2_continue(void *LZ4HC_Data, const char *source, char *dest, int inputSize, int compressionLevel)
U32 hashTable[HASHTABLESIZE]
GLM_FUNC_DECL genType::value_type length(genType const &x)
const char char int inputSize
char * LZ4_slideInputBufferHC(void *LZ4HC_Data)
FORCE_INLINE int LZ4HC_InsertAndGetWiderMatch(LZ4HC_Data_Structure *hc4, const BYTE *const ip, const BYTE *const iLowLimit, const BYTE *const iHighLimit, int longest, const BYTE **matchpos, const BYTE **startpos, const int maxNbAttempts)
FORCE_INLINE int LZ4HC_InsertAndFindBestMatch(LZ4HC_Data_Structure *hc4, const BYTE *ip, const BYTE *const iLimit, const BYTE **matchpos, const int maxNbAttempts)
static const int g_maxCompressionLevel
int LZ4_compressHC_limitedOutput_withStateHC(void *state, const char *src, char *dst, int srcSize, int maxDstSize)
static const int LZ4HC_compressionLevel_default
static unsigned LZ4_count(const BYTE *pIn, const BYTE *pMatch, const BYTE *pInLimit)
FORCE_INLINE int LZ4HC_encodeSequence(const BYTE **ip, BYTE **op, const BYTE **anchor, int matchLength, const BYTE *const match, limitedOutput_directive limitedOutputBuffer, BYTE *oend)
int LZ4_saveDictHC(LZ4_streamHC_t *LZ4_streamHCPtr, char *safeBuffer, int dictSize)