summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2023-05-29 19:19:29 -0400
committerAndreas Kling <kling@serenityos.org>2023-05-30 06:14:56 +0200
commitb7e31ba19499f7be8f89fb0d2a4b5adb7b30d8a1 (patch)
tree7111a7e6730c08d3efc96ca59d812a0e34a8ddf0
parenta22cbc9a2814071279cdc29f1ca966819eba0cf3 (diff)
downloadserenity-b7e31ba19499f7be8f89fb0d2a4b5adb7b30d8a1.zip
WebP/Lossy: Add test for lossy webp with uncompressed alpha
The alpha channel of a lossy webp is always stored separately from the (lossy) RGB data. Alpha is either compressed in a lossless webp that stores just the alpha data, or it's stored completely uncompressed. (But again, even if it's compressed, it's losslessly compressed.) This adds a test for uncompressed alpha, which I hadn't tested before. It seems to work correctly, though :^) I generated the test image by running: ~/Downloads/libwebp-1.3.0-mac-arm64/bin/cwebp \ -alpha_method 0 \ Tests/LibGfx/test-inputs/extended-lossless.webp \ -o Tests/LibGfx/test-inputs/extended-lossy-uncompressed-alpha.webp
-rw-r--r--Tests/LibGfx/TestImageDecoder.cpp25
-rw-r--r--Tests/LibGfx/test-inputs/extended-lossy-uncompressed-alpha.webpbin0 -> 95004 bytes
2 files changed, 25 insertions, 0 deletions
diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp
index 5ab61de362..6900920b34 100644
--- a/Tests/LibGfx/TestImageDecoder.cpp
+++ b/Tests/LibGfx/TestImageDecoder.cpp
@@ -379,6 +379,31 @@ TEST_CASE(test_webp_extended_lossy)
EXPECT_EQ(frame.image->get_pixel(341, 75), Gfx::Color(0, 0, 0, 128));
}
+TEST_CASE(test_webp_extended_lossy_uncompressed_alpha)
+{
+ auto file = MUST(Core::MappedFile::map(TEST_INPUT("extended-lossy-uncompressed-alpha.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(417, 223));
+
+ auto frame = MUST(plugin_decoder->frame(0));
+ EXPECT_EQ(frame.image->size(), Gfx::IntSize(417, 223));
+
+ // While VP8 YUV contents are defined bit-exact, the YUV->RGB conversion isn't.
+ // So pixels changing by 1 or so below is fine if you change code.
+ EXPECT_EQ(frame.image->get_pixel(89, 72), Gfx::Color(255, 0, 4, 255));
+ EXPECT_EQ(frame.image->get_pixel(174, 69), Gfx::Color(4, 255, 0, 255));
+ EXPECT_EQ(frame.image->get_pixel(245, 84), Gfx::Color(0, 0, 255, 255));
+ EXPECT_EQ(frame.image->get_pixel(352, 125), Gfx::Color(0, 0, 0, 128));
+ EXPECT_EQ(frame.image->get_pixel(355, 106), Gfx::Color(0, 0, 0, 0));
+}
+
TEST_CASE(test_webp_lossy_5)
{
// This is https://commons.wikimedia.org/wiki/File:Fr%C3%BChling_bl%C3%BChender_Kirschenbaum.jpg,
diff --git a/Tests/LibGfx/test-inputs/extended-lossy-uncompressed-alpha.webp b/Tests/LibGfx/test-inputs/extended-lossy-uncompressed-alpha.webp
new file mode 100644
index 0000000000..27800164f4
--- /dev/null
+++ b/Tests/LibGfx/test-inputs/extended-lossy-uncompressed-alpha.webp
Binary files differ