diff options
author | Nico Weber <thakis@chromium.org> | 2023-05-07 21:25:31 -0400 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-05-09 06:35:56 +0200 |
commit | d15dc28833a9f7344a8b7bdede18c057c5493fbc (patch) | |
tree | fa6f88f02c895d30ed13a047889ab60df8e22484 | |
parent | e13c319972b0deaa615b751ec64a895bbd13561f (diff) | |
download | serenity-d15dc28833a9f7344a8b7bdede18c057c5493fbc.zip |
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.
-rw-r--r-- | Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp index 9e01397601..d3be4e4630 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp @@ -283,18 +283,18 @@ static ErrorOr<VP8Header> 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<NonnullRefPtr<Bitmap>> decode_webp_chunk_VP8(Chunk const& vp8_chunk) +static ErrorOr<NonnullRefPtr<Bitmap>> 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<NonnullRefPtr<Bitmap>> 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)); |