From 62ac31815680693c6ff2ce3b4eaf283d6b91bbba Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Tue, 19 Oct 2021 08:17:36 +0200 Subject: [PATCH] Apply change from upstream: 749a8b99 "Better estimate of the cache cost." --- .../WebP/Lossless/BackwardReferenceEncoder.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs b/src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs index a37082638..267cedd91 100644 --- a/src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs +++ b/src/ImageSharp/Formats/WebP/Lossless/BackwardReferenceEncoder.cs @@ -181,17 +181,17 @@ namespace SixLabors.ImageSharp.Formats.Webp.Lossless // 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 = v.Len; uint bgraPrev = bgra[pos] ^ 0xffffffffu; - // TODO: Original has this loop? - // int extraBits = 0, extraBitsValue = 0; - // int code = LosslessUtils.PrefixEncode(len, ref extraBits, ref extraBitsValue); - // for (int i = 0; i <= cacheBitsMax; ++i) - // { - // ++histos[i].Literal[WebPConstants.NumLiteralCodes + code]; - // } + int extraBits = 0, extraBitsValue = 0; + int code = LosslessUtils.PrefixEncode(len, ref extraBits, ref extraBitsValue); + for (int i = 0; i <= cacheBitsMax; ++i) + { + ++histos[i].Literal[WebpConstants.NumLiteralCodes + code]; + } // Update the color caches. do