From 65565d377b7f0398a35a026c794cbe2841a2980f Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Sat, 24 Jun 2023 14:38:02 -0400 Subject: [PATCH] LibGfx/JPEGXL: Accept images with high bit depth Instead of rejecting them, we truncate each value to 8 bits. This is clearly a hack, but given the lack of support of variable bit-depth in `Bitmap` this is the only sensible change. This allows us to display "Iceberg" on https://jpegxl.info/art/. --- Userland/Libraries/LibGfx/ImageFormats/JPEGXLLoader.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGXLLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGXLLoader.cpp index 7aaab0cc19..3886350862 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JPEGXLLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGXLLoader.cpp @@ -1081,11 +1081,16 @@ public: auto bitmap = TRY(Bitmap::create(BitmapFormat::BGRx8888, { width, height })); // FIXME: This assumes a raw image with RGB channels, other cases are possible - VERIFY(bits_per_sample == 8); + VERIFY(bits_per_sample >= 8); for (u32 y {}; y < height; ++y) { for (u32 x {}; x < width; ++x) { auto const to_u8 = [&, bits_per_sample](i32 sample) -> u8 { - return clamp(sample + .5, 0, (1 << bits_per_sample) - 1); + // FIXME: Don't truncate the result to 8 bits + static constexpr auto maximum_supported_bit_depth = 8; + if (bits_per_sample > maximum_supported_bit_depth) + sample >>= (bits_per_sample - maximum_supported_bit_depth); + + return clamp(sample + .5, 0, (1 << maximum_supported_bit_depth) - 1); }; Color const color {