mirror of
https://github.com/webmproject/libwebp.git
synced 2025-07-19 15:29:48 +02:00
Fix bug in VP8LCalculateEstimateForCacheSize.
The method VP8LCalculateEstimateForCacheSize is not evaluating the all possible range for cache_bits. Also added a small penality for choosing the larger cache-size. This is done to strike a balance between additional memory/CPU cost (with larger cache-size) and byte savings from smaller WebP lossless files. This change saves about 0.07% bytes and speeds up compression by 8% (default settings). There's small speedup at Q=50 along with byte savings as well. Compression at Quality=25 is not effected by this change. Change-Id: Id8f87dee6b5bccb2baa6dbdee479ee9cda8f4f77
This commit is contained in:
@ -284,7 +284,7 @@ static int GetTransformBits(int method, int histo_bits) {
|
||||
static int GetCacheBits(int use_palette, float quality) {
|
||||
// Color cache is disabled for compression at lower quality or when a palette
|
||||
// is used.
|
||||
return (use_palette || (quality <= 25.f)) ? 0 : 7;
|
||||
return (use_palette || (quality <= 25.f)) ? 0 : MAX_COLOR_CACHE_BITS;
|
||||
}
|
||||
|
||||
static int EvalSubtractGreenForPalette(int palette_size, float quality) {
|
||||
@ -1309,13 +1309,11 @@ WebPEncodingError VP8LEncodeStream(const WebPConfig* const config,
|
||||
// ---------------------------------------------------------------------------
|
||||
// Estimate the color cache size.
|
||||
|
||||
if (enc->cache_bits_ > 0) {
|
||||
if (!VP8LCalculateEstimateForCacheSize(enc->argb_, enc->current_width_,
|
||||
height, quality, &enc->hash_chain_,
|
||||
&enc->refs_[0], &enc->cache_bits_)) {
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
}
|
||||
if (!VP8LCalculateEstimateForCacheSize(enc->argb_, enc->current_width_,
|
||||
height, quality, &enc->hash_chain_,
|
||||
&enc->refs_[0], &enc->cache_bits_)) {
|
||||
err = VP8_ENC_ERROR_OUT_OF_MEMORY;
|
||||
goto Error;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user