From 4cb4626c5aaae8a9d7c9602340526d190ebabd14 Mon Sep 17 00:00:00 2001 From: Ram Mohan M Date: Tue, 10 Dec 2024 22:34:37 +0530 Subject: [PATCH] enable support for xmp, iso to be build time configurable Android.bp enables xmp support by default, cmakelists.txt enables iso support by default. Based on the build system the encoded bitstream may vary. This change has no effect on decoder. The decoder by default supports both iso and xmp. If both exists iso packet is preferred. Test: ./ultrahdr_unit_test --- Android.bp | 3 ++- CMakeLists.txt | 12 ++++++++++++ docs/building.md | 2 ++ lib/src/jpegr.cpp | 18 ++++++++---------- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/Android.bp b/Android.bp index 194fc1c3..09ee9d5e 100644 --- a/Android.bp +++ b/Android.bp @@ -40,7 +40,8 @@ cc_library { "lib/include", ], local_include_dirs: ["lib/include"], - cflags: ["-DUHDR_ENABLE_INTRINSICS"], + cflags: ["-DUHDR_ENABLE_INTRINSICS", + "-DUHDR_WRITE_XMP",], srcs: [ "lib/src/icc.cpp", "lib/src/jpegr.cpp", diff --git a/CMakeLists.txt b/CMakeLists.txt index c518d85e..45251e8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,6 +124,12 @@ option_if_not_defined(UHDR_ENABLE_INTRINSICS "Build with SIMD acceleration " TRU option_if_not_defined(UHDR_ENABLE_GLES "Build with GPU acceleration " FALSE) option_if_not_defined(UHDR_ENABLE_WERROR "Build with -Werror" FALSE) +# These options effect only encoding process. +# Decoding continues to support both iso and xmp irrespective of this configuration. +# Also, if both packets are present iso is prioritized over xmp. +option_if_not_defined(UHDR_WRITE_XMP "Write gainmap metadata in XMP packet" FALSE) +option_if_not_defined(UHDR_WRITE_ISO "Write gainmap metadata in ISO 21496_1 packet" TRUE) + # pre-requisites if(UHDR_BUILD_TESTS AND EMSCRIPTEN) message(FATAL_ERROR "Building tests not supported for wasm targets") @@ -199,6 +205,12 @@ endif() if(UHDR_ENABLE_INTRINSICS) add_compile_options(-DUHDR_ENABLE_INTRINSICS) endif() +if(UHDR_WRITE_XMP) + add_compile_options(-DUHDR_WRITE_XMP) +endif() +if(UHDR_WRITE_ISO) + add_compile_options(-DUHDR_WRITE_ISO) +endif() include(CheckCXXCompilerFlag) function(CheckCompilerOption opt res) diff --git a/docs/building.md b/docs/building.md index bb2a3cf4..46d4a18d 100644 --- a/docs/building.md +++ b/docs/building.md @@ -64,6 +64,8 @@ Following is a list of available options: | `UHDR_ENABLE_GLES` | OFF | Build with GPU acceleration. | | `UHDR_ENABLE_WERROR` | OFF | Enable -Werror when building. | | `UHDR_MAX_DIMENSION` | 8192 | Maximum dimension supported by the library. The library defaults to handling images upto resolution 8192x8192. For different resolution needs use this option. For example, `-DUHDR_MAX_DIMENSION=4096`. | +| `UHDR_WRITE_XMP` | OFF | Enable writing gainmap metadata in XMP packet. | +| `UHDR_WRITE_ISO` | ON | Enable writing gainmap metadata in ISO 21496-1 format. | | `UHDR_SANITIZE_OPTIONS` | OFF | Build library with sanitize options. Values set to this parameter are passed to directly to compilation option `-fsanitize`. For example, `-DUHDR_SANITIZE_OPTIONS=address,undefined` adds `-fsanitize=address,undefined` to the list of compilation options. CMake configuration errors are raised if the compiler does not support these flags. This is useful during fuzz testing. | | `UHDR_BUILD_PACKAGING` | OFF | Build distribution packages using CPack. | | | | | diff --git a/lib/src/jpegr.cpp b/lib/src/jpegr.cpp index 4a222149..ce4d6e09 100644 --- a/lib/src/jpegr.cpp +++ b/lib/src/jpegr.cpp @@ -54,8 +54,16 @@ uhdr_error_info_t applyGainMapGLES(uhdr_raw_image_t* sdr_intent, uhdr_raw_image_ #endif // Gain map metadata +#ifdef UHDR_WRITE_XMP static const bool kWriteXmpMetadata = true; +#else +static const bool kWriteXmpMetadata = false; +#endif +#ifdef UHDR_WRITE_ISO +static const bool kWriteIso21496_1Metadata = true; +#else static const bool kWriteIso21496_1Metadata = false; +#endif static const string kXmpNameSpace = "http://ns.adobe.com/xap/1.0/"; static const string kIsoNameSpace = "urn:iso:std:iso:ts:21496:-1"; @@ -552,16 +560,6 @@ uhdr_error_info_t JpegR::generateGainMap(uhdr_raw_image_t* sdr_intent, uhdr_raw_ return status; } - /*if (mUseMultiChannelGainMap) { - if (!kWriteIso21496_1Metadata || kWriteXmpMetadata) { - status.error_code = UHDR_CODEC_UNSUPPORTED_FEATURE; - status.has_detail = 1; - snprintf(status.detail, sizeof status.detail, - "Multi-channel gain map is only supported for ISO 21496-1 metadata"); - return status; - } - }*/ - ColorTransformFn hdrInvOetf = getInverseOetfFn(hdr_intent->ct); if (hdrInvOetf == nullptr) { status.error_code = UHDR_CODEC_UNSUPPORTED_FEATURE;