summaryrefslogtreecommitdiff
path: root/deflate.c
diff options
context:
space:
mode:
Diffstat (limited to 'deflate.c')
-rw-r--r--deflate.c60
1 files changed, 46 insertions, 14 deletions
diff --git a/deflate.c b/deflate.c
index 29ce1f6..ccffede 100644
--- a/deflate.c
+++ b/deflate.c
@@ -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.2.3 Copyright 1995-2005 Jean-loup Gailly "; 55 " deflate 1.2.3.1 Copyright 1995-2005 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
@@ -481,33 +481,65 @@ int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
481 * resulting from using fixed blocks instead of stored blocks, which deflate 481 * resulting from using fixed blocks instead of stored blocks, which deflate
482 * can emit on compressed data for some combinations of the parameters. 482 * can emit on compressed data for some combinations of the parameters.
483 * 483 *
484 * This function could be more sophisticated to provide closer upper bounds 484 * This function could be more sophisticated to provide closer upper bounds for
485 * for every combination of windowBits and memLevel, as well as wrap. 485 * every combination of windowBits and memLevel. But even the conservative
486 * But even the conservative upper bound of about 14% expansion does not 486 * upper bound of about 14% expansion does not seem onerous for output buffer
487 * seem onerous for output buffer allocation. 487 * allocation.
488 */ 488 */
489uLong ZEXPORT deflateBound(strm, sourceLen) 489uLong ZEXPORT deflateBound(strm, sourceLen)
490 z_streamp strm; 490 z_streamp strm;
491 uLong sourceLen; 491 uLong sourceLen;
492{ 492{
493 deflate_state *s; 493 deflate_state *s;
494 uLong destLen; 494 uLong complen, wraplen;
495 Bytef *str;
495 496
496 /* conservative upper bound */ 497 /* conservative upper bound for compressed data */
497 destLen = sourceLen + 498 complen = sourceLen +
498 ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11; 499 ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5;
499 500
500 /* if can't get parameters, return conservative bound */ 501 /* if can't get parameters, return conservative bound plus zlib wrapper */
501 if (strm == Z_NULL || strm->state == Z_NULL) 502 if (strm == Z_NULL || strm->state == Z_NULL)
502 return destLen; 503 return complen + 6;
503 504
504 /* if not default parameters, return conservative bound */ 505 /* compute wrapper length */
505 s = strm->state; 506 s = strm->state;
507 switch (s->wrap) {
508 case 0: /* raw deflate */
509 wraplen = 0;
510 break;
511 case 1: /* zlib wrapper */
512 wraplen = 6 + (s->strstart ? 4 : 0);
513 break;
514 case 2: /* gzip wrapper */
515 wraplen = 18;
516 if (s->gzhead != NULL) { /* user-supplied gzip header */
517 if (s->gzhead->extra != NULL)
518 wraplen += 2 + s->gzhead->extra_len;
519 str = s->gzhead->name;
520 if (str != NULL)
521 do {
522 wraplen++;
523 } while (*str++);
524 str = s->gzhead->comment;
525 if (str != NULL)
526 do {
527 wraplen++;
528 } while (*str++);
529 if (s->gzhead->hcrc)
530 wraplen += 2;
531 }
532 break;
533 default: /* for compiler happiness */
534 wraplen = 6;
535 }
536
537 /* if not default parameters, return conservative bound */
506 if (s->w_bits != 15 || s->hash_bits != 8 + 7) 538 if (s->w_bits != 15 || s->hash_bits != 8 + 7)
507 return destLen; 539 return complen + wraplen;
508 540
509 /* default settings: return tight bound for that case */ 541 /* default settings: return tight bound for that case */
510 return compressBound(sourceLen); 542 return compressBound(sourceLen) - 6 + wraplen;
511} 543}
512 544
513/* ========================================================================= 545/* =========================================================================