version 1.1, 2012/02/21 16:23:02
|
version 1.1.1.2, 2013/07/22 10:46:14
|
Line 1
|
Line 1
|
/* trees.c -- output deflated data using Huffman coding |
/* trees.c -- output deflated data using Huffman coding |
* Copyright (C) 1995-2010 Jean-loup Gailly | * Copyright (C) 1995-2012 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 |
*/ |
*/ |
Line 74 local const uch bl_order[BL_CODES]
|
Line 74 local const uch bl_order[BL_CODES]
|
* probability, to avoid transmitting the lengths for unused bit length codes. |
* probability, to avoid transmitting the lengths for unused bit length codes. |
*/ |
*/ |
|
|
#define Buf_size (8 * 2*sizeof(char)) |
|
/* Number of bits used within bi_buf. (bi_buf might be implemented on |
|
* more than 16 bits on some systems.) |
|
*/ |
|
|
|
/* =========================================================================== |
/* =========================================================================== |
* Local data. These are initialized only once. |
* Local data. These are initialized only once. |
*/ |
*/ |
Line 399 void ZLIB_INTERNAL _tr_init(s)
|
Line 394 void ZLIB_INTERNAL _tr_init(s)
|
|
|
s->bi_buf = 0; |
s->bi_buf = 0; |
s->bi_valid = 0; |
s->bi_valid = 0; |
s->last_eob_len = 8; /* enough lookahead for inflate */ |
|
#ifdef DEBUG |
#ifdef DEBUG |
s->compressed_len = 0L; |
s->compressed_len = 0L; |
s->bits_sent = 0L; |
s->bits_sent = 0L; |
Line 883 void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len
|
Line 877 void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len
|
} |
} |
|
|
/* =========================================================================== |
/* =========================================================================== |
|
* Flush the bits in the bit buffer to pending output (leaves at most 7 bits) |
|
*/ |
|
void ZLIB_INTERNAL _tr_flush_bits(s) |
|
deflate_state *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. |
* The current inflate code requires 9 bits of lookahead. If the |
|
* last two codes for the previous block (real code plus EOB) were coded |
|
* on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode |
|
* the last real code. In this case we send two empty static blocks instead |
|
* of one. (There are no problems if the previous block is stored or fixed.) |
|
* To simplify the code, we assume the worst case of last real code encoded |
|
* on one bit only. |
|
*/ |
*/ |
void ZLIB_INTERNAL _tr_align(s) |
void ZLIB_INTERNAL _tr_align(s) |
deflate_state *s; |
deflate_state *s; |
Line 902 void ZLIB_INTERNAL _tr_align(s)
|
Line 898 void ZLIB_INTERNAL _tr_align(s)
|
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); |
/* Of the 10 bits for the empty block, we have already sent |
|
* (10 - bi_valid) bits. The lookahead for the last real code (before |
|
* the EOB of the previous block) was thus at least one plus the length |
|
* of the EOB plus what we have just sent of the empty static block. |
|
*/ |
|
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 DEBUG |
|
s->compressed_len += 10L; |
|
#endif |
|
bi_flush(s); |
|
} |
|
s->last_eob_len = 7; |
|
} |
} |
|
|
/* =========================================================================== |
/* =========================================================================== |
Line 1118 local void compress_block(s, ltree, dtree)
|
Line 1100 local void compress_block(s, ltree, dtree)
|
} while (lx < s->last_lit); |
} while (lx < s->last_lit); |
|
|
send_code(s, END_BLOCK, ltree); |
send_code(s, END_BLOCK, ltree); |
s->last_eob_len = ltree[END_BLOCK].Len; |
|
} |
} |
|
|
/* =========================================================================== |
/* =========================================================================== |
Line 1226 local void copy_block(s, buf, len, header)
|
Line 1207 local void copy_block(s, buf, len, header)
|
int header; /* true if block header must be written */ |
int header; /* true if block header must be written */ |
{ |
{ |
bi_windup(s); /* align on byte boundary */ |
bi_windup(s); /* align on byte boundary */ |
s->last_eob_len = 8; /* enough lookahead for inflate */ |
|
|
|
if (header) { |
if (header) { |
put_short(s, (ush)len); |
put_short(s, (ush)len); |