mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
TestImageWriter: Add a test for writing a webp animation
This commit is contained in:
parent
f506818052
commit
4b1c1d1cae
Notes:
sideshowbarker
2024-07-17 00:59:43 +09:00
Author: https://github.com/nico Commit: https://github.com/SerenityOS/serenity/commit/4b1c1d1cae Pull-request: https://github.com/SerenityOS/serenity/pull/24269 Reviewed-by: https://github.com/LucasChollet ✅ Reviewed-by: https://github.com/trflynn89
1 changed files with 31 additions and 0 deletions
|
@ -145,3 +145,34 @@ TEST_CASE(test_webp_icc)
|
|||
auto reencoded_icc_data = TRY_OR_FAIL(Gfx::ICC::encode(decoded_rgba_profile));
|
||||
EXPECT_EQ(sRGB_icc_data, reencoded_icc_data);
|
||||
}
|
||||
|
||||
TEST_CASE(test_webp_animation)
|
||||
{
|
||||
auto rgb_bitmap = TRY_OR_FAIL(create_test_rgb_bitmap());
|
||||
auto rgba_bitmap = TRY_OR_FAIL(create_test_rgba_bitmap());
|
||||
|
||||
// 20 kiB is enough for two 47x33 frames.
|
||||
auto stream_buffer = TRY_OR_FAIL(ByteBuffer::create_uninitialized(20 * 1024));
|
||||
FixedMemoryStream stream { Bytes { stream_buffer } };
|
||||
|
||||
auto animation_writer = TRY_OR_FAIL(Gfx::WebPWriter::start_encoding_animation(stream, rgb_bitmap->size()));
|
||||
|
||||
TRY_OR_FAIL(animation_writer->add_frame(*rgb_bitmap, 100));
|
||||
TRY_OR_FAIL(animation_writer->add_frame(*rgba_bitmap, 200));
|
||||
|
||||
auto encoded_animation = ReadonlyBytes { stream_buffer.data(), stream.offset() };
|
||||
|
||||
auto decoded_animation_plugin = TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(encoded_animation));
|
||||
EXPECT(decoded_animation_plugin->is_animated());
|
||||
EXPECT_EQ(decoded_animation_plugin->frame_count(), 2u);
|
||||
EXPECT_EQ(decoded_animation_plugin->loop_count(), 0u);
|
||||
EXPECT_EQ(decoded_animation_plugin->size(), rgb_bitmap->size());
|
||||
|
||||
auto frame0 = TRY_OR_FAIL(decoded_animation_plugin->frame(0));
|
||||
EXPECT_EQ(frame0.duration, 100);
|
||||
expect_bitmaps_equal(*frame0.image, *rgb_bitmap);
|
||||
|
||||
auto frame1 = TRY_OR_FAIL(decoded_animation_plugin->frame(1));
|
||||
EXPECT_EQ(frame1.duration, 200);
|
||||
expect_bitmaps_equal(*frame1.image, *rgba_bitmap);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue