From d15dc28833a9f7344a8b7bdede18c057c5493fbc Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 7 May 2023 21:25:31 -0400 Subject: [PATCH] LibGfx/WebP: Tell decode_webp_chunk_VP8() if it needs an alpha channel decode_webp_chunk_VP8() itself will only ever decode RGB data from a lossy webp stream, but a separate ALPH chunk could add alpha data later on. Let the function know if that will happen, so that it can return a bitmap with an alpha channel if appropriate. Since lossy decoding isn't implemented yet, no behavior change. But it makes it a bit easier to implement lossy decoding in the future. --- Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp index 9e01397601e..d3be4e46308 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp @@ -283,18 +283,18 @@ static ErrorOr decode_webp_chunk_VP8_header(Chunk const& vp8_chunk) return VP8Header { version, show_frame, size_of_first_partition, width, horizontal_scale, height, vertical_scale }; } -static ErrorOr> decode_webp_chunk_VP8(Chunk const& vp8_chunk) +static ErrorOr> decode_webp_chunk_VP8(Chunk const& vp8_chunk, bool include_alpha_channel) { VERIFY(vp8_chunk.type == FourCC("VP8 ")); + auto bitmap_format = include_alpha_channel ? BitmapFormat::BGRA8888 : BitmapFormat::BGRx8888; // Uncomment this to test ALPH decoding for WebP-lossy-with-alpha images while lossy decoding isn't implemented yet. #if 0 auto vp8_header = TRY(decode_webp_chunk_VP8_header(vp8_chunk)); - - // FIXME: probably want to pass in the bitmap format based on if there's an ALPH chunk. - return Bitmap::create(BitmapFormat::BGRA8888, { vp8_header.width, vp8_header.height }); + return Bitmap::create(bitmap_format, { vp8_header.width, vp8_header.height }); #else // FIXME: Implement webp lossy decoding. + (void)bitmap_format; return Error::from_string_literal("WebPImageDecoderPlugin: decoding lossy webps not yet implemented"); #endif } @@ -641,7 +641,7 @@ static ErrorOr> decode_webp_image_data(ImageData const& im } VERIFY(image_data.image_data_chunk.type == FourCC("VP8 ")); - auto bitmap = TRY(decode_webp_chunk_VP8(image_data.image_data_chunk)); + auto bitmap = TRY(decode_webp_chunk_VP8(image_data.image_data_chunk, image_data.alpha_chunk.has_value())); if (image_data.alpha_chunk.has_value()) TRY(decode_webp_chunk_ALPH(image_data.alpha_chunk.value(), *bitmap));