From e9f5c9ab9d3bca8990c020e5003caadc46b47a1f Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sat, 6 May 2023 16:34:45 -0400 Subject: [PATCH] Tests/LibGfx: More preparation for lossy and alpha handling If someone comes along who wants to implement lossy webp decoding, they now only need to implement decode_webp_chunk_VP8() and everything might Just Work. It also makes it possible to implement alpha chunk decoding before implementing lossy decoding (by making decode_webp_chunk_VP8() return an empty black bitmap for testing). --- .../Libraries/LibGfx/ImageFormats/WebPLoader.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp index 4b5c193dc6..610ff8df55 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp @@ -299,6 +299,14 @@ static ErrorOr decode_webp_chunk_VP8_header(WebPLoadingContext& conte return VP8Header { version, show_frame, size_of_first_partition, width, horizontal_scale, height, vertical_scale }; } +static ErrorOr> decode_webp_chunk_VP8(WebPLoadingContext& context, Chunk const& vp8_chunk) +{ + VERIFY(vp8_chunk.type == FourCC("VP8 ")); + + // FIXME: Implement webp lossy decoding. + return context.error("WebPImageDecoderPlugin: decoding lossy webps not yet implemented"); +} + // https://developers.google.com/speed/webp/docs/riff_container#simple_file_format_lossless // https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#7_overall_structure_of_the_format static ErrorOr decode_webp_chunk_VP8L_header(WebPLoadingContext& context, Chunk const& vp8l_chunk) @@ -1584,9 +1592,13 @@ static ErrorOr> decode_webp_image_data(WebPLoadingContext& } VERIFY(image_data.image_data_chunk->type == FourCC("VP8 ")); + auto bitmap = TRY(decode_webp_chunk_VP8(context, image_data.image_data_chunk.value())); - // FIXME: Implement. - return context.error("WebPImageDecoderPlugin: decoding lossy webps not yet implemented"); + if (image_data.alpha_chunk.has_value()) { + // FIXME: Decode alpha chunk and store decoded alpha in `bitmap`. + } + + return bitmap; } // https://developers.google.com/speed/webp/docs/riff_container#assembling_the_canvas_from_frames