From 830a3a25dc6d1422caf31aa88b381ce2e63471ef Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 31 May 2023 09:08:26 -0400 Subject: WebP/Lossy: Add a missing clamp() in `TM_PRED` prediction The spec has that clamp at the end of https://datatracker.ietf.org/doc/html/rfc6386#section-12.2: The exact algorithm is as follows: [...] b[r][c] = clamp255(L[r]+ A[c] - P); For the test images I'm looking at, it doesn't seem to make a dramatic difference, but omitting it in `B_TM_PRED` did make a dramatic difference, so add it. (Also, the spec demands it.) --- Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Userland') diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp index dbb124d481..499a546ecf 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp @@ -924,7 +924,7 @@ void predict_macroblock(Span prediction, IntraMacroblockMode mode, int mb_x VERIFY(mode == TM_PRED); for (int y = 0; y < N; ++y) for (int x = 0; x < N; ++x) - prediction[y * N + x] = left[y] + above[mb_x * N + x] - truemotion_corner; + prediction[y * N + x] = clamp(left[y] + above[mb_x * N + x] - truemotion_corner, 0, 255); } } -- cgit v1.2.3