diff options
| author | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:14:39 -0700 |
|---|---|---|
| committer | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:14:39 -0700 |
| commit | 423eb40306489f9c88f7dba32c2f69179166730b (patch) | |
| tree | b5a83b0b1e52bbe0de973dcbc7ec008c1d7cf7d9 /trees.c | |
| parent | 8a2acbffc86012de3523ecf91db2c4ea1b1c4ea2 (diff) | |
| download | zlib-423eb40306489f9c88f7dba32c2f69179166730b.tar.gz zlib-423eb40306489f9c88f7dba32c2f69179166730b.tar.bz2 zlib-423eb40306489f9c88f7dba32c2f69179166730b.zip | |
zlib 1.0.1v1.0.1
Diffstat (limited to '')
| -rw-r--r-- | trees.c | 36 |
1 files changed, 18 insertions, 18 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* trees.c -- output deflated data using Huffman coding | 1 | /* trees.c -- output deflated data using Huffman coding |
| 2 | * Copyright (C) 1995 Jean-loup Gailly | 2 | * Copyright (C) 1995-1996 Jean-loup Gailly |
| 3 | * For conditions of distribution and use, see copyright notice in zlib.h | 3 | * For conditions of distribution and use, see copyright notice in zlib.h |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| @@ -83,7 +83,7 @@ local uch bl_order[BL_CODES] | |||
| 83 | local ct_data static_ltree[L_CODES+2]; | 83 | local ct_data static_ltree[L_CODES+2]; |
| 84 | /* The static literal tree. Since the bit lengths are imposed, there is no | 84 | /* The static literal tree. Since the bit lengths are imposed, there is no |
| 85 | * need for the L_CODES extra codes used during heap construction. However | 85 | * need for the L_CODES extra codes used during heap construction. However |
| 86 | * The codes 286 and 287 are needed to build a canonical tree (see tr_init | 86 | * The codes 286 and 287 are needed to build a canonical tree (see _tr_init |
| 87 | * below). | 87 | * below). |
| 88 | */ | 88 | */ |
| 89 | 89 | ||
| @@ -232,7 +232,7 @@ local void send_bits(s, value, length) | |||
| 232 | */ | 232 | */ |
| 233 | local void tr_static_init() | 233 | local void tr_static_init() |
| 234 | { | 234 | { |
| 235 | static static_init_done = 0; | 235 | static int static_init_done = 0; |
| 236 | int n; /* iterates over tree elements */ | 236 | int n; /* iterates over tree elements */ |
| 237 | int bits; /* bit counter */ | 237 | int bits; /* bit counter */ |
| 238 | int length; /* length value */ | 238 | int length; /* length value */ |
| @@ -292,7 +292,7 @@ local void tr_static_init() | |||
| 292 | /* The static distance tree is trivial: */ | 292 | /* The static distance tree is trivial: */ |
| 293 | for (n = 0; n < D_CODES; n++) { | 293 | for (n = 0; n < D_CODES; n++) { |
| 294 | static_dtree[n].Len = 5; | 294 | static_dtree[n].Len = 5; |
| 295 | static_dtree[n].Code = bi_reverse(n, 5); | 295 | static_dtree[n].Code = bi_reverse((unsigned)n, 5); |
| 296 | } | 296 | } |
| 297 | static_init_done = 1; | 297 | static_init_done = 1; |
| 298 | } | 298 | } |
| @@ -300,7 +300,7 @@ local void tr_static_init() | |||
| 300 | /* =========================================================================== | 300 | /* =========================================================================== |
| 301 | * Initialize the tree data structures for a new zlib stream. | 301 | * Initialize the tree data structures for a new zlib stream. |
| 302 | */ | 302 | */ |
| 303 | void tr_init(s) | 303 | void _tr_init(s) |
| 304 | deflate_state *s; | 304 | deflate_state *s; |
| 305 | { | 305 | { |
| 306 | tr_static_init(); | 306 | tr_static_init(); |
| @@ -785,14 +785,14 @@ local void send_all_trees(s, lcodes, dcodes, blcodes) | |||
| 785 | /* =========================================================================== | 785 | /* =========================================================================== |
| 786 | * Send a stored block | 786 | * Send a stored block |
| 787 | */ | 787 | */ |
| 788 | void tr_stored_block(s, buf, stored_len, eof) | 788 | void _tr_stored_block(s, buf, stored_len, eof) |
| 789 | deflate_state *s; | 789 | deflate_state *s; |
| 790 | charf *buf; /* input block */ | 790 | charf *buf; /* input block */ |
| 791 | ulg stored_len; /* length of input block */ | 791 | ulg stored_len; /* length of input block */ |
| 792 | int eof; /* true if this is the last block for a file */ | 792 | int eof; /* true if this is the last block for a file */ |
| 793 | { | 793 | { |
| 794 | send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */ | 794 | send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */ |
| 795 | s->compressed_len = (s->compressed_len + 3 + 7) & ~7L; | 795 | s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; |
| 796 | s->compressed_len += (stored_len + 4) << 3; | 796 | s->compressed_len += (stored_len + 4) << 3; |
| 797 | 797 | ||
| 798 | copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ | 798 | copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ |
| @@ -809,7 +809,7 @@ void tr_stored_block(s, buf, stored_len, eof) | |||
| 809 | * To simplify the code, we assume the worst case of last real code encoded | 809 | * To simplify the code, we assume the worst case of last real code encoded |
| 810 | * on one bit only. | 810 | * on one bit only. |
| 811 | */ | 811 | */ |
| 812 | void tr_align(s) | 812 | void _tr_align(s) |
| 813 | deflate_state *s; | 813 | deflate_state *s; |
| 814 | { | 814 | { |
| 815 | send_bits(s, STATIC_TREES<<1, 3); | 815 | send_bits(s, STATIC_TREES<<1, 3); |
| @@ -835,20 +835,20 @@ void tr_align(s) | |||
| 835 | * trees or store, and output the encoded block to the zip file. This function | 835 | * trees or store, and output the encoded block to the zip file. This function |
| 836 | * returns the total compressed length for the file so far. | 836 | * returns the total compressed length for the file so far. |
| 837 | */ | 837 | */ |
| 838 | ulg tr_flush_block(s, buf, stored_len, eof) | 838 | ulg _tr_flush_block(s, buf, stored_len, eof) |
| 839 | deflate_state *s; | 839 | deflate_state *s; |
| 840 | charf *buf; /* input block, or NULL if too old */ | 840 | charf *buf; /* input block, or NULL if too old */ |
| 841 | ulg stored_len; /* length of input block */ | 841 | ulg stored_len; /* length of input block */ |
| 842 | int eof; /* true if this is the last block for a file */ | 842 | int eof; /* true if this is the last block for a file */ |
| 843 | { | 843 | { |
| 844 | ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ | 844 | ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ |
| 845 | int max_blindex; /* index of last bit length code of non zero freq */ | 845 | int max_blindex = 0; /* index of last bit length code of non zero freq */ |
| 846 | 846 | ||
| 847 | /* Build the Huffman trees unless a stored block is forced */ | 847 | /* Build the Huffman trees unless a stored block is forced */ |
| 848 | if (s->level > 0) { | 848 | if (s->level > 0) { |
| 849 | 849 | ||
| 850 | /* Check if the file is ascii or binary */ | 850 | /* Check if the file is ascii or binary */ |
| 851 | if (s->data_type == UNKNOWN) set_data_type(s); | 851 | if (s->data_type == Z_UNKNOWN) set_data_type(s); |
| 852 | 852 | ||
| 853 | /* Construct the literal and distance trees */ | 853 | /* Construct the literal and distance trees */ |
| 854 | build_tree(s, (tree_desc *)(&(s->l_desc))); | 854 | build_tree(s, (tree_desc *)(&(s->l_desc))); |
| @@ -879,7 +879,7 @@ ulg tr_flush_block(s, buf, stored_len, eof) | |||
| 879 | 879 | ||
| 880 | } else { | 880 | } else { |
| 881 | Assert(buf != (char*)0, "lost buf"); | 881 | Assert(buf != (char*)0, "lost buf"); |
| 882 | opt_lenb = stored_len + 5; /* force a stored block */ | 882 | opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ |
| 883 | } | 883 | } |
| 884 | 884 | ||
| 885 | /* If compression failed and this is the first and last block, | 885 | /* If compression failed and this is the first and last block, |
| @@ -913,7 +913,7 @@ ulg tr_flush_block(s, buf, stored_len, eof) | |||
| 913 | * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to | 913 | * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to |
| 914 | * transform a block into a stored block. | 914 | * transform a block into a stored block. |
| 915 | */ | 915 | */ |
| 916 | tr_stored_block(s, buf, stored_len, eof); | 916 | _tr_stored_block(s, buf, stored_len, eof); |
| 917 | 917 | ||
| 918 | #ifdef FORCE_STATIC | 918 | #ifdef FORCE_STATIC |
| 919 | } else if (static_lenb >= 0) { /* force static trees */ | 919 | } else if (static_lenb >= 0) { /* force static trees */ |
| @@ -947,10 +947,10 @@ ulg tr_flush_block(s, buf, stored_len, eof) | |||
| 947 | * Save the match info and tally the frequency counts. Return true if | 947 | * Save the match info and tally the frequency counts. Return true if |
| 948 | * the current block must be flushed. | 948 | * the current block must be flushed. |
| 949 | */ | 949 | */ |
| 950 | int tr_tally (s, dist, lc) | 950 | int _tr_tally (s, dist, lc) |
| 951 | deflate_state *s; | 951 | deflate_state *s; |
| 952 | int dist; /* distance of matched string */ | 952 | unsigned dist; /* distance of matched string */ |
| 953 | int lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ | 953 | unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ |
| 954 | { | 954 | { |
| 955 | s->d_buf[s->last_lit] = (ush)dist; | 955 | s->d_buf[s->last_lit] = (ush)dist; |
| 956 | s->l_buf[s->last_lit++] = (uch)lc; | 956 | s->l_buf[s->last_lit++] = (uch)lc; |
| @@ -963,7 +963,7 @@ int tr_tally (s, dist, lc) | |||
| 963 | dist--; /* dist = match distance - 1 */ | 963 | dist--; /* dist = match distance - 1 */ |
| 964 | Assert((ush)dist < (ush)MAX_DIST(s) && | 964 | Assert((ush)dist < (ush)MAX_DIST(s) && |
| 965 | (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && | 965 | (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && |
| 966 | (ush)d_code(dist) < (ush)D_CODES, "tr_tally: bad match"); | 966 | (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); |
| 967 | 967 | ||
| 968 | s->dyn_ltree[length_code[lc]+LITERALS+1].Freq++; | 968 | s->dyn_ltree[length_code[lc]+LITERALS+1].Freq++; |
| 969 | s->dyn_dtree[d_code(dist)].Freq++; | 969 | s->dyn_dtree[d_code(dist)].Freq++; |
| @@ -1057,7 +1057,7 @@ local void set_data_type(s) | |||
| 1057 | while (n < 7) bin_freq += s->dyn_ltree[n++].Freq; | 1057 | while (n < 7) bin_freq += s->dyn_ltree[n++].Freq; |
| 1058 | while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq; | 1058 | while (n < 128) ascii_freq += s->dyn_ltree[n++].Freq; |
| 1059 | while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq; | 1059 | while (n < LITERALS) bin_freq += s->dyn_ltree[n++].Freq; |
| 1060 | s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? BINARY : ASCII); | 1060 | s->data_type = (Byte)(bin_freq > (ascii_freq >> 2) ? Z_BINARY : Z_ASCII); |
| 1061 | } | 1061 | } |
| 1062 | 1062 | ||
| 1063 | /* =========================================================================== | 1063 | /* =========================================================================== |
