diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 9fa7da25c39..24469211506 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -366,12 +366,14 @@ jobs: run: | set -x sudo cmake --build build -- install + if [[ "${RUNNER_OS}" == "Linux" ]]; then sudo ldconfig; fi # GCC does not know how to refer to shared libraries properly export CC=clang export CXX=clang++ cmake -Bbuild-example -Hexamples -G Ninja cmake --build build-example # Test that the built binaries run. + build-example/gain_map_api_roundtrip echo -e -n "PF\n1 1\n-1.0\n\0\0\x80\x3f\0\0\x80\x3f\0\0\x80\x3f" > test.pfm build-example/encode_oneshot test.pfm test.jxl build-example/decode_oneshot test.jxl dec.pfm dec.icc diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 4c5d08023ab..e4f952347e3 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -12,6 +12,7 @@ project(SAMPLE_LIBJXL LANGUAGES C CXX) # Use pkg-config to find libjxl. find_package(PkgConfig) pkg_check_modules(Jxl REQUIRED IMPORTED_TARGET libjxl libjxl_cms libjxl_threads) +pkg_check_modules(JxlOnly REQUIRED IMPORTED_TARGET libjxl) # Build the example encoder/decoder binaries using the default shared libraries # installed. @@ -26,3 +27,7 @@ target_link_libraries(decode_progressive PkgConfig::Jxl) add_executable(encode_oneshot encode_oneshot.cc) target_link_libraries(encode_oneshot PkgConfig::Jxl) + +# Exercise the public gain-map and ICC helpers through libjxl alone. +add_executable(gain_map_api_roundtrip gain_map_api_roundtrip.c) +target_link_libraries(gain_map_api_roundtrip PkgConfig::JxlOnly) diff --git a/examples/gain_map_api_roundtrip.c b/examples/gain_map_api_roundtrip.c new file mode 100644 index 00000000000..01d63c69571 --- /dev/null +++ b/examples/gain_map_api_roundtrip.c @@ -0,0 +1,139 @@ +/* Copyright (c) the JPEG XL Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file. + * + * This is a linkage and serialization smoke test with synthetic payloads. It + * does not decode image data or use a valid color profile. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static void* Allocate(void* opaque, size_t size) { + (void)opaque; + return malloc(size); +} + +static void Release(void* opaque, void* address) { + (void)opaque; + free(address); +} + +int main(void) { + /* The ICC codec preserves bytes; these are not a valid color profile. */ + static const uint8_t icc_data[] = { + 0x00, 0x00, 0x00, 0x3c, 's', 'y', 'n', 't', 'h', 'e', 't', 'i', + 'c', '-', 'I', 'C', 'C', '-', 't', 'e', 's', 't', '-', 'd', + 'a', 't', 'a', '-', 'f', 'o', 'r', '-', 'l', 'i', 'b', 'j', + 'x', 'l', 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, + }; + static const uint8_t metadata[] = {0x00, 0x01, 0x02, 0x03, 0x7f, 0xff}; + static const uint8_t gain_map[] = {0xff, 0x00, 0x80, 0x40, 0x20}; + + JxlMemoryManager memory_manager = {NULL, Allocate, Release}; + uint8_t* compressed_icc = NULL; + size_t compressed_icc_size = 0; + uint8_t* decoded_icc = NULL; + size_t decoded_icc_size = 0; + uint8_t* bundle_buffer = NULL; + size_t bundle_size = 0; + size_t bytes_written = 0; + size_t bytes_read = 0; + int result = EXIT_FAILURE; + JxlGainMapBundle input_bundle = {0}; + JxlGainMapBundle output_bundle = {0}; + + if (!JxlICCProfileEncode(&memory_manager, icc_data, sizeof(icc_data), + &compressed_icc, &compressed_icc_size)) { + fprintf(stderr, "JxlICCProfileEncode failed\n"); + goto cleanup; + } + if (compressed_icc_size > UINT32_MAX) { + fprintf(stderr, "compressed ICC data does not fit in a gain map bundle\n"); + goto cleanup; + } + + input_bundle.jhgm_version = 0; + input_bundle.gain_map_metadata_size = sizeof(metadata); + input_bundle.gain_map_metadata = metadata; + input_bundle.has_color_encoding = JXL_TRUE; + JxlColorEncodingSetToLinearSRGB(&input_bundle.color_encoding, JXL_FALSE); + input_bundle.alt_icc_size = (uint32_t)compressed_icc_size; + input_bundle.alt_icc = compressed_icc; + input_bundle.gain_map_size = sizeof(gain_map); + input_bundle.gain_map = gain_map; + + if (!JxlGainMapGetBundleSize(&input_bundle, &bundle_size)) { + fprintf(stderr, "JxlGainMapGetBundleSize failed\n"); + goto cleanup; + } + bundle_buffer = (uint8_t*)malloc(bundle_size); + if (bundle_buffer == NULL) { + fprintf(stderr, "allocating gain map bundle failed\n"); + goto cleanup; + } + if (!JxlGainMapWriteBundle(&input_bundle, bundle_buffer, bundle_size, + &bytes_written)) { + fprintf(stderr, "JxlGainMapWriteBundle failed\n"); + goto cleanup; + } + if (bytes_written != bundle_size) { + fprintf(stderr, "JxlGainMapWriteBundle wrote an unexpected size\n"); + goto cleanup; + } + if (!JxlGainMapReadBundle(&output_bundle, bundle_buffer, bundle_size, + &bytes_read)) { + fprintf(stderr, "JxlGainMapReadBundle failed\n"); + goto cleanup; + } + if (bytes_read != bundle_size || output_bundle.jhgm_version != 0 || + output_bundle.gain_map_metadata_size != sizeof(metadata) || + memcmp(output_bundle.gain_map_metadata, metadata, sizeof(metadata)) != + 0 || + !output_bundle.has_color_encoding || + output_bundle.color_encoding.color_space != + input_bundle.color_encoding.color_space || + output_bundle.color_encoding.white_point != + input_bundle.color_encoding.white_point || + output_bundle.color_encoding.primaries != + input_bundle.color_encoding.primaries || + output_bundle.color_encoding.transfer_function != + input_bundle.color_encoding.transfer_function || + output_bundle.color_encoding.rendering_intent != + input_bundle.color_encoding.rendering_intent || + output_bundle.alt_icc_size != compressed_icc_size || + memcmp(output_bundle.alt_icc, compressed_icc, compressed_icc_size) != 0 || + output_bundle.gain_map_size != sizeof(gain_map) || + memcmp(output_bundle.gain_map, gain_map, sizeof(gain_map)) != 0) { + fprintf(stderr, "gain map bundle roundtrip mismatch\n"); + goto cleanup; + } + if (!JxlICCProfileDecode(&memory_manager, output_bundle.alt_icc, + output_bundle.alt_icc_size, &decoded_icc, + &decoded_icc_size)) { + fprintf(stderr, "ICC byte-stream decode failed\n"); + goto cleanup; + } + if (decoded_icc_size != sizeof(icc_data) || + memcmp(decoded_icc, icc_data, sizeof(icc_data)) != 0) { + fprintf(stderr, "ICC byte-stream roundtrip mismatch\n"); + goto cleanup; + } + + result = EXIT_SUCCESS; + +cleanup: + memory_manager.free(memory_manager.opaque, decoded_icc); + memory_manager.free(memory_manager.opaque, compressed_icc); + free(bundle_buffer); + return result; +} diff --git a/lib/gain_map_public_api_decode_test.c b/lib/gain_map_public_api_decode_test.c new file mode 100644 index 00000000000..51badb9ec27 --- /dev/null +++ b/lib/gain_map_public_api_decode_test.c @@ -0,0 +1,89 @@ +/* Copyright (c) the JPEG XL Project Authors. All rights reserved. + * + * Use of this source code is governed by a BSD-style + * license that can be found in the LICENSE file. + */ + +#include +#include +#include +#include +#include +#include +#include + +/* These fixed bytes were generated once from synthetic data with the public + * bundle and ICC helpers. This test calls only their decoder counterparts. + * The ICC payload is opaque test data, not a color profile. */ +static const uint8_t kSyntheticIccBytes[] = { + 0x00, 0x00, 0x00, 0x3c, 0x73, 0x79, 0x6e, 0x74, 0x68, 0x65, 0x74, 0x69, + 0x63, 0x2d, 0x49, 0x43, 0x43, 0x2d, 0x74, 0x65, 0x73, 0x74, 0x2d, 0x64, + 0x61, 0x74, 0x61, 0x2d, 0x66, 0x6f, 0x72, 0x2d, 0x6c, 0x69, 0x62, 0x6a, + 0x78, 0x6c, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, +}; + +static const uint8_t kGainMapBundleBytes[] = { + 0x00, 0x00, 0x03, 0x10, 0x20, 0x30, 0x03, 0x50, 0xb4, 0x00, 0x00, + 0x00, 0x00, 0x46, 0xb6, 0xc8, 0xf1, 0x7a, 0xd6, 0xe4, 0x3e, 0xc0, + 0x80, 0xcd, 0x5a, 0x55, 0x93, 0xa8, 0xbb, 0x5f, 0x4b, 0x9b, 0x5b, + 0x11, 0x11, 0x49, 0x49, 0xc4, 0x55, 0x10, 0xa5, 0x22, 0xeb, 0x7e, + 0x5f, 0xb4, 0xe0, 0x8f, 0x75, 0xae, 0x5e, 0x85, 0x61, 0xc9, 0x47, + 0x84, 0x8a, 0x88, 0x62, 0xbc, 0x26, 0x0a, 0x93, 0x08, 0xea, 0x9b, + 0x6c, 0x19, 0x9b, 0xb6, 0xeb, 0x87, 0x71, 0x32, 0xf3, 0xb2, 0x6e, + 0xfb, 0x61, 0x39, 0xb6, 0x7b, 0xf2, 0x00, 0xff, 0x00, 0x80, +}; + +static void* Allocate(void* opaque, size_t size) { + (void)opaque; + return malloc(size); +} + +static void Release(void* opaque, void* address) { + (void)opaque; + free(address); +} + +int main(void) { + JxlMemoryManager memory_manager = {NULL, Allocate, Release}; + JxlGainMapBundle bundle = {0}; + uint8_t* icc_bytes = NULL; + size_t icc_size = 0; + size_t bytes_read = 0; + int result = EXIT_FAILURE; + + if (!JxlGainMapReadBundle(&bundle, kGainMapBundleBytes, + sizeof(kGainMapBundleBytes), &bytes_read)) { + fprintf(stderr, "JxlGainMapReadBundle failed\n"); + goto cleanup; + } + if (bytes_read != sizeof(kGainMapBundleBytes) || bundle.jhgm_version != 0 || + bundle.gain_map_metadata_size != 3 || + memcmp(bundle.gain_map_metadata, "\x10\x20\x30", 3) != 0 || + !bundle.has_color_encoding || + bundle.color_encoding.color_space != JXL_COLOR_SPACE_RGB || + bundle.color_encoding.white_point != JXL_WHITE_POINT_D65 || + bundle.color_encoding.primaries != JXL_PRIMARIES_SRGB || + bundle.color_encoding.transfer_function != JXL_TRANSFER_FUNCTION_LINEAR || + bundle.gain_map_size != 3 || + memcmp(bundle.gain_map, "\xff\x00\x80", 3) != 0) { + fprintf(stderr, "gain map reader returned unexpected data\n"); + goto cleanup; + } + if (!JxlICCProfileDecode(&memory_manager, bundle.alt_icc, bundle.alt_icc_size, + &icc_bytes, &icc_size)) { + fprintf(stderr, "JxlICCProfileDecode failed\n"); + goto cleanup; + } + if (icc_size != sizeof(kSyntheticIccBytes) || + memcmp(icc_bytes, kSyntheticIccBytes, sizeof(kSyntheticIccBytes)) != 0) { + fprintf(stderr, "ICC decoder returned unexpected bytes\n"); + goto cleanup; + } + + result = EXIT_SUCCESS; + +cleanup: + memory_manager.free(memory_manager.opaque, icc_bytes); + return result; +} diff --git a/lib/extras/compressed_icc.cc b/lib/jxl/compressed_icc.cc similarity index 58% rename from lib/extras/compressed_icc.cc rename to lib/jxl/compressed_icc.cc index 952f9f38209..590c2a2bad1 100644 --- a/lib/extras/compressed_icc.cc +++ b/lib/jxl/compressed_icc.cc @@ -14,35 +14,9 @@ #include "lib/jxl/base/span.h" #include "lib/jxl/base/status.h" #include "lib/jxl/dec_bit_reader.h" -#include "lib/jxl/enc_aux_out.h" -#include "lib/jxl/enc_bit_writer.h" -#include "lib/jxl/enc_icc_codec.h" #include "lib/jxl/icc_codec.h" #include "lib/jxl/memory_manager_internal.h" -JXL_BOOL JxlICCProfileEncode(const JxlMemoryManager* memory_manager, - const uint8_t* icc, size_t icc_size, - uint8_t** compressed_icc, - size_t* compressed_icc_size) { - JxlMemoryManager local_memory_manager; - if (!jxl::MemoryManagerInit(&local_memory_manager, memory_manager)) { - return JXL_FALSE; - } - jxl::BitWriter writer(&local_memory_manager); - JXL_RETURN_IF_ERROR(jxl::WriteICC(jxl::Span(icc, icc_size), - &writer, jxl::LayerType::Header, nullptr)); - writer.ZeroPadToByte(); - jxl::Bytes bytes = writer.GetSpan(); - *compressed_icc_size = bytes.size(); - *compressed_icc = static_cast( - jxl::MemoryManagerAlloc(&local_memory_manager, *compressed_icc_size)); - if (*compressed_icc == nullptr) { - return JXL_FALSE; - } - memcpy(*compressed_icc, bytes.data(), bytes.size()); - return JXL_TRUE; -} - JXL_BOOL JxlICCProfileDecode(const JxlMemoryManager* memory_manager, const uint8_t* compressed_icc, size_t compressed_icc_size, uint8_t** icc, diff --git a/lib/jxl/enc_compressed_icc.cc b/lib/jxl/enc_compressed_icc.cc new file mode 100644 index 00000000000..5ccc3ba8815 --- /dev/null +++ b/lib/jxl/enc_compressed_icc.cc @@ -0,0 +1,42 @@ +// Copyright (c) the JPEG XL Project Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include +#include +#include + +#include +#include +#include + +#include "lib/jxl/base/span.h" +#include "lib/jxl/base/status.h" +#include "lib/jxl/enc_aux_out.h" +#include "lib/jxl/enc_bit_writer.h" +#include "lib/jxl/enc_icc_codec.h" +#include "lib/jxl/memory_manager_internal.h" + +JXL_BOOL JxlICCProfileEncode(const JxlMemoryManager* memory_manager, + const uint8_t* icc, size_t icc_size, + uint8_t** compressed_icc, + size_t* compressed_icc_size) { + JxlMemoryManager local_memory_manager; + if (!jxl::MemoryManagerInit(&local_memory_manager, memory_manager)) { + return JXL_FALSE; + } + jxl::BitWriter writer(&local_memory_manager); + JXL_RETURN_IF_ERROR(jxl::WriteICC(jxl::Span(icc, icc_size), + &writer, jxl::LayerType::Header, nullptr)); + writer.ZeroPadToByte(); + jxl::Bytes bytes = writer.GetSpan(); + *compressed_icc_size = bytes.size(); + *compressed_icc = static_cast( + jxl::MemoryManagerAlloc(&local_memory_manager, *compressed_icc_size)); + if (*compressed_icc == nullptr) { + return JXL_FALSE; + } + memcpy(*compressed_icc, bytes.data(), bytes.size()); + return JXL_TRUE; +} diff --git a/lib/extras/gain_map.cc b/lib/jxl/enc_gain_map.cc similarity index 62% rename from lib/extras/gain_map.cc rename to lib/jxl/enc_gain_map.cc index 36adb9c5b9e..3528a9ba139 100644 --- a/lib/extras/gain_map.cc +++ b/lib/jxl/enc_gain_map.cc @@ -11,14 +11,11 @@ #include #include #include -#include #include "lib/jxl/base/byte_order.h" #include "lib/jxl/base/common.h" -#include "lib/jxl/base/span.h" #include "lib/jxl/base/status.h" #include "lib/jxl/color_encoding_internal.h" -#include "lib/jxl/dec_bit_reader.h" #include "lib/jxl/enc_aux_out.h" #include "lib/jxl/enc_bit_writer.h" #include "lib/jxl/fields.h" @@ -152,87 +149,3 @@ JXL_BOOL JxlGainMapWriteBundle(const JxlGainMapBundle* map_bundle, *bytes_written = cursor; // Ensure size_t compatibility return cursor == output_buffer_size ? JXL_TRUE : JXL_FALSE; } - -JXL_BOOL JxlGainMapReadBundle(JxlGainMapBundle* map_bundle, - const uint8_t* input_buffer, - const size_t input_buffer_size, - size_t* bytes_read) { - if (map_bundle == nullptr || input_buffer == nullptr || - input_buffer_size == 0) { - return JXL_FALSE; - } - - uint64_t cursor = 0; - uint64_t next_cursor = 0; - -#define SAFE_CURSOR_UPDATE(n) \ - do { \ - cursor = next_cursor; \ - if (!jxl::SafeAdd(cursor, n, next_cursor) || \ - next_cursor > input_buffer_size) { \ - return JXL_FALSE; \ - } \ - } while (false) - - // Read the version byte - SAFE_CURSOR_UPDATE(1); - map_bundle->jhgm_version = input_buffer[cursor]; - - // Read gain_map_metadata_size - SAFE_CURSOR_UPDATE(2); - uint16_t gain_map_metadata_size = LoadBE16(input_buffer + cursor); - - SAFE_CURSOR_UPDATE(gain_map_metadata_size); - map_bundle->gain_map_metadata_size = gain_map_metadata_size; - map_bundle->gain_map_metadata = input_buffer + cursor; - - // Read compressed_color_encoding_size - SAFE_CURSOR_UPDATE(1); - uint8_t compressed_color_encoding_size; - memcpy(&compressed_color_encoding_size, input_buffer + cursor, 1); - - map_bundle->has_color_encoding = (compressed_color_encoding_size > 0); - if (map_bundle->has_color_encoding) { - SAFE_CURSOR_UPDATE(compressed_color_encoding_size); - // Decode color encoding - jxl::Span color_encoding_span( - input_buffer + cursor, compressed_color_encoding_size); - jxl::BitReader color_encoding_reader(color_encoding_span); - jxl::ColorEncoding internal_color_encoding; - if (!jxl::Bundle::Read(&color_encoding_reader, &internal_color_encoding)) { - return JXL_FALSE; - } - JXL_RETURN_IF_ERROR(color_encoding_reader.Close()); - map_bundle->color_encoding = internal_color_encoding.ToExternal(); - } - - // Read compressed_icc_size - SAFE_CURSOR_UPDATE(4); - uint32_t compressed_icc_size = LoadBE32(input_buffer + cursor); - - SAFE_CURSOR_UPDATE(compressed_icc_size); - map_bundle->alt_icc_size = compressed_icc_size; - map_bundle->alt_icc = input_buffer + cursor; - - // Calculate remaining bytes for gain map - cursor = next_cursor; - // Compute remaining buffer size and ensure it fits into the public - // `uint32_t gain_map_size` field to avoid silent truncation on platforms - // where `size_t` is wider than 32 bits. - size_t remaining = input_buffer_size - cursor; - if (remaining > std::numeric_limits::max()) { - return JXL_FALSE; - } - map_bundle->gain_map_size = static_cast(remaining); - SAFE_CURSOR_UPDATE(map_bundle->gain_map_size); - map_bundle->gain_map = input_buffer + cursor; - -#undef SAFE_CURSOR_UPDATE - - cursor = next_cursor; - - if (bytes_read != nullptr) { - *bytes_read = cursor; - } - return JXL_TRUE; -} diff --git a/lib/jxl/gain_map.cc b/lib/jxl/gain_map.cc new file mode 100644 index 00000000000..91b5bedf5b3 --- /dev/null +++ b/lib/jxl/gain_map.cc @@ -0,0 +1,104 @@ +// Copyright (c) the JPEG XL Project Authors. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include +#include + +#include +#include +#include +#include + +#include "lib/jxl/base/byte_order.h" +#include "lib/jxl/base/common.h" +#include "lib/jxl/base/span.h" +#include "lib/jxl/base/status.h" +#include "lib/jxl/color_encoding_internal.h" +#include "lib/jxl/dec_bit_reader.h" +#include "lib/jxl/fields.h" + +JXL_BOOL JxlGainMapReadBundle(JxlGainMapBundle* map_bundle, + const uint8_t* input_buffer, + const size_t input_buffer_size, + size_t* bytes_read) { + if (map_bundle == nullptr || input_buffer == nullptr || + input_buffer_size == 0) { + return JXL_FALSE; + } + + uint64_t cursor = 0; + uint64_t next_cursor = 0; + +#define SAFE_CURSOR_UPDATE(n) \ + do { \ + cursor = next_cursor; \ + if (!jxl::SafeAdd(cursor, n, next_cursor) || \ + next_cursor > input_buffer_size) { \ + return JXL_FALSE; \ + } \ + } while (false) + + // Read the version byte + SAFE_CURSOR_UPDATE(1); + map_bundle->jhgm_version = input_buffer[cursor]; + + // Read gain_map_metadata_size + SAFE_CURSOR_UPDATE(2); + uint16_t gain_map_metadata_size = LoadBE16(input_buffer + cursor); + + SAFE_CURSOR_UPDATE(gain_map_metadata_size); + map_bundle->gain_map_metadata_size = gain_map_metadata_size; + map_bundle->gain_map_metadata = input_buffer + cursor; + + // Read compressed_color_encoding_size + SAFE_CURSOR_UPDATE(1); + uint8_t compressed_color_encoding_size; + memcpy(&compressed_color_encoding_size, input_buffer + cursor, 1); + + map_bundle->has_color_encoding = (compressed_color_encoding_size > 0); + if (map_bundle->has_color_encoding) { + SAFE_CURSOR_UPDATE(compressed_color_encoding_size); + // Decode color encoding + jxl::Span color_encoding_span( + input_buffer + cursor, compressed_color_encoding_size); + jxl::BitReader color_encoding_reader(color_encoding_span); + jxl::ColorEncoding internal_color_encoding; + if (!jxl::Bundle::Read(&color_encoding_reader, &internal_color_encoding)) { + return JXL_FALSE; + } + JXL_RETURN_IF_ERROR(color_encoding_reader.Close()); + map_bundle->color_encoding = internal_color_encoding.ToExternal(); + } + + // Read compressed_icc_size + SAFE_CURSOR_UPDATE(4); + uint32_t compressed_icc_size = LoadBE32(input_buffer + cursor); + + SAFE_CURSOR_UPDATE(compressed_icc_size); + map_bundle->alt_icc_size = compressed_icc_size; + map_bundle->alt_icc = input_buffer + cursor; + + // Calculate remaining bytes for gain map + cursor = next_cursor; + // Compute remaining bytes and ensure they fit into the public + // `uint32_t gain_map_size` field to avoid silent truncation on platforms + // where `size_t` is wider than 32 bits. + size_t remaining = input_buffer_size - cursor; + if (remaining > std::numeric_limits::max()) { + return JXL_FALSE; + } + map_bundle->gain_map_size = static_cast(remaining); + SAFE_CURSOR_UPDATE(map_bundle->gain_map_size); + map_bundle->gain_map = input_buffer + cursor; + +#undef SAFE_CURSOR_UPDATE + + cursor = next_cursor; + + if (bytes_read != nullptr) { + *bytes_read = cursor; + } + return JXL_TRUE; +} diff --git a/lib/jxl_lists.bzl b/lib/jxl_lists.bzl index 0517a670a94..5618d0a81df 100644 --- a/lib/jxl_lists.bzl +++ b/lib/jxl_lists.bzl @@ -136,6 +136,7 @@ libjxl_dec_sources = [ "jxl/common.h", "jxl/compressed_dc.cc", "jxl/compressed_dc.h", + "jxl/compressed_icc.cc", "jxl/convolve-inl.h", "jxl/convolve.h", "jxl/convolve_slow.cc", @@ -184,6 +185,7 @@ libjxl_dec_sources = [ "jxl/frame_dimensions.h", "jxl/frame_header.cc", "jxl/frame_header.h", + "jxl/gain_map.cc", "jxl/headers.cc", "jxl/headers.h", "jxl/huffman_table.cc", @@ -319,6 +321,7 @@ libjxl_enc_sources = [ "jxl/enc_coeff_order.h", "jxl/enc_comparator.cc", "jxl/enc_comparator.h", + "jxl/enc_compressed_icc.cc", "jxl/enc_context_map.cc", "jxl/enc_context_map.h", "jxl/enc_convolve_separable5.cc", @@ -340,6 +343,7 @@ libjxl_enc_sources = [ "jxl/enc_frame.h", "jxl/enc_gaborish.cc", "jxl/enc_gaborish.h", + "jxl/enc_gain_map.cc", "jxl/enc_gamma_correct.h", "jxl/enc_group.cc", "jxl/enc_group.h", @@ -425,7 +429,6 @@ libjxl_extras_sources = [ "extras/alpha_blend.h", "extras/common.cc", "extras/common.h", - "extras/compressed_icc.cc", "extras/dec/color_description.cc", "extras/dec/color_description.h", "extras/dec/color_hints.cc", @@ -436,7 +439,6 @@ libjxl_extras_sources = [ "extras/enc/encode.h", "extras/exif.cc", "extras/exif.h", - "extras/gain_map.cc", "extras/include_jpeglib.h", "extras/mmap.cc", "extras/mmap.h", diff --git a/lib/jxl_lists.cmake b/lib/jxl_lists.cmake index 1f2b510e227..61cbbead5ed 100644 --- a/lib/jxl_lists.cmake +++ b/lib/jxl_lists.cmake @@ -133,6 +133,7 @@ set(JPEGXL_INTERNAL_DEC_SOURCES jxl/common.h jxl/compressed_dc.cc jxl/compressed_dc.h + jxl/compressed_icc.cc jxl/convolve-inl.h jxl/convolve.h jxl/convolve_slow.cc @@ -181,6 +182,7 @@ set(JPEGXL_INTERNAL_DEC_SOURCES jxl/frame_dimensions.h jxl/frame_header.cc jxl/frame_header.h + jxl/gain_map.cc jxl/headers.cc jxl/headers.h jxl/huffman_table.cc @@ -316,6 +318,7 @@ set(JPEGXL_INTERNAL_ENC_SOURCES jxl/enc_coeff_order.h jxl/enc_comparator.cc jxl/enc_comparator.h + jxl/enc_compressed_icc.cc jxl/enc_context_map.cc jxl/enc_context_map.h jxl/enc_convolve_separable5.cc @@ -337,6 +340,7 @@ set(JPEGXL_INTERNAL_ENC_SOURCES jxl/enc_frame.h jxl/enc_gaborish.cc jxl/enc_gaborish.h + jxl/enc_gain_map.cc jxl/enc_gamma_correct.h jxl/enc_group.cc jxl/enc_group.h @@ -422,7 +426,6 @@ set(JPEGXL_INTERNAL_EXTRAS_SOURCES extras/alpha_blend.h extras/common.cc extras/common.h - extras/compressed_icc.cc extras/dec/color_description.cc extras/dec/color_description.h extras/dec/color_hints.cc @@ -433,7 +436,6 @@ set(JPEGXL_INTERNAL_EXTRAS_SOURCES extras/enc/encode.h extras/exif.cc extras/exif.h - extras/gain_map.cc extras/include_jpeglib.h extras/mmap.cc extras/mmap.h diff --git a/lib/jxl_tests.cmake b/lib/jxl_tests.cmake index 74ac05fbb03..3ef08dde105 100644 --- a/lib/jxl_tests.cmake +++ b/lib/jxl_tests.cmake @@ -56,6 +56,29 @@ if (EMSCRIPTEN) endif() endif() # EMSCRIPTEN +# Keep this public C API check independent of the writer, extras, and test-only +# libraries so it detects decoder-only link regressions. +add_executable(gain_map_public_api_decode_test + gain_map_public_api_decode_test.c +) +target_link_libraries(gain_map_public_api_decode_test PRIVATE jxl_dec) +set_target_properties(gain_map_public_api_decode_test PROPERTIES + LINKER_LANGUAGE CXX + RUNTIME_OUTPUT_DIRECTORY "$" +) +if(EMSCRIPTEN) + set_target_properties(gain_map_public_api_decode_test PROPERTIES + LINK_FLAGS "${JXL_WASM_TEST_LINK_FLAGS}" + ) +else() + set_target_properties(gain_map_public_api_decode_test PROPERTIES + LINK_FLAGS "${JPEGXL_COVERAGE_LINK_FLAGS}" + ) +endif() +add_test(NAME gain_map_public_api_decode_test + COMMAND gain_map_public_api_decode_test +) + # Individual test binaries: file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests) foreach (TESTFILE IN LISTS JPEGXL_INTERNAL_TESTS) diff --git a/lib/lib.gni b/lib/lib.gni index b1bc975e606..1bb6ce6e395 100644 --- a/lib/lib.gni +++ b/lib/lib.gni @@ -134,6 +134,7 @@ libjxl_dec_sources = [ "jxl/common.h", "jxl/compressed_dc.cc", "jxl/compressed_dc.h", + "jxl/compressed_icc.cc", "jxl/convolve-inl.h", "jxl/convolve.h", "jxl/convolve_slow.cc", @@ -182,6 +183,7 @@ libjxl_dec_sources = [ "jxl/frame_dimensions.h", "jxl/frame_header.cc", "jxl/frame_header.h", + "jxl/gain_map.cc", "jxl/headers.cc", "jxl/headers.h", "jxl/huffman_table.cc", @@ -317,6 +319,7 @@ libjxl_enc_sources = [ "jxl/enc_coeff_order.h", "jxl/enc_comparator.cc", "jxl/enc_comparator.h", + "jxl/enc_compressed_icc.cc", "jxl/enc_context_map.cc", "jxl/enc_context_map.h", "jxl/enc_convolve_separable5.cc", @@ -338,6 +341,7 @@ libjxl_enc_sources = [ "jxl/enc_frame.h", "jxl/enc_gaborish.cc", "jxl/enc_gaborish.h", + "jxl/enc_gain_map.cc", "jxl/enc_gamma_correct.h", "jxl/enc_group.cc", "jxl/enc_group.h", @@ -423,7 +427,6 @@ libjxl_extras_sources = [ "extras/alpha_blend.h", "extras/common.cc", "extras/common.h", - "extras/compressed_icc.cc", "extras/dec/color_description.cc", "extras/dec/color_description.h", "extras/dec/color_hints.cc", @@ -434,7 +437,6 @@ libjxl_extras_sources = [ "extras/enc/encode.h", "extras/exif.cc", "extras/exif.h", - "extras/gain_map.cc", "extras/include_jpeglib.h", "extras/mmap.cc", "extras/mmap.h",