20#define FSE_STATIC_LINKING_ONLY
22#define HUF_STATIC_LINKING_ONLY
41size_t FSE_readNCount (
short* normalizedCounter,
unsigned* maxSVPtr,
unsigned* tableLogPtr,
42 const void* headerBuffer,
size_t hbSize)
44 const BYTE*
const istart = (
const BYTE*) headerBuffer;
45 const BYTE*
const iend = istart + hbSize;
60 {
size_t const countSize =
FSE_readNCount(normalizedCounter, maxSVPtr, tableLogPtr,
63 if (countSize > hbSize)
return ERROR(corruption_detected);
69 memset(normalizedCounter, 0, (*maxSVPtr+1) *
sizeof(normalizedCounter[0]));
71 nbBits = (bitStream & 0xF) + FSE_MIN_TABLELOG;
72 if (nbBits > FSE_TABLELOG_ABSOLUTE_MAX)
return ERROR(tableLog_tooLarge);
75 *tableLogPtr = nbBits;
76 remaining = (1<<nbBits)+1;
77 threshold = 1<<nbBits;
80 while ((remaining>1) & (charnum<=*maxSVPtr)) {
82 unsigned n0 = charnum;
83 while ((bitStream & 0xFFFF) == 0xFFFF) {
92 while ((bitStream & 3) == 3) {
99 if (n0 > *maxSVPtr)
return ERROR(maxSymbolValue_tooSmall);
100 while (charnum < n0) normalizedCounter[charnum++] = 0;
101 if ((
ip <= iend-7) || (
ip + (bitCount>>3) <= iend-4)) {
102 assert((bitCount >> 3) <= 3);
109 {
int const max = (2*threshold-1) - remaining;
112 if ((bitStream & (threshold-1)) < (
U32)
max) {
113 count = bitStream & (threshold-1);
114 bitCount += nbBits-1;
116 count = bitStream & (2*threshold-1);
125 while (remaining < threshold) {
130 if ((
ip <= iend-7) || (
ip + (bitCount>>3) <= iend-4)) {
134 bitCount -= (
int)(8 * (iend - 4 -
ip));
139 if (remaining != 1)
return ERROR(corruption_detected);
140 if (bitCount > 32)
return ERROR(corruption_detected);
141 *maxSVPtr = charnum-1;
143 ip += (bitCount+7)>>3;
156 U32* nbSymbolsPtr,
U32* tableLogPtr,
157 const void*
src,
size_t srcSize)
164 if (!srcSize)
return ERROR(srcSize_wrong);
170 iSize = ((oSize+1)/2);
171 if (iSize+1 > srcSize)
return ERROR(srcSize_wrong);
172 if (oSize >= hwSize)
return ERROR(corruption_detected);
175 for (
n=0;
n<oSize;
n+=2) {
176 huffWeight[
n] =
ip[
n/2] >> 4;
177 huffWeight[
n+1] =
ip[
n/2] & 15;
180 FSE_DTable fseWorkspace[FSE_DTABLE_SIZE_U32(6)];
181 if (iSize+1 > srcSize)
return ERROR(srcSize_wrong);
187 memset(rankStats, 0, (HUF_TABLELOG_MAX + 1) *
sizeof(
U32));
189 {
U32 n;
for (
n=0;
n<oSize;
n++) {
190 if (huffWeight[
n] >= HUF_TABLELOG_MAX)
return ERROR(corruption_detected);
191 rankStats[huffWeight[
n]]++;
192 weightTotal += (1 << huffWeight[
n]) >> 1;
194 if (weightTotal == 0)
return ERROR(corruption_detected);
198 if (tableLog > HUF_TABLELOG_MAX)
return ERROR(corruption_detected);
199 *tableLogPtr = tableLog;
202 U32 const rest =
total - weightTotal;
205 if (verif != rest)
return ERROR(corruption_detected);
206 huffWeight[oSize] = (
BYTE)lastWeight;
207 rankStats[lastWeight]++;
211 if ((rankStats[1] < 2) || (rankStats[1] & 1))
return ERROR(corruption_detected);
214 *nbSymbolsPtr = (
U32)(oSize+1);
MEM_STATIC unsigned BIT_highbit32(U32 val)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
MEM_STATIC U32 MEM_readLE32(const void *memPtr)
const char * HUF_getErrorName(size_t code)
unsigned FSE_versionNumber(void)
size_t FSE_readNCount(short *normalizedCounter, unsigned *maxSVPtr, unsigned *tableLogPtr, const void *headerBuffer, size_t hbSize)
size_t HUF_readStats(BYTE *huffWeight, size_t hwSize, U32 *rankStats, U32 *nbSymbolsPtr, U32 *tableLogPtr, const void *src, size_t srcSize)
const char * FSE_getErrorName(size_t code)
ERR_STATIC unsigned ERR_isError(size_t code)
ERR_STATIC const char * ERR_getErrorName(size_t code)
#define FSE_VERSION_NUMBER
size_t FSE_decompress_wksp(void *dst, size_t dstCapacity, const void *cSrc, size_t cSrcSize, FSE_DTable *workSpace, unsigned maxLog)
GLuint GLuint GLsizei count
#define memcpy(s1, s2, n)