LibGfx: Use libjxl to decode JPEG XL images

It currently doesn't support animated image.

Note that Gfx::Bitmap has no support for get_pixel when the format is
RGBA8888. This is why it has been removed from the tests.
This commit is contained in:
Lucas CHOLLET 2024-07-21 17:23:28 -04:00 committed by Andreas Kling
parent d417b75683
commit 1039561280
Notes: github-actions[bot] 2024-07-22 07:16:05 +00:00
6 changed files with 124 additions and 2652 deletions

View file

@ -986,27 +986,6 @@ TEST_CASE(test_jxl_modular_simple_tree_upsample2_10bits)
TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 128, 128 })); TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 128, 128 }));
auto frame = TRY_OR_FAIL(plugin_decoder->frame(0)); auto frame = TRY_OR_FAIL(plugin_decoder->frame(0));
EXPECT_EQ(frame.image->get_pixel(42, 57), Gfx::Color::from_string("#4c0072"sv));
}
TEST_CASE(test_jxl_modular_property_8)
{
auto file = TRY_OR_FAIL(Core::MappedFile::map(TEST_INPUT("jxl/modular_property_8.jxl"sv)));
EXPECT(Gfx::JPEGXLImageDecoderPlugin::sniff(file->bytes()));
auto plugin_decoder = TRY_OR_FAIL(Gfx::JPEGXLImageDecoderPlugin::create(file->bytes()));
TRY_OR_FAIL(expect_single_frame_of_size(*plugin_decoder, { 32, 32 }));
auto frame = TRY_OR_FAIL(plugin_decoder->frame(0));
for (u8 i = 0; i < 32; ++i) {
for (u8 j = 0; j < 32; ++j) {
auto const color = frame.image->get_pixel(i, j);
if ((i + j) % 2 == 0)
EXPECT_EQ(color, Gfx::Color::Black);
else
EXPECT_EQ(color, Gfx::Color::Yellow);
}
}
} }
TEST_CASE(test_avif_simple_lossy) TEST_CASE(test_avif_simple_lossy)

View file

@ -93,6 +93,7 @@ find_package(JPEG REQUIRED)
find_package(PNG REQUIRED) find_package(PNG REQUIRED)
find_package(LIBAVIF REQUIRED) find_package(LIBAVIF REQUIRED)
find_package(WebP REQUIRED) find_package(WebP REQUIRED)
pkg_check_modules(Jxl REQUIRED IMPORTED_TARGET libjxl)
target_link_libraries(LibGfx PRIVATE PkgConfig::WOFF2 JPEG::JPEG PNG::PNG avif WebP::webp WebP::webpdecoder target_link_libraries(LibGfx PRIVATE PkgConfig::WOFF2 JPEG::JPEG PkgConfig::Jxl PNG::PNG avif WebP::webp WebP::webpdecoder
WebP::webpdemux WebP::libwebpmux) WebP::webpdemux WebP::libwebpmux)

File diff suppressed because it is too large Load diff

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2023, Lucas Chollet <lucas.chollet@serenityos.org> * Copyright (c) 2023-2024, Lucas Chollet <lucas.chollet@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -30,7 +30,7 @@ public:
virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) override; virtual ErrorOr<ImageFrameDescriptor> frame(size_t index, Optional<IntSize> ideal_size = {}) override;
private: private:
JPEGXLImageDecoderPlugin(NonnullOwnPtr<FixedMemoryStream>); JPEGXLImageDecoderPlugin(OwnPtr<JPEGXLLoadingContext>);
OwnPtr<JPEGXLLoadingContext> m_context; OwnPtr<JPEGXLLoadingContext> m_context;
}; };

View file

@ -7,6 +7,7 @@
}, },
"icu", "icu",
"libjpeg-turbo", "libjpeg-turbo",
"libjxl",
{ {
"name": "libpng", "name": "libpng",
"features": [ "features": [
@ -70,6 +71,10 @@
"name": "libjpeg-turbo", "name": "libjpeg-turbo",
"version": "3.0.2" "version": "3.0.2"
}, },
{
"name": "libjxl",
"version": "0.10.2"
},
{ {
"name": "libpng", "name": "libpng",
"version": "1.6.43#1" "version": "1.6.43#1"