From d8103247d9eeeb42083cea67ded448dcf4a4f5fb Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 31 May 2024 13:33:39 -0400 Subject: [PATCH] Tests: Check that color indexing reduces file size --- Tests/LibGfx/TestImageWriter.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Tests/LibGfx/TestImageWriter.cpp b/Tests/LibGfx/TestImageWriter.cpp index c9cbd84456..be10b09a51 100644 --- a/Tests/LibGfx/TestImageWriter.cpp +++ b/Tests/LibGfx/TestImageWriter.cpp @@ -203,7 +203,16 @@ TEST_CASE(test_webp_color_indexing_transform) for (int x = 0; x < bitmap->width(); ++x) bitmap->set_pixel(x, y, colors[(x * bitmap->width() + y) % number_of_colors]); - TRY_OR_FAIL((test_roundtrip(bitmap))); + auto encoded_data = TRY_OR_FAIL(encode_bitmap(bitmap)); + auto decoded_bitmap = TRY_OR_FAIL(expect_single_frame_of_size(*TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(encoded_data)), bitmap->size())); + expect_bitmaps_equal(*decoded_bitmap, *bitmap); + + Gfx::WebPEncoderOptions options; + options.vp8l_options.allowed_transforms = 0; + auto encoded_data_without_color_indexing = TRY_OR_FAIL(encode_bitmap(bitmap, options)); + EXPECT(encoded_data.size() < encoded_data_without_color_indexing.size()); + auto decoded_bitmap_without_color_indexing = TRY_OR_FAIL(expect_single_frame_of_size(*TRY_OR_FAIL(Gfx::WebPImageDecoderPlugin::create(encoded_data)), bitmap->size())); + expect_bitmaps_equal(*decoded_bitmap_without_color_indexing, *decoded_bitmap); } }