|
|
@ -3769,7 +3769,7 @@ stbi_inline static int stbi__bit_reverse(int v, int bits) |
|
|
|
return stbi__bitreverse16(v) >> (16-bits); |
|
|
|
return stbi__bitreverse16(v) >> (16-bits); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static int stbi__zbuild_huffman(stbi__zhuffman *z, stbi_uc *sizelist, int num) |
|
|
|
static int stbi__zbuild_huffman(stbi__zhuffman *z, const stbi_uc *sizelist, int num) |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i,k=0; |
|
|
|
int i,k=0; |
|
|
|
int code, next_code[16], sizes[17]; |
|
|
|
int code, next_code[16], sizes[17]; |
|
|
@ -4059,9 +4059,33 @@ static int stbi__parse_zlib_header(stbi__zbuf *a) |
|
|
|
return 1; |
|
|
|
return 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// @TODO: should statically initialize these for optimal thread safety
|
|
|
|
static const stbi_uc stbi__zdefault_length[288] = { |
|
|
|
static stbi_uc stbi__zdefault_length[288], stbi__zdefault_distance[32]; |
|
|
|
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, |
|
|
|
static void stbi__init_zdefaults(void) |
|
|
|
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, |
|
|
|
|
|
|
|
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, |
|
|
|
|
|
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
|
|
|
|
|
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
|
|
|
|
|
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
|
|
|
|
|
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
|
|
|
|
|
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
|
|
|
|
|
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
|
|
|
|
|
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
|
|
|
|
|
|
|
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
|
|
|
|
|
|
|
7, 7, 7, 7, 7, 7, 7, 7, |
|
|
|
|
|
|
|
8, 8, 8, 8, 8, 8, 8, 8 |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
static const stbi_uc stbi__zdefault_distance[32] = { |
|
|
|
|
|
|
|
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, |
|
|
|
|
|
|
|
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Init algorithm: |
|
|
|
{ |
|
|
|
{ |
|
|
|
int i; // use <= to match clearly with spec
|
|
|
|
int i; // use <= to match clearly with spec
|
|
|
|
for (i=0; i <= 143; ++i) stbi__zdefault_length[i] = 8; |
|
|
|
for (i=0; i <= 143; ++i) stbi__zdefault_length[i] = 8; |
|
|
@ -4071,6 +4095,7 @@ static void stbi__init_zdefaults(void) |
|
|
|
|
|
|
|
|
|
|
|
for (i=0; i <= 31; ++i) stbi__zdefault_distance[i] = 5; |
|
|
|
for (i=0; i <= 31; ++i) stbi__zdefault_distance[i] = 5; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
static int stbi__parse_zlib(stbi__zbuf *a, int parse_header) |
|
|
|
static int stbi__parse_zlib(stbi__zbuf *a, int parse_header) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -4089,7 +4114,6 @@ static int stbi__parse_zlib(stbi__zbuf *a, int parse_header) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (type == 1) { |
|
|
|
if (type == 1) { |
|
|
|
// use fixed code lengths
|
|
|
|
// use fixed code lengths
|
|
|
|
if (!stbi__zdefault_distance[31]) stbi__init_zdefaults(); |
|
|
|
|
|
|
|
if (!stbi__zbuild_huffman(&a->z_length , stbi__zdefault_length , 288)) return 0; |
|
|
|
if (!stbi__zbuild_huffman(&a->z_length , stbi__zdefault_length , 288)) return 0; |
|
|
|
if (!stbi__zbuild_huffman(&a->z_distance, stbi__zdefault_distance, 32)) return 0; |
|
|
|
if (!stbi__zbuild_huffman(&a->z_distance, stbi__zdefault_distance, 32)) return 0; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|