ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
trees.c
Go to the documentation of this file.
1/* trees.c -- output deflated data using Huffman coding
2 * Copyright (C) 1995-2010 Jean-loup Gailly
3 * detect_data_type() function provided freely by Cosmin Truta, 2006
4 * For conditions of distribution and use, see copyright notice in zlib.h
5 */
6
7/*
8 * ALGORITHM
9 *
10 * The "deflation" process uses several Huffman trees. The more
11 * common source values are represented by shorter bit sequences.
12 *
13 * Each code tree is stored in a compressed form which is itself
14 * a Huffman encoding of the lengths of all the code strings (in
15 * ascending order by source values). The actual code strings are
16 * reconstructed from the lengths in the inflate process, as described
17 * in the deflate specification.
18 *
19 * REFERENCES
20 *
21 * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification".
22 * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc
23 *
24 * Storer, James A.
25 * Data Compression: Methods and Theory, pp. 49-50.
26 * Computer Science Press, 1988. ISBN 0-7167-8156-5.
27 *
28 * Sedgewick, R.
29 * Algorithms, p290.
30 * Addison-Wesley, 1983. ISBN 0-201-06672-6.
31 */
32
33/* @(#) $Id$ */
34
35/* #define GEN_TREES_H */
36
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
41
42#include "deflate.h"
43
44#ifdef DEBUG
45# include <ctype.h>
46#endif
47
49
50/* ===========================================================================
51 * Constants
52 */
53
54#define MAX_BL_BITS 7
55/* Bit length codes must not exceed MAX_BL_BITS bits */
56
57#define END_BLOCK 256
58/* end of block literal code */
59
60#define REP_3_6 16
61/* repeat previous bit length 3-6 times (2 bits of repeat count) */
62
63#define REPZ_3_10 17
64/* repeat a zero length 3-10 times (3 bits of repeat count) */
65
66#define REPZ_11_138 18
67/* repeat a zero length 11-138 times (7 bits of repeat count) */
68
69local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
70 = {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};
71
72local const int extra_dbits[D_CODES] /* extra bits for each distance code */
73 = {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};
74
75local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
76 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
77
79 = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
80/* The lengths of the bit length codes are sent in order of decreasing
81 * probability, to avoid transmitting the lengths for unused bit length codes.
82 */
83
84#define Buf_size (8 * 2*sizeof(char))
85/* Number of bits used within bi_buf. (bi_buf might be implemented on
86 * more than 16 bits on some systems.)
87 */
88
89/* ===========================================================================
90 * Local data. These are initialized only once.
91 */
92
93#define DIST_CODE_LEN 512 /* see definition of array dist_code below */
94
95#if defined(GEN_TREES_H) || !defined(STDC)
96/* non ANSI compilers may not accept trees.h */
97
99/* The static literal tree. Since the bit lengths are imposed, there is no
100 * need for the L_CODES extra codes used during heap construction. However
101 * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
102 * below).
103 */
104
106/* The static distance tree. (Actually a trivial tree since all codes use
107 * 5 bits.)
108 */
109
111/* Distance codes. The first 256 values correspond to the distances
112 * 3 .. 258, the last 256 values correspond to the top 8 bits of
113 * the 15 bit distances.
114 */
115
117/* length code for each normalized match length (0 == MIN_MATCH) */
118
120/* First normalized length for each code (0 = MIN_MATCH) */
121
123/* First normalized distance for each code (0 = distance of 1) */
124
125#else
127# include "trees.h"
129#endif /* GEN_TREES_H */
130
131struct static_tree_desc_s {
132 const ct_data *static_tree; /* static tree or NULL */
133 const intf *extra_bits; /* extra bits for each code or NULL */
134 int extra_base; /* base index for extra_bits */
135 int elems; /* max number of elements in the tree */
136 int max_length; /* max bit length for the codes */
137};
138
141
144
147
148/* ===========================================================================
149 * Local (static) routines in this file.
150 */
151
154local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
156local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
157local void build_tree OF((deflate_state *s, tree_desc *desc));
158local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
159local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
161local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
162 int blcodes));
164 ct_data *dtree));
166local unsigned bi_reverse OF((unsigned value, int length));
168local void bi_flush OF((deflate_state *s));
169local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
170 int header));
171
172#ifdef GEN_TREES_H
173local void gen_trees_header OF((void));
174#endif
175
176#ifndef DEBUG
177# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
178 /* Send a code of the given tree. c and tree must not have side effects */
179
180#else /* DEBUG */
181# define send_code(s, c, tree) \
182 { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
183 send_bits(s, tree[c].Code, tree[c].Len); }
184#endif
185
186/* ===========================================================================
187 * Output a short LSB first on the stream.
188 * IN assertion: there is enough room in pendingBuf.
189 */
190#define put_short(s, w) { \
191 put_byte(s, (uch)((w) & 0xff)); \
192 put_byte(s, (uch)((ush)(w) >> 8)); \
193}
194
195/* ===========================================================================
196 * Send a value on a given number of bits.
197 * IN assertion: length <= 16 and value fits in length bits.
198 */
199#ifdef DEBUG
200local void send_bits OF((deflate_state *s, int value, int length));
201
202local void send_bits(deflate_state *s, int value, int length)
203{
204 Tracevv((stderr," l %2d v %4x ", length, value));
205 Assert(length > 0 && length <= 15, "invalid length");
206 s->bits_sent += (ulg)length;
207
208 /* If not enough room in bi_buf, use (valid) bits from bi_buf and
209 * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
210 * unused bits in value.
211 */
212 if (s->bi_valid > (int)Buf_size - length) {
213 s->bi_buf |= (ush)value << s->bi_valid;
214 put_short(s, s->bi_buf);
215 s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
216 s->bi_valid += length - Buf_size;
217 } else {
218 s->bi_buf |= (ush)value << s->bi_valid;
219 s->bi_valid += length;
220 }
221}
222#else /* !DEBUG */
223
224#define send_bits(s, value, length) \
225{ int len = length;\
226 if (s->bi_valid > (int)Buf_size - len) {\
227 int val = value;\
228 s->bi_buf |= (ush)val << s->bi_valid;\
229 put_short(s, s->bi_buf);\
230 s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
231 s->bi_valid += len - Buf_size;\
232 } else {\
233 s->bi_buf |= (ush)(value) << s->bi_valid;\
234 s->bi_valid += len;\
235 }\
236}
237#endif /* DEBUG */
238
239
240/* the arguments must not have side effects */
241
242/* ===========================================================================
243 * Initialize the various 'constant' tables.
244 */
246{
247#if defined(GEN_TREES_H) || !defined(STDC)
248 static int static_init_done = 0;
249 int n; /* iterates over tree elements */
250 int bits; /* bit counter */
251 int length; /* length value */
252 int code; /* code value */
253 int dist; /* distance index */
254 ush bl_count[MAX_BITS+1];
255 /* number of codes at each bit length for an optimal tree */
256
257 if (static_init_done) return;
258
259 /* For some embedded targets, global variables are not initialized: */
260#ifdef NO_INIT_GLOBAL_POINTERS
261 static_l_desc.static_tree = static_ltree;
262 static_l_desc.extra_bits = extra_lbits;
263 static_d_desc.static_tree = static_dtree;
264 static_d_desc.extra_bits = extra_dbits;
265 static_bl_desc.extra_bits = extra_blbits;
266#endif
267
268 /* Initialize the mapping length (0..255) -> length code (0..28) */
269 length = 0;
270 for (code = 0; code < LENGTH_CODES-1; code++) {
271 base_length[code] = length;
272 for (n = 0; n < (1<<extra_lbits[code]); n++) {
273 _length_code[length++] = (uch)code;
274 }
275 }
276 Assert (length == 256, "tr_static_init: length != 256");
277 /* Note that the length 255 (match length 258) can be represented
278 * in two different ways: code 284 + 5 bits or code 285, so we
279 * overwrite length_code[255] to use the best encoding:
280 */
281 _length_code[length-1] = (uch)code;
282
283 /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
284 dist = 0;
285 for (code = 0 ; code < 16; code++) {
286 base_dist[code] = dist;
287 for (n = 0; n < (1<<extra_dbits[code]); n++) {
288 _dist_code[dist++] = (uch)code;
289 }
290 }
291 Assert (dist == 256, "tr_static_init: dist != 256");
292 dist >>= 7; /* from now on, all distances are divided by 128 */
293 for ( ; code < D_CODES; code++) {
294 base_dist[code] = dist << 7;
295 for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
296 _dist_code[256 + dist++] = (uch)code;
297 }
298 }
299 Assert (dist == 256, "tr_static_init: 256+dist != 512");
300
301 /* Construct the codes of the static literal tree */
302 for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
303 n = 0;
304 while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
305 while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
306 while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
307 while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
308 /* Codes 286 and 287 do not exist, but we must include them in the
309 * tree construction to get a canonical Huffman tree (longest code
310 * all ones)
311 */
312 gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
313
314 /* The static distance tree is trivial: */
315 for (n = 0; n < D_CODES; n++) {
316 static_dtree[n].Len = 5;
317 static_dtree[n].Code = bi_reverse((unsigned)n, 5);
318 }
319 static_init_done = 1;
320
321# ifdef GEN_TREES_H
322 gen_trees_header();
323# endif
324#endif /* defined(GEN_TREES_H) || !defined(STDC) */
325}
326
327/* ===========================================================================
328 * Genererate the file trees.h describing the static trees.
329 */
330#ifdef GEN_TREES_H
331# ifndef DEBUG
333# include <stdio.h>
335# endif
336
337# define SEPARATOR(i, last, width) \
338 ((i) == (last)? "\n};\n\n" : \
339 ((i) % (width) == (width)-1 ? ",\n" : ", "))
340
341void gen_trees_header()
342{
343 FILE *header = fopen("trees.h", "w");
344 int i;
345
346 Assert (header != NULL, "Can't open trees.h");
347 fprintf(header,
348 "/* header created automatically with -DGEN_TREES_H */\n\n");
349
350 fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
351 for (i = 0; i < L_CODES+2; i++) {
352 fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
353 static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
354 }
355
356 fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
357 for (i = 0; i < D_CODES; i++) {
358 fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
359 static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
360 }
361
362 fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n");
363 for (i = 0; i < DIST_CODE_LEN; i++) {
364 fprintf(header, "%2u%s", _dist_code[i],
365 SEPARATOR(i, DIST_CODE_LEN-1, 20));
366 }
367
368 fprintf(header,
369 "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
370 for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
371 fprintf(header, "%2u%s", _length_code[i],
372 SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
373 }
374
375 fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
376 for (i = 0; i < LENGTH_CODES; i++) {
377 fprintf(header, "%1u%s", base_length[i],
378 SEPARATOR(i, LENGTH_CODES-1, 20));
379 }
380
381 fprintf(header, "local const int base_dist[D_CODES] = {\n");
382 for (i = 0; i < D_CODES; i++) {
383 fprintf(header, "%5u%s", base_dist[i],
384 SEPARATOR(i, D_CODES-1, 10));
385 }
386
387 fclose(header);
388}
389#endif /* GEN_TREES_H */
390
391/* ===========================================================================
392 * Initialize the tree data structures for a new zlib stream.
393 */
395{
397
398 s->l_desc.dyn_tree = s->dyn_ltree;
400
401 s->d_desc.dyn_tree = s->dyn_dtree;
403
404 s->bl_desc.dyn_tree = s->bl_tree;
406
407 s->bi_buf = 0;
408 s->bi_valid = 0;
409 s->last_eob_len = 8; /* enough lookahead for inflate */
410#ifdef DEBUG
411 s->compressed_len = 0L;
412 s->bits_sent = 0L;
413#endif
414
415 /* Initialize the first block of the first file: */
416 init_block(s);
417}
418
419/* ===========================================================================
420 * Initialize a new block.
421 */
423{
424 int n; /* iterates over tree elements */
425
426 /* Initialize the trees. */
427 for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
428 for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
429 for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
430
431 s->dyn_ltree[END_BLOCK].Freq = 1;
432 s->opt_len = s->static_len = 0L;
433 s->last_lit = s->matches = 0;
434}
435
436#define SMALLEST 1
437/* Index within the heap array of least frequent node in the Huffman tree */
438
439
440/* ===========================================================================
441 * Remove the smallest element from the heap and recreate the heap with
442 * one less element. Updates heap and heap_len.
443 */
444#define pqremove(s, tree, top) \
445{\
446 top = s->heap[SMALLEST]; \
447 s->heap[SMALLEST] = s->heap[s->heap_len--]; \
448 pqdownheap(s, tree, SMALLEST); \
449}
450
451/* ===========================================================================
452 * Compares to subtrees, using the tree depth as tie breaker when
453 * the subtrees have equal frequency. This minimizes the worst case length.
454 */
455#define smaller(tree, n, m, depth) \
456 (tree[n].Freq < tree[m].Freq || \
457 (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
458
459/* ===========================================================================
460 * Restore the heap property by moving down the tree starting at node k,
461 * exchanging a node with the smallest of its two sons if necessary, stopping
462 * when the heap property is re-established (each father smaller than its
463 * two sons).
464 */
465local void pqdownheap(deflate_state *s, ct_data *tree, int k)
466{
467 int v = s->heap[k];
468 int j = k << 1; /* left son of k */
469 while (j <= s->heap_len) {
470 /* Set j to the smallest of the two sons: */
471 if (j < s->heap_len &&
472 smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
473 j++;
474 }
475 /* Exit if v is smaller than both sons */
476 if (smaller(tree, v, s->heap[j], s->depth)) break;
477
478 /* Exchange v with the smallest son */
479 s->heap[k] = s->heap[j]; k = j;
480
481 /* And continue down the tree, setting j to the left son of k */
482 j <<= 1;
483 }
484 s->heap[k] = v;
485}
486
487/* ===========================================================================
488 * Compute the optimal bit lengths for a tree and update the total bit length
489 * for the current block.
490 * IN assertion: the fields freq and dad are set, heap[heap_max] and
491 * above are the tree nodes sorted by increasing frequency.
492 * OUT assertions: the field len is set to the optimal bit length, the
493 * array bl_count contains the frequencies for each bit length.
494 * The length opt_len is updated; static_len is also updated if stree is
495 * not null.
496 */
498{
499 ct_data *tree = desc->dyn_tree;
500 int max_code = desc->max_code;
501 const ct_data *stree = desc->stat_desc->static_tree;
502 const intf *extra = desc->stat_desc->extra_bits;
503 int base = desc->stat_desc->extra_base;
504 int max_length = desc->stat_desc->max_length;
505 int h; /* heap index */
506 int n, m; /* iterate over the tree elements */
507 int bits; /* bit length */
508 int xbits; /* extra bits */
509 ush f; /* frequency */
510 int overflow = 0; /* number of elements with bit length too large */
511
512 for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
513
514 /* In a first pass, compute the optimal bit lengths (which may
515 * overflow in the case of the bit length tree).
516 */
517 tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
518
519 for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
520 n = s->heap[h];
521 bits = tree[tree[n].Dad].Len + 1;
522 if (bits > max_length) bits = max_length, overflow++;
523 tree[n].Len = (ush)bits;
524 /* We overwrite tree[n].Dad which is no longer needed */
525
526 if (n > max_code) continue; /* not a leaf node */
527
528 s->bl_count[bits]++;
529 xbits = 0;
530 if (n >= base) xbits = extra[n-base];
531 f = tree[n].Freq;
532 s->opt_len += (ulg)f * (bits + xbits);
533 if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
534 }
535 if (overflow == 0) return;
536
537 Trace((stderr,"\nbit length overflow\n"));
538 /* This happens for example on obj2 and pic of the Calgary corpus */
539
540 /* Find the first bit length which could increase: */
541 do {
542 bits = max_length-1;
543 while (s->bl_count[bits] == 0) bits--;
544 s->bl_count[bits]--; /* move one leaf down the tree */
545 s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
546 s->bl_count[max_length]--;
547 /* The brother of the overflow item also moves one step up,
548 * but this does not affect bl_count[max_length]
549 */
550 overflow -= 2;
551 } while (overflow > 0);
552
553 /* Now recompute all bit lengths, scanning in increasing frequency.
554 * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
555 * lengths instead of fixing only the wrong ones. This idea is taken
556 * from 'ar' written by Haruhiko Okumura.)
557 */
558 for (bits = max_length; bits != 0; bits--) {
559 n = s->bl_count[bits];
560 while (n != 0) {
561 m = s->heap[--h];
562 if (m > max_code) continue;
563 if ((unsigned) tree[m].Len != (unsigned) bits) {
564 Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
565 s->opt_len += ((long)bits - (long)tree[m].Len)
566 *(long)tree[m].Freq;
567 tree[m].Len = (ush)bits;
568 }
569 n--;
570 }
571 }
572}
573
574/* ===========================================================================
575 * Generate the codes for a given tree and bit counts (which need not be
576 * optimal).
577 * IN assertion: the array bl_count contains the bit length statistics for
578 * the given tree and the field len is set for all tree elements.
579 * OUT assertion: the field code is set for all tree elements of non
580 * zero code length.
581 */
582local void gen_codes (ct_data *tree, int max_code, ushf *bl_count)
583 /* the tree to decorate */
584 /* largest code with non zero frequency */
585 /* number of codes at each bit length */
586{
587 ush next_code[MAX_BITS+1]; /* next code value for each bit length */
588 ush code = 0; /* running code value */
589 int bits; /* bit index */
590 int n; /* code index */
591
592 /* The distribution counts are first used to generate the code values
593 * without bit reversal.
594 */
595 for (bits = 1; bits <= MAX_BITS; bits++) {
596 next_code[bits] = code = (code + bl_count[bits-1]) << 1;
597 }
598 /* Check that the bit counts in bl_count are consistent. The last code
599 * must be all ones.
600 */
601 Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
602 "inconsistent bit counts");
603 Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
604
605 for (n = 0; n <= max_code; n++) {
606 int len = tree[n].Len;
607 if (len == 0) continue;
608 /* Now reverse the bits */
609 tree[n].Code = bi_reverse(next_code[len]++, len);
610
611 Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
612 n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
613 }
614}
615
616/* ===========================================================================
617 * Construct one Huffman tree and assigns the code bit strings and lengths.
618 * Update the total bit length for the current block.
619 * IN assertion: the field freq is set for all tree elements.
620 * OUT assertions: the fields len and code are set to the optimal bit length
621 * and corresponding code. The length opt_len is updated; static_len is
622 * also updated if stree is not null. The field max_code is set.
623 */
625{
626 ct_data *tree = desc->dyn_tree;
627 const ct_data *stree = desc->stat_desc->static_tree;
628 int elems = desc->stat_desc->elems;
629 int n, m; /* iterate over heap elements */
630 int max_code = -1; /* largest code with non zero frequency */
631 int node; /* new node being created */
632
633 /* Construct the initial heap, with least frequent element in
634 * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
635 * heap[0] is not used.
636 */
637 s->heap_len = 0, s->heap_max = HEAP_SIZE;
638
639 for (n = 0; n < elems; n++) {
640 if (tree[n].Freq != 0) {
641 s->heap[++(s->heap_len)] = max_code = n;
642 s->depth[n] = 0;
643 } else {
644 tree[n].Len = 0;
645 }
646 }
647
648 /* The pkzip format requires that at least one distance code exists,
649 * and that at least one bit should be sent even if there is only one
650 * possible code. So to avoid special checks later on we force at least
651 * two codes of non zero frequency.
652 */
653 while (s->heap_len < 2) {
654 node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
655 tree[node].Freq = 1;
656 s->depth[node] = 0;
657 s->opt_len--; if (stree) s->static_len -= stree[node].Len;
658 /* node is 0 or 1 so it does not have extra bits */
659 }
660 desc->max_code = max_code;
661
662 /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
663 * establish sub-heaps of increasing lengths:
664 */
665 for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
666
667 /* Construct the Huffman tree by repeatedly combining the least two
668 * frequent nodes.
669 */
670 node = elems; /* next internal node of the tree */
671 do {
672 pqremove(s, tree, n); /* n = node of least frequency */
673 m = s->heap[SMALLEST]; /* m = node of next least frequency */
674
675 s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
676 s->heap[--(s->heap_max)] = m;
677
678 /* Create a new node father of n and m */
679 tree[node].Freq = tree[n].Freq + tree[m].Freq;
680 s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
681 s->depth[n] : s->depth[m]) + 1);
682 tree[n].Dad = tree[m].Dad = (ush)node;
683#ifdef DUMP_BL_TREE
684 if (tree == s->bl_tree) {
685 fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
686 node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
687 }
688#endif
689 /* and insert the new node in the heap */
690 s->heap[SMALLEST] = node++;
691 pqdownheap(s, tree, SMALLEST);
692
693 } while (s->heap_len >= 2);
694
695 s->heap[--(s->heap_max)] = s->heap[SMALLEST];
696
697 /* At this point, the fields freq and dad are set. We can now
698 * generate the bit lengths.
699 */
700 gen_bitlen(s, (tree_desc *)desc);
701
702 /* The field len is now set, we can generate the bit codes */
703 gen_codes ((ct_data *)tree, max_code, s->bl_count);
704}
705
706/* ===========================================================================
707 * Scan a literal or distance tree to determine the frequencies of the codes
708 * in the bit length tree.
709 */
710local void scan_tree (deflate_state *s, ct_data *tree, int max_code)
711{
712 int n; /* iterates over all tree elements */
713 int prevlen = -1; /* last emitted length */
714 int curlen; /* length of current code */
715 int nextlen = tree[0].Len; /* length of next code */
716 int count = 0; /* repeat count of the current code */
717 int max_count = 7; /* max repeat count */
718 int min_count = 4; /* min repeat count */
719
720 if (nextlen == 0) max_count = 138, min_count = 3;
721 tree[max_code+1].Len = (ush)0xffff; /* guard */
722
723 for (n = 0; n <= max_code; n++) {
724 curlen = nextlen; nextlen = tree[n+1].Len;
725 if (++count < max_count && curlen == nextlen) {
726 continue;
727 } else if (count < min_count) {
728 s->bl_tree[curlen].Freq += count;
729 } else if (curlen != 0) {
730 if (curlen != prevlen) s->bl_tree[curlen].Freq++;
731 s->bl_tree[REP_3_6].Freq++;
732 } else if (count <= 10) {
733 s->bl_tree[REPZ_3_10].Freq++;
734 } else {
735 s->bl_tree[REPZ_11_138].Freq++;
736 }
737 count = 0; prevlen = curlen;
738 if (nextlen == 0) {
739 max_count = 138, min_count = 3;
740 } else if (curlen == nextlen) {
741 max_count = 6, min_count = 3;
742 } else {
743 max_count = 7, min_count = 4;
744 }
745 }
746}
747
748/* ===========================================================================
749 * Send a literal or distance tree in compressed form, using the codes in
750 * bl_tree.
751 */
752local void send_tree (deflate_state *s, ct_data *tree, int max_code)
753{
754 int n; /* iterates over all tree elements */
755 int prevlen = -1; /* last emitted length */
756 int curlen; /* length of current code */
757 int nextlen = tree[0].Len; /* length of next code */
758 int count = 0; /* repeat count of the current code */
759 int max_count = 7; /* max repeat count */
760 int min_count = 4; /* min repeat count */
761
762 /* tree[max_code+1].Len = -1; */ /* guard already set */
763 if (nextlen == 0) max_count = 138, min_count = 3;
764
765 for (n = 0; n <= max_code; n++) {
766 curlen = nextlen; nextlen = tree[n+1].Len;
767 if (++count < max_count && curlen == nextlen) {
768 continue;
769 } else if (count < min_count) {
770 do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
771
772 } else if (curlen != 0) {
773 if (curlen != prevlen) {
774 send_code(s, curlen, s->bl_tree); count--;
775 }
776 Assert(count >= 3 && count <= 6, " 3_6?");
777 send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
778
779 } else if (count <= 10) {
780 send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
781
782 } else {
783 send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
784 }
785 count = 0; prevlen = curlen;
786 if (nextlen == 0) {
787 max_count = 138, min_count = 3;
788 } else if (curlen == nextlen) {
789 max_count = 6, min_count = 3;
790 } else {
791 max_count = 7, min_count = 4;
792 }
793 }
794}
795
796/* ===========================================================================
797 * Construct the Huffman tree for the bit lengths and return the index in
798 * bl_order of the last bit length code to send.
799 */
801{
802 int max_blindex; /* index of last bit length code of non zero freq */
803
804 /* Determine the bit length frequencies for literal and distance trees */
807
808 /* Build the bit length tree: */
809 build_tree(s, (tree_desc *)(&(s->bl_desc)));
810 /* opt_len now includes the length of the tree representations, except
811 * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
812 */
813
814 /* Determine the number of bit length codes to send. The pkzip format
815 * requires that at least 4 bit length codes be sent. (appnote.txt says
816 * 3 but the actual value used is 4.)
817 */
818 for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
819 if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
820 }
821 /* Update opt_len to include the bit length tree and counts */
822 s->opt_len += 3*(max_blindex+1) + 5+5+4;
823 Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
824 s->opt_len, s->static_len));
825
826 return max_blindex;
827}
828
829/* ===========================================================================
830 * Send the header for a block using dynamic Huffman trees: the counts, the
831 * lengths of the bit length codes, the literal tree and the distance tree.
832 * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
833 */
834local void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes)
835{
836 int rank; /* index in bl_order */
837
838 Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
839 Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
840 "too many codes");
841 Tracev((stderr, "\nbl counts: "));
842 send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
843 send_bits(s, dcodes-1, 5);
844 send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
845 for (rank = 0; rank < blcodes; rank++) {
846 Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
847 send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
848 }
849 Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
850
851 send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
852 Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
853
854 send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
855 Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
856}
857
858/* ===========================================================================
859 * Send a stored block
860 */
861void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int last)
862{
863 send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */
864#ifdef DEBUG
865 s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
866 s->compressed_len += (stored_len + 4) << 3;
867#endif
868 copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
869}
870
871/* ===========================================================================
872 * Send one empty static block to give enough lookahead for inflate.
873 * This takes 10 bits, of which 7 may remain in the bit buffer.
874 * The current inflate code requires 9 bits of lookahead. If the
875 * last two codes for the previous block (real code plus EOB) were coded
876 * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
877 * the last real code. In this case we send two empty static blocks instead
878 * of one. (There are no problems if the previous block is stored or fixed.)
879 * To simplify the code, we assume the worst case of last real code encoded
880 * on one bit only.
881 */
883{
884 send_bits(s, STATIC_TREES<<1, 3);
886#ifdef DEBUG
887 s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
888#endif
889 bi_flush(s);
890 /* Of the 10 bits for the empty block, we have already sent
891 * (10 - bi_valid) bits. The lookahead for the last real code (before
892 * the EOB of the previous block) was thus at least one plus the length
893 * of the EOB plus what we have just sent of the empty static block.
894 */
895 if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
896 send_bits(s, STATIC_TREES<<1, 3);
898#ifdef DEBUG
899 s->compressed_len += 10L;
900#endif
901 bi_flush(s);
902 }
903 s->last_eob_len = 7;
904}
905
906/* ===========================================================================
907 * Determine the best encoding for the current block: dynamic trees, static
908 * trees or store, and output the encoded block to the zip file.
909 */
910void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len, int last)
911{
912 ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
913 int max_blindex = 0; /* index of last bit length code of non zero freq */
914
915 /* Build the Huffman trees unless a stored block is forced */
916 if (s->level > 0) {
917
918 /* Check if the file is binary or text */
919 if (s->strm->data_type == Z_UNKNOWN)
920 s->strm->data_type = detect_data_type(s);
921
922 /* Construct the literal and distance trees */
923 build_tree(s, (tree_desc *)(&(s->l_desc)));
924 Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
925 s->static_len));
926
927 build_tree(s, (tree_desc *)(&(s->d_desc)));
928 Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
929 s->static_len));
930 /* At this point, opt_len and static_len are the total bit lengths of
931 * the compressed block data, excluding the tree representations.
932 */
933
934 /* Build the bit length tree for the above two trees, and get the index
935 * in bl_order of the last bit length code to send.
936 */
937 max_blindex = build_bl_tree(s);
938
939 /* Determine the best encoding. Compute the block lengths in bytes. */
940 opt_lenb = (s->opt_len+3+7)>>3;
941 static_lenb = (s->static_len+3+7)>>3;
942
943 Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
944 opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
945 s->last_lit));
946
947 if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
948
949 } else {
950 Assert(buf != (char*)0, "lost buf");
951 opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
952 }
953
954#ifdef FORCE_STORED
955 if (buf != (char*)0) { /* force stored block */
956#else
957 if (stored_len+4 <= opt_lenb && buf != (char*)0) {
958 /* 4: two words for the lengths */
959#endif
960 /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
961 * Otherwise we can't have processed more than WSIZE input bytes since
962 * the last block flush, because compression would have been
963 * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
964 * transform a block into a stored block.
965 */
966 _tr_stored_block(s, buf, stored_len, last);
967
968#ifdef FORCE_STATIC
969 } else if (static_lenb >= 0) { /* force static trees */
970#else
971 } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
972#endif
973 send_bits(s, (STATIC_TREES<<1)+last, 3);
975#ifdef DEBUG
976 s->compressed_len += 3 + s->static_len;
977#endif
978 } else {
979 send_bits(s, (DYN_TREES<<1)+last, 3);
981 max_blindex+1);
983#ifdef DEBUG
984 s->compressed_len += 3 + s->opt_len;
985#endif
986 }
987 Assert (s->compressed_len == s->bits_sent, "bad compressed size");
988 /* The above check is made mod 2^32, for files larger than 512 MB
989 * and uLong implemented on 32 bits.
990 */
991 init_block(s);
992
993 if (last) {
994 bi_windup(s);
995#ifdef DEBUG
996 s->compressed_len += 7; /* align on byte boundary */
997#endif
998 }
999 Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
1000 s->compressed_len-7*last));
1001}
1002
1003/* ===========================================================================
1004 * Save the match info and tally the frequency counts. Return true if
1005 * the current block must be flushed.
1006 */
1007int ZLIB_INTERNAL _tr_tally (deflate_state *s, unsigned dist, unsigned lc)
1008{
1009 s->d_buf[s->last_lit] = (ush)dist;
1010 s->l_buf[s->last_lit++] = (uch)lc;
1011 if (dist == 0) {
1012 /* lc is the unmatched char */
1013 s->dyn_ltree[lc].Freq++;
1014 } else {
1015 s->matches++;
1016 /* Here, lc is the match length - MIN_MATCH */
1017 dist--; /* dist = match distance - 1 */
1018 Assert((ush)dist < (ush)MAX_DIST(s) &&
1019 (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
1020 (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
1021
1022 s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
1023 s->dyn_dtree[d_code(dist)].Freq++;
1024 }
1025
1026#ifdef TRUNCATE_BLOCK
1027 /* Try to guess if it is profitable to stop the current block here */
1028 if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
1029 /* Compute an upper bound for the compressed length */
1030 ulg out_length = (ulg)s->last_lit*8L;
1031 ulg in_length = (ulg)((long)s->strstart - s->block_start);
1032 int dcode;
1033 for (dcode = 0; dcode < D_CODES; dcode++) {
1034 out_length += (ulg)s->dyn_dtree[dcode].Freq *
1035 (5L+extra_dbits[dcode]);
1036 }
1037 out_length >>= 3;
1038 Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
1039 s->last_lit, in_length, out_length,
1040 100L - out_length*100L/in_length));
1041 if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
1042 }
1043#endif
1044 return (s->last_lit == s->lit_bufsize-1);
1045 /* We avoid equality with lit_bufsize because of wraparound at 64K
1046 * on 16 bit machines and because stored blocks are restricted to
1047 * 64K-1 bytes.
1048 */
1049}
1050
1051/* ===========================================================================
1052 * Send the block data compressed using the given Huffman trees
1053 */
1055{
1056 unsigned dist; /* distance of matched string */
1057 int lc; /* match length or unmatched char (if dist == 0) */
1058 unsigned lx = 0; /* running index in l_buf */
1059 unsigned code; /* the code to send */
1060 int extra; /* number of extra bits to send */
1061
1062 if (s->last_lit != 0) do {
1063 dist = s->d_buf[lx];
1064 lc = s->l_buf[lx++];
1065 if (dist == 0) {
1066 send_code(s, lc, ltree); /* send a literal byte */
1067 Tracecv(isgraph(lc), (stderr," '%c' ", lc));
1068 } else {
1069 /* Here, lc is the match length - MIN_MATCH */
1070 code = _length_code[lc];
1071 send_code(s, code+LITERALS+1, ltree); /* send the length code */
1072 extra = extra_lbits[code];
1073 if (extra != 0) {
1074 lc -= base_length[code];
1075 send_bits(s, lc, extra); /* send the extra length bits */
1076 }
1077 dist--; /* dist is now the match distance - 1 */
1078 code = d_code(dist);
1079 Assert (code < D_CODES, "bad d_code");
1080
1081 send_code(s, code, dtree); /* send the distance code */
1082 extra = extra_dbits[code];
1083 if (extra != 0) {
1084 dist -= base_dist[code];
1085 send_bits(s, dist, extra); /* send the extra distance bits */
1086 }
1087 } /* literal or match pair ? */
1088
1089 /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
1090 Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
1091 "pendingBuf overflow");
1092
1093 } while (lx < s->last_lit);
1094
1095 send_code(s, END_BLOCK, ltree);
1096 s->last_eob_len = ltree[END_BLOCK].Len;
1097}
1098
1099/* ===========================================================================
1100 * Check if the data type is TEXT or BINARY, using the following algorithm:
1101 * - TEXT if the two conditions below are satisfied:
1102 * a) There are no non-portable control characters belonging to the
1103 * "black list" (0..6, 14..25, 28..31).
1104 * b) There is at least one printable character belonging to the
1105 * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255).
1106 * - BINARY otherwise.
1107 * - The following partially-portable control characters form a
1108 * "gray list" that is ignored in this detection algorithm:
1109 * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}).
1110 * IN assertion: the fields Freq of dyn_ltree are set.
1111 */
1113{
1114 /* black_mask is the bit mask of black-listed bytes
1115 * set bits 0..6, 14..25, and 28..31
1116 * 0xf3ffc07f = binary 11110011111111111100000001111111
1117 */
1118 unsigned long black_mask = 0xf3ffc07fUL;
1119 int n;
1120
1121 /* Check for non-textual ("black-listed") bytes. */
1122 for (n = 0; n <= 31; n++, black_mask >>= 1)
1123 if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0))
1124 return Z_BINARY;
1125
1126 /* Check for textual ("white-listed") bytes. */
1127 if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0
1128 || s->dyn_ltree[13].Freq != 0)
1129 return Z_TEXT;
1130 for (n = 32; n < LITERALS; n++)
1131 if (s->dyn_ltree[n].Freq != 0)
1132 return Z_TEXT;
1133
1134 /* There are no "black-listed" or "white-listed" bytes:
1135 * this stream either is empty or has tolerated ("gray-listed") bytes only.
1136 */
1137 return Z_BINARY;
1138}
1139
1140/* ===========================================================================
1141 * Reverse the first len bits of a code, using straightforward code (a faster
1142 * method would use a table)
1143 * IN assertion: 1 <= len <= 15
1144 */
1145local unsigned bi_reverse(unsigned code, int len)
1146{
1147 unsigned res = 0;
1148 do {
1149 res |= code & 1;
1150 code >>= 1, res <<= 1;
1151 } while (--len > 0);
1152 return res >> 1;
1153}
1154
1155/* ===========================================================================
1156 * Flush the bit buffer, keeping at most 7 bits in it.
1157 */
1159{
1160 if (s->bi_valid == 16) {
1161 put_short(s, s->bi_buf);
1162 s->bi_buf = 0;
1163 s->bi_valid = 0;
1164 } else if (s->bi_valid >= 8) {
1165 put_byte(s, (Byte)s->bi_buf);
1166 s->bi_buf >>= 8;
1167 s->bi_valid -= 8;
1168 }
1169}
1170
1171/* ===========================================================================
1172 * Flush the bit buffer and align the output on a byte boundary
1173 */
1175{
1176 if (s->bi_valid > 8) {
1177 put_short(s, s->bi_buf);
1178 } else if (s->bi_valid > 0) {
1179 put_byte(s, (Byte)s->bi_buf);
1180 }
1181 s->bi_buf = 0;
1182 s->bi_valid = 0;
1183#ifdef DEBUG
1184 s->bits_sent = (s->bits_sent+7) & ~7;
1185#endif
1186}
1187
1188/* ===========================================================================
1189 * Copy a stored block, storing first the length and its
1190 * one's complement if requested.
1191 */
1192local void copy_block(deflate_state *s, charf *buf, unsigned len, int header)
1193{
1194 bi_windup(s); /* align on byte boundary */
1195 s->last_eob_len = 8; /* enough lookahead for inflate */
1196
1197 if (header) {
1198 put_short(s, (ush)len);
1199 put_short(s, (ush)~len);
1200#ifdef DEBUG
1201 s->bits_sent += 2*16;
1202#endif
1203 }
1204#ifdef DEBUG
1205 s->bits_sent += (ulg)len<<3;
1206#endif
1207 while (len--) {
1208 put_byte(s, *buf++);
1209 }
1210}
1211
1212
1213
1215
1216
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
#define local
Definition adler32.c:17
ABC_NAMESPACE_IMPL_START typedef signed char value
#define ZLIB_INTERNAL
Definition compress_.c:8
#define Code
Definition deflate.h:76
struct ct_data_s ct_data
#define HEAP_SIZE
Definition deflate.h:47
#define MAX_DIST(s)
Definition deflate.h:285
#define L_CODES
Definition deflate.h:38
#define LITERALS
Definition deflate.h:35
#define Len
Definition deflate.h:78
#define MAX_BITS
Definition deflate.h:50
#define d_code(dist)
Definition deflate.h:303
#define put_byte(s, c)
Definition deflate.h:277
#define D_CODES
Definition deflate.h:41
#define Freq
Definition deflate.h:75
#define LENGTH_CODES
Definition deflate.h:32
struct static_tree_desc_s static_tree_desc
Definition deflate.h:80
#define BL_CODES
Definition deflate.h:44
uch ZLIB_INTERNAL _length_code[]
Definition trees.c:116
struct tree_desc_s tree_desc
struct internal_state deflate_state
uch ZLIB_INTERNAL _dist_code[]
Definition trees.c:110
struct tree_desc_s l_desc
Definition deflate.h:198
uInt lit_bufsize
Definition deflate.h:218
struct ct_data_s dyn_dtree[2 *D_CODES+1]
Definition deflate.h:195
long block_start
Definition deflate.h:150
uchf * l_buf
Definition deflate.h:216
uch depth[2 *L_CODES+1]
Definition deflate.h:212
struct ct_data_s bl_tree[2 *BL_CODES+1]
Definition deflate.h:196
struct tree_desc_s bl_desc
Definition deflate.h:200
z_streamp strm
Definition deflate.h:97
struct tree_desc_s d_desc
Definition deflate.h:199
ush bl_count[MAX_BITS+1]
Definition deflate.h:202
ushf * d_buf
Definition deflate.h:240
int heap[2 *L_CODES+1]
Definition deflate.h:205
struct ct_data_s dyn_ltree[HEAP_SIZE]
Definition deflate.h:194
const intf * extra_bits
Definition trees.c:133
const ct_data * static_tree
Definition trees.c:132
int max_code
Definition deflate.h:84
ct_data * dyn_tree
Definition deflate.h:83
static_tree_desc * stat_desc
Definition deflate.h:85
#define Buf_size
Definition trees.c:84
local ct_data static_dtree[D_CODES]
Definition trees.c:105
local void gen_bitlen(deflate_state *s, tree_desc *desc)
Definition trees.c:497
local const int extra_dbits[D_CODES]
Definition trees.c:73
#define END_BLOCK
Definition trees.c:57
local void copy_block(deflate_state *s, charf *buf, unsigned len, int header)
Definition trees.c:1192
int ZLIB_INTERNAL _tr_tally(deflate_state *s, unsigned dist, unsigned lc)
Definition trees.c:1007
void ZLIB_INTERNAL _tr_init(deflate_state *s)
Definition trees.c:394
#define REPZ_11_138
Definition trees.c:66
#define DIST_CODE_LEN
Definition trees.c:93
#define REPZ_3_10
Definition trees.c:63
local void pqdownheap(deflate_state *s, ct_data *tree, int k)
Definition trees.c:465
#define send_code(s, c, tree)
Definition trees.c:177
local ct_data static_ltree[L_CODES+2]
Definition trees.c:98
local void compress_block(deflate_state *s, ct_data *ltree, ct_data *dtree)
Definition trees.c:1054
local void gen_codes(ct_data *tree, int max_code, ushf *bl_count)
Definition trees.c:582
local static_tree_desc static_bl_desc
Definition trees.c:145
#define REP_3_6
Definition trees.c:60
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int last)
Definition trees.c:861
local void send_tree(deflate_state *s, ct_data *tree, int max_code)
Definition trees.c:752
local static_tree_desc static_d_desc
Definition trees.c:142
local const uch bl_order[BL_CODES]
Definition trees.c:79
#define smaller(tree, n, m, depth)
Definition trees.c:455
local void scan_tree(deflate_state *s, ct_data *tree, int max_code)
Definition trees.c:710
local const int extra_lbits[LENGTH_CODES]
Definition trees.c:70
local void bi_windup(deflate_state *s)
Definition trees.c:1174
local int base_length[LENGTH_CODES]
Definition trees.c:119
local void send_all_trees(deflate_state *s, int lcodes, int dcodes, int blcodes)
Definition trees.c:834
#define MAX_BL_BITS
Definition trees.c:54
void ZLIB_INTERNAL _tr_flush_block(deflate_state *s, charf *buf, ulg stored_len, int last)
Definition trees.c:910
local void bi_flush(deflate_state *s)
Definition trees.c:1158
local int detect_data_type(deflate_state *s)
Definition trees.c:1112
void ZLIB_INTERNAL _tr_align(deflate_state *s)
Definition trees.c:882
#define pqremove(s, tree, top)
Definition trees.c:444
local void init_block(deflate_state *s)
Definition trees.c:422
local unsigned bi_reverse(unsigned code, int len)
Definition trees.c:1145
#define SMALLEST
Definition trees.c:436
local static_tree_desc static_l_desc
Definition trees.c:139
local const int extra_blbits[BL_CODES]
Definition trees.c:76
local void build_tree(deflate_state *s, tree_desc *desc)
Definition trees.c:624
#define put_short(s, w)
Definition trees.c:190
#define send_bits(s, value, length)
Definition trees.c:224
local int build_bl_tree(deflate_state *s)
Definition trees.c:800
local void tr_static_init()
Definition trees.c:245
local int base_dist[D_CODES]
Definition trees.c:122
unsigned rank
Definition vector.c:142
char FAR charf
Definition zconf.h:344
unsigned int uInt
Definition zconf.h:335
#define OF(args)
Definition zconf.h:242
int FAR intf
Definition zconf.h:345
unsigned char Byte
Definition zconf.h:333
#define Z_BINARY
Definition zlib.h:207
#define Z_UNKNOWN
Definition zlib.h:210
#define Z_FIXED
Definition zlib.h:203
#define Z_TEXT
Definition zlib.h:208
#define STATIC_TREES
Definition zutil.h:69
unsigned short ush
Definition zutil.h:41
#define DYN_TREES
Definition zutil.h:70
#define Tracecv(c, x)
Definition zutil.h:273
#define Assert(cond, msg)
Definition zutil.h:268
#define Tracev(x)
Definition zutil.h:270
#define MIN_MATCH
Definition zutil.h:73
#define Trace(x)
Definition zutil.h:269
#define STORED_BLOCK
Definition zutil.h:68
#define MAX_MATCH
Definition zutil.h:74
ush FAR ushf
Definition zutil.h:42
unsigned long ulg
Definition zutil.h:43
#define Tracevv(x)
Definition zutil.h:271
unsigned char uch
Definition zutil.h:39