From 6151a251f5725559110c683e571f7679c03142db Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 7 Apr 2023 15:21:57 -0400 Subject: [PATCH] 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@0825faa4c10d622f2 (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. --- Tests/LibGfx/TestImageDecoder.cpp | 20 ++++++++++++++++++++ Tests/LibGfx/test-inputs/Qpalette.webp | Bin 0 -> 4658 bytes 2 files changed, 20 insertions(+) create mode 100644 Tests/LibGfx/test-inputs/Qpalette.webp diff --git a/Tests/LibGfx/TestImageDecoder.cpp b/Tests/LibGfx/TestImageDecoder.cpp index 7ff34a1c49..74d395fb0a 100644 --- a/Tests/LibGfx/TestImageDecoder.cpp +++ b/Tests/LibGfx/TestImageDecoder.cpp @@ -360,6 +360,26 @@ TEST_CASE(test_webp_extended_lossless) 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) { auto file = MUST(Core::MappedFile::map(TEST_INPUT("extended-lossless-animated.webp"sv))); diff --git a/Tests/LibGfx/test-inputs/Qpalette.webp b/Tests/LibGfx/test-inputs/Qpalette.webp new file mode 100644 index 0000000000000000000000000000000000000000..56e05311c47c7dcd653b8a67397c16d74920e938 GIT binary patch literal 4658 zcmWIYbaT@ZVqge&bqWXzu<(%;Vqnn!f54t$zWVj8+mbJ@d*rvzdZzVE{_i)o^-h|5 z`(+JJTIS|0xwk({@6CN}a%EfY;UqqyK?)n=BB0w%}a7M^}nkhq+qrIw+%!9d9} zYp$$JLnr?mF-OKi2Ie{jW{Cp~%Rc4&wJ~=(!n}Yr4a4Mc1z-O&JqhPN?OExS{nUt6u(ZQynUBiG=^S6yKGVO^eADlV zV&x^~u%k0K^UvLI{b<~@qn|kH?)CJF>BiXv9htpdzn3xbSPy6YDj%ctrze&5JvJoR zdvyzns`Q(0eG>R@QERZTS+|(ZjSLk@frq?511ui-^SI;4K>XAJ4(U)aalf0HuP^fE5}jLj!?mAQcVRq5*a^;ExKO8R$jM+L`^pn?{sg#j8OT&++F8fsAL@WTQN z8NPN1_53j^5Ee%T;lZfj@^w_OeG4imDMAIGzM%p>G~nlf3Qn9s1%LjFqs0v`TH0)% zfdc)fFF^y#P{FhR z@kkNrv@ifE7aUA5Ktv=cJ`K@8C>lVG%HUwsMC9&{T1wUbN6S?!rl5gKXy6$dIEMx% zq5;%W_~y;6XyAXnBpPT%16xs3-y} zEp()$Q9*PBD!6eE6`=an&Tii>R8Uoi3jX~sFGK@bXaLoL87p?9fsJSYwOn7LV~Pfh zP{F11XaFrmpSytyBG4+@iL=o_CmLu$1uUqgulV=>_wS;CuV`Q<8bE7GJnTaQs5Q&4 zUx(1Z6Ex6)3OLHqKrtFX&49VNf~a8P|LO1Fp#neD)`dT6EfL^ zRw8Gi_Pv~(kQ?p?AN;T1xdRoLpcTQnIjG>!VN`&Y`iryC09yNy9WC;gZ%557+tA9# zK0P#$hnCvrqjomu#i48y|GD!~!F{xb5PA$&qP1dj(Ske*ErxfZ0Y{Vs umx1P=`*%>m9#rS