diff options
Diffstat (limited to 'deflate.c')
-rw-r--r-- | deflate.c | 82 |
1 files changed, 72 insertions, 10 deletions
@@ -52,7 +52,7 @@ | |||
52 | #include "deflate.h" | 52 | #include "deflate.h" |
53 | 53 | ||
54 | const char deflate_copyright[] = | 54 | const char deflate_copyright[] = |
55 | " deflate 1.2.2.3 Copyright 1995-2005 Jean-loup Gailly "; | 55 | " deflate 1.2.2.4 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 |
@@ -600,10 +600,10 @@ int ZEXPORT deflate (strm, flush) | |||
600 | (s->gzhead->name == Z_NULL ? 0 : 8) + | 600 | (s->gzhead->name == Z_NULL ? 0 : 8) + |
601 | (s->gzhead->comment == Z_NULL ? 0 : 16) | 601 | (s->gzhead->comment == Z_NULL ? 0 : 16) |
602 | ); | 602 | ); |
603 | put_byte(s, s->gzhead->time & 0xff); | 603 | put_byte(s, (Byte)(s->gzhead->time & 0xff)); |
604 | put_byte(s, (s->gzhead->time >> 8) & 0xff); | 604 | put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); |
605 | put_byte(s, (s->gzhead->time >> 16) & 0xff); | 605 | put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); |
606 | put_byte(s, (s->gzhead->time >> 24) & 0xff); | 606 | put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); |
607 | put_byte(s, s->level == 9 ? 2 : | 607 | put_byte(s, s->level == 9 ? 2 : |
608 | (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? | 608 | (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? |
609 | 4 : 0)); | 609 | 4 : 0)); |
@@ -651,7 +651,7 @@ int ZEXPORT deflate (strm, flush) | |||
651 | #ifdef GZIP | 651 | #ifdef GZIP |
652 | if (s->status == EXTRA_STATE) { | 652 | if (s->status == EXTRA_STATE) { |
653 | if (s->gzhead->extra != NULL) { | 653 | if (s->gzhead->extra != NULL) { |
654 | int beg = s->pending; /* start of bytes to update crc */ | 654 | uInt beg = s->pending; /* start of bytes to update crc */ |
655 | 655 | ||
656 | while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { | 656 | while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { |
657 | if (s->pending == s->pending_buf_size) { | 657 | if (s->pending == s->pending_buf_size) { |
@@ -679,7 +679,7 @@ int ZEXPORT deflate (strm, flush) | |||
679 | } | 679 | } |
680 | if (s->status == NAME_STATE) { | 680 | if (s->status == NAME_STATE) { |
681 | if (s->gzhead->name != NULL) { | 681 | if (s->gzhead->name != NULL) { |
682 | int beg = s->pending; /* start of bytes to update crc */ | 682 | uInt beg = s->pending; /* start of bytes to update crc */ |
683 | int val; | 683 | int val; |
684 | 684 | ||
685 | do { | 685 | do { |
@@ -710,7 +710,7 @@ int ZEXPORT deflate (strm, flush) | |||
710 | } | 710 | } |
711 | if (s->status == COMMENT_STATE) { | 711 | if (s->status == COMMENT_STATE) { |
712 | if (s->gzhead->comment != NULL) { | 712 | if (s->gzhead->comment != NULL) { |
713 | int beg = s->pending; /* start of bytes to update crc */ | 713 | uInt beg = s->pending; /* start of bytes to update crc */ |
714 | int val; | 714 | int val; |
715 | 715 | ||
716 | do { | 716 | do { |
@@ -742,8 +742,8 @@ int ZEXPORT deflate (strm, flush) | |||
742 | if (s->pending + 2 > s->pending_buf_size) | 742 | if (s->pending + 2 > s->pending_buf_size) |
743 | flush_pending(strm); | 743 | flush_pending(strm); |
744 | if (s->pending + 2 <= s->pending_buf_size) { | 744 | if (s->pending + 2 <= s->pending_buf_size) { |
745 | put_byte(s, strm->adler & 0xff); | 745 | put_byte(s, (Byte)(strm->adler & 0xff)); |
746 | put_byte(s, (strm->adler >> 8) & 0xff); | 746 | put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); |
747 | strm->adler = crc32(0L, Z_NULL, 0); | 747 | strm->adler = crc32(0L, Z_NULL, 0); |
748 | s->status = BUSY_STATE; | 748 | s->status = BUSY_STATE; |
749 | } | 749 | } |
@@ -1303,6 +1303,7 @@ local void fill_window(s) | |||
1303 | later. (Using level 0 permanently is not an optimal usage of | 1303 | later. (Using level 0 permanently is not an optimal usage of |
1304 | zlib, so we don't care about this pathological case.) | 1304 | zlib, so we don't care about this pathological case.) |
1305 | */ | 1305 | */ |
1306 | /* %%% avoid this when Z_RLE */ | ||
1306 | n = s->hash_size; | 1307 | n = s->hash_size; |
1307 | p = &s->head[n]; | 1308 | p = &s->head[n]; |
1308 | do { | 1309 | do { |
@@ -1672,3 +1673,64 @@ local block_state deflate_slow(s, flush) | |||
1672 | return flush == Z_FINISH ? finish_done : block_done; | 1673 | return flush == Z_FINISH ? finish_done : block_done; |
1673 | } | 1674 | } |
1674 | #endif /* FASTEST */ | 1675 | #endif /* FASTEST */ |
1676 | |||
1677 | #if 0 | ||
1678 | /* =========================================================================== | ||
1679 | * For Z_RLE, simply look for runs of bytes, generate matches only of distance | ||
1680 | * one. Do not maintain a hash table. (It will be regenerated if this run of | ||
1681 | * deflate switches away from Z_RLE.) | ||
1682 | */ | ||
1683 | local block_state deflate_rle(s, flush) | ||
1684 | deflate_state *s; | ||
1685 | int flush; | ||
1686 | { | ||
1687 | int bflush; /* set if current block must be flushed */ | ||
1688 | uInt run; /* length of run */ | ||
1689 | uInt max; /* maximum length of run */ | ||
1690 | uInt prev; /* byte at distance one to match */ | ||
1691 | Bytef *scan; /* scan for end of run */ | ||
1692 | |||
1693 | for (;;) { | ||
1694 | /* Make sure that we always have enough lookahead, except | ||
1695 | * at the end of the input file. We need MAX_MATCH bytes | ||
1696 | * for the longest encodable run. | ||
1697 | */ | ||
1698 | if (s->lookahead < MAX_MATCH) { | ||
1699 | fill_window(s); | ||
1700 | if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) { | ||
1701 | return need_more; | ||
1702 | } | ||
1703 | if (s->lookahead == 0) break; /* flush the current block */ | ||
1704 | } | ||
1705 | |||
1706 | /* See how many times the previous byte repeats */ | ||
1707 | run = 0; | ||
1708 | if (s->strstart > 0) { /* if there is a previous byte, that is */ | ||
1709 | max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH; | ||
1710 | scan = s->window + s->strstart - 1; | ||
1711 | prev = *scan++; | ||
1712 | do { | ||
1713 | if (*scan++ != prev) | ||
1714 | break; | ||
1715 | } while (++run < max); | ||
1716 | } | ||
1717 | |||
1718 | /* Emit match if have run of MIN_MATCH or longer, else emit literal */ | ||
1719 | if (run >= MIN_MATCH) { | ||
1720 | check_match(s, s->strstart, s->strstart - 1, run); | ||
1721 | _tr_tally_dist(s, 1, run - MIN_MATCH, bflush); | ||
1722 | s->lookahead -= run; | ||
1723 | s->strstart += run; | ||
1724 | } else { | ||
1725 | /* No match, output a literal byte */ | ||
1726 | Tracevv((stderr,"%c", s->window[s->strstart])); | ||
1727 | _tr_tally_lit (s, s->window[s->strstart], bflush); | ||
1728 | s->lookahead--; | ||
1729 | s->strstart++; | ||
1730 | } | ||
1731 | if (bflush) FLUSH_BLOCK(s, 0); | ||
1732 | } | ||
1733 | FLUSH_BLOCK(s, flush == Z_FINISH); | ||
1734 | return flush == Z_FINISH ? finish_done : block_done; | ||
1735 | } | ||
1736 | #endif | ||