Skip to content

Commit

Permalink
enable support for xmp, iso to be build time configurable
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ram-mohan authored and DichenZhang1 committed Dec 11, 2024
1 parent 98814d4 commit 4cb4626
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. <ul><li> Current implementation of XMP format supports writing only single channel gainmap metadata. To support encoding multi channel gainmap metadata, XMP format encoding is disabled by default. If enabled, metadata of all channels of gainmap image is merged into one and signalled. </li></ul> |
| `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. <ul><li> As `-fsanitize` is an instrumentation option, dependencies are also built from source instead of using pre-builts. This is done by forcing `UHDR_BUILD_DEPS` to **ON** internally. </li></ul> |
| `UHDR_BUILD_PACKAGING` | OFF | Build distribution packages using CPack. |
| | | |
Expand Down
18 changes: 8 additions & 10 deletions lib/src/jpegr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4cb4626

Please sign in to comment.