From 7266d8c35d073621eea4657d6c66427e3a18c4f1 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Sat, 16 Dec 2023 23:28:29 -0500 Subject: [PATCH] LibGfx/TIFF: Correctly upscale samples with a resolution lower than 8 As pointed out by @nico, while doing a right-shift to downscale is fine, a left-shift to upscale gives wrong results. As an example, imagine a 2- bits value containing 3, left-shifting it would give 192 instead of 255. --- Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp index ec74c37594..185fb54af7 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp @@ -83,7 +83,7 @@ private: if (bits > 8) return value >> (bits - 8); - return value << (8 - bits); + return NumericLimits::max() * value / ((1 << bits) - 1); } ErrorOr read_color(BigEndianInputBitStream& stream)