62 " deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler ";
96 void match_init
OF((
void));
115 # define TOO_FAR 4096
161 #ifndef NO_DUMMY_DECL
171 #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
185 #define INSERT_STRING(s, str, match_head) \
186 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
187 match_head = s->head[s->ins_h], \
188 s->head[s->ins_h] = (Pos)(str))
190 #define INSERT_STRING(s, str, match_head) \
191 (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
192 match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
193 s->head[s->ins_h] = (Pos)(str))
200 #define CLEAR_HASH(s) \
201 s->head[s->hash_size-1] = NIL; \
202 zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
214 const char *
version,
int stream_size)
225 if (version ==
Z_NULL || version[0] != my_version[0] ||
232 if (strm->zalloc == (alloc_func)0) {
236 if (strm->zfree == (free_func)0) strm->zfree =
zcfree;
239 if (level != 0) level = 1;
244 if (windowBits < 0) {
246 windowBits = -windowBits;
249 else if (windowBits > 15) {
255 windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
256 strategy < 0 || strategy >
Z_FIXED) {
259 if (windowBits == 8) windowBits = 9;
309 uInt length = dictLength;
314 strm->state->wrap == 2 ||
315 (strm->state->wrap == 1 && strm->state->status !=
INIT_STATE))
320 strm->adler =
adler32(strm->adler, dictionary, dictLength);
325 dictionary += dictLength - length;
337 for (n = 0; n <= length -
MIN_MATCH; n++) {
340 if (hash_head) hash_head = 0;
350 strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
354 strm->total_in = strm->total_out = 0;
384 strm->state->gzhead =
head;
392 strm->state->bi_valid =
bits;
393 strm->state->bi_buf = (
ush)(value & ((1 << bits) - 1));
408 if (level != 0) level = 1;
412 if (level < 0 || level > 9 || strategy < 0 || strategy >
Z_FIXED) {
415 func = configuration_table[s->
level].func;
417 if ((strategy != s->
strategy || func != configuration_table[level].func) &&
418 strm->total_in != 0) {
422 if (s->
level != level) {
467 uLong complen, wraplen;
471 complen = sourceLen +
472 ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
485 wraplen = 6 + (s->
strstart ? 4 : 0);
491 wraplen += 2 + s->
gzhead->extra_len;
512 return complen + wraplen;
515 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
516 (sourceLen >> 25) + 13 - 6 + wraplen;
538 unsigned len = strm->state->pending;
540 if (len > strm->avail_out) len = strm->avail_out;
541 if (len == 0)
return;
543 zmemcpy(strm->next_out, strm->state->pending_out, len);
544 strm->next_out += len;
545 strm->state->pending_out += len;
546 strm->total_out += len;
547 strm->avail_out -= len;
548 strm->state->pending -= len;
549 if (strm->state->pending == 0) {
550 strm->state->pending_out = strm->state->pending_buf;
561 flush >
Z_BLOCK || flush < 0) {
566 if (strm->next_out ==
Z_NULL ||
567 (strm->next_in ==
Z_NULL && strm->avail_in != 0) ||
599 (s->
gzhead->hcrc ? 2 : 0) +
631 else if (s->
level < 6)
633 else if (s->
level == 6)
637 header |= (level_flags << 6);
639 header += 31 - (header % 31);
760 if (strm->avail_out == 0) {
775 }
else if (strm->avail_in == 0 && flush <= old_flush &&
787 if (strm->avail_in != 0 || s->
lookahead != 0 ||
793 (*(configuration_table[s->
level].func))(s, flush));
799 if (strm->avail_out == 0) {
828 if (strm->avail_out == 0) {
834 Assert(strm->avail_out > 0,
"bug2");
872 status = strm->state->status;
884 TRY_FREE(strm, strm->state->pending_buf);
887 TRY_FREE(strm, strm->state->window);
889 ZFREE(strm, strm->state);
962 unsigned len = strm->avail_in;
964 if (len > size) len =
size;
965 if (len == 0)
return 0;
967 strm->avail_in -= len;
969 if (strm->state->wrap == 1) {
970 strm->adler =
adler32(strm->adler, strm->next_in, len);
973 else if (strm->state->wrap == 2) {
974 strm->adler =
crc32(strm->adler, strm->next_in, len);
977 zmemcpy(buf, strm->next_in, len);
978 strm->next_in += len;
979 strm->total_in += len;
1048 register ush scan_start = *(
ushf*)scan;
1049 register ush scan_end = *(
ushf*)(scan+best_len-1);
1052 register Byte scan_end1 = scan[best_len-1];
1053 register Byte scan_end = scan[best_len];
1074 match = s->
window + cur_match;
1084 #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
1088 if (*(
ushf*)(match+best_len-1) != scan_end ||
1089 *(
ushf*)match != scan_start)
continue;
1100 Assert(scan[2] == match[2],
"scan[2]?");
1103 }
while (*(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
1104 *(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
1105 *(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
1106 *(
ushf*)(scan+=2) == *(
ushf*)(match+=2) &&
1112 if (*scan == *match) scan++;
1114 len = (
MAX_MATCH - 1) - (
int)(strend-scan);
1119 if (match[best_len] != scan_end ||
1120 match[best_len-1] != scan_end1 ||
1122 *++match != scan[1])
continue;
1131 Assert(*scan == *match,
"match[2]?");
1137 }
while (*++scan == *++match && *++scan == *++match &&
1138 *++scan == *++match && *++scan == *++match &&
1139 *++scan == *++match && *++scan == *++match &&
1140 *++scan == *++match && *++scan == *++match &&
1150 if (len > best_len) {
1153 if (len >= nice_match)
break;
1155 scan_end = *(
ushf*)(scan+best_len-1);
1157 scan_end1 = scan[best_len-1];
1158 scan_end = scan[best_len];
1161 }
while ((cur_match = prev[cur_match & wmask]) > limit
1162 && --chain_length != 0);
1190 match = s->
window + cur_match;
1194 if (match[0] != scan[0] || match[1] != scan[1])
return MIN_MATCH-1;
1202 scan += 2, match += 2;
1203 Assert(*scan == *match,
"match[2]?");
1209 }
while (*++scan == *++match && *++scan == *++match &&
1210 *++scan == *++match && *++scan == *++match &&
1211 *++scan == *++match && *++scan == *++match &&
1212 *++scan == *++match && *++scan == *++match &&
1236 fprintf(stderr,
" start %u, match %u, length %d\n",
1237 start, match, length);
1239 fprintf(stderr,
"%c%c", s->
window[match++], s->
window[start++]);
1240 }
while (--length != 0);
1241 z_error(
"invalid match");
1243 if (z_verbose > 1) {
1244 fprintf(stderr,
"\\[%d,%d]", start-match, length);
1245 do { putc(s->
window[start++], stderr); }
while (--length != 0);
1249 # define check_match(s, start, match, length)
1264 register unsigned n, m;
1273 if (
sizeof(
int) <= 2) {
1277 }
else if (more == (
unsigned)(-1)) {
1305 *p = (
Pos)(m >= wsize ? m-wsize :
NIL);
1313 *p = (
Pos)(m >= wsize ? m-wsize :
NIL);
1321 if (s->
strm->avail_in == 0)
return;
1334 Assert(more >= 2,
"more < 2");
1392 #define FLUSH_BLOCK_ONLY(s, last) { \
1393 _tr_flush_block(s, (s->block_start >= 0L ? \
1394 (charf *)&s->window[(unsigned)s->block_start] : \
1396 (ulg)((long)s->strstart - s->block_start), \
1398 s->block_start = s->strstart; \
1399 flush_pending(s->strm); \
1400 Tracev((stderr,"[FLUSH]")); \
1404 #define FLUSH_BLOCK(s, last) { \
1405 FLUSH_BLOCK_ONLY(s, last); \
1406 if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \
1423 ulg max_block_size = 0xffff;
1695 Bytef *scan, *strend;
1715 if (prev == *++scan && prev == *++scan && prev == *++scan) {
1718 }
while (prev == *++scan && prev == *++scan &&
1719 prev == *++scan && prev == *++scan &&
1720 prev == *++scan && prev == *++scan &&
1721 prev == *++scan && prev == *++scan &&
int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
#define INSERT_STRING(s, str, match_head)
#define check_match(s, start, match, length)
local void flush_pending(z_streamp strm)
void ZLIB_INTERNAL _tr_align(deflate_state *s)
#define Assert(cond, msg)
local uInt longest_match(deflate_state *s, IPos cur_match)
#define UPDATE_HASH(s, h, c)
struct ct_data_s dyn_ltree[HEAP_SIZE]
int ZEXPORT deflateInit2_(z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
uLong ZEXPORT deflateBound(z_streamp strm, uLong sourceLen)
int ZEXPORT deflateEnd(z_streamp strm)
int ZEXPORT deflatePrime(z_streamp strm, int bits, int value)
gz_header FAR * gz_headerp
local int read_buf(z_streamp strm, Bytef *buf, unsigned size)
#define _tr_tally_lit(s, c, flush)
#define ZALLOC(strm, items, size)
local block_state deflate_huff(deflate_state *s, int flush)
ABC_NAMESPACE_IMPL_START const char deflate_copyright[]
local block_state deflate_stored(deflate_state *s, int flush)
struct tree_desc_s bl_desc
struct tree_desc_s d_desc
int ZEXPORT deflateCopy(z_streamp dest, z_streamp source)
int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
void ZLIB_INTERNAL _tr_init(deflate_state *s)
#define ZFREE(strm, addr)
local block_state deflate_fast(deflate_state *s, int flush)
#define ABC_NAMESPACE_IMPL_END
static bool match(B &in, const char *str)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
void ZLIB_INTERNAL zmemzero(Bytef *dest, uInt len)
void ZLIB_INTERNAL zmemcpy(Bytef *dest, const Bytef *source, uInt len)
local const config configuration_table[10]
#define _tr_tally_dist(s, distance, length, flush)
int ZLIB_INTERNAL zmemcmp(const Bytef *s1, const Bytef *s2, uInt len)
int ZEXPORT deflate(z_streamp strm, int flush)
void ZLIB_INTERNAL _tr_stored_block(deflate_state *s, charf *buf, ulg stored_len, int last)
#define ABC_NAMESPACE_IMPL_START
struct ct_data_s dyn_dtree[2 *D_CODES+1]
local void fill_window(deflate_state *s)
struct tree_desc_s l_desc
local block_state deflate_rle(deflate_state *s, int flush)
uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
local void putShortMSB(deflate_state *s, uInt b)
int ZEXPORT deflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt dictLength)
#define ERR_RETURN(strm, err)
int ZEXPORT deflateSetHeader(z_streamp strm, gz_headerp head)
#define FLUSH_BLOCK(s, last)
local void lm_init(deflate_state *s)
int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
local block_state deflate_slow(deflate_state *s, int flush)
#define Z_DEFAULT_STRATEGY
int ZEXPORT deflateReset(z_streamp strm)
static char * bits(int n)
voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size)
struct ct_data_s bl_tree[2 *BL_CODES+1]
block_state compress_func OF((deflate_state *s, int flush))
#define Z_DEFAULT_COMPRESSION
#define FLUSH_BLOCK_ONLY(s, last)
void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr)