59 #define REPZ_11_138 18 63 = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
66 = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
69 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
72 = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
81 #define DIST_CODE_LEN 512 83 #if defined(GEN_TREES_H) || !defined(STDC) 157 local void gen_trees_header
OF((
void));
161 # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) 165 # define send_code(s, c, tree) \ 166 { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ 167 send_bits(s, tree[c].Code, tree[c].Len); } 174 #define put_short(s, w) { \ 175 put_byte(s, (uch)((w) & 0xff)); \ 176 put_byte(s, (uch)((ush)(w) >> 8)); \ 211 #define send_bits(s, value, length) \ 213 if (s->bi_valid > (int)Buf_size - len) {\ 214 int val = (int)value;\ 215 s->bi_buf |= (ush)val << s->bi_valid;\ 216 put_short(s, s->bi_buf);\ 217 s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ 218 s->bi_valid += len - Buf_size;\ 220 s->bi_buf |= (ush)(value) << s->bi_valid;\ 234 #if defined(GEN_TREES_H) || !defined(STDC) 235 static int static_init_done = 0;
244 if (static_init_done)
return;
247 #ifdef NO_INIT_GLOBAL_POINTERS 263 Assert (
length == 256,
"tr_static_init: length != 256");
278 Assert (dist == 256,
"tr_static_init: dist != 256");
286 Assert (dist == 256,
"tr_static_init: 256+dist != 512");
306 static_init_done = 1;
322 # define SEPARATOR(i, last, width) \ 323 ((i) == (last)? "\n};\n\n" : \ 324 ((i) % (width) == (width)-1 ? ",\n" : ", ")) 326 void gen_trees_header()
333 "/* header created automatically with -DGEN_TREES_H */\n\n");
335 fprintf(
header,
"local const ct_data static_ltree[L_CODES+2] = {\n");
341 fprintf(
header,
"local const ct_data static_dtree[D_CODES] = {\n");
347 fprintf(
header,
"const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n");
354 "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
360 fprintf(
header,
"local const int base_length[LENGTH_CODES] = {\n");
384 s->l_desc.dyn_tree =
s->dyn_ltree;
387 s->d_desc.dyn_tree =
s->dyn_dtree;
390 s->bl_desc.dyn_tree =
s->bl_tree;
396 s->compressed_len = 0
L;
418 s->opt_len =
s->static_len = 0
L;
419 s->last_lit =
s->matches = 0;
430 #define pqremove(s, tree, top) \ 432 top = s->heap[SMALLEST]; \ 433 s->heap[SMALLEST] = s->heap[s->heap_len--]; \ 434 pqdownheap(s, tree, SMALLEST); \ 441 #define smaller(tree, n, m, depth) \ 442 (tree[n].Freq < tree[m].Freq || \ 443 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) 458 while (j <= s->heap_len) {
460 if (j < s->heap_len &&
468 s->heap[
k] =
s->heap[
j];
k =
j;
491 int max_code =
desc->max_code;
492 const ct_data *stree =
desc->stat_desc->static_tree;
494 int base =
desc->stat_desc->extra_base;
495 int max_length =
desc->stat_desc->max_length;
508 tree[
s->heap[
s->heap_max]].Len = 0;
513 if (
bits > max_length)
bits = max_length, overflow++;
517 if (
n > max_code)
continue;
523 s->opt_len += (
ulg)
f * (
unsigned)(
bits + xbits);
524 if (stree)
s->static_len += (
ulg)
f * (
unsigned)(stree[
n].Len + xbits);
526 if (overflow == 0)
return;
536 s->bl_count[
bits+1] += 2;
537 s->bl_count[max_length]--;
542 }
while (overflow > 0);
553 if (
m > max_code)
continue;
593 "inconsistent bit counts");
596 for (
n = 0;
n <= max_code;
n++) {
598 if (
len == 0)
continue;
620 const ct_data *stree =
desc->stat_desc->static_tree;
621 int elems =
desc->stat_desc->elems;
632 for (
n = 0;
n < elems;
n++) {
634 s->heap[++(
s->heap_len)] = max_code =
n;
646 while (
s->heap_len < 2) {
647 node =
s->heap[++(
s->heap_len)] = (max_code < 2 ? ++max_code : 0);
650 s->opt_len--;
if (stree)
s->static_len -= stree[
node].Len;
653 desc->max_code = max_code;
668 s->heap[--(
s->heap_max)] =
n;
669 s->heap[--(
s->heap_max)] =
m;
674 s->depth[
n] :
s->depth[
m]) + 1);
677 if (
tree ==
s->bl_tree) {
686 }
while (
s->heap_len >= 2);
711 int nextlen =
tree[0].Len;
716 if (nextlen == 0) max_count = 138, min_count = 3;
717 tree[max_code+1].Len = (
ush)0xffff;
719 for (
n = 0;
n <= max_code;
n++) {
720 curlen = nextlen; nextlen =
tree[
n+1].Len;
721 if (++
count < max_count && curlen == nextlen) {
723 }
else if (
count < min_count) {
724 s->bl_tree[curlen].Freq +=
count;
725 }
else if (curlen != 0) {
726 if (curlen != prevlen)
s->bl_tree[curlen].Freq++;
728 }
else if (
count <= 10) {
733 count = 0; prevlen = curlen;
735 max_count = 138, min_count = 3;
736 }
else if (curlen == nextlen) {
737 max_count = 6, min_count = 3;
739 max_count = 7, min_count = 4;
756 int nextlen =
tree[0].Len;
762 if (nextlen == 0) max_count = 138, min_count = 3;
764 for (
n = 0;
n <= max_code;
n++) {
765 curlen = nextlen; nextlen =
tree[
n+1].Len;
766 if (++
count < max_count && curlen == nextlen) {
768 }
else if (
count < min_count) {
771 }
else if (curlen != 0) {
772 if (curlen != prevlen) {
778 }
else if (
count <= 10) {
784 count = 0; prevlen = curlen;
786 max_count = 138, min_count = 3;
787 }
else if (curlen == nextlen) {
788 max_count = 6, min_count = 3;
790 max_count = 7, min_count = 4;
818 for (max_blindex =
BL_CODES-1; max_blindex >= 3; max_blindex--) {
819 if (
s->bl_tree[
bl_order[max_blindex]].Len != 0)
break;
822 s->opt_len += 3*((
ulg)max_blindex+1) + 5+5+4;
824 s->opt_len,
s->static_len));
836 int lcodes, dcodes, blcodes;
840 Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4,
"not enough codes");
847 for (rank = 0; rank < blcodes; rank++) {
874 s->pending += stored_len;
876 s->compressed_len = (
s->compressed_len + 3 + 7) & (
ulg)~7
L;
877 s->compressed_len += (stored_len + 4) << 3;
878 s->bits_sent += 2*16;
879 s->bits_sent += stored_len<<3;
902 s->compressed_len += 10
L;
917 ulg opt_lenb, static_lenb;
933 Tracev((
stderr,
"\ndist data: dyn %ld, stat %ld",
s->opt_len,
945 opt_lenb = (
s->opt_len+3+7)>>3;
946 static_lenb = (
s->static_len+3+7)>>3;
948 Tracev((
stderr,
"\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
949 opt_lenb,
s->opt_len, static_lenb,
s->static_len, stored_len,
952 if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
956 opt_lenb = static_lenb = stored_len + 5;
960 if (
buf != (
char*)0) {
962 if (stored_len+4 <= opt_lenb &&
buf != (
char*)0) {
974 }
else if (static_lenb >= 0) {
976 }
else if (
s->strategy ==
Z_FIXED || static_lenb == opt_lenb) {
982 s->compressed_len += 3 +
s->static_len;
991 s->compressed_len += 3 +
s->opt_len;
994 Assert (
s->compressed_len ==
s->bits_sent,
"bad compressed size");
1003 s->compressed_len += 7;
1006 Tracev((
stderr,
"\ncomprlen %lu(%lu) ",
s->compressed_len>>3,
1007 s->compressed_len-7*
last));
1019 s->d_buf[
s->last_lit] = (
ush)dist;
1020 s->l_buf[
s->last_lit++] = (
uch)lc;
1023 s->dyn_ltree[lc].Freq++;
1033 s->dyn_dtree[
d_code(dist)].Freq++;
1036 #ifdef TRUNCATE_BLOCK 1038 if ((
s->last_lit & 0x1fff) == 0 &&
s->level > 2) {
1040 ulg out_length = (
ulg)
s->last_lit*8
L;
1041 ulg in_length = (
ulg)((
long)
s->strstart -
s->block_start);
1043 for (dcode = 0; dcode <
D_CODES; dcode++) {
1044 out_length += (
ulg)
s->dyn_dtree[dcode].Freq *
1048 Tracev((
stderr,
"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
1049 s->last_lit, in_length, out_length,
1050 100
L - out_length*100
L/in_length));
1051 if (
s->matches <
s->last_lit/2 && out_length < in_length/2)
return 1;
1054 return (
s->last_lit ==
s->lit_bufsize-1);
1075 if (
s->last_lit != 0)
do {
1076 dist =
s->d_buf[lx];
1077 lc =
s->l_buf[lx++];
1104 "pendingBuf overflow");
1106 }
while (lx < s->last_lit);
1131 unsigned long black_mask = 0xf3ffc07f
UL;
1136 if ((black_mask & 1) && (
s->dyn_ltree[
n].Freq != 0))
1140 if (
s->dyn_ltree[9].Freq != 0 ||
s->dyn_ltree[10].Freq != 0
1141 ||
s->dyn_ltree[13].Freq != 0)
1144 if (
s->dyn_ltree[
n].Freq != 0)
1162 register unsigned res = 0;
1166 }
while (--
len > 0);
1176 if (
s->bi_valid == 16) {
1180 }
else if (
s->bi_valid >= 8) {
1193 if (
s->bi_valid > 8) {
1195 }
else if (
s->bi_valid > 0) {
1201 s->bits_sent = (
s->bits_sent+7) & ~7;
void scan_tree(deflate_state *s, ct_data *tree, int max_code)
void bi_flush(deflate_state *s)
unsigned bi_reverse(unsigned code, int len)
const int extra_dbits[D_CODES]
const static_tree_desc static_bl_desc
int base_length[LENGTH_CODES]
ct_data static_ltree[L_CODES+2]
GLuint GLuint GLsizei count
void gen_bitlen(deflate_state *s, tree_desc *desc)
void ZLIB_INTERNAL _tr_align(deflate_state *s)
void init_block(deflate_state *s)
void pqdownheap(deflate_state *s, ct_data *tree, int k)
GLenum GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * bits
GLfloat GLfloat GLfloat GLfloat h
GLenum GLuint GLenum GLsizei const GLchar * buf
#define smaller(tree, n, m, depth)
void gen_codes(ct_data *tree, int max_code, ushf *bl_count)
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
static const WCHAR desc[]
GLenum GLuint GLenum GLsizei length
const uch bl_order[BL_CODES]
ct_data static_dtree[D_CODES]
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
void ZLIB_INTERNAL _tr_init(deflate_state *s)
#define send_bits(s, value, length)
void bi_windup(deflate_state *s)
void ZLIB_INTERNAL _tr_flush_bits(deflate_state *s)
_Check_return_ _CRTIMP int __cdecl isgraph(_In_ int _C)
void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes)
const static_tree_desc static_d_desc
int detect_data_type(deflate_state *s)
const int extra_blbits[BL_CODES]
_In_ UCHAR _In_ UCHAR _In_ ULONG Code
GLsizei const GLfloat * value
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int last)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
#define pqremove(s, tree, top)
void send_tree(deflate_state *s, ct_data *tree, int max_code)
uch _dist_code[DIST_CODE_LEN]
const int extra_lbits[LENGTH_CODES]
int build_bl_tree(deflate_state *s)
int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc)
const static_tree_desc static_l_desc
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
uch _length_code[MAX_MATCH-MIN_MATCH+1]
void tr_static_init OF((void))
void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len, int last)
const ct_data * static_tree
void compress_block(deflate_state *s, const ct_data *ltree, const ct_data *dtree)
void build_tree(deflate_state *s, tree_desc *desc)
#define Assert(cond, msg)
#define send_code(s, c, tree)
static unsigned(__cdecl *hash_bstr)(bstr_t s)