mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
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.
This commit is contained in:
parent
e13c319972
commit
d15dc28833
1 changed files with 5 additions and 5 deletions
|
@ -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 };
|
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 "));
|
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.
|
// Uncomment this to test ALPH decoding for WebP-lossy-with-alpha images while lossy decoding isn't implemented yet.
|
||||||
#if 0
|
#if 0
|
||||||
auto vp8_header = TRY(decode_webp_chunk_VP8_header(vp8_chunk));
|
auto vp8_header = TRY(decode_webp_chunk_VP8_header(vp8_chunk));
|
||||||
|
return Bitmap::create(bitmap_format, { vp8_header.width, vp8_header.height });
|
||||||
// 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 });
|
|
||||||
#else
|
#else
|
||||||
// FIXME: Implement webp lossy decoding.
|
// FIXME: Implement webp lossy decoding.
|
||||||
|
(void)bitmap_format;
|
||||||
return Error::from_string_literal("WebPImageDecoderPlugin: decoding lossy webps not yet implemented");
|
return Error::from_string_literal("WebPImageDecoderPlugin: decoding lossy webps not yet implemented");
|
||||||
#endif
|
#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 "));
|
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())
|
if (image_data.alpha_chunk.has_value())
|
||||||
TRY(decode_webp_chunk_ALPH(image_data.alpha_chunk.value(), *bitmap));
|
TRY(decode_webp_chunk_ALPH(image_data.alpha_chunk.value(), *bitmap));
|
||||||
|
|
Loading…
Add table
Reference in a new issue