mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:37:46 +00:00
LibGfx: Teach webp image reading function to read entropy coded images
This commit is contained in:
parent
4bd7090bc5
commit
48f88b3cdd
1 changed files with 17 additions and 9 deletions
|
@ -443,11 +443,17 @@ static ErrorOr<PrefixCodeGroup> decode_webp_chunk_VP8L_prefix_code_group(WebPLoa
|
||||||
return group;
|
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#623_decoding_entropy-coded_image_data
|
||||||
// https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#523_color_cache_coding
|
// https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#523_color_cache_coding
|
||||||
// spatially-coded-image = color-cache-info meta-prefix data
|
// spatially-coded-image = color-cache-info meta-prefix data
|
||||||
|
// entropy-coded-image = color-cache-info data
|
||||||
|
|
||||||
// color-cache-info = %b0
|
// color-cache-info = %b0
|
||||||
// color-cache-info =/ (%b1 4BIT) ; 1 followed by color cache size
|
// 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));
|
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
|
if (image_kind == ImageKind::SpatiallyCoded) {
|
||||||
// "Meta prefix codes may be used only when the image is being used in the role of an ARGB image."
|
// https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#622_decoding_of_meta_prefix_codes
|
||||||
// meta-prefix = %b0 / (%b1 entropy-image)
|
// "Meta prefix codes may be used only when the image is being used in the role of an ARGB image."
|
||||||
bool has_meta_prefix = TRY(bit_stream.read_bits(1));
|
// meta-prefix = %b0 / (%b1 entropy-image)
|
||||||
dbgln_if(WEBP_DEBUG, "has_meta_prefix {}", has_meta_prefix);
|
bool has_meta_prefix = TRY(bit_stream.read_bits(1));
|
||||||
if (has_meta_prefix)
|
dbgln_if(WEBP_DEBUG, "has_meta_prefix {}", has_meta_prefix);
|
||||||
return context.error("WebPImageDecoderPlugin: VP8L meta_prefix not yet implemented");
|
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
|
// https://developers.google.com/speed/webp/docs/webp_lossless_bitstream_specification#52_encoding_of_image_data
|
||||||
// "The encoded image data consists of several parts:
|
// "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 {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue