1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-09 09:34:57 +09:00

LibGfx: Set correct alpha type for webp decoding

The libwebp decoder gives us unpremultiplied color data, so mark our
bitmaps as such.
This commit is contained in:
Jelle Raaijmakers 2024-10-02 13:44:50 +02:00 committed by Sam Atkins
parent 07300a5bb4
commit 768d814ffd
Notes: github-actions[bot] 2024-10-02 20:04:31 +00:00
3 changed files with 15 additions and 2 deletions

View file

@ -927,6 +927,19 @@ TEST_CASE(test_webp_extended_lossless_animated)
}
}
TEST_CASE(test_webp_unpremultiplied_alpha)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("webp/semi-transparent-pixel.webp"sv)));
EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
auto plugin_decoder = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
auto frame = TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 1, 1 }));
// Webp decodes with unpremultiplied color data, so {R,G,B} can be >A (unlike with premultiplied colors).
EXPECT_EQ(frame.image->alpha_type(), Gfx::AlphaType::Unpremultiplied);
EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(255, 255, 255, 128));
}
TEST_CASE(test_tvg)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("tvg/yak.tvg"sv)));