summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2023-04-08 17:50:54 -0400
committerLinus Groh <mail@linusgroh.de>2023-04-09 00:14:15 +0200
commit95e35b7f5ecc4528a2feda60b371ddae71a4203e (patch)
tree9f8bd449a9ded213af38ac69592a2fd0fee0a8e8 /Tests
parent625b29f507343025dd957804f56f77c78fd9f721 (diff)
downloadserenity-95e35b7f5ecc4528a2feda60b371ddae71a4203e.zip
LibGfx: Correctly decode webp lossless with small palette and odd width
WebP lossless files that use a color indexing transform with <= 16 colors use pixel bundling to pack 2, 4, or 8 pixels into a single pixel. If the image's width doesn't happen to be an exact multiple of the bundling factor, we need to: 1. Use ceil_div() instead of just dividing the width by the bundling factor 2. Remember the original width and use it instead of computing reduced width times bundling factor This does these changes, and adds a simple test for it -- it at least checks that the decoded images have the right size. (I created these images myself in Photoshop, and used the same technique as for Tests/LibGfx/test-inputs/catdog-alert-*.webp to create images with a certain number of colors.)
Diffstat (limited to 'Tests')
-rw-r--r--Tests/LibGfx/TestImageDecoder.cpp21
-rw-r--r--Tests/LibGfx/test-inputs/width11-height11-colors15.webpbin0 -> 228 bytes
-rw-r--r--Tests/LibGfx/test-inputs/width11-height11-colors2.webpbin0 -> 172 bytes
-rw-r--r--Tests/LibGfx/test-inputs/width11-height11-colors3.webpbin0 -> 190 bytes
4 files changed, 21 insertions, 0 deletions
diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp
index c8e2ced9a3..4a843d37e0 100644
--- a/Tests/LibGfx/TestImageDecoder.cpp
+++ b/Tests/LibGfx/TestImageDecoder.cpp
@@ -420,6 +420,27 @@ TEST_CASE(test_webp_simple_lossless_color_index_transform_pixel_bundling)
}
}
+TEST_CASE(test_webp_simple_lossless_color_index_transform_pixel_bundling_odd_width)
+{
+ StringView file_names[] = {
+ "width11-height11-colors2.webp"sv,
+ "width11-height11-colors3.webp"sv,
+ "width11-height11-colors15.webp"sv,
+ };
+
+ for (auto file_name : file_names) {
+ auto file = MUST(Core::MappedFile::map(MUST(String::formatted("{}{}", TEST_INPUT(""), file_name))));
+ 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(11, 11));
+
+ auto frame = MUST(plugin_decoder->frame(0));
+ EXPECT_EQ(frame.image->size(), Gfx::IntSize(11, 11));
+ }
+}
+
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/width11-height11-colors15.webp b/Tests/LibGfx/test-inputs/width11-height11-colors15.webp
new file mode 100644
index 0000000000..cfb395d11a
--- /dev/null
+++ b/Tests/LibGfx/test-inputs/width11-height11-colors15.webp
Binary files differ
diff --git a/Tests/LibGfx/test-inputs/width11-height11-colors2.webp b/Tests/LibGfx/test-inputs/width11-height11-colors2.webp
new file mode 100644
index 0000000000..8e213bda95
--- /dev/null
+++ b/Tests/LibGfx/test-inputs/width11-height11-colors2.webp
Binary files differ
diff --git a/Tests/LibGfx/test-inputs/width11-height11-colors3.webp b/Tests/LibGfx/test-inputs/width11-height11-colors3.webp
new file mode 100644
index 0000000000..c11285c401
--- /dev/null
+++ b/Tests/LibGfx/test-inputs/width11-height11-colors3.webp
Binary files differ