"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "zlib/zlib/trees.c" between
muscle7.61.zip and muscle7.62.zip

About: MUSCLE (Multi User Server Client Linking Environment) is a messaging server and networking API. The included server program ("muscled") lets its clients message each other, and/or store information in its serverside hierarchical database.

trees.c  (muscle7.61):trees.c  (muscle7.62)
/* trees.c -- output deflated data using Huffman coding /* trees.c -- output deflated data using Huffman coding
* Copyright (C) 1995-2012 Jean-loup Gailly * Copyright (C) 1995-2017 Jean-loup Gailly
* detect_data_type() function provided freely by Cosmin Truta, 2006 * detect_data_type() function provided freely by Cosmin Truta, 2006
* For conditions of distribution and use, see copyright notice in zlib.h * For conditions of distribution and use, see copyright notice in zlib.h
*/ */
/* /*
* ALGORITHM * ALGORITHM
* *
* The "deflation" process uses several Huffman trees. The more * The "deflation" process uses several Huffman trees. The more
* common source values are represented by shorter bit sequences. * common source values are represented by shorter bit sequences.
* *
skipping to change at line 39 skipping to change at line 39
* Algorithms, p290. * Algorithms, p290.
* Addison-Wesley, 1983. ISBN 0-201-06672-6. * Addison-Wesley, 1983. ISBN 0-201-06672-6.
*/ */
/* @(#) $Id$ */ /* @(#) $Id$ */
/* #define GEN_TREES_H */ /* #define GEN_TREES_H */
#include "deflate.h" #include "deflate.h"
#ifdef DEBUG #ifdef ZLIB_DEBUG
# include <ctype.h> # include <ctype.h>
#endif #endif
/* =========================================================================== /* ===========================================================================
* Constants * Constants
*/ */
#define MAX_BL_BITS 7 #define MAX_BL_BITS 7
/* Bit length codes must not exceed MAX_BL_BITS bits */ /* Bit length codes must not exceed MAX_BL_BITS bits */
skipping to change at line 125 skipping to change at line 125
#endif /* GEN_TREES_H */ #endif /* GEN_TREES_H */
struct static_tree_desc_s { struct static_tree_desc_s {
const ct_data *static_tree; /* static tree or NULL */ const ct_data *static_tree; /* static tree or NULL */
const intf *extra_bits; /* extra bits for each code or NULL */ const intf *extra_bits; /* extra bits for each code or NULL */
int extra_base; /* base index for extra_bits */ int extra_base; /* base index for extra_bits */
int elems; /* max number of elements in the tree */ int elems; /* max number of elements in the tree */
int max_length; /* max bit length for the codes */ int max_length; /* max bit length for the codes */
}; };
local static_tree_desc static_l_desc = local const static_tree_desc static_l_desc =
{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
local static_tree_desc static_d_desc = local const static_tree_desc static_d_desc =
{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
local static_tree_desc static_bl_desc = local const static_tree_desc static_bl_desc =
{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
/* =========================================================================== /* ===========================================================================
* Local (static) routines in this file. * Local (static) routines in this file.
*/ */
local void tr_static_init OF((void)); local void tr_static_init OF((void));
local void init_block OF((deflate_state *s)); local void init_block OF((deflate_state *s));
local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
skipping to change at line 155 skipping to change at line 155
local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
local int build_bl_tree OF((deflate_state *s)); local int build_bl_tree OF((deflate_state *s));
local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
int blcodes)); int blcodes));
local void compress_block OF((deflate_state *s, const ct_data *ltree, local void compress_block OF((deflate_state *s, const ct_data *ltree,
const ct_data *dtree)); const ct_data *dtree));
local int detect_data_type OF((deflate_state *s)); local int detect_data_type OF((deflate_state *s));
local unsigned bi_reverse OF((unsigned value, int length)); local unsigned bi_reverse OF((unsigned value, int length));
local void bi_windup OF((deflate_state *s)); local void bi_windup OF((deflate_state *s));
local void bi_flush OF((deflate_state *s)); local void bi_flush OF((deflate_state *s));
local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
int header));
#ifdef GEN_TREES_H #ifdef GEN_TREES_H
local void gen_trees_header OF((void)); local void gen_trees_header OF((void));
#endif #endif
#ifndef DEBUG #ifndef ZLIB_DEBUG
# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
/* Send a code of the given tree. c and tree must not have side effects */ /* Send a code of the given tree. c and tree must not have side effects */
#else /* DEBUG */ #else /* !ZLIB_DEBUG */
# define send_code(s, c, tree) \ # define send_code(s, c, tree) \
{ if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
send_bits(s, tree[c].Code, tree[c].Len); } send_bits(s, tree[c].Code, tree[c].Len); }
#endif #endif
/* =========================================================================== /* ===========================================================================
* Output a short LSB first on the stream. * Output a short LSB first on the stream.
* IN assertion: there is enough room in pendingBuf. * IN assertion: there is enough room in pendingBuf.
*/ */
#define put_short(s, w) { \ #define put_short(s, w) { \
put_byte(s, (uch)((w) & 0xff)); \ put_byte(s, (uch)((w) & 0xff)); \
put_byte(s, (uch)((ush)(w) >> 8)); \ put_byte(s, (uch)((ush)(w) >> 8)); \
} }
/* =========================================================================== /* ===========================================================================
* Send a value on a given number of bits. * Send a value on a given number of bits.
* IN assertion: length <= 16 and value fits in length bits. * IN assertion: length <= 16 and value fits in length bits.
*/ */
#ifdef DEBUG #ifdef ZLIB_DEBUG
local void send_bits OF((deflate_state *s, int value, int length)); local void send_bits OF((deflate_state *s, int value, int length));
local void send_bits(s, value, length) local void send_bits(s, value, length)
deflate_state *s; deflate_state *s;
int value; /* value to send */ int value; /* value to send */
int length; /* number of bits */ int length; /* number of bits */
{ {
Tracevv((stderr," l %2d v %4x ", length, value)); Tracevv((stderr," l %2d v %4x ", length, value));
Assert(length > 0 && length <= 15, "invalid length"); Assert(length > 0 && length <= 15, "invalid length");
s->bits_sent += (ulg)length; s->bits_sent += (ulg)length;
skipping to change at line 211 skipping to change at line 209
if (s->bi_valid > (int)Buf_size - length) { if (s->bi_valid > (int)Buf_size - length) {
s->bi_buf |= (ush)value << s->bi_valid; s->bi_buf |= (ush)value << s->bi_valid;
put_short(s, s->bi_buf); put_short(s, s->bi_buf);
s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
s->bi_valid += length - Buf_size; s->bi_valid += length - Buf_size;
} else { } else {
s->bi_buf |= (ush)value << s->bi_valid; s->bi_buf |= (ush)value << s->bi_valid;
s->bi_valid += length; s->bi_valid += length;
} }
} }
#else /* !DEBUG */ #else /* !ZLIB_DEBUG */
#define send_bits(s, value, length) \ #define send_bits(s, value, length) \
{ int len = length;\ { int len = length;\
if (s->bi_valid > (int)Buf_size - len) {\ if (s->bi_valid > (int)Buf_size - len) {\
int val = value;\ int val = (int)value;\
s->bi_buf |= (ush)val << s->bi_valid;\ s->bi_buf |= (ush)val << s->bi_valid;\
put_short(s, s->bi_buf);\ put_short(s, s->bi_buf);\
s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
s->bi_valid += len - Buf_size;\ s->bi_valid += len - Buf_size;\
} else {\ } else {\
s->bi_buf |= (ush)(value) << s->bi_valid;\ s->bi_buf |= (ush)(value) << s->bi_valid;\
s->bi_valid += len;\ s->bi_valid += len;\
}\ }\
} }
#endif /* DEBUG */ #endif /* ZLIB_DEBUG */
/* the arguments must not have side effects */ /* the arguments must not have side effects */
/* =========================================================================== /* ===========================================================================
* Initialize the various 'constant' tables. * Initialize the various 'constant' tables.
*/ */
local void tr_static_init() local void tr_static_init()
{ {
#if defined(GEN_TREES_H) || !defined(STDC) #if defined(GEN_TREES_H) || !defined(STDC)
static int static_init_done = 0; static int static_init_done = 0;
skipping to change at line 319 skipping to change at line 317
# ifdef GEN_TREES_H # ifdef GEN_TREES_H
gen_trees_header(); gen_trees_header();
# endif # endif
#endif /* defined(GEN_TREES_H) || !defined(STDC) */ #endif /* defined(GEN_TREES_H) || !defined(STDC) */
} }
/* =========================================================================== /* ===========================================================================
* Genererate the file trees.h describing the static trees. * Genererate the file trees.h describing the static trees.
*/ */
#ifdef GEN_TREES_H #ifdef GEN_TREES_H
# ifndef DEBUG # ifndef ZLIB_DEBUG
# include <stdio.h> # include <stdio.h>
# endif # endif
# define SEPARATOR(i, last, width) \ # define SEPARATOR(i, last, width) \
((i) == (last)? "\n};\n\n" : \ ((i) == (last)? "\n};\n\n" : \
((i) % (width) == (width)-1 ? ",\n" : ", ")) ((i) % (width) == (width)-1 ? ",\n" : ", "))
void gen_trees_header() void gen_trees_header()
{ {
FILE *header = fopen("trees.h", "w"); FILE *header = fopen("trees.h", "w");
skipping to change at line 396 skipping to change at line 394
s->l_desc.stat_desc = &static_l_desc; s->l_desc.stat_desc = &static_l_desc;
s->d_desc.dyn_tree = s->dyn_dtree; s->d_desc.dyn_tree = s->dyn_dtree;
s->d_desc.stat_desc = &static_d_desc; s->d_desc.stat_desc = &static_d_desc;
s->bl_desc.dyn_tree = s->bl_tree; s->bl_desc.dyn_tree = s->bl_tree;
s->bl_desc.stat_desc = &static_bl_desc; s->bl_desc.stat_desc = &static_bl_desc;
s->bi_buf = 0; s->bi_buf = 0;
s->bi_valid = 0; s->bi_valid = 0;
#ifdef DEBUG #ifdef ZLIB_DEBUG
s->compressed_len = 0L; s->compressed_len = 0L;
s->bits_sent = 0L; s->bits_sent = 0L;
#endif #endif
/* Initialize the first block of the first file: */ /* Initialize the first block of the first file: */
init_block(s); init_block(s);
} }
/* =========================================================================== /* ===========================================================================
* Initialize a new block. * Initialize a new block.
skipping to change at line 523 skipping to change at line 521
if (bits > max_length) bits = max_length, overflow++; if (bits > max_length) bits = max_length, overflow++;
tree[n].Len = (ush)bits; tree[n].Len = (ush)bits;
/* We overwrite tree[n].Dad which is no longer needed */ /* We overwrite tree[n].Dad which is no longer needed */
if (n > max_code) continue; /* not a leaf node */ if (n > max_code) continue; /* not a leaf node */
s->bl_count[bits]++; s->bl_count[bits]++;
xbits = 0; xbits = 0;
if (n >= base) xbits = extra[n-base]; if (n >= base) xbits = extra[n-base];
f = tree[n].Freq; f = tree[n].Freq;
s->opt_len += (ulg)f * (bits + xbits); s->opt_len += (ulg)f * (unsigned)(bits + xbits);
if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); if (stree) s->static_len += (ulg)f * (unsigned)(stree[n].Len + xbits);
} }
if (overflow == 0) return; if (overflow == 0) return;
Trace((stderr,"\nbit length overflow\n")); Tracev((stderr,"\nbit length overflow\n"));
/* This happens for example on obj2 and pic of the Calgary corpus */ /* This happens for example on obj2 and pic of the Calgary corpus */
/* Find the first bit length which could increase: */ /* Find the first bit length which could increase: */
do { do {
bits = max_length-1; bits = max_length-1;
while (s->bl_count[bits] == 0) bits--; while (s->bl_count[bits] == 0) bits--;
s->bl_count[bits]--; /* move one leaf down the tree */ s->bl_count[bits]--; /* move one leaf down the tree */
s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
s->bl_count[max_length]--; s->bl_count[max_length]--;
/* The brother of the overflow item also moves one step up, /* The brother of the overflow item also moves one step up,
skipping to change at line 555 skipping to change at line 553
* h is still equal to HEAP_SIZE. (It is simpler to reconstruct all * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
* lengths instead of fixing only the wrong ones. This idea is taken * lengths instead of fixing only the wrong ones. This idea is taken
* from 'ar' written by Haruhiko Okumura.) * from 'ar' written by Haruhiko Okumura.)
*/ */
for (bits = max_length; bits != 0; bits--) { for (bits = max_length; bits != 0; bits--) {
n = s->bl_count[bits]; n = s->bl_count[bits];
while (n != 0) { while (n != 0) {
m = s->heap[--h]; m = s->heap[--h];
if (m > max_code) continue; if (m > max_code) continue;
if ((unsigned) tree[m].Len != (unsigned) bits) { if ((unsigned) tree[m].Len != (unsigned) bits) {
Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); Tracev((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
s->opt_len += ((long)bits - (long)tree[m].Len) s->opt_len += ((ulg)bits - tree[m].Len) * tree[m].Freq;
*(long)tree[m].Freq;
tree[m].Len = (ush)bits; tree[m].Len = (ush)bits;
} }
n--; n--;
} }
} }
} }
/* =========================================================================== /* ===========================================================================
* Generate the codes for a given tree and bit counts (which need not be * Generate the codes for a given tree and bit counts (which need not be
* optimal). * optimal).
skipping to change at line 579 skipping to change at line 576
* the given tree and the field len is set for all tree elements. * the given tree and the field len is set for all tree elements.
* OUT assertion: the field code is set for all tree elements of non * OUT assertion: the field code is set for all tree elements of non
* zero code length. * zero code length.
*/ */
local void gen_codes (tree, max_code, bl_count) local void gen_codes (tree, max_code, bl_count)
ct_data *tree; /* the tree to decorate */ ct_data *tree; /* the tree to decorate */
int max_code; /* largest code with non zero frequency */ int max_code; /* largest code with non zero frequency */
ushf *bl_count; /* number of codes at each bit length */ ushf *bl_count; /* number of codes at each bit length */
{ {
ush next_code[MAX_BITS+1]; /* next code value for each bit length */ ush next_code[MAX_BITS+1]; /* next code value for each bit length */
ush code = 0; /* running code value */ unsigned code = 0; /* running code value */
int bits; /* bit index */ int bits; /* bit index */
int n; /* code index */ int n; /* code index */
/* The distribution counts are first used to generate the code values /* The distribution counts are first used to generate the code values
* without bit reversal. * without bit reversal.
*/ */
for (bits = 1; bits <= MAX_BITS; bits++) { for (bits = 1; bits <= MAX_BITS; bits++) {
next_code[bits] = code = (code + bl_count[bits-1]) << 1; code = (code + bl_count[bits-1]) << 1;
next_code[bits] = (ush)code;
} }
/* Check that the bit counts in bl_count are consistent. The last code /* Check that the bit counts in bl_count are consistent. The last code
* must be all ones. * must be all ones.
*/ */
Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1, Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
"inconsistent bit counts"); "inconsistent bit counts");
Tracev((stderr,"\ngen_codes: max_code %d ", max_code)); Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
for (n = 0; n <= max_code; n++) { for (n = 0; n <= max_code; n++) {
int len = tree[n].Len; int len = tree[n].Len;
if (len == 0) continue; if (len == 0) continue;
/* Now reverse the bits */ /* Now reverse the bits */
tree[n].Code = bi_reverse(next_code[len]++, len); tree[n].Code = (ush)bi_reverse(next_code[len]++, len);
Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ", Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1)); n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
} }
} }
/* =========================================================================== /* ===========================================================================
* Construct one Huffman tree and assigns the code bit strings and lengths. * Construct one Huffman tree and assigns the code bit strings and lengths.
* Update the total bit length for the current block. * Update the total bit length for the current block.
* IN assertion: the field freq is set for all tree elements. * IN assertion: the field freq is set for all tree elements.
skipping to change at line 822 skipping to change at line 820
*/ */
/* Determine the number of bit length codes to send. The pkzip format /* Determine the number of bit length codes to send. The pkzip format
* requires that at least 4 bit length codes be sent. (appnote.txt says * requires that at least 4 bit length codes be sent. (appnote.txt says
* 3 but the actual value used is 4.) * 3 but the actual value used is 4.)
*/ */
for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
} }
/* Update opt_len to include the bit length tree and counts */ /* Update opt_len to include the bit length tree and counts */
s->opt_len += 3*(max_blindex+1) + 5+5+4; s->opt_len += 3*((ulg)max_blindex+1) + 5+5+4;
Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
s->opt_len, s->static_len)); s->opt_len, s->static_len));
return max_blindex; return max_blindex;
} }
/* =========================================================================== /* ===========================================================================
* Send the header for a block using dynamic Huffman trees: the counts, the * Send the header for a block using dynamic Huffman trees: the counts, the
* lengths of the bit length codes, the literal tree and the distance tree. * lengths of the bit length codes, the literal tree and the distance tree.
* IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
skipping to change at line 870 skipping to change at line 868
/* =========================================================================== /* ===========================================================================
* Send a stored block * Send a stored block
*/ */
void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last)
deflate_state *s; deflate_state *s;
charf *buf; /* input block */ charf *buf; /* input block */
ulg stored_len; /* length of input block */ ulg stored_len; /* length of input block */
int last; /* one if this is the last block for a file */ int last; /* one if this is the last block for a file */
{ {
send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */
#ifdef DEBUG bi_windup(s); /* align on byte boundary */
put_short(s, (ush)stored_len);
put_short(s, (ush)~stored_len);
zmemcpy(s->pending_buf + s->pending, (Bytef *)buf, stored_len);
s->pending += stored_len;
#ifdef ZLIB_DEBUG
s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
s->compressed_len += (stored_len + 4) << 3; s->compressed_len += (stored_len + 4) << 3;
s->bits_sent += 2*16;
s->bits_sent += stored_len<<3;
#endif #endif
copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
} }
/* =========================================================================== /* ===========================================================================
* Flush the bits in the bit buffer to pending output (leaves at most 7 bits) * Flush the bits in the bit buffer to pending output (leaves at most 7 bits)
*/ */
void ZLIB_INTERNAL _tr_flush_bits(s) void ZLIB_INTERNAL _tr_flush_bits(s)
deflate_state *s; deflate_state *s;
{ {
bi_flush(s); bi_flush(s);
} }
/* =========================================================================== /* ===========================================================================
* Send one empty static block to give enough lookahead for inflate. * Send one empty static block to give enough lookahead for inflate.
* This takes 10 bits, of which 7 may remain in the bit buffer. * This takes 10 bits, of which 7 may remain in the bit buffer.
*/ */
void ZLIB_INTERNAL _tr_align(s) void ZLIB_INTERNAL _tr_align(s)
deflate_state *s; deflate_state *s;
{ {
send_bits(s, STATIC_TREES<<1, 3); send_bits(s, STATIC_TREES<<1, 3);
send_code(s, END_BLOCK, static_ltree); send_code(s, END_BLOCK, static_ltree);
#ifdef DEBUG #ifdef ZLIB_DEBUG
s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
#endif #endif
bi_flush(s); bi_flush(s);
} }
/* =========================================================================== /* ===========================================================================
* Determine the best encoding for the current block: dynamic trees, static * Determine the best encoding for the current block: dynamic trees, static
* trees or store, and output the encoded block to the zip file. * trees or store, and write out the encoded block.
*/ */
void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last)
deflate_state *s; deflate_state *s;
charf *buf; /* input block, or NULL if too old */ charf *buf; /* input block, or NULL if too old */
ulg stored_len; /* length of input block */ ulg stored_len; /* length of input block */
int last; /* one if this is the last block for a file */ int last; /* one if this is the last block for a file */
{ {
ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
int max_blindex = 0; /* index of last bit length code of non zero freq */ int max_blindex = 0; /* index of last bit length code of non zero freq */
skipping to change at line 975 skipping to change at line 979
_tr_stored_block(s, buf, stored_len, last); _tr_stored_block(s, buf, stored_len, last);
#ifdef FORCE_STATIC #ifdef FORCE_STATIC
} else if (static_lenb >= 0) { /* force static trees */ } else if (static_lenb >= 0) { /* force static trees */
#else #else
} else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
#endif #endif
send_bits(s, (STATIC_TREES<<1)+last, 3); send_bits(s, (STATIC_TREES<<1)+last, 3);
compress_block(s, (const ct_data *)static_ltree, compress_block(s, (const ct_data *)static_ltree,
(const ct_data *)static_dtree); (const ct_data *)static_dtree);
#ifdef DEBUG #ifdef ZLIB_DEBUG
s->compressed_len += 3 + s->static_len; s->compressed_len += 3 + s->static_len;
#endif #endif
} else { } else {
send_bits(s, (DYN_TREES<<1)+last, 3); send_bits(s, (DYN_TREES<<1)+last, 3);
send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
max_blindex+1); max_blindex+1);
compress_block(s, (const ct_data *)s->dyn_ltree, compress_block(s, (const ct_data *)s->dyn_ltree,
(const ct_data *)s->dyn_dtree); (const ct_data *)s->dyn_dtree);
#ifdef DEBUG #ifdef ZLIB_DEBUG
s->compressed_len += 3 + s->opt_len; s->compressed_len += 3 + s->opt_len;
#endif #endif
} }
Assert (s->compressed_len == s->bits_sent, "bad compressed size"); Assert (s->compressed_len == s->bits_sent, "bad compressed size");
/* The above check is made mod 2^32, for files larger than 512 MB /* The above check is made mod 2^32, for files larger than 512 MB
* and uLong implemented on 32 bits. * and uLong implemented on 32 bits.
*/ */
init_block(s); init_block(s);
if (last) { if (last) {
bi_windup(s); bi_windup(s);
#ifdef DEBUG #ifdef ZLIB_DEBUG
s->compressed_len += 7; /* align on byte boundary */ s->compressed_len += 7; /* align on byte boundary */
#endif #endif
} }
Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
s->compressed_len-7*last)); s->compressed_len-7*last));
} }
/* =========================================================================== /* ===========================================================================
* Save the match info and tally the frequency counts. Return true if * Save the match info and tally the frequency counts. Return true if
* the current block must be flushed. * the current block must be flushed.
skipping to change at line 1091 skipping to change at line 1095
lc -= base_length[code]; lc -= base_length[code];
send_bits(s, lc, extra); /* send the extra length bits */ send_bits(s, lc, extra); /* send the extra length bits */
} }
dist--; /* dist is now the match distance - 1 */ dist--; /* dist is now the match distance - 1 */
code = d_code(dist); code = d_code(dist);
Assert (code < D_CODES, "bad d_code"); Assert (code < D_CODES, "bad d_code");
send_code(s, code, dtree); /* send the distance code */ send_code(s, code, dtree); /* send the distance code */
extra = extra_dbits[code]; extra = extra_dbits[code];
if (extra != 0) { if (extra != 0) {
dist -= base_dist[code]; dist -= (unsigned)base_dist[code];
send_bits(s, dist, extra); /* send the extra distance bits */ send_bits(s, dist, extra); /* send the extra distance bits */
} }
} /* literal or match pair ? */ } /* literal or match pair ? */
/* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
"pendingBuf overflow"); "pendingBuf overflow");
} while (lx < s->last_lit); } while (lx < s->last_lit);
skipping to change at line 1194 skipping to change at line 1198
local void bi_windup(s) local void bi_windup(s)
deflate_state *s; deflate_state *s;
{ {
if (s->bi_valid > 8) { if (s->bi_valid > 8) {
put_short(s, s->bi_buf); put_short(s, s->bi_buf);
} else if (s->bi_valid > 0) { } else if (s->bi_valid > 0) {
put_byte(s, (Byte)s->bi_buf); put_byte(s, (Byte)s->bi_buf);
} }
s->bi_buf = 0; s->bi_buf = 0;
s->bi_valid = 0; s->bi_valid = 0;
#ifdef DEBUG #ifdef ZLIB_DEBUG
s->bits_sent = (s->bits_sent+7) & ~7; s->bits_sent = (s->bits_sent+7) & ~7;
#endif #endif
} }
/* ===========================================================================
* Copy a stored block, storing first the length and its
* one's complement if requested.
*/
local void copy_block(s, buf, len, header)
deflate_state *s;
charf *buf; /* the input data */
unsigned len; /* its length */
int header; /* true if block header must be written */
{
bi_windup(s); /* align on byte boundary */
if (header) {
put_short(s, (ush)len);
put_short(s, (ush)~len);
#ifdef DEBUG
s->bits_sent += 2*16;
#endif
}
#ifdef DEBUG
s->bits_sent += (ulg)len<<3;
#endif
while (len--) {
put_byte(s, *buf++);
}
}
 End of changes. 32 change blocks. 
34 lines changed or deleted 38 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)