mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-13 06:24:27 +02:00
speed-up lossless (~3%) with ad-hoc histogram cost evaluation
* merge cost calculation functions (BitsEntropy() and HuffmanCost()) * have HistogramAdd() specialized into separate functions * use threshold to bail-out early * revamp code a bit * also: save memory by freeing free(histogram_image) Change-Id: I8ee5d2cfa1462d5d6ea6361f5c89925a3720ef55
This commit is contained in:
@ -563,6 +563,9 @@ static int EncodeImageInternal(VP8LBitWriter* const bw,
|
||||
!GetHuffBitLengthsAndCodes(histogram_image, huffman_codes)) {
|
||||
goto Error;
|
||||
}
|
||||
// Free combined histograms.
|
||||
free(histogram_image);
|
||||
histogram_image = NULL;
|
||||
|
||||
// Color Cache parameters.
|
||||
VP8LWriteBits(bw, 1, use_color_cache);
|
||||
@ -609,9 +612,6 @@ static int EncodeImageInternal(VP8LBitWriter* const bw,
|
||||
ClearHuffmanTreeIfOnlyOneSymbol(codes);
|
||||
}
|
||||
}
|
||||
// Free combined histograms.
|
||||
free(histogram_image);
|
||||
histogram_image = NULL;
|
||||
|
||||
// Store actual literals.
|
||||
StoreImageToBitMask(bw, width, histogram_bits, &refs,
|
||||
@ -619,7 +619,7 @@ static int EncodeImageInternal(VP8LBitWriter* const bw,
|
||||
ok = 1;
|
||||
|
||||
Error:
|
||||
if (!ok) free(histogram_image);
|
||||
free(histogram_image);
|
||||
|
||||
VP8LClearBackwardRefs(&refs);
|
||||
if (huffman_codes != NULL) {
|
||||
|
Reference in New Issue
Block a user