mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:37:35 +00:00
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.)
This commit is contained in:
parent
625b29f507
commit
95e35b7f5e
5 changed files with 31 additions and 7 deletions
|
@ -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)));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue