Skip to content

build: Add automated libheif dependency build with ISO 21496-1 gain map patch - #431

Merged
DichenZhang1 merged 3 commits into
mainfrom
build/libheif-iso21496-patch
Aug 9, 2026
Merged

build: Add automated libheif dependency build with ISO 21496-1 gain map patch#431
DichenZhang1 merged 3 commits into
mainfrom
build/libheif-iso21496-patch

Conversation

@DichenZhang1

Copy link
Copy Markdown
Collaborator

Summary

This PR enables automated fetching, patching, and building of libheif with ISO 21496-1 tone map (tmap) item support when UHDR_ENABLE_HEIF=ON and UHDR_BUILD_DEPS=ON.

Gain map encapsulation in HEIF (.heic) and AVIF (.avif) containers in libultrahdr v2.0.0 relies on the ISO 21496-1 tmap APIs introduced in strukturag/libheif#1503. Because this PR is not yet merged upstream into release tags of libheif, this change adds a patch file and integrates it into CMake's dependency management flow so libultrahdr can build standalone with full HEIF and AVIF support out-of-the-box.


Key Changes

  1. Patch File:
    • Added cmake/patches/libheif_pr1503.patch containing the ISO 21496-1 tmap item patch from strukturag/libheif PR #1503.
  2. CMake ExternalProject_Add:
    • Configured ExternalProject_Add(libheif) in CMakeLists.txt to fetch libheif, apply the patch idempotently, and build with -DWITH_EXPERIMENTAL_GAIN_MAP=ON and -DWITH_LIBSHARPYUV=OFF.
  3. Compiler & Target Graph:
    • Added -DWITH_EXPERIMENTAL_GAIN_MAP=1 to compiler flags when LIBHEIF_FOUND is true.
    • Added target dependencies add_dependencies(core libheif) and add_dependencies(ultrahdr_unit_test libheif).

Verification

  • Verified clean build and execution with cmake -B build -DUHDR_BUILD_DEPS=ON -DUHDR_ENABLE_HEIF=ON -DUHDR_BUILD_TESTS=ON.
  • Verified internal Google3 test suite passes 100% (blaze test //third_party/libultrahdr:ultrahdr_api_test).
  • Verified real end-to-end HEIC and AVIF gain map encoding and decoding.

- Enables UHDR_ENABLE_HEIF by default to build libheif with ISO 21496-1 gain map support
- Applies PR 1503 patch from upstream libheif with cross-platform C++17 compatibility
- Configures ExternalProject_Add for libheif with direct static target builds, disabling unused auxiliary decoders (heifio, doxygen, gdk-pixbuf)
- Supports cross-platform builds across Linux, macOS (native ARM64 & cross x86_64), Windows (MSVC), and Android NDK
…/AVIF

- Fix -Wshadow and -Wunused-function compiler warnings in heif/avif codecs
- Fix argument count in convert_raw_input_to_ycbcr_neon calls
- Prevent heap-use-after-free and ensure graceful fallthrough to JPEG probe in uhdr_dec_probe
…r tests

- Skip HEIC and AVIF encode tests gracefully with GTEST_SKIP when encoder plugins are absent
- Ensure encoder instances are released before GTEST_SKIP to prevent LeakSanitizer warnings
@DichenZhang1
DichenZhang1 force-pushed the build/libheif-iso21496-patch branch from a9e46a3 to 04b76e5 Compare August 9, 2026 05:11
@DichenZhang1
DichenZhang1 merged commit b2aacb3 into main Aug 9, 2026
45 checks passed
@lovell

lovell commented Aug 10, 2026

Copy link
Copy Markdown

The side effects of this PR and the subsequent version re-tagging are causing quite a bit of backscatter in downstream consumers, which reflects quite badly on Google.

It would be most considerate of the maintainers to offer a bit more delay and/or greater human review of dependency-related changes before the merge and release process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants