Changeset 5a7aa10 in rtems
- Timestamp:
- 03/18/11 10:11:21 (13 years ago)
- Branches:
- 4.11, 5, master
- Children:
- d71b3a7
- Parents:
- f7d9aea2
- Location:
- cpukit/zlib
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpukit/zlib/deflate.c
rf7d9aea2 r5a7aa10 1 1 /* deflate.c -- compress data using the deflation algorithm 2 * Copyright (C) 1995-20 05 Jean-loup Gailly.2 * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler 3 3 * For conditions of distribution and use, see copyright notice in zlib.h 4 4 */ … … 53 53 54 54 const char deflate_copyright[] = 55 " deflate 1.2. 3 Copyright 1995-2005 Jean-loup Gailly";55 " deflate 1.2.4 Copyright 1995-2010 Jean-loup Gailly and Mark Adler "; 56 56 /* 57 57 If you use the zlib library in a product, an acknowledgment is welcome … … 80 80 local block_state deflate_slow OF((deflate_state *s, int flush)); 81 81 #endif 82 local block_state deflate_rle OF((deflate_state *s, int flush)); 83 local block_state deflate_huff OF((deflate_state *s, int flush)); 82 84 local void lm_init OF((deflate_state *s)); 83 85 local void putShortMSB OF((deflate_state *s, uInt b)); 84 86 local void flush_pending OF((z_streamp strm)); 85 87 local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); 86 #ifndef FASTEST87 88 #ifdef ASMV 88 89 void match_init OF((void)); /* asm code initialization */ … … 91 92 local uInt longest_match OF((deflate_state *s, IPos cur_match)); 92 93 #endif 93 #endif94 local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));95 94 96 95 #ifdef DEBUG … … 110 109 #endif 111 110 /* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ 112 113 #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)114 /* Minimum amount of lookahead, except at the end of the input file.115 * See deflate.c for comments about the MIN_MATCH+1.116 */117 111 118 112 /* Values for max_lazy_match, good_match and max_chain_length, depending on … … 289 283 s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); 290 284 285 s->high_water = 0; /* nothing written to s->window yet */ 286 291 287 s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ 292 288 … … 333 329 334 330 if (length < MIN_MATCH) return Z_OK; 335 if (length > MAX_DIST(s)) {336 length = MAX_DIST(s);331 if (length > s->w_size) { 332 length = s->w_size; 337 333 dictionary += dictLength - length; /* use the tail of the dictionary */ 338 334 } … … 436 432 func = configuration_table[s->level].func; 437 433 438 if (func != configuration_table[level].func && strm->total_in != 0) { 434 if ((strategy != s->strategy || func != configuration_table[level].func) && 435 strm->total_in != 0) { 439 436 /* Flush the last buffer: */ 440 err = deflate(strm, Z_ PARTIAL_FLUSH);437 err = deflate(strm, Z_BLOCK); 441 438 } 442 439 if (s->level != level) { … … 482 479 * can emit on compressed data for some combinations of the parameters. 483 480 * 484 * This function could be more sophisticated to provide closer upper bounds 485 * for every combination of windowBits and memLevel, as well as wrap.486 * But even the conservative upper bound of about 14% expansion does not487 * seem onerous for output bufferallocation.481 * This function could be more sophisticated to provide closer upper bounds for 482 * every combination of windowBits and memLevel. But even the conservative 483 * upper bound of about 14% expansion does not seem onerous for output buffer 484 * allocation. 488 485 */ 489 486 uLong ZEXPORT deflateBound(strm, sourceLen) … … 492 489 { 493 490 deflate_state *s; 494 uLong destLen; 495 496 /* conservative upper bound */ 497 destLen = sourceLen + 498 ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11; 499 500 /* if can't get parameters, return conservative bound */ 491 uLong complen, wraplen; 492 Bytef *str; 493 494 /* conservative upper bound for compressed data */ 495 complen = sourceLen + 496 ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; 497 498 /* if can't get parameters, return conservative bound plus zlib wrapper */ 501 499 if (strm == Z_NULL || strm->state == Z_NULL) 502 return destLen; 500 return complen + 6; 501 502 /* compute wrapper length */ 503 s = strm->state; 504 switch (s->wrap) { 505 case 0: /* raw deflate */ 506 wraplen = 0; 507 break; 508 case 1: /* zlib wrapper */ 509 wraplen = 6 + (s->strstart ? 4 : 0); 510 break; 511 case 2: /* gzip wrapper */ 512 wraplen = 18; 513 if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ 514 if (s->gzhead->extra != Z_NULL) 515 wraplen += 2 + s->gzhead->extra_len; 516 str = s->gzhead->name; 517 if (str != Z_NULL) 518 do { 519 wraplen++; 520 } while (*str++); 521 str = s->gzhead->comment; 522 if (str != Z_NULL) 523 do { 524 wraplen++; 525 } while (*str++); 526 if (s->gzhead->hcrc) 527 wraplen += 2; 528 } 529 break; 530 default: /* for compiler happiness */ 531 wraplen = 6; 532 } 503 533 504 534 /* if not default parameters, return conservative bound */ 505 s = strm->state;506 535 if (s->w_bits != 15 || s->hash_bits != 8 + 7) 507 return destLen;536 return complen + wraplen; 508 537 509 538 /* default settings: return tight bound for that case */ 510 return compressBound(sourceLen); 539 return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 540 (sourceLen >> 25) + 13 - 6 + wraplen; 511 541 } 512 542 … … 558 588 559 589 if (strm == Z_NULL || strm->state == Z_NULL || 560 flush > Z_ FINISH|| flush < 0) {590 flush > Z_BLOCK || flush < 0) { 561 591 return Z_STREAM_ERROR; 562 592 } … … 582 612 put_byte(s, 139); 583 613 put_byte(s, 8); 584 if (s->gzhead == NULL) {614 if (s->gzhead == Z_NULL) { 585 615 put_byte(s, 0); 586 616 put_byte(s, 0); … … 609 639 4 : 0)); 610 640 put_byte(s, s->gzhead->os & 0xff); 611 if (s->gzhead->extra != NULL) {641 if (s->gzhead->extra != Z_NULL) { 612 642 put_byte(s, s->gzhead->extra_len & 0xff); 613 643 put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); … … 651 681 #ifdef GZIP 652 682 if (s->status == EXTRA_STATE) { 653 if (s->gzhead->extra != NULL) {683 if (s->gzhead->extra != Z_NULL) { 654 684 uInt beg = s->pending; /* start of bytes to update crc */ 655 685 … … 679 709 } 680 710 if (s->status == NAME_STATE) { 681 if (s->gzhead->name != NULL) {711 if (s->gzhead->name != Z_NULL) { 682 712 uInt beg = s->pending; /* start of bytes to update crc */ 683 713 int val; … … 710 740 } 711 741 if (s->status == COMMENT_STATE) { 712 if (s->gzhead->comment != NULL) {742 if (s->gzhead->comment != Z_NULL) { 713 743 uInt beg = s->pending; /* start of bytes to update crc */ 714 744 int val; … … 788 818 block_state bstate; 789 819 790 bstate = (*(configuration_table[s->level].func))(s, flush); 820 bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : 821 (s->strategy == Z_RLE ? deflate_rle(s, flush) : 822 (*(configuration_table[s->level].func))(s, flush)); 791 823 792 824 if (bstate == finish_started || bstate == finish_done) { … … 809 841 if (flush == Z_PARTIAL_FLUSH) { 810 842 _tr_align(s); 811 } else { /* FULL_FLUSH or SYNC_FLUSH */843 } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ 812 844 _tr_stored_block(s, (char*)0, 0L, 0); 813 845 /* For a full flush, this empty block will be recognized … … 816 848 if (flush == Z_FULL_FLUSH) { 817 849 CLEAR_HASH(s); /* forget history */ 850 if (s->lookahead == 0) { 851 s->strstart = 0; 852 s->block_start = 0L; 853 } 818 854 } 819 855 } … … 1168 1204 } 1169 1205 #endif /* ASMV */ 1170 #endif /* FASTEST */ 1206 1207 #else /* FASTEST */ 1171 1208 1172 1209 /* --------------------------------------------------------------------------- 1173 * Optimized version for level == 1 or strategy == Z_RLEonly1174 */ 1175 local uInt longest_match _fast(s, cur_match)1210 * Optimized version for FASTEST only 1211 */ 1212 local uInt longest_match(s, cur_match) 1176 1213 deflate_state *s; 1177 1214 IPos cur_match; /* current match */ … … 1226 1263 } 1227 1264 1265 #endif /* FASTEST */ 1266 1228 1267 #ifdef DEBUG 1229 1268 /* =========================================================================== … … 1304 1343 zlib, so we don't care about this pathological case.) 1305 1344 */ 1306 /* %%% avoid this when Z_RLE */1307 1345 n = s->hash_size; 1308 1346 p = &s->head[n]; … … 1356 1394 1357 1395 } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); 1396 1397 /* If the WIN_INIT bytes after the end of the current data have never been 1398 * written, then zero those bytes in order to avoid memory check reports of 1399 * the use of uninitialized (or uninitialised as Julian writes) bytes by 1400 * the longest match routines. Update the high water mark for the next 1401 * time through here. WIN_INIT is set to MAX_MATCH since the longest match 1402 * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. 1403 */ 1404 if (s->high_water < s->window_size) { 1405 ulg curr = s->strstart + (ulg)(s->lookahead); 1406 ulg init; 1407 1408 if (s->high_water < curr) { 1409 /* Previous high water mark below current data -- zero WIN_INIT 1410 * bytes or up to end of window, whichever is less. 1411 */ 1412 init = s->window_size - curr; 1413 if (init > WIN_INIT) 1414 init = WIN_INIT; 1415 zmemzero(s->window + curr, (unsigned)init); 1416 s->high_water = curr + init; 1417 } 1418 else if (s->high_water < (ulg)curr + WIN_INIT) { 1419 /* High water mark at or above current data, but below current data 1420 * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up 1421 * to end of window, whichever is less. 1422 */ 1423 init = (ulg)curr + WIN_INIT - s->high_water; 1424 if (init > s->window_size - s->high_water) 1425 init = s->window_size - s->high_water; 1426 zmemzero(s->window + s->high_water, (unsigned)init); 1427 s->high_water += init; 1428 } 1429 } 1358 1430 } 1359 1431 … … 1362 1434 * IN assertion: strstart is set to the end of the current match. 1363 1435 */ 1364 #define FLUSH_BLOCK_ONLY(s, eof) { \1436 #define FLUSH_BLOCK_ONLY(s, last) { \ 1365 1437 _tr_flush_block(s, (s->block_start >= 0L ? \ 1366 1438 (charf *)&s->window[(unsigned)s->block_start] : \ 1367 1439 (charf *)Z_NULL), \ 1368 1440 (ulg)((long)s->strstart - s->block_start), \ 1369 ( eof)); \1441 (last)); \ 1370 1442 s->block_start = s->strstart; \ 1371 1443 flush_pending(s->strm); \ … … 1374 1446 1375 1447 /* Same but force premature exit if necessary. */ 1376 #define FLUSH_BLOCK(s, eof) { \1377 FLUSH_BLOCK_ONLY(s, eof); \1378 if (s->strm->avail_out == 0) return ( eof) ? finish_started : need_more; \1448 #define FLUSH_BLOCK(s, last) { \ 1449 FLUSH_BLOCK_ONLY(s, last); \ 1450 if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ 1379 1451 } 1380 1452 … … 1450 1522 int flush; 1451 1523 { 1452 IPos hash_head = NIL;/* head of the hash chain */1524 IPos hash_head; /* head of the hash chain */ 1453 1525 int bflush; /* set if current block must be flushed */ 1454 1526 … … 1470 1542 * dictionary, and set hash_head to the head of the hash chain: 1471 1543 */ 1544 hash_head = NIL; 1472 1545 if (s->lookahead >= MIN_MATCH) { 1473 1546 INSERT_STRING(s, s->strstart, hash_head); … … 1482 1555 * of the string with itself at the start of the input file). 1483 1556 */ 1484 #ifdef FASTEST 1485 if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) || 1486 (s->strategy == Z_RLE && s->strstart - hash_head == 1)) { 1487 s->match_length = longest_match_fast (s, hash_head); 1488 } 1489 #else 1490 if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) { 1491 s->match_length = longest_match (s, hash_head); 1492 } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { 1493 s->match_length = longest_match_fast (s, hash_head); 1494 } 1495 #endif 1496 /* longest_match() or longest_match_fast() sets match_start */ 1557 s->match_length = longest_match (s, hash_head); 1558 /* longest_match() sets match_start */ 1497 1559 } 1498 1560 if (s->match_length >= MIN_MATCH) { … … 1556 1618 int flush; 1557 1619 { 1558 IPos hash_head = NIL;/* head of hash chain */1620 IPos hash_head; /* head of hash chain */ 1559 1621 int bflush; /* set if current block must be flushed */ 1560 1622 … … 1577 1639 * dictionary, and set hash_head to the head of the hash chain: 1578 1640 */ 1641 hash_head = NIL; 1579 1642 if (s->lookahead >= MIN_MATCH) { 1580 1643 INSERT_STRING(s, s->strstart, hash_head); … … 1592 1655 * of the string with itself at the start of the input file). 1593 1656 */ 1594 if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) { 1595 s->match_length = longest_match (s, hash_head); 1596 } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) { 1597 s->match_length = longest_match_fast (s, hash_head); 1598 } 1599 /* longest_match() or longest_match_fast() sets match_start */ 1657 s->match_length = longest_match (s, hash_head); 1658 /* longest_match() sets match_start */ 1600 1659 1601 1660 if (s->match_length <= 5 && (s->strategy == Z_FILTERED … … 1675 1734 #endif /* FASTEST */ 1676 1735 1677 #if 01678 1736 /* =========================================================================== 1679 1737 * For Z_RLE, simply look for runs of bytes, generate matches only of distance … … 1685 1743 int flush; 1686 1744 { 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 */ 1745 int bflush; /* set if current block must be flushed */ 1746 uInt prev; /* byte at distance one to match */ 1747 Bytef *scan, *strend; /* scan goes up to strend for length of run */ 1692 1748 1693 1749 for (;;) { … … 1705 1761 1706 1762 /* 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; 1763 s->match_length = 0; 1764 if (s->lookahead >= MIN_MATCH && s->strstart > 0) { 1710 1765 scan = s->window + s->strstart - 1; 1711 prev = *scan++; 1712 do { 1713 if (*scan++ != prev) 1714 break; 1715 } while (++run < max); 1766 prev = *scan; 1767 if (prev == *++scan && prev == *++scan && prev == *++scan) { 1768 strend = s->window + s->strstart + MAX_MATCH; 1769 do { 1770 } while (prev == *++scan && prev == *++scan && 1771 prev == *++scan && prev == *++scan && 1772 prev == *++scan && prev == *++scan && 1773 prev == *++scan && prev == *++scan && 1774 scan < strend); 1775 s->match_length = MAX_MATCH - (int)(strend - scan); 1776 if (s->match_length > s->lookahead) 1777 s->match_length = s->lookahead; 1778 } 1716 1779 } 1717 1780 1718 1781 /* 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; 1782 if (s->match_length >= MIN_MATCH) { 1783 check_match(s, s->strstart, s->strstart - 1, s->match_length); 1784 1785 _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); 1786 1787 s->lookahead -= s->match_length; 1788 s->strstart += s->match_length; 1789 s->match_length = 0; 1724 1790 } else { 1725 1791 /* No match, output a literal byte */ … … 1734 1800 return flush == Z_FINISH ? finish_done : block_done; 1735 1801 } 1736 #endif 1802 1803 /* =========================================================================== 1804 * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. 1805 * (It will be regenerated if this run of deflate switches away from Huffman.) 1806 */ 1807 local block_state deflate_huff(s, flush) 1808 deflate_state *s; 1809 int flush; 1810 { 1811 int bflush; /* set if current block must be flushed */ 1812 1813 for (;;) { 1814 /* Make sure that we have a literal to write. */ 1815 if (s->lookahead == 0) { 1816 fill_window(s); 1817 if (s->lookahead == 0) { 1818 if (flush == Z_NO_FLUSH) 1819 return need_more; 1820 break; /* flush the current block */ 1821 } 1822 } 1823 1824 /* Output a literal byte */ 1825 s->match_length = 0; 1826 Tracevv((stderr,"%c", s->window[s->strstart])); 1827 _tr_tally_lit (s, s->window[s->strstart], bflush); 1828 s->lookahead--; 1829 s->strstart++; 1830 if (bflush) FLUSH_BLOCK(s, 0); 1831 } 1832 FLUSH_BLOCK(s, flush == Z_FINISH); 1833 return flush == Z_FINISH ? finish_done : block_done; 1834 } -
cpukit/zlib/deflate.h
rf7d9aea2 r5a7aa10 1 1 /* deflate.h -- internal compression state 2 * Copyright (C) 1995-200 4Jean-loup Gailly2 * Copyright (C) 1995-2009 Jean-loup Gailly 3 3 * For conditions of distribution and use, see copyright notice in zlib.h 4 4 */ … … 261 261 */ 262 262 263 ulg high_water; 264 /* High water mark offset in window for initialized bytes -- bytes above 265 * this are set to zero in order to avoid memory check warnings when 266 * longest match routines access bytes past the input. This is then 267 * updated to the new high water mark. 268 */ 269 263 270 } FAR deflate_state; 264 271 … … 278 285 * distances are limited to MAX_DIST instead of WSIZE. 279 286 */ 287 288 #define WIN_INIT MAX_MATCH 289 /* Number of bytes after end of data in window to initialize in order to avoid 290 memory checker errors from longest match routines */ 280 291 281 292 /* in trees.c */ … … 283 294 int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); 284 295 void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len, 285 int eof));296 int last)); 286 297 void _tr_align OF((deflate_state *s)); 287 298 void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len, 288 int eof));299 int last)); 289 300 290 301 #define d_code(dist) \ -
cpukit/zlib/trees.c
rf7d9aea2 r5a7aa10 1 1 /* trees.c -- output deflated data using Huffman coding 2 * Copyright (C) 1995-2005 Jean-loup Gailly 2 * Copyright (C) 1995-2009 Jean-loup Gailly 3 * detect_data_type() function provided freely by Cosmin Truta, 2006 3 4 * For conditions of distribution and use, see copyright notice in zlib.h 4 5 */ … … 153 154 local void compress_block OF((deflate_state *s, ct_data *ltree, 154 155 ct_data *dtree)); 155 local void set_data_typeOF((deflate_state *s));156 local int detect_data_type OF((deflate_state *s)); 156 157 local unsigned bi_reverse OF((unsigned value, int length)); 157 158 local void bi_windup OF((deflate_state *s)); … … 204 205 */ 205 206 if (s->bi_valid > (int)Buf_size - length) { 206 s->bi_buf |= ( value << s->bi_valid);207 s->bi_buf |= (ush)value << s->bi_valid; 207 208 put_short(s, s->bi_buf); 208 209 s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); 209 210 s->bi_valid += length - Buf_size; 210 211 } else { 211 s->bi_buf |= value << s->bi_valid;212 s->bi_buf |= (ush)value << s->bi_valid; 212 213 s->bi_valid += length; 213 214 } … … 219 220 if (s->bi_valid > (int)Buf_size - len) {\ 220 221 int val = value;\ 221 s->bi_buf |= ( val << s->bi_valid);\222 s->bi_buf |= (ush)val << s->bi_valid;\ 222 223 put_short(s, s->bi_buf);\ 223 224 s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ 224 225 s->bi_valid += len - Buf_size;\ 225 226 } else {\ 226 s->bi_buf |= ( value) << s->bi_valid;\227 s->bi_buf |= (ush)(value) << s->bi_valid;\ 227 228 s->bi_valid += len;\ 228 229 }\ … … 251 252 252 253 /* For some embedded targets, global variables are not initialized: */ 254 #ifdef NO_INIT_GLOBAL_POINTERS 253 255 static_l_desc.static_tree = static_ltree; 254 256 static_l_desc.extra_bits = extra_lbits; … … 256 258 static_d_desc.extra_bits = extra_dbits; 257 259 static_bl_desc.extra_bits = extra_blbits; 260 #endif 258 261 259 262 /* Initialize the mapping length (0..255) -> length code (0..28) */ … … 865 868 * Send a stored block 866 869 */ 867 void _tr_stored_block(s, buf, stored_len, eof)870 void _tr_stored_block(s, buf, stored_len, last) 868 871 deflate_state *s; 869 872 charf *buf; /* input block */ 870 873 ulg stored_len; /* length of input block */ 871 int eof; /* true if this is the last block for a file */872 { 873 send_bits(s, (STORED_BLOCK<<1)+ eof, 3);/* send block type */874 int last; /* one if this is the last block for a file */ 875 { 876 send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ 874 877 #ifdef DEBUG 875 878 s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; … … 919 922 * trees or store, and output the encoded block to the zip file. 920 923 */ 921 void _tr_flush_block(s, buf, stored_len, eof)924 void _tr_flush_block(s, buf, stored_len, last) 922 925 deflate_state *s; 923 926 charf *buf; /* input block, or NULL if too old */ 924 927 ulg stored_len; /* length of input block */ 925 int eof; /* true if this is the last block for a file */928 int last; /* one if this is the last block for a file */ 926 929 { 927 930 ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ … … 932 935 933 936 /* Check if the file is binary or text */ 934 if (s tored_len > 0 && s->strm->data_type == Z_UNKNOWN)935 s et_data_type(s);937 if (s->strm->data_type == Z_UNKNOWN) 938 s->strm->data_type = detect_data_type(s); 936 939 937 940 /* Construct the literal and distance trees */ … … 979 982 * transform a block into a stored block. 980 983 */ 981 _tr_stored_block(s, buf, stored_len, eof);984 _tr_stored_block(s, buf, stored_len, last); 982 985 983 986 #ifdef FORCE_STATIC … … 986 989 } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { 987 990 #endif 988 send_bits(s, (STATIC_TREES<<1)+ eof, 3);991 send_bits(s, (STATIC_TREES<<1)+last, 3); 989 992 compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); 990 993 #ifdef DEBUG … … 992 995 #endif 993 996 } else { 994 send_bits(s, (DYN_TREES<<1)+ eof, 3);997 send_bits(s, (DYN_TREES<<1)+last, 3); 995 998 send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, 996 999 max_blindex+1); … … 1006 1009 init_block(s); 1007 1010 1008 if ( eof) {1011 if (last) { 1009 1012 bi_windup(s); 1010 1013 #ifdef DEBUG … … 1013 1016 } 1014 1017 Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, 1015 s->compressed_len-7* eof));1018 s->compressed_len-7*last)); 1016 1019 } 1017 1020 … … 1119 1122 1120 1123 /* =========================================================================== 1121 * Set the data type to BINARY or TEXT, using a crude approximation: 1122 * set it to Z_TEXT if all symbols are either printable characters (33 to 255) 1123 * or white spaces (9 to 13, or 32); or set it to Z_BINARY otherwise. 1124 * Check if the data type is TEXT or BINARY, using the following algorithm: 1125 * - TEXT if the two conditions below are satisfied: 1126 * a) There are no non-portable control characters belonging to the 1127 * "black list" (0..6, 14..25, 28..31). 1128 * b) There is at least one printable character belonging to the 1129 * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). 1130 * - BINARY otherwise. 1131 * - The following partially-portable control characters form a 1132 * "gray list" that is ignored in this detection algorithm: 1133 * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). 1124 1134 * IN assertion: the fields Freq of dyn_ltree are set. 1125 1135 */ 1126 local void set_data_type(s) 1127 deflate_state *s; 1128 { 1136 local int detect_data_type(s) 1137 deflate_state *s; 1138 { 1139 /* black_mask is the bit mask of black-listed bytes 1140 * set bits 0..6, 14..25, and 28..31 1141 * 0xf3ffc07f = binary 11110011111111111100000001111111 1142 */ 1143 unsigned long black_mask = 0xf3ffc07fUL; 1129 1144 int n; 1130 1145 1131 for (n = 0; n < 9; n++) 1146 /* Check for non-textual ("black-listed") bytes. */ 1147 for (n = 0; n <= 31; n++, black_mask >>= 1) 1148 if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0)) 1149 return Z_BINARY; 1150 1151 /* Check for textual ("white-listed") bytes. */ 1152 if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 1153 || s->dyn_ltree[13].Freq != 0) 1154 return Z_TEXT; 1155 for (n = 32; n < LITERALS; n++) 1132 1156 if (s->dyn_ltree[n].Freq != 0) 1133 break;1134 if (n == 9) 1135 for (n = 14; n < 32; n++)1136 if (s->dyn_ltree[n].Freq != 0)1137 break;1138 s->strm->data_type = (n == 32) ? Z_TEXT :Z_BINARY;1157 return Z_TEXT; 1158 1159 /* There are no "black-listed" or "white-listed" bytes: 1160 * this stream either is empty or has tolerated ("gray-listed") bytes only. 1161 */ 1162 return Z_BINARY; 1139 1163 } 1140 1164
Note: See TracChangeset
for help on using the changeset viewer.