deflate.c (pigz-2.5) | : | deflate.c (pigz-2.6) | ||
---|---|---|---|---|

skipping to change at line 434 | skipping to change at line 434 | |||

return x - y; | return x - y; | |||

else | else | |||

return y - x; | return y - x; | |||

} | } | |||

/* | /* | |||

Changes the population counts in a way that the consequent Huffman tree | Changes the population counts in a way that the consequent Huffman tree | |||

compression, especially its rle-part, will be more likely to compress this data | compression, especially its rle-part, will be more likely to compress this data | |||

more efficiently. length contains the size of the histogram. | more efficiently. length contains the size of the histogram. | |||

*/ | */ | |||

void OptimizeHuffmanForRle(int length, size_t* counts) { | void OptimizeHuffmanForRle(unsigned length, size_t* counts) { | |||

int i, k, stride; | unsigned i; | |||

int k, stride; | ||||

size_t symbol, sum, limit; | size_t symbol, sum, limit; | |||

int* good_for_rle; | int* good_for_rle; | |||

/* 1) We don't want to touch the trailing zeros. We may break the | /* 1) We don't want to touch the trailing zeros. We may break the | |||

rules of the format by adding more data in the distance codes. */ | rules of the format by adding more data in the distance codes. */ | |||

for (; length >= 0; --length) { | for (; length > 0; --length) { | |||

if (length == 0) { | ||||

return; | ||||

} | ||||

if (counts[length - 1] != 0) { | if (counts[length - 1] != 0) { | |||

/* Now counts[0..length - 1] does not have trailing zeros. */ | /* Now counts[0..length - 1] does not have trailing zeros. */ | |||

break; | break; | |||

} | } | |||

} | } | |||

if (length == 0) { | ||||

return; | ||||

} | ||||

/* 2) Let's mark all population counts that already can be encoded | /* 2) Let's mark all population counts that already can be encoded | |||

with an rle code.*/ | with an rle code.*/ | |||

good_for_rle = (int*)malloc(length * sizeof(int)); | good_for_rle = (int*)malloc(length * sizeof(int)); | |||

for (i = 0; i < length; ++i) good_for_rle[i] = 0; | for (i = 0; i < length; ++i) good_for_rle[i] = 0; | |||

/* Let's not spoil any of the existing good rle codes. | /* Let's not spoil any of the existing good rle codes. | |||

Mark any seq of 0's that is longer than 5 as a good_for_rle. | Mark any seq of 0's that is longer than 5 as a good_for_rle. | |||

Mark any seq of non-0's that is longer than 7 as a good_for_rle.*/ | Mark any seq of non-0's that is longer than 7 as a good_for_rle.*/ | |||

symbol = counts[0]; | symbol = counts[0]; | |||

stride = 0; | stride = 0; | |||

End of changes. 3 change blocks. | ||||

6 lines changed or deleted | | 7 lines changed or added |