diff options
author | Nico Weber <thakis@chromium.org> | 2023-04-04 09:45:09 -0400 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-04-06 00:16:52 +0100 |
commit | 48f88b3cdd6b362c3547dba832e31a1d57cc5572 (patch) | |
tree | cbb3c454af2ac805e7bbce0437cbb9529e5025d4 /Userland/Libraries/LibGfx | |
parent | 4bd7090bc5550c1fecf28cc3b3e2a9195098a262 (diff) | |
download | serenity-48f88b3cdd6b362c3547dba832e31a1d57cc5572.zip |
LibGfx: Teach webp image reading function to read entropy coded images
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r-- | Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp index 3ca1a04924..912a8bff31 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp @@ -443,11 +443,17 @@ static ErrorOr<PrefixCodeGroup> decode_webp_chunk_VP8L_prefix_code_group(WebPLoa return group; } -static ErrorOr<NonnullRefPtr<Bitmap>> decode_webp_chunk_VP8L_image(WebPLoadingContext& context, VP8LHeader const& vp8l_header, LittleEndianInputBitStream& bit_stream) +enum class ImageKind { + SpatiallyCoded, + EntropyCoded, +}; + +static ErrorOr<NonnullRefPtr<Bitmap>> decode_webp_chunk_VP8L_image(WebPLoadingContext& context, ImageKind image_kind, VP8LHeader const& vp8l_header, LittleEndianInputBitStream& bit_stream) { // https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#623_decoding_entropy-coded_image_data // https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#523_color_cache_coding // spatially-coded-image = color-cache-info meta-prefix data + // entropy-coded-image = color-cache-info data // color-cache-info = %b0 // color-cache-info =/ (%b1 4BIT) ; 1 followed by color cache size @@ -469,13 +475,15 @@ static ErrorOr<NonnullRefPtr<Bitmap>> decode_webp_chunk_VP8L_image(WebPLoadingCo TRY(color_cache.try_resize(color_cache_size)); } - // https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#622_decoding_of_meta_prefix_codes - // "Meta prefix codes may be used only when the image is being used in the role of an ARGB image." - // meta-prefix = %b0 / (%b1 entropy-image) - bool has_meta_prefix = TRY(bit_stream.read_bits(1)); - dbgln_if(WEBP_DEBUG, "has_meta_prefix {}", has_meta_prefix); - if (has_meta_prefix) - return context.error("WebPImageDecoderPlugin: VP8L meta_prefix not yet implemented"); + if (image_kind == ImageKind::SpatiallyCoded) { + // https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#622_decoding_of_meta_prefix_codes + // "Meta prefix codes may be used only when the image is being used in the role of an ARGB image." + // meta-prefix = %b0 / (%b1 entropy-image) + bool has_meta_prefix = TRY(bit_stream.read_bits(1)); + dbgln_if(WEBP_DEBUG, "has_meta_prefix {}", has_meta_prefix); + if (has_meta_prefix) + return context.error("WebPImageDecoderPlugin: VP8L meta_prefix not yet implemented"); + } // https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#52_encoding_of_image_data // "The encoded image data consists of several parts: @@ -673,7 +681,7 @@ static ErrorOr<void> decode_webp_chunk_VP8L(WebPLoadingContext& context, Chunk c } } - context.bitmap = TRY(decode_webp_chunk_VP8L_image(context, vp8l_header, bit_stream)); + context.bitmap = TRY(decode_webp_chunk_VP8L_image(context, ImageKind::SpatiallyCoded, vp8l_header, bit_stream)); return {}; } |