summaryrefslogtreecommitdiff
path: root/Tests/LibGfx
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2023-04-07 18:40:28 -0400
committerLinus Groh <mail@linusgroh.de>2023-04-08 19:24:13 +0200
commitf2efb97578ce8073e063d4c4a486f53e6817f492 (patch)
tree44eeb50cfc048b4b17df805f9e98a216567bf07c /Tests/LibGfx
parent1dab48001590f59aecfa2067cc6f47d739a5f4b2 (diff)
downloadserenity-f2efb97578ce8073e063d4c4a486f53e6817f492.zip
Tests: Add webp lossless test with color index and < 16 colors
For the test files, I opened Base/res/icons/catdog/alert.png in Adobe Photoshop 2023, used Image->Mode->Index Color...-> Palette: Local (Perceptive) to reduce the number of colors to 13, 8, and 3 with transparency, and 2 without transparency, then converted it back to Image->Mode->RGB Color (else it can't be saved as webp), then File->Save a Copy... to save a WebP (mode lossless) for every palette size.
Diffstat (limited to 'Tests/LibGfx')
-rw-r--r--Tests/LibGfx/TestImageDecoder.cpp40
-rw-r--r--Tests/LibGfx/test-inputs/catdog-alert-13.webpbin0 -> 400 bytes
-rw-r--r--Tests/LibGfx/test-inputs/catdog-alert-2.webpbin0 -> 270 bytes
-rw-r--r--Tests/LibGfx/test-inputs/catdog-alert-3.webpbin0 -> 298 bytes
-rw-r--r--Tests/LibGfx/test-inputs/catdog-alert-8.webpbin0 -> 350 bytes
5 files changed, 40 insertions, 0 deletions
diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp
index 74d395fb0a..c8e2ced9a3 100644
--- a/Tests/LibGfx/TestImageDecoder.cpp
+++ b/Tests/LibGfx/TestImageDecoder.cpp
@@ -380,6 +380,46 @@ TEST_CASE(test_webp_simple_lossless_color_index_transform)
EXPECT_EQ(frame.image->get_pixel(100, 100), Gfx::Color(0x73, 0x37, 0x23, 0xff));
}
+TEST_CASE(test_webp_simple_lossless_color_index_transform_pixel_bundling)
+{
+ struct TestCase {
+ StringView file_name;
+ Gfx::Color line_color;
+ Gfx::Color background_color;
+ };
+
+ // The number after the dash is the number of colors in each file's color index bitmap.
+ // catdog-alert-2 tests the 1-bit-per-pixel case,
+ // catdog-alert-3 tests the 2-bit-per-pixel case,
+ // catdog-alert-8 and catdog-alert-13 both test the 4-bits-per-pixel case.
+ TestCase test_cases[] = {
+ { "catdog-alert-2.webp"sv, Gfx::Color(0x35, 0x12, 0x0a, 0xff), Gfx::Color(0xf3, 0xe6, 0xd8, 0xff) },
+ { "catdog-alert-3.webp"sv, Gfx::Color(0x35, 0x12, 0x0a, 0xff), Gfx::Color(0, 0, 0, 0) },
+ { "catdog-alert-8.webp"sv, Gfx::Color(0, 0, 0, 255), Gfx::Color(0, 0, 0, 0) },
+ { "catdog-alert-13.webp"sv, Gfx::Color(0, 0, 0, 255), Gfx::Color(0, 0, 0, 0) },
+ };
+
+ for (auto test_case : test_cases) {
+ auto file = MUST(Core::MappedFile::map(MUST(String::formatted("{}{}", TEST_INPUT(""), test_case.file_name))));
+ EXPECT(Gfx::WebPImageDecoderPlugin::sniff(file->bytes()));
+ auto plugin_decoder = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
+ EXPECT(plugin_decoder->initialize());
+
+ EXPECT_EQ(plugin_decoder->frame_count(), 1u);
+ EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(32, 32));
+
+ auto frame = MUST(plugin_decoder->frame(0));
+ EXPECT_EQ(frame.image->size(), Gfx::IntSize(32, 32));
+
+ EXPECT_EQ(frame.image->get_pixel(4, 0), test_case.background_color);
+ EXPECT_EQ(frame.image->get_pixel(5, 0), test_case.line_color);
+
+ EXPECT_EQ(frame.image->get_pixel(9, 5), test_case.background_color);
+ EXPECT_EQ(frame.image->get_pixel(10, 5), test_case.line_color);
+ EXPECT_EQ(frame.image->get_pixel(11, 5), test_case.background_color);
+ }
+}
+
TEST_CASE(test_webp_extended_lossless_animated)
{
auto file = MUST(Core::MappedFile::map(TEST_INPUT("extended-lossless-animated.webp"sv)));
diff --git a/Tests/LibGfx/test-inputs/catdog-alert-13.webp b/Tests/LibGfx/test-inputs/catdog-alert-13.webp
new file mode 100644
index 0000000000..3c3254d3e2
--- /dev/null
+++ b/Tests/LibGfx/test-inputs/catdog-alert-13.webp
Binary files differ
diff --git a/Tests/LibGfx/test-inputs/catdog-alert-2.webp b/Tests/LibGfx/test-inputs/catdog-alert-2.webp
new file mode 100644
index 0000000000..5a675b9450
--- /dev/null
+++ b/Tests/LibGfx/test-inputs/catdog-alert-2.webp
Binary files differ
diff --git a/Tests/LibGfx/test-inputs/catdog-alert-3.webp b/Tests/LibGfx/test-inputs/catdog-alert-3.webp
new file mode 100644
index 0000000000..c6a178d499
--- /dev/null
+++ b/Tests/LibGfx/test-inputs/catdog-alert-3.webp
Binary files differ
diff --git a/Tests/LibGfx/test-inputs/catdog-alert-8.webp b/Tests/LibGfx/test-inputs/catdog-alert-8.webp
new file mode 100644
index 0000000000..2d355dc0b8
--- /dev/null
+++ b/Tests/LibGfx/test-inputs/catdog-alert-8.webp
Binary files differ