From 749a8b99f7828a22d09dad8a4afe5c381db498d4 Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Fri, 5 Jun 2020 16:07:58 +0200 Subject: [PATCH] Better estimate of the cache cost. Change-Id: I171a8f80f1597bbdeb724957e789b947df3c2885 --- src/enc/backward_references_enc.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/enc/backward_references_enc.c b/src/enc/backward_references_enc.c index d445b40f..4c18bb9d 100644 --- a/src/enc/backward_references_enc.c +++ b/src/enc/backward_references_enc.c @@ -753,12 +753,18 @@ static int CalculateBestCacheSize(const uint32_t* argb, int quality, } } } else { + int code, extra_bits, extra_bits_value; // We should compute the contribution of the (distance,length) // histograms but those are the same independently from the cache size. // As those constant contributions are in the end added to the other - // histogram contributions, we can safely ignore them. + // histogram contributions, we can ignore them, except for the length + // prefix that is part of the literal_ histogram. int len = PixOrCopyLength(v); uint32_t argb_prev = *argb ^ 0xffffffffu; + VP8LPrefixEncode(len, &code, &extra_bits, &extra_bits_value); + for (i = 0; i <= cache_bits_max; ++i) { + ++histos[i]->literal_[NUM_LITERAL_CODES + code]; + } // Update the color caches. do { if (*argb != argb_prev) {