|
|
|
@ -3993,6 +3993,7 @@ static int stbi__jpeg_info(stbi__context *s, int *x, int *y, int *comp) |
|
|
|
|
// fast-way is faster to check than jpeg huffman, but slow way is slower
|
|
|
|
|
#define STBI__ZFAST_BITS 9 // accelerate all cases in default tables
|
|
|
|
|
#define STBI__ZFAST_MASK ((1 << STBI__ZFAST_BITS) - 1) |
|
|
|
|
#define STBI__ZNSYMS 288 // number of symbols in literal/length alphabet
|
|
|
|
|
|
|
|
|
|
// zlib-style huffman encoding
|
|
|
|
|
// (jpegs packs from left, zlib from right, so can't share code)
|
|
|
|
@ -4002,8 +4003,8 @@ typedef struct |
|
|
|
|
stbi__uint16 firstcode[16]; |
|
|
|
|
int maxcode[17]; |
|
|
|
|
stbi__uint16 firstsymbol[16]; |
|
|
|
|
stbi_uc size[288]; |
|
|
|
|
stbi__uint16 value[288]; |
|
|
|
|
stbi_uc size[STBI__ZNSYMS]; |
|
|
|
|
stbi__uint16 value[STBI__ZNSYMS]; |
|
|
|
|
} stbi__zhuffman; |
|
|
|
|
|
|
|
|
|
stbi_inline static int stbi__bitreverse16(int n) |
|
|
|
@ -4134,7 +4135,7 @@ static int stbi__zhuffman_decode_slowpath(stbi__zbuf *a, stbi__zhuffman *z) |
|
|
|
|
if (s >= 16) return -1; // invalid code!
|
|
|
|
|
// code size is s, so:
|
|
|
|
|
b = (k >> (16-s)) - z->firstcode[s] + z->firstsymbol[s]; |
|
|
|
|
if (b >= sizeof (z->size)) return -1; // some data was corrupt somewhere!
|
|
|
|
|
if (b >= STBI__ZNSYMS) return -1; // some data was corrupt somewhere!
|
|
|
|
|
if (z->size[b] != s) return -1; // was originally an assert, but report failure instead.
|
|
|
|
|
a->code_buffer >>= s; |
|
|
|
|
a->num_bits -= s; |
|
|
|
@ -4331,7 +4332,7 @@ static int stbi__parse_zlib_header(stbi__zbuf *a) |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static const stbi_uc stbi__zdefault_length[288] = |
|
|
|
|
static const stbi_uc stbi__zdefault_length[STBI__ZNSYMS] = |
|
|
|
|
{ |
|
|
|
|
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, |
|
|
|
|
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8, |
|
|
|
@ -4377,7 +4378,7 @@ static int stbi__parse_zlib(stbi__zbuf *a, int parse_header) |
|
|
|
|
} else { |
|
|
|
|
if (type == 1) { |
|
|
|
|
// use fixed code lengths
|
|
|
|
|
if (!stbi__zbuild_huffman(&a->z_length , stbi__zdefault_length , 288)) return 0; |
|
|
|
|
if (!stbi__zbuild_huffman(&a->z_length , stbi__zdefault_length , STBI__ZNSYMS)) return 0; |
|
|
|
|
if (!stbi__zbuild_huffman(&a->z_distance, stbi__zdefault_distance, 32)) return 0; |
|
|
|
|
} else { |
|
|
|
|
if (!stbi__compute_huffman_codes(a)) return 0; |
|
|
|
|