diff --git a/Tests/LibGfx/CMakeLists.txt b/Tests/LibGfx/CMakeLists.txt index 9345fa930c..b5b928039f 100644 --- a/Tests/LibGfx/CMakeLists.txt +++ b/Tests/LibGfx/CMakeLists.txt @@ -1,6 +1,7 @@ set(TEST_SOURCES BenchmarkGfxPainter.cpp TestFontHandling.cpp + TestICCProfile.cpp TestImageDecoder.cpp ) diff --git a/Tests/LibGfx/TestICCProfile.cpp b/Tests/LibGfx/TestICCProfile.cpp new file mode 100644 index 0000000000..1ad04195cf --- /dev/null +++ b/Tests/LibGfx/TestICCProfile.cpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023, Nico Weber + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include +#include + +#ifdef AK_OS_SERENITY +# define TEST_INPUT(x) ("/usr/Tests/LibGfx/test-inputs/" x) +#else +# define TEST_INPUT(x) ("test-inputs/" x) +#endif + +TEST_CASE(png) +{ + auto file = MUST(Core::MappedFile::map(TEST_INPUT("icc-v2.png"sv))); + auto png = MUST(Gfx::PNGImageDecoderPlugin::create(file->bytes())); + EXPECT(png->initialize()); + auto icc_bytes = MUST(png->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(jpg) +{ + auto file = MUST(Core::MappedFile::map(TEST_INPUT("icc-v4.jpg"sv))); + auto jpg = MUST(Gfx::JPGImageDecoderPlugin::create(file->bytes())); + EXPECT(jpg->initialize()); + auto icc_bytes = MUST(jpg->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_v4()); +} diff --git a/Tests/LibGfx/test-inputs/icc-v2.png b/Tests/LibGfx/test-inputs/icc-v2.png new file mode 100644 index 0000000000..2062d8994c Binary files /dev/null and b/Tests/LibGfx/test-inputs/icc-v2.png differ diff --git a/Tests/LibGfx/test-inputs/icc-v4.jpg b/Tests/LibGfx/test-inputs/icc-v4.jpg new file mode 100644 index 0000000000..23927fb9f1 Binary files /dev/null and b/Tests/LibGfx/test-inputs/icc-v4.jpg differ