summaryrefslogtreecommitdiff
path: root/deflate.c
diff options
context:
space:
mode:
Diffstat (limited to 'deflate.c')
-rw-r--r--deflate.c54
1 files changed, 49 insertions, 5 deletions
diff --git a/deflate.c b/deflate.c
index 16ebdad..d13627e 100644
--- a/deflate.c
+++ b/deflate.c
@@ -1,5 +1,5 @@
1/* deflate.c -- compress data using the deflation algorithm 1/* deflate.c -- compress data using the deflation algorithm
2 * Copyright (C) 1995-2002 Jean-loup Gailly. 2 * Copyright (C) 1995-2003 Jean-loup Gailly.
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
@@ -52,7 +52,7 @@
52#include "deflate.h" 52#include "deflate.h"
53 53
54const char deflate_copyright[] = 54const char deflate_copyright[] =
55 " deflate 1.1.4 Copyright 1995-2002 Jean-loup Gailly "; 55 " deflate 1.2.0 Copyright 1995-2003 Jean-loup Gailly ";
56/* 56/*
57 If you use the zlib library in a product, an acknowledgment is welcome 57 If you use the zlib library in a product, an acknowledgment is welcome
58 in the documentation of your product. If for some reason you cannot 58 in the documentation of your product. If for some reason you cannot
@@ -212,7 +212,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
212{ 212{
213 deflate_state *s; 213 deflate_state *s;
214 int noheader = 0; 214 int noheader = 0;
215 static const char* my_version = ZLIB_VERSION; 215 static const char my_version[] = ZLIB_VERSION;
216 216
217 ushf *overlay; 217 ushf *overlay;
218 /* We overlay pending_buf and d_buf+l_buf. This works since the average 218 /* We overlay pending_buf and d_buf+l_buf. This works since the average
@@ -273,6 +273,7 @@ int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
273 273
274 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || 274 if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
275 s->pending_buf == Z_NULL) { 275 s->pending_buf == Z_NULL) {
276 s->status = FINISH_STATE;
276 strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); 277 strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
277 deflateEnd (strm); 278 deflateEnd (strm);
278 return Z_MEM_ERROR; 279 return Z_MEM_ERROR;
@@ -299,10 +300,12 @@ int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
299 IPos hash_head = 0; 300 IPos hash_head = 0;
300 301
301 if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL || 302 if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
302 strm->state->status != INIT_STATE) return Z_STREAM_ERROR; 303 (!strm->state->noheader && strm->state->status != INIT_STATE))
304 return Z_STREAM_ERROR;
303 305
304 s = strm->state; 306 s = strm->state;
305 strm->adler = adler32(strm->adler, dictionary, dictLength); 307 if (!s->noheader)
308 strm->adler = adler32(strm->adler, dictionary, dictLength);
306 309
307 if (length < MIN_MATCH) return Z_OK; 310 if (length < MIN_MATCH) return Z_OK;
308 if (length > MAX_DIST(s)) { 311 if (length > MAX_DIST(s)) {
@@ -395,6 +398,47 @@ int ZEXPORT deflateParams(strm, level, strategy)
395} 398}
396 399
397/* ========================================================================= 400/* =========================================================================
401 * For the default windowBits of 15 and memLevel of 8, this function returns
402 * a close to exact, as well as small, upper bound on the compressed size.
403 * They are coded as constants here for a reason--if the #define's are
404 * changed, then this function needs to be changed as well. The return
405 * value for 15 and 8 only works for those exact settings.
406 *
407 * For any setting other than those defaults for windowBits and memLevel,
408 * the value returned is a conservative worst case for the maximum expansion
409 * resulting from using fixed blocks instead of stored blocks, which deflate
410 * can emit on compressed data for some combinations of the parameters.
411 *
412 * This function could be more sophisticated to provide closer upper bounds
413 * for every combination of windowBits and memLevel, as well as noheader.
414 * But even the conservative upper bound of about 14% expansion does not
415 * seem onerous for output buffer allocation.
416 */
417uLong ZEXPORT deflateBound(strm, sourceLen)
418 z_streamp strm;
419 uLong sourceLen;
420{
421 deflate_state *s;
422 uLong destLen;
423
424 /* conservative upper bound */
425 destLen = sourceLen +
426 ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
427
428 /* if can't get parameters, return conservative bound */
429 if (strm == Z_NULL || strm->state == Z_NULL)
430 return destLen;
431
432 /* if not default parameters, return conservative bound */
433 s = strm->state;
434 if (s->w_bits != 15 || s->hash_bits != 8 + 7)
435 return destLen;
436
437 /* default settings: return tight bound for that case */
438 return compressBound(sourceLen);
439}
440
441/* =========================================================================
398 * Put a short in the pending buffer. The 16-bit value is put in MSB order. 442 * Put a short in the pending buffer. The 16-bit value is put in MSB order.
399 * IN assertion: the stream state is correct and there is enough room in 443 * IN assertion: the stream state is correct and there is enough room in
400 * pending_buf. 444 * pending_buf.