55 " deflate 1.2.2 Copyright 1995-2004 Jean-loup Gailly ";
88 void match_init
OF((
void));
113#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
170#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
184#define INSERT_STRING(s, str, match_head) \
185 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
186 match_head = s->head[s->ins_h], \
187 s->head[s->ins_h] = (Pos)(str))
189#define INSERT_STRING(s, str, match_head) \
190 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
191 match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
192 s->head[s->ins_h] = (Pos)(str))
199#define CLEAR_HASH(s) \
200 s->head[s->hash_size-1] = NIL; \
201 zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
213 const char *version,
int stream_size)
224 if (version ==
Z_NULL || version[0] != my_version[0] ||
231 if (strm->zalloc == (alloc_func)0) {
235 if (strm->zfree == (free_func)0) strm->zfree =
zcfree;
238 if (level != 0) level = 1;
243 if (windowBits < 0) {
245 windowBits = -windowBits;
248 else if (windowBits > 15) {
254 windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
255 strategy < 0 || strategy >
Z_RLE) {
258 if (windowBits == 8) windowBits = 9;
305 uInt length = dictLength;
310 strm->state->wrap == 2 ||
322 dictionary += dictLength - length;
335 for (n = 0; n <= length -
MIN_MATCH; n++) {
338 if (hash_head) hash_head = 0;
348 strm->zalloc == (alloc_func)0 ||
strm->zfree == (free_func)0) {
352 strm->total_in =
strm->total_out = 0;
381 strm->state->bi_valid = bits;
382 strm->state->bi_buf = (
ush)(value & ((1 << bits) - 1));
401 if (level < 0 || level > 9 || strategy < 0 || strategy >
Z_RLE) {
444 destLen = sourceLen +
445 ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
479 unsigned len =
strm->state->pending;
481 if (len >
strm->avail_out) len =
strm->avail_out;
482 if (len == 0)
return;
485 strm->next_out += len;
486 strm->state->pending_out += len;
487 strm->total_out += len;
488 strm->avail_out -= len;
489 strm->state->pending -= len;
490 if (
strm->state->pending == 0) {
491 strm->state->pending_out =
strm->state->pending_buf;
545 else if (s->
level < 6)
547 else if (s->
level == 6)
551 header |= (level_flags << 6);
553 header += 31 - (header % 31);
570 if (
strm->avail_out == 0) {
585 }
else if (
strm->avail_in == 0 && flush <= old_flush &&
607 if (
strm->avail_out == 0) {
632 if (
strm->avail_out == 0) {
761 unsigned len =
strm->avail_in;
763 if (len > size) len = size;
764 if (len == 0)
return 0;
766 strm->avail_in -= len;
768 if (
strm->state->wrap == 1) {
772 else if (
strm->state->wrap == 2) {
777 strm->next_in += len;
778 strm->total_in += len;
828 register Bytef *match;
845 register ush scan_start = *(
ushf*)scan;
846 register ush scan_end = *(
ushf*)(scan+best_len-1);
849 register Byte scan_end1 = scan[best_len-1];
850 register Byte scan_end = scan[best_len];
871 match = s->
window + cur_match;
876#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
880 if (*(
ushf*)(match+best_len-1) != scan_end ||
881 *(
ushf*)match != scan_start)
continue;
892 Assert(scan[2] == match[2], (
char*)
"scan[2]?");
895 }
while (*(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
896 *(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
897 *(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
898 *(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
904 if (*scan == *match) scan++;
906 len = (
MAX_MATCH - 1) - (
int)(strend-scan);
911 if (match[best_len] != scan_end ||
912 match[best_len-1] != scan_end1 ||
914 *++match != scan[1])
continue;
923 Assert(*scan == *match, (
char*)
"match[2]?");
929 }
while (*++scan == *++match && *++scan == *++match &&
930 *++scan == *++match && *++scan == *++match &&
931 *++scan == *++match && *++scan == *++match &&
932 *++scan == *++match && *++scan == *++match &&
942 if (len > best_len) {
947 scan_end = *(
ushf*)(scan+best_len-1);
949 scan_end1 = scan[best_len-1];
950 scan_end = scan[best_len];
953 }
while ((cur_match =
prev[cur_match & wmask]) > limit
954 && --chain_length != 0);
968 register Bytef *match;
981 match = s->
window + cur_match;
985 if (match[0] != scan[0] || match[1] != scan[1])
return MIN_MATCH-1;
993 scan += 2, match += 2;
994 Assert(*scan == *match, (
char*)
"match[2]?");
1000 }
while (*++scan == *++match && *++scan == *++match &&
1001 *++scan == *++match && *++scan == *++match &&
1002 *++scan == *++match && *++scan == *++match &&
1003 *++scan == *++match && *++scan == *++match &&
1025 fprintf(stderr, (
char*)
" start %u, match %u, length %d\n",
1026 start, match, length);
1028 fprintf(stderr, (
char*)
"%c%c", s->
window[match++], s->
window[start++]);
1029 }
while (--length != 0);
1030 z_error((
char*)
"invalid match");
1032 if (z_verbose > 1) {
1033 fprintf(stderr,(
char*)
"\\[%d,%d]", start-match, length);
1034 do { putc(s->
window[start++], stderr); }
while (--length != 0);
1038# define check_match(s, start, match, length)
1053 register unsigned n, m;
1062 if (
sizeof(
int) <= 2) {
1066 }
else if (more == (
unsigned)(-1)) {
1094 *p = (
Pos)(m >= wsize ? m-wsize :
NIL);
1102 *p = (
Pos)(m >= wsize ? m-wsize :
NIL);
1110 if (s->
strm->avail_in == 0)
return;
1123 Assert(more >= 2, (
char*)
"more < 2");
1147#define FLUSH_BLOCK_ONLY(s, eof) { \
1148 _tr_flush_block(s, (s->block_start >= 0L ? \
1149 (charf *)&s->window[(unsigned)s->block_start] : \
1151 (ulg)((long)s->strstart - s->block_start), \
1153 s->block_start = s->strstart; \
1154 flush_pending(s->strm); \
1155 Tracev((stderr,(char*)"[FLUSH]")); \
1159#define FLUSH_BLOCK(s, eof) { \
1160 FLUSH_BLOCK_ONLY(s, eof); \
1161 if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
1178 ulg max_block_size = 0xffff;
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
uLong ZEXPORT compressBound(uLong sourceLen)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, unsigned len)
const config configuration_table[10]
int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
block_state deflate_stored(deflate_state *s, int flush)
#define check_match(s, start, match, length)
void putShortMSB(deflate_state *s, uInt b)
#define UPDATE_HASH(s, h, c)
int ZEXPORT deflateCopy(z_streamp dest, z_streamp source)
int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
void flush_pending(z_streamp strm)
int ZEXPORT deflateReset(z_streamp strm)
block_state compress_func OF((deflate_state *s, int flush))
#define INSERT_STRING(s, str, match_head)
#define FLUSH_BLOCK(s, eof)
uInt longest_match_fast(deflate_state *s, IPos cur_match)
int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen)
const char deflate_copyright[]
block_state deflate_fast(deflate_state *s, int flush)
block_state deflate_slow(deflate_state *s, int flush)
int read_buf(z_streamp strm, Bytef *buf, unsigned size)
uInt longest_match(deflate_state *s, IPos cur_match)
int ZEXPORT deflatePrime(z_streamp strm, int bits, int value)
int ZEXPORT deflateEnd(z_streamp strm)
void fill_window(deflate_state *s)
int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
void lm_init(deflate_state *s)
int ZEXPORT deflate(z_streamp strm, int flush)
#define FLUSH_BLOCK_ONLY(s, eof)
#define _tr_tally_dist(s, distance, length, flush)
#define _tr_tally_lit(s, c, flush)
struct tree_desc_s l_desc
struct ct_data_s dyn_dtree[2 *D_CODES+1]
struct ct_data_s bl_tree[2 *BL_CODES+1]
struct tree_desc_s bl_desc
struct tree_desc_s d_desc
struct ct_data_s dyn_ltree[HEAP_SIZE]
void _tr_init(deflate_state *s)
void _tr_align(deflate_state *s)
void _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int eof)
#define Z_DEFAULT_STRATEGY
#define Z_DEFAULT_COMPRESSION
int zmemcmp(const Bytef *s1, const Bytef *s2, uInt len)
void zmemcpy(Bytef *dest, const Bytef *source, uInt len)
void zcfree(voidpf opaque, voidpf ptr)
voidpf zcalloc(voidpf opaque, unsigned items, unsigned size)
#define ERR_RETURN(strm, err)
#define ZALLOC(strm, items, size)
#define Assert(cond, msg)
#define ZFREE(strm, addr)