diff options
author | Julian Seward <jseward@acm.org> | 2005-02-15 22:13:13 +0100 |
---|---|---|
committer | Julian Seward <jseward@acm.org> | 2005-02-15 22:13:13 +0100 |
commit | 4d540bfc95a4b0eefc1d1f388ec33534aaeb3a2f (patch) | |
tree | 3b7e9c650b4c61d114e1716c4698e40d5c8d7ef7 /huffman.c | |
parent | 099d844292f60f9d58914da29e5773204dc55e7a (diff) | |
download | bzip2-4d540bfc95a4b0eefc1d1f388ec33534aaeb3a2f.tar.gz bzip2-4d540bfc95a4b0eefc1d1f388ec33534aaeb3a2f.tar.bz2 bzip2-4d540bfc95a4b0eefc1d1f388ec33534aaeb3a2f.zip |
bzip2-1.0.3bzip2-1.0.3
Diffstat (limited to 'huffman.c')
-rw-r--r-- | huffman.c | 23 |
1 files changed, 20 insertions, 3 deletions
@@ -8,7 +8,7 @@ | |||
8 | This file is a part of bzip2 and/or libbzip2, a program and | 8 | This file is a part of bzip2 and/or libbzip2, a program and |
9 | library for lossless, block-sorting data compression. | 9 | library for lossless, block-sorting data compression. |
10 | 10 | ||
11 | Copyright (C) 1996-2002 Julian R Seward. All rights reserved. | 11 | Copyright (C) 1996-2005 Julian R Seward. All rights reserved. |
12 | 12 | ||
13 | Redistribution and use in source and binary forms, with or without | 13 | Redistribution and use in source and binary forms, with or without |
14 | modification, are permitted provided that the following conditions | 14 | modification, are permitted provided that the following conditions |
@@ -42,7 +42,7 @@ | |||
42 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 42 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
43 | 43 | ||
44 | Julian Seward, Cambridge, UK. | 44 | Julian Seward, Cambridge, UK. |
45 | jseward@acm.org | 45 | jseward@bzip.org |
46 | bzip2/libbzip2 version 1.0 of 21 March 2000 | 46 | bzip2/libbzip2 version 1.0 of 21 March 2000 |
47 | 47 | ||
48 | This program is based on (at least) the work of: | 48 | This program is based on (at least) the work of: |
@@ -162,7 +162,24 @@ void BZ2_hbMakeCodeLengths ( UChar *len, | |||
162 | 162 | ||
163 | if (! tooLong) break; | 163 | if (! tooLong) break; |
164 | 164 | ||
165 | for (i = 1; i < alphaSize; i++) { | 165 | /* 17 Oct 04: keep-going condition for the following loop used |
166 | to be 'i < alphaSize', which missed the last element, | ||
167 | theoretically leading to the possibility of the compressor | ||
168 | looping. However, this count-scaling step is only needed if | ||
169 | one of the generated Huffman code words is longer than | ||
170 | maxLen, which up to and including version 1.0.2 was 20 bits, | ||
171 | which is extremely unlikely. In version 1.0.3 maxLen was | ||
172 | changed to 17 bits, which has minimal effect on compression | ||
173 | ratio, but does mean this scaling step is used from time to | ||
174 | time, enough to verify that it works. | ||
175 | |||
176 | This means that bzip2-1.0.3 and later will only produce | ||
177 | Huffman codes with a maximum length of 17 bits. However, in | ||
178 | order to preserve backwards compatibility with bitstreams | ||
179 | produced by versions pre-1.0.3, the decompressor must still | ||
180 | handle lengths of up to 20. */ | ||
181 | |||
182 | for (i = 1; i <= alphaSize; i++) { | ||
166 | j = weight[i] >> 8; | 183 | j = weight[i] >> 8; |
167 | j = 1 + (j / 2); | 184 | j = 1 + (j / 2); |
168 | weight[i] = j << 8; | 185 | weight[i] = j << 8; |