From 287e2655cb64009874a80f2bb12ccf5b64f7b3e6 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 1 Jun 2023 08:27:27 -0400 Subject: [PATCH] WebP/Lossy: Add a missing clamp The spec says that the AC dequantization factor for Y2 data should be at least 8, so do that. This only has a very small effect (only the first two AC table entries are < 8 after multiplying with 155 / 100, so this would have only a small effect on brightness), and this case is hit exactly 0 times in all my test images. But it's still good to match the spec. --- Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp index 0714f94e57..811620fdbd 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp @@ -609,7 +609,7 @@ i16 dequantize_value(i16 value, bool is_dc, QuantizationIndices const& quantizat // can be found in related lookup functions in dixie.c (Section 20.4)." // Apparently spec writing became too much work at this point. In section 20.4, in dequant_init(): // * For y2, the output (!) of dc_qlookup is multiplied by 2, the output of ac_qlookup is multiplied by 155 / 100 - // * Also for y2, ac_qlookup is at least 8 for lower table entries (XXX!) + // * Also for y2, ac_qlookup is at least 8 for lower table entries // * For uv, the dc_qlookup index is clamped to 117 (instead of 127 for everything else) // (or, alternatively, the value is clamped to 132 at most) @@ -646,7 +646,7 @@ i16 dequantize_value(i16 value, bool is_dc, QuantizationIndices const& quantizat if (is_dc) dequantization_factor *= 2; else - dequantization_factor = (dequantization_factor * 155) / 100; + dequantization_factor = max((dequantization_factor * 155) / 100, 8); } return dequantization_factor * value;