diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index 998804bacf5..5787845c25b 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -342,10 +342,33 @@ TEST_CASE(test_webp_simple_lossless) auto frame = MUST(plugin_decoder->frame(0)); EXPECT_EQ(frame.image->size(), Gfx::IntSize(386, 395)); + EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(0, 0, 0, 0)); + // This pixel tests all predictor modes except 5, 7, 8, 9, and 13. EXPECT_EQ(frame.image->get_pixel(289, 332), Gfx::Color(0xf2, 0xee, 0xd3, 255)); } +TEST_CASE(test_webp_simple_lossless_alpha_used_false) +{ + // This file is identical to simple-vp8l.webp, but the `is_alpha_used` used bit is false. + // The file still contains alpha data. This tests that the decoder replaces the stored alpha data with 0xff if `is_alpha_used` is false. + auto file = MUST(Core::MappedFile::map(TEST_INPUT("simple-vp8l-alpha-used-false.webp"sv))); + EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes())); + auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes())); + MUST(plugin_decoder->initialize()); + + EXPECT_EQ(plugin_decoder->frame_count(), 1u); + EXPECT(!plugin_decoder->is_animated()); + EXPECT(!plugin_decoder->loop_count()); + + EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(386, 395)); + + auto frame = MUST(plugin_decoder->frame(0)); + EXPECT_EQ(frame.image->size(), Gfx::IntSize(386, 395)); + + EXPECT_EQ(frame.image->get_pixel(0, 0), Gfx::Color(0, 0, 0, 0xff)); +} + TEST_CASE(test_webp_extended_lossy) { // This extended lossy image has an ALPH chunk for (losslessly compressed) alpha data. diff --git a/Tests/LibGfx/test-inputs/simple-vp8l-alpha-used-false.webp b/Tests/LibGfx/test-inputs/simple-vp8l-alpha-used-false.webp new file mode 100644 index 00000000000..67fc16f8ed6 Binary files /dev/null and b/Tests/LibGfx/test-inputs/simple-vp8l-alpha-used-false.webp differ diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossless.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossless.cpp index 139250e0ec6..92ff7bffc86 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossless.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossless.cpp @@ -1000,6 +1000,9 @@ ErrorOr> decode_webp_chunk_VP8L_contents(VP8LHeader const& for (auto const& transform : transforms.in_reverse()) bitmap = TRY(transform->transform(bitmap)); + if (!vp8l_header.is_alpha_used) + bitmap->strip_alpha_channel(); + return bitmap; }