Tests: Add test for lossless webp file using a color indexing tranform

The image is https://quakewiki.org/wiki/File:Qpalette.png in lossless
webp format with a color indexing transform.

I've created Qpalette.webp by running

    examples/cwebp -z 0 ~/src/serenity/tmp.ppm -o Qpalette.webp

built at libwebp webmproject/libwebp@0825faa4c1 (without
png support, so I first ran

    Build/lagom/image ~/Downloads/Qpalette.png -o tmp.ppm

to convert it from png to a format my cwebp binary could read).

This file also happens to explicitly set max_symbol, so it serves
as a test for that code path as well.
This commit is contained in:
Nico Weber 2023-04-07 15:21:57 -04:00 committed by Linus Groh
parent 24967b0d29
commit 6151a251f5
Notes: sideshowbarker 2024-07-17 08:36:27 +09:00
2 changed files with 20 additions and 0 deletions

View File

@ -360,6 +360,26 @@ TEST_CASE(test_webp_extended_lossless)
EXPECT_EQ(frame.image->get_pixel(359, 73), Gfx::Color(0, 0, 0, 128)); EXPECT_EQ(frame.image->get_pixel(359, 73), Gfx::Color(0, 0, 0, 128));
} }
TEST_CASE(test_webp_simple_lossless_color_index_transform)
{
// In addition to testing the index transform, this file also tests handling of explicity setting max_symbol.
auto file = MUST(Core::MappedFile::map(TEST_INPUT("Qpalette.webp"sv)));
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(!plugin_decoder->is_animated());
EXPECT(!plugin_decoder->loop_count());
EXPECT_EQ(plugin_decoder->size(), Gfx::IntSize(256, 256));
auto frame = MUST(plugin_decoder->frame(0));
EXPECT_EQ(frame.image->size(), Gfx::IntSize(256, 256));
EXPECT_EQ(frame.image->get_pixel(100, 100), Gfx::Color(0x73, 0x37, 0x23, 0xff));
}
TEST_CASE(test_webp_extended_lossless_animated) TEST_CASE(test_webp_extended_lossless_animated)
{ {
auto file = MUST(Core::MappedFile::map(TEST_INPUT("extended-lossless-animated.webp"sv))); auto file = MUST(Core::MappedFile::map(TEST_INPUT("extended-lossless-animated.webp"sv)));

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB