trees.c (131380) | trees.c (146081) |
---|---|
1/* trees.c -- output deflated data using Huffman coding 2 * Copyright (C) 1995-2003 Jean-loup Gailly 3 * For conditions of distribution and use, see copyright notice in zlib.h 4 */ 5 6/* 7 * ALGORITHM 8 * --- 15 unchanged lines hidden (view full) --- 24 * Data Compression: Methods and Theory, pp. 49-50. 25 * Computer Science Press, 1988. ISBN 0-7167-8156-5. 26 * 27 * Sedgewick, R. 28 * Algorithms, p290. 29 * Addison-Wesley, 1983. ISBN 0-201-06672-6. 30 */ 31 | 1/* trees.c -- output deflated data using Huffman coding 2 * Copyright (C) 1995-2003 Jean-loup Gailly 3 * For conditions of distribution and use, see copyright notice in zlib.h 4 */ 5 6/* 7 * ALGORITHM 8 * --- 15 unchanged lines hidden (view full) --- 24 * Data Compression: Methods and Theory, pp. 49-50. 25 * Computer Science Press, 1988. ISBN 0-7167-8156-5. 26 * 27 * Sedgewick, R. 28 * Algorithms, p290. 29 * Addison-Wesley, 1983. ISBN 0-201-06672-6. 30 */ 31 |
32#include <sys/cdefs.h> 33__FBSDID("$FreeBSD: head/lib/libz/trees.c 131380 2004-06-30 23:54:46Z tjr $"); | 32/* @(#) $Id$ */ |
34 35/* #define GEN_TREES_H */ 36 37#include "deflate.h" 38 39#ifdef DEBUG 40# include <ctype.h> 41#endif --- 885 unchanged lines hidden (view full) --- 927{ 928 ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ 929 int max_blindex = 0; /* index of last bit length code of non zero freq */ 930 931 /* Build the Huffman trees unless a stored block is forced */ 932 if (s->level > 0) { 933 934 /* Check if the file is ascii or binary */ | 33 34/* #define GEN_TREES_H */ 35 36#include "deflate.h" 37 38#ifdef DEBUG 39# include <ctype.h> 40#endif --- 885 unchanged lines hidden (view full) --- 926{ 927 ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ 928 int max_blindex = 0; /* index of last bit length code of non zero freq */ 929 930 /* Build the Huffman trees unless a stored block is forced */ 931 if (s->level > 0) { 932 933 /* Check if the file is ascii or binary */ |
935 if (s->data_type == Z_UNKNOWN) set_data_type(s); | 934 if (s->strm->data_type == Z_UNKNOWN) set_data_type(s); |
936 937 /* Construct the literal and distance trees */ 938 build_tree(s, (tree_desc *)(&(s->l_desc))); 939 Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, 940 s->static_len)); 941 942 build_tree(s, (tree_desc *)(&(s->d_desc))); 943 Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, --- 183 unchanged lines hidden (view full) --- 1127 deflate_state *s; 1128{ 1129 int n = 0; 1130 unsigned ascii_freq = 0; 1131 unsigned bin_freq = 0; 1132 while (n < 7) bin_freq += s->dyn_ltree[n++].Freq; 1133 while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq; 1134 while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq; | 935 936 /* Construct the literal and distance trees */ 937 build_tree(s, (tree_desc *)(&(s->l_desc))); 938 Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, 939 s->static_len)); 940 941 build_tree(s, (tree_desc *)(&(s->d_desc))); 942 Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, --- 183 unchanged lines hidden (view full) --- 1126 deflate_state *s; 1127{ 1128 int n = 0; 1129 unsigned ascii_freq = 0; 1130 unsigned bin_freq = 0; 1131 while (n < 7) bin_freq += s->dyn_ltree[n++].Freq; 1132 while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq; 1133 while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq; |
1135 s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII); | 1134 s->strm->data_type = bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII; |
1136} 1137 1138/* =========================================================================== 1139 * Reverse the first len bits of a code, using straightforward code (a faster 1140 * method would use a table) 1141 * IN assertion: 1 <= len <= 15 1142 */ 1143local unsigned bi_reverse(code, len) --- 73 unchanged lines hidden --- | 1135} 1136 1137/* =========================================================================== 1138 * Reverse the first len bits of a code, using straightforward code (a faster 1139 * method would use a table) 1140 * IN assertion: 1 <= len <= 15 1141 */ 1142local unsigned bi_reverse(code, len) --- 73 unchanged lines hidden --- |