summaryrefslogtreecommitdiff
path: root/trees.c
diff options
context:
space:
mode:
Diffstat (limited to 'trees.c')
-rw-r--r--trees.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/trees.c b/trees.c
index 4c7c136..f6b97ff 100644
--- a/trees.c
+++ b/trees.c
@@ -110,7 +110,7 @@ local int base_dist[D_CODES];
110 110
111struct static_tree_desc_s { 111struct static_tree_desc_s {
112 ct_data *static_tree; /* static tree or NULL */ 112 ct_data *static_tree; /* static tree or NULL */
113 int *extra_bits; /* extra bits for each code or NULL */ 113 intf *extra_bits; /* extra bits for each code or NULL */
114 int extra_base; /* base index for extra_bits */ 114 int extra_base; /* base index for extra_bits */
115 int elems; /* max number of elements in the tree */ 115 int elems; /* max number of elements in the tree */
116 int max_length; /* max bit length for the codes */ 116 int max_length; /* max bit length for the codes */
@@ -129,25 +129,25 @@ local static_tree_desc static_bl_desc =
129 * Local (static) routines in this file. 129 * Local (static) routines in this file.
130 */ 130 */
131 131
132local void ct_static_init __P((void)); 132local void ct_static_init OF((void));
133local void init_block __P((deflate_state *s)); 133local void init_block OF((deflate_state *s));
134local void pqdownheap __P((deflate_state *s, ct_data *tree, int k)); 134local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
135local void gen_bitlen __P((deflate_state *s, tree_desc *desc)); 135local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
136local void gen_codes __P((ct_data *tree, int max_code, ush bl_count[])); 136local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
137local void build_tree __P((deflate_state *s, tree_desc *desc)); 137local void build_tree OF((deflate_state *s, tree_desc *desc));
138local void scan_tree __P((deflate_state *s, ct_data *tree, int max_code)); 138local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
139local void send_tree __P((deflate_state *s, ct_data *tree, int max_code)); 139local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
140local int build_bl_tree __P((deflate_state *s)); 140local int build_bl_tree OF((deflate_state *s));
141local void send_all_trees __P((deflate_state *s, int lcodes, int dcodes, 141local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
142 int blcodes)); 142 int blcodes));
143local void compress_block __P((deflate_state *s, ct_data *ltree, 143local void compress_block OF((deflate_state *s, ct_data *ltree,
144 ct_data *dtree)); 144 ct_data *dtree));
145local void set_data_type __P((deflate_state *s)); 145local void set_data_type OF((deflate_state *s));
146local void send_bits __P((deflate_state *s, int value, int length)); 146local void send_bits OF((deflate_state *s, int value, int length));
147local unsigned bi_reverse __P((unsigned value, int length)); 147local unsigned bi_reverse OF((unsigned value, int length));
148local void bi_windup __P((deflate_state *s)); 148local void bi_windup OF((deflate_state *s));
149local void copy_block __P((deflate_state *s, char *buf, unsigned len, 149local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
150 int header)); 150 int header));
151 151
152#ifndef DEBUG 152#ifndef DEBUG
153# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) 153# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
@@ -356,7 +356,7 @@ local void gen_bitlen(s, desc)
356 ct_data *tree = desc->dyn_tree; 356 ct_data *tree = desc->dyn_tree;
357 int max_code = desc->max_code; 357 int max_code = desc->max_code;
358 ct_data *stree = desc->stat_desc->static_tree; 358 ct_data *stree = desc->stat_desc->static_tree;
359 int *extra = desc->stat_desc->extra_bits; 359 intf *extra = desc->stat_desc->extra_bits;
360 int base = desc->stat_desc->extra_base; 360 int base = desc->stat_desc->extra_base;
361 int max_length = desc->stat_desc->max_length; 361 int max_length = desc->stat_desc->max_length;
362 int h; /* heap index */ 362 int h; /* heap index */
@@ -439,7 +439,7 @@ local void gen_bitlen(s, desc)
439local void gen_codes (tree, max_code, bl_count) 439local void gen_codes (tree, max_code, bl_count)
440 ct_data *tree; /* the tree to decorate */ 440 ct_data *tree; /* the tree to decorate */
441 int max_code; /* largest code with non zero frequency */ 441 int max_code; /* largest code with non zero frequency */
442 ush bl_count[]; /* number of codes at each bit length */ 442 ushf *bl_count; /* number of codes at each bit length */
443{ 443{
444 ush next_code[MAX_BITS+1]; /* next code value for each bit length */ 444 ush next_code[MAX_BITS+1]; /* next code value for each bit length */
445 ush code = 0; /* running code value */ 445 ush code = 0; /* running code value */
@@ -487,8 +487,7 @@ local void build_tree(s, desc)
487 int elems = desc->stat_desc->elems; 487 int elems = desc->stat_desc->elems;
488 int n, m; /* iterate over heap elements */ 488 int n, m; /* iterate over heap elements */
489 int max_code = -1; /* largest code with non zero frequency */ 489 int max_code = -1; /* largest code with non zero frequency */
490 int node = elems; /* next internal node of the tree */ 490 int node; /* new node being created */
491 int new; /* new node being created */
492 491
493 /* Construct the initial heap, with least frequent element in 492 /* Construct the initial heap, with least frequent element in
494 * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. 493 * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
@@ -511,11 +510,11 @@ local void build_tree(s, desc)
511 * two codes of non zero frequency. 510 * two codes of non zero frequency.
512 */ 511 */
513 while (s->heap_len < 2) { 512 while (s->heap_len < 2) {
514 new = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); 513 node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
515 tree[new].Freq = 1; 514 tree[node].Freq = 1;
516 s->depth[new] = 0; 515 s->depth[node] = 0;
517 s->opt_len--; if (stree) s->static_len -= stree[new].Len; 516 s->opt_len--; if (stree) s->static_len -= stree[node].Len;
518 /* new is 0 or 1 so it does not have extra bits */ 517 /* node is 0 or 1 so it does not have extra bits */
519 } 518 }
520 desc->max_code = max_code; 519 desc->max_code = max_code;
521 520
@@ -527,6 +526,7 @@ local void build_tree(s, desc)
527 /* Construct the Huffman tree by repeatedly combining the least two 526 /* Construct the Huffman tree by repeatedly combining the least two
528 * frequent nodes. 527 * frequent nodes.
529 */ 528 */
529 node = elems; /* next internal node of the tree */
530 do { 530 do {
531 pqremove(s, tree, n); /* n = node of least frequency */ 531 pqremove(s, tree, n); /* n = node of least frequency */
532 m = s->heap[SMALLEST]; /* m = node of next least frequency */ 532 m = s->heap[SMALLEST]; /* m = node of next least frequency */
@@ -727,7 +727,7 @@ local void send_all_trees(s, lcodes, dcodes, blcodes)
727 */ 727 */
728void ct_stored_block(s, buf, stored_len, eof) 728void ct_stored_block(s, buf, stored_len, eof)
729 deflate_state *s; 729 deflate_state *s;
730 char *buf; /* input block */ 730 charf *buf; /* input block */
731 ulg stored_len; /* length of input block */ 731 ulg stored_len; /* length of input block */
732 int eof; /* true if this is the last block for a file */ 732 int eof; /* true if this is the last block for a file */
733{ 733{
@@ -756,7 +756,7 @@ void ct_align(s)
756 */ 756 */
757ulg ct_flush_block(s, buf, stored_len, eof) 757ulg ct_flush_block(s, buf, stored_len, eof)
758 deflate_state *s; 758 deflate_state *s;
759 char *buf; /* input block, or NULL if too old */ 759 charf *buf; /* input block, or NULL if too old */
760 ulg stored_len; /* length of input block */ 760 ulg stored_len; /* length of input block */
761 int eof; /* true if this is the last block for a file */ 761 int eof; /* true if this is the last block for a file */
762{ 762{
@@ -804,7 +804,7 @@ ulg ct_flush_block(s, buf, stored_len, eof)
804 if (stored_len <= opt_lenb && eof && s->compressed_len==0L && seekable()) { 804 if (stored_len <= opt_lenb && eof && s->compressed_len==0L && seekable()) {
805# endif 805# endif
806 /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */ 806 /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */
807 if (buf == (char*)0) error ("block vanished"); 807 if (buf == (charf*)0) error ("block vanished");
808 808
809 copy_block(buf, (unsigned)stored_len, 0); /* without header */ 809 copy_block(buf, (unsigned)stored_len, 0); /* without header */
810 s->compressed_len = stored_len << 3; 810 s->compressed_len = stored_len << 3;
@@ -1049,7 +1049,7 @@ local void bi_windup(s)
1049 */ 1049 */
1050local void copy_block(s, buf, len, header) 1050local void copy_block(s, buf, len, header)
1051 deflate_state *s; 1051 deflate_state *s;
1052 char *buf; /* the input data */ 1052 charf *buf; /* the input data */
1053 unsigned len; /* its length */ 1053 unsigned len; /* its length */
1054 int header; /* true if block header must be written */ 1054 int header; /* true if block header must be written */
1055{ 1055{