diff options
Diffstat (limited to 'zlib/deflate.c')
-rw-r--r-- | zlib/deflate.c | 104 |
1 files changed, 91 insertions, 13 deletions
diff --git a/zlib/deflate.c b/zlib/deflate.c index 50aa0ab9a..60f0c8ff2 100644 --- a/zlib/deflate.c +++ b/zlib/deflate.c @@ -1,5 +1,5 @@ /* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2004 Jean-loup Gailly. + * Copyright (C) 1995-2005 Jean-loup Gailly. * For conditions of distribution and use, see copyright notice in zlib.h */ @@ -53,7 +53,7 @@ #include "deflate.h" const char deflate_copyright[] = - " deflate 1.2.2.f-rpm-rsync Copyright 1995-2004 Jean-loup Gailly "; + " deflate 1.2.2.f-rpm-rsync Copyright 1995-2005 Jean-loup Gailly "; /* If you use the zlib library in a product, an acknowledgment is welcome in the documentation of your product. If for some reason you cannot @@ -139,6 +139,7 @@ local void check_match OF((deflate_state *s, IPos start, IPos match, /* Whether window sum matches magic value */ /* Global rsync mode control variable */ +/*@unchecked@*/ int zlib_rsync = 1; /* Values for max_lazy_match, good_match and max_chain_length, depending on @@ -346,9 +347,7 @@ int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt if (length < MIN_MATCH) return Z_OK; if (length > MAX_DIST(s)) { length = MAX_DIST(s); -#ifndef USE_DICT_HEAD dictionary += dictLength - length; /* use the tail of the dictionary */ -#endif } zmemcpy(s->window, dictionary, length); s->strstart = length; @@ -455,6 +454,20 @@ int ZEXPORT deflateParams(z_streamp strm, int level, int strategy) return err; } +/* ========================================================================= */ +int ZEXPORT deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain) +{ + deflate_state *s; + + if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; + s = strm->state; + s->good_match = good_length; + s->max_lazy_match = max_lazy; + s->nice_match = nice_length; + s->max_chain_length = max_chain; + return Z_OK; +} + /* ========================================================================= * For the default windowBits of 15 and memLevel of 8, this function returns * a close to exact, as well as small, upper bound on the compressed size. @@ -579,10 +592,10 @@ int ZEXPORT deflate (z_streamp strm, int flush) (s->gzhead->name == Z_NULL ? 0 : 8) + (s->gzhead->comment == Z_NULL ? 0 : 16) ); - put_byte(s, s->gzhead->time & 0xff); - put_byte(s, (s->gzhead->time >> 8) & 0xff); - put_byte(s, (s->gzhead->time >> 16) & 0xff); - put_byte(s, (s->gzhead->time >> 24) & 0xff); + put_byte(s, (Byte)(s->gzhead->time & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); + put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); put_byte(s, s->level == 9 ? 2 : (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? 4 : 0)); @@ -630,7 +643,7 @@ int ZEXPORT deflate (z_streamp strm, int flush) #ifdef GZIP if (s->status == EXTRA_STATE) { if (s->gzhead->extra != NULL) { - int beg = s->pending; /* start of bytes to update crc */ + uInt beg = s->pending; /* start of bytes to update crc */ while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { if (s->pending == s->pending_buf_size) { @@ -658,7 +671,7 @@ int ZEXPORT deflate (z_streamp strm, int flush) } if (s->status == NAME_STATE) { if (s->gzhead->name != NULL) { - int beg = s->pending; /* start of bytes to update crc */ + uInt beg = s->pending; /* start of bytes to update crc */ int val; do { @@ -689,7 +702,7 @@ int ZEXPORT deflate (z_streamp strm, int flush) } if (s->status == COMMENT_STATE) { if (s->gzhead->comment != NULL) { - int beg = s->pending; /* start of bytes to update crc */ + uInt beg = s->pending; /* start of bytes to update crc */ int val; do { @@ -721,8 +734,8 @@ int ZEXPORT deflate (z_streamp strm, int flush) if (s->pending + 2 > s->pending_buf_size) flush_pending(strm); if (s->pending + 2 <= s->pending_buf_size) { - put_byte(s, strm->adler & 0xff); - put_byte(s, (strm->adler >> 8) & 0xff); + put_byte(s, (Byte)(strm->adler & 0xff)); + put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); strm->adler = crc32(0L, Z_NULL, 0); s->status = BUSY_STATE; } @@ -975,9 +988,11 @@ local void lm_init (deflate_state *s) s->match_length = s->prev_length = MIN_MATCH-1; s->match_available = 0; s->ins_h = 0; +#ifndef FASTEST #ifdef ASMV match_init(); /* initialize the asm code */ #endif +#endif /* rsync params */ s->rsync_chunk_end = 0xFFFFFFFFUL; @@ -1271,6 +1286,7 @@ local void fill_window(deflate_state *s) later. (Using level 0 permanently is not an optimal usage of zlib, so we don't care about this pathological case.) */ + /* %%% avoid this when Z_RLE */ n = s->hash_size; p = &s->head[n]; do { @@ -1325,6 +1341,7 @@ local void fill_window(deflate_state *s) } local void rsync_roll(deflate_state *s, unsigned start, unsigned num) + /*@modifies *s @*/ { unsigned i; @@ -1690,3 +1707,64 @@ local block_state deflate_slow(deflate_state *s, int flush) return flush == Z_FINISH ? finish_done : block_done; } #endif /* FASTEST */ + +#if 0 +/* =========================================================================== + * For Z_RLE, simply look for runs of bytes, generate matches only of distance + * one. Do not maintain a hash table. (It will be regenerated if this run of + * deflate switches away from Z_RLE.) + */ +local block_state deflate_rle(s, flush) + deflate_state *s; + int flush; +{ + int bflush; /* set if current block must be flushed */ + uInt run; /* length of run */ + uInt max; /* maximum length of run */ + uInt prev; /* byte at distance one to match */ + Bytef *scan; /* scan for end of run */ + + for (;;) { + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the longest encodable run. + */ + if (s->lookahead < MAX_MATCH) { + fill_window(s); + if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) { + return need_more; + } + if (s->lookahead == 0) break; /* flush the current block */ + } + + /* See how many times the previous byte repeats */ + run = 0; + if (s->strstart > 0) { /* if there is a previous byte, that is */ + max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH; + scan = s->window + s->strstart - 1; + prev = *scan++; + do { + if (*scan++ != prev) + break; + } while (++run < max); + } + + /* Emit match if have run of MIN_MATCH or longer, else emit literal */ + if (run >= MIN_MATCH) { + check_match(s, s->strstart, s->strstart - 1, run); + _tr_tally_dist(s, 1, run - MIN_MATCH, bflush); + s->lookahead -= run; + s->strstart += run; + } else { + /* No match, output a literal byte */ + Tracevv((stderr,"%c", s->window[s->strstart])); + _tr_tally_lit (s, s->window[s->strstart], bflush); + s->lookahead--; + s->strstart++; + } + if (bflush) FLUSH_BLOCK(s, 0); + } + FLUSH_BLOCK(s, flush == Z_FINISH); + return flush == Z_FINISH ? finish_done : block_done; +} +#endif |