Deleted Added
full compact
compress.c (90067) compress.c (146293)
1
2/*-------------------------------------------------------------*/
3/*--- Compression machinery (not incl block sorting) ---*/
4/*--- compress.c ---*/
5/*-------------------------------------------------------------*/
6
7/*--
8 This file is a part of bzip2 and/or libbzip2, a program and
9 library for lossless, block-sorting data compression.
10
1
2/*-------------------------------------------------------------*/
3/*--- Compression machinery (not incl block sorting) ---*/
4/*--- compress.c ---*/
5/*-------------------------------------------------------------*/
6
7/*--
8 This file is a part of bzip2 and/or libbzip2, a program and
9 library for lossless, block-sorting data compression.
10
11 Copyright (C) 1996-2002 Julian R Seward. All rights reserved.
11 Copyright (C) 1996-2005 Julian R Seward. All rights reserved.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions
15 are met:
16
17 1. Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
19

--- 17 unchanged lines hidden (view full) ---

37 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
38 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43
44 Julian Seward, Cambridge, UK.
12
13 Redistribution and use in source and binary forms, with or without
14 modification, are permitted provided that the following conditions
15 are met:
16
17 1. Redistributions of source code must retain the above copyright
18 notice, this list of conditions and the following disclaimer.
19

--- 17 unchanged lines hidden (view full) ---

37 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
38 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
40 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43
44 Julian Seward, Cambridge, UK.
45 jseward@acm.org
45 jseward@bzip.org
46 bzip2/libbzip2 version 1.0 of 21 March 2000
47
48 This program is based on (at least) the work of:
49 Mike Burrows
50 David Wheeler
51 Peter Fenwick
52 Alistair Moffat
53 Radford Neal

--- 429 unchanged lines hidden (view full) ---

483 for (t = 0; t < nGroups; t++)
484 VPrintf1 ( "%d ", fave[t] );
485 VPrintf0 ( "\n" );
486 }
487
488 /*--
489 Recompute the tables based on the accumulated frequencies.
490 --*/
46 bzip2/libbzip2 version 1.0 of 21 March 2000
47
48 This program is based on (at least) the work of:
49 Mike Burrows
50 David Wheeler
51 Peter Fenwick
52 Alistair Moffat
53 Radford Neal

--- 429 unchanged lines hidden (view full) ---

483 for (t = 0; t < nGroups; t++)
484 VPrintf1 ( "%d ", fave[t] );
485 VPrintf0 ( "\n" );
486 }
487
488 /*--
489 Recompute the tables based on the accumulated frequencies.
490 --*/
491 /* maxLen was changed from 20 to 17 in bzip2-1.0.3. See
492 comment in huffman.c for details. */
491 for (t = 0; t < nGroups; t++)
492 BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]),
493 for (t = 0; t < nGroups; t++)
494 BZ2_hbMakeCodeLengths ( &(s->len[t][0]), &(s->rfreq[t][0]),
493 alphaSize, 20 );
495 alphaSize, 17 /*20*/ );
494 }
495
496
497 AssertH( nGroups < 8, 3002 );
498 AssertH( nSelectors < 32768 &&
499 nSelectors <= (2 + (900000 / BZ_G_SIZE)),
500 3003 );
501

--- 20 unchanged lines hidden (view full) ---

522 /*--- Assign actual codes for the tables. --*/
523 for (t = 0; t < nGroups; t++) {
524 minLen = 32;
525 maxLen = 0;
526 for (i = 0; i < alphaSize; i++) {
527 if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
528 if (s->len[t][i] < minLen) minLen = s->len[t][i];
529 }
496 }
497
498
499 AssertH( nGroups < 8, 3002 );
500 AssertH( nSelectors < 32768 &&
501 nSelectors <= (2 + (900000 / BZ_G_SIZE)),
502 3003 );
503

--- 20 unchanged lines hidden (view full) ---

524 /*--- Assign actual codes for the tables. --*/
525 for (t = 0; t < nGroups; t++) {
526 minLen = 32;
527 maxLen = 0;
528 for (i = 0; i < alphaSize; i++) {
529 if (s->len[t][i] > maxLen) maxLen = s->len[t][i];
530 if (s->len[t][i] < minLen) minLen = s->len[t][i];
531 }
530 AssertH ( !(maxLen > 20), 3004 );
532 AssertH ( !(maxLen > 17 /*20*/ ), 3004 );
531 AssertH ( !(minLen < 1), 3005 );
532 BZ2_hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]),
533 minLen, maxLen, alphaSize );
534 }
535
536 /*--- Transmit the mapping table. ---*/
537 {
538 Bool inUse16[16];

--- 107 unchanged lines hidden (view full) ---

646 if (s->nblock > 0) {
647
648 BZ_FINALISE_CRC ( s->blockCRC );
649 s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
650 s->combinedCRC ^= s->blockCRC;
651 if (s->blockNo > 1) s->numZ = 0;
652
653 if (s->verbosity >= 2)
533 AssertH ( !(minLen < 1), 3005 );
534 BZ2_hbAssignCodes ( &(s->code[t][0]), &(s->len[t][0]),
535 minLen, maxLen, alphaSize );
536 }
537
538 /*--- Transmit the mapping table. ---*/
539 {
540 Bool inUse16[16];

--- 107 unchanged lines hidden (view full) ---

648 if (s->nblock > 0) {
649
650 BZ_FINALISE_CRC ( s->blockCRC );
651 s->combinedCRC = (s->combinedCRC << 1) | (s->combinedCRC >> 31);
652 s->combinedCRC ^= s->blockCRC;
653 if (s->blockNo > 1) s->numZ = 0;
654
655 if (s->verbosity >= 2)
654 VPrintf4( " block %d: crc = 0x%8x, "
655 "combined CRC = 0x%8x, size = %d\n",
656 VPrintf4( " block %d: crc = 0x%08x, "
657 "combined CRC = 0x%08x, size = %d\n",
656 s->blockNo, s->blockCRC, s->combinedCRC, s->nblock );
657
658 BZ2_blockSort ( s );
659 }
660
661 s->zbits = (UChar*) (&((UChar*)s->arr2)[s->nblock]);
662
663 /*-- If this is the first block, create the stream header. --*/

--- 34 unchanged lines hidden (view full) ---

698 /*-- If this is the last block, add the stream trailer. --*/
699 if (is_last_block) {
700
701 bsPutUChar ( s, 0x17 ); bsPutUChar ( s, 0x72 );
702 bsPutUChar ( s, 0x45 ); bsPutUChar ( s, 0x38 );
703 bsPutUChar ( s, 0x50 ); bsPutUChar ( s, 0x90 );
704 bsPutUInt32 ( s, s->combinedCRC );
705 if (s->verbosity >= 2)
658 s->blockNo, s->blockCRC, s->combinedCRC, s->nblock );
659
660 BZ2_blockSort ( s );
661 }
662
663 s->zbits = (UChar*) (&((UChar*)s->arr2)[s->nblock]);
664
665 /*-- If this is the first block, create the stream header. --*/

--- 34 unchanged lines hidden (view full) ---

700 /*-- If this is the last block, add the stream trailer. --*/
701 if (is_last_block) {
702
703 bsPutUChar ( s, 0x17 ); bsPutUChar ( s, 0x72 );
704 bsPutUChar ( s, 0x45 ); bsPutUChar ( s, 0x38 );
705 bsPutUChar ( s, 0x50 ); bsPutUChar ( s, 0x90 );
706 bsPutUInt32 ( s, s->combinedCRC );
707 if (s->verbosity >= 2)
706 VPrintf1( " final combined CRC = 0x%x\n ", s->combinedCRC );
708 VPrintf1( " final combined CRC = 0x%08x\n ", s->combinedCRC );
707 bsFinishWrite ( s );
708 }
709}
710
711
712/*-------------------------------------------------------------*/
713/*--- end compress.c ---*/
714/*-------------------------------------------------------------*/
709 bsFinishWrite ( s );
710 }
711}
712
713
714/*-------------------------------------------------------------*/
715/*--- end compress.c ---*/
716/*-------------------------------------------------------------*/