X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e6ebb51430cd8e4a9a11c6c5a5ca7c3ff9d7a72a..d3e780ecdf69233c872d51216eedbc64a1b6db25:/src/zlib/trees.c diff --git a/src/zlib/trees.c b/src/zlib/trees.c index a1b4304bb4..d37dff4951 100644 --- a/src/zlib/trees.c +++ b/src/zlib/trees.c @@ -1,5 +1,5 @@ /* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-1998 Jean-loup Gailly + * Copyright (C) 1995-2002 Jean-loup Gailly * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -189,7 +189,7 @@ local void gen_trees_header OF((void)); #ifdef __WXDEBUG__ local void send_bits OF((deflate_state *s, int value, int length)); -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local void send_bits(deflate_state* s, int value, int length) #else local void send_bits(s, value, length) @@ -254,6 +254,13 @@ local void tr_static_init() if (static_init_done) return; + /* For some embedded targets, global variables are not initialized: */ + static_l_desc.static_tree = static_ltree; + static_l_desc.extra_bits = extra_lbits; + static_d_desc.static_tree = static_dtree; + static_d_desc.extra_bits = extra_dbits; + static_bl_desc.extra_bits = extra_blbits; + /* Initialize the mapping length (0..255) -> length code (0..28) */ length = 0; for (code = 0; code < LENGTH_CODES-1; code++) { @@ -377,7 +384,7 @@ void gen_trees_header() /* =========================================================================== * Initialize the tree data structures for a new zlib stream. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ void _tr_init(deflate_state* s) #else void _tr_init(s) @@ -386,8 +393,6 @@ void _tr_init(s) { tr_static_init(); - s->compressed_len = 0L; - s->l_desc.dyn_tree = s->dyn_ltree; s->l_desc.stat_desc = &static_l_desc; @@ -401,6 +406,7 @@ void _tr_init(s) s->bi_valid = 0; s->last_eob_len = 8; /* enough lookahead for inflate */ #ifdef __WXDEBUG__ + s->compressed_len = 0L; s->bits_sent = 0L; #endif @@ -411,7 +417,7 @@ void _tr_init(s) /* =========================================================================== * Initialize a new block. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local void init_block(deflate_state* s) #else local void init_block(s) @@ -459,7 +465,7 @@ local void init_block(s) * when the heap property is re-established (each father smaller than its * two sons). */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local void pqdownheap(deflate_state* s, ct_data* tree, int k) #else local void pqdownheap(s, tree, k) @@ -498,7 +504,7 @@ local void pqdownheap(s, tree, k) * The length opt_len is updated; static_len is also updated if stree is * not null. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local void gen_bitlen(deflate_state* s, tree_desc* desc) #else local void gen_bitlen(s, desc) @@ -589,7 +595,7 @@ local void gen_bitlen(s, desc) * OUT assertion: the field code is set for all tree elements of non * zero code length. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local void gen_codes (ct_data* tree, int max_code, ushf* bl_count) #else local void gen_codes (tree, max_code, bl_count) @@ -612,7 +618,7 @@ local void gen_codes (tree, max_code, bl_count) /* Check that the bit counts in bl_count are consistent. The last code * must be all ones. */ - Assert (code + bl_count[MAX_BITS]-1 == (ush)(1<= 257, dcodes >= 1, blcodes >= 4. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local void send_all_trees(deflate_state* s, int lcodes, int dcodes, int blcodes) #else local void send_all_trees(s, lcodes, dcodes, blcodes) @@ -902,7 +908,7 @@ local void send_all_trees(s, lcodes, dcodes, blcodes) /* =========================================================================== * Send a stored block */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ void _tr_stored_block(deflate_state* s, charf* buf, ulg stored_len, int eof) #else void _tr_stored_block(s, buf, stored_len, eof) @@ -913,9 +919,10 @@ void _tr_stored_block(s, buf, stored_len, eof) #endif { send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */ +#ifdef __WXDEBUG__ s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; s->compressed_len += (stored_len + 4) << 3; - +#endif copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ } @@ -930,7 +937,7 @@ void _tr_stored_block(s, buf, stored_len, eof) * To simplify the code, we assume the worst case of last real code encoded * on one bit only. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ void _tr_align(deflate_state* s) #else void _tr_align(s) @@ -939,7 +946,9 @@ void _tr_align(s) { send_bits(s, STATIC_TREES<<1, 3); send_code(s, END_BLOCK, static_ltree); +#ifdef __WXDEBUG__ s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ +#endif bi_flush(s); /* Of the 10 bits for the empty block, we have already sent * (10 - bi_valid) bits. The lookahead for the last real code (before @@ -949,7 +958,9 @@ void _tr_align(s) if (1 + s->last_eob_len + 10 - s->bi_valid < 9) { send_bits(s, STATIC_TREES<<1, 3); send_code(s, END_BLOCK, static_ltree); +#ifdef __WXDEBUG__ s->compressed_len += 10L; +#endif bi_flush(s); } s->last_eob_len = 7; @@ -957,13 +968,12 @@ void _tr_align(s) /* =========================================================================== * Determine the best encoding for the current block: dynamic trees, static - * trees or store, and output the encoded block to the zip file. This function - * returns the total compressed length for the file so far. + * trees or store, and output the encoded block to the zip file. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface -ulg _tr_flush_block(deflate_state* s, charf* buf, ulg stored_len, int eof) +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ +void _tr_flush_block(deflate_state* s, charf* buf, ulg stored_len, int eof) #else -ulg _tr_flush_block(s, buf, stored_len, eof) +void _tr_flush_block(s, buf, stored_len, eof) deflate_state *s; charf *buf; /* input block, or NULL if too old */ ulg stored_len; /* length of input block */ @@ -1011,25 +1021,6 @@ ulg _tr_flush_block(s, buf, stored_len, eof) opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ } - /* If compression failed and this is the first and last block, - * and if the .zip file can be seeked (to rewrite the local header), - * the whole file is transformed into a stored file: - */ -#ifdef STORED_FILE_OK -# ifdef FORCE_STORED_FILE - if (eof && s->compressed_len == 0L) { /* force stored file */ -# else - if (stored_len <= opt_lenb && eof && s->compressed_len==0L && seekable()) { -# endif - /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */ - if (buf == (charf*)0) error ("block vanished"); - - copy_block(buf, (unsigned)stored_len, 0); /* without header */ - s->compressed_len = stored_len << 3; - s->method = STORED; - } else -#endif /* STORED_FILE_OK */ - #ifdef FORCE_STORED if (buf != (char*)0) { /* force stored block */ #else @@ -1051,32 +1042,39 @@ ulg _tr_flush_block(s, buf, stored_len, eof) #endif send_bits(s, (STATIC_TREES<<1)+eof, 3); compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); +#ifdef __WXDEBUG__ s->compressed_len += 3 + s->static_len; +#endif } else { send_bits(s, (DYN_TREES<<1)+eof, 3); send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, max_blindex+1); compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); +#ifdef __WXDEBUG__ s->compressed_len += 3 + s->opt_len; +#endif } Assert (s->compressed_len == s->bits_sent, "bad compressed size"); + /* The above check is made mod 2^32, for files larger than 512 MB + * and uLong implemented on 32 bits. + */ init_block(s); if (eof) { bi_windup(s); +#ifdef __WXDEBUG__ s->compressed_len += 7; /* align on byte boundary */ +#endif } Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, s->compressed_len-7*eof)); - - return s->compressed_len >> 3; } /* =========================================================================== * Save the match info and tally the frequency counts. Return true if * the current block must be flushed. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ int _tr_tally (deflate_state* s, unsigned dist, unsigned lc) #else int _tr_tally (s, dist, lc) @@ -1130,7 +1128,7 @@ int _tr_tally (s, dist, lc) /* =========================================================================== * Send the block data compressed using the given Huffman trees */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local void compress_block(deflate_state* s, ct_data* ltree, ct_data* dtree) #else local void compress_block(s, ltree, dtree) @@ -1173,7 +1171,7 @@ local void compress_block(s, ltree, dtree) } /* literal or match pair ? */ /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ - Assert((unsigned)s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow"); + Assert(s->pending < s->lit_bufsize + 2*lx, "pendingBuf overflow"); } while (lx < s->last_lit); @@ -1187,7 +1185,7 @@ local void compress_block(s, ltree, dtree) * IN assertion: the fields freq of dyn_ltree are set and the total of all * frequencies does not exceed 64K (to fit in an int on 16 bit machines). */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local void set_data_type(deflate_state* s) #else local void set_data_type(s) @@ -1208,7 +1206,7 @@ local void set_data_type(s) * method would use a table) * IN assertion: 1 <= len <= 15 */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local unsigned bi_reverse(unsigned code, int len) #else local unsigned bi_reverse(code, len) @@ -1227,7 +1225,7 @@ local unsigned bi_reverse(code, len) /* =========================================================================== * Flush the bit buffer, keeping at most 7 bits in it. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local void bi_flush(deflate_state* s) #else local void bi_flush(s) @@ -1248,7 +1246,7 @@ local void bi_flush(s) /* =========================================================================== * Flush the bit buffer and align the output on a byte boundary */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local void bi_windup(deflate_state* s) #else local void bi_windup(s) @@ -1271,7 +1269,7 @@ local void bi_windup(s) * Copy a stored block, storing first the length and its * one's complement if requested. */ -#if defined(__VISAGECPP__) // Visual game can't handle this antiquated interface +#if defined(__VISAGECPP__) /* Visualage can't handle this antiquated interface */ local void copy_block(deflate_state* s, charf* buf, unsigned len, int header) #else local void copy_block(s, buf, len, header)