1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:17:44 +00:00

LibGfx+Tests: Add test for webp ICC loading and fix bug

I drew the two webp files in Photoshop and saved them using the
"Save a Copy..." dialog, with ICC profile and all other boxes checked.

(I also tried saving with all the boxes unchecked, but it still wrote an
extended webp instead of a basic file.)

The lossless file exposed a bug: I didn't handle chunk padding
correctly before this patch.
This commit is contained in:
Nico Weber 2023-02-24 14:04:21 -05:00 committed by Linus Groh
parent 7485521619
commit 14c0bae704
4 changed files with 45 additions and 0 deletions

View file

@ -9,6 +9,7 @@
#include <LibGfx/ICC/Profile.h>
#include <LibGfx/JPEGLoader.h>
#include <LibGfx/PNGLoader.h>
#include <LibGfx/WebPLoader.h>
#include <LibTest/TestCase.h>
#ifdef AK_OS_SERENITY
@ -41,6 +42,30 @@ TEST_CASE(jpg)
EXPECT(icc_profile->is_v4());
}
TEST_CASE(webp_extended_lossless)
{
auto file = MUST(Core::MappedFile::map(TEST_INPUT("extended-lossless.webp"sv)));
auto webp = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
EXPECT(webp->initialize());
auto icc_bytes = MUST(webp->icc_data());
EXPECT(icc_bytes.has_value());
auto icc_profile = MUST(Gfx::ICC::Profile::try_load_from_externally_owned_memory(icc_bytes.value()));
EXPECT(icc_profile->is_v2());
}
TEST_CASE(webp_extended_lossy)
{
auto file = MUST(Core::MappedFile::map(TEST_INPUT("extended-lossy.webp"sv)));
auto webp = MUST(Gfx::WebPImageDecoderPlugin::create(file->bytes()));
EXPECT(webp->initialize());
auto icc_bytes = MUST(webp->icc_data());
EXPECT(icc_bytes.has_value());
auto icc_profile = MUST(Gfx::ICC::Profile::try_load_from_externally_owned_memory(icc_bytes.value()));
EXPECT(icc_profile->is_v2());
}
TEST_CASE(serialize_icc)
{
auto file = MUST(Core::MappedFile::map(TEST_INPUT("p3-v4.icc"sv)));