Repository navigation
Add runtime-aware gain map routing predicate - #462
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
f6f8571 to
816c3ba
Compare
816c3ba to
af90073
Compare
|
Thanks for the contribution! This change generally looks good to me, with a minor comment: could you please split the version bump (
Thanks! |
|
@DichenZhang1 Thanks! Removed the version bump in dd6405d. This PR now contains only the routing changes, with the version remaining at 2.0.2. All checks pass. |
|
Thanks for adding this — a cheap "can this runtime actually decode it?" probe is genuinely useful, and the implementation is careful (RAII handles, bounds-checked MPF parsing, fuzzer coverage). Before it lands, I'd point out three blocking issues:
Let me know if you think these are reasonable or you'd like me providing more info. Thank you! |
Preserve the legacy probe implementation, make item inspection optional for system libheif, and validate direct alpha decoder dependencies. Update the public contract and compatibility regressions.
|
@DichenZhang1 Thanks for the review. Sounds good on all three points. I’ve updated the PR:
The alpha check still verifies that the directly associated alpha item has a supported layout and an available decoder. Derived, unresolved, duplicate, or nested alpha dependencies conservatively return 0, without recursively walking the item graph. This keeps the runtime-support check without rejecting alpha itself. Local tests passed, including compatibility checks for builds without item inspection or HEIF support, plus sanitizer checks. Linux, Windows, macOS, and Android CI also passed on the fork at e92c3c9. The version is unchanged. |
DichenZhang1
left a comment
There was a problem hiding this comment.
Look good to me. Thank you for PR.
Summary
This adds a routing helper for image loaders that already have a complete encoded image in memory:
A return of
1means the loader can try libultrahdr. A return of0means it should use another route, not necessarily that the image has no gain map. A positive result is a routing hint, not a decode guarantee.The helper checks gain-map structure and, for AVIF/HEIF, decoder availability without decoding pixels or copying the complete encoded stream. Existing
is_uhdr_image()anduhdr_dec_probe()behavior is unchanged.Behavior and compatibility
0; inspection is limited to 16 auxiliary items per alpha-bearing image.0for AVIF/HEIF, while existing encoding, decoding, and JPEG routing remain available.These changes address the review concerns about preserving the legacy probe, keeping system libheif builds usable without item inspection, and accepting supported alpha rather than rejecting it outright.
Callers should retain cheap format prefilters and normal decode-error handling. This requires a complete buffer, not a prefix or stream. Downstreams should check for the new symbol until a released version provides it; adapting a JPEG-only loader to AVIF/HEIF remains separate work.
Validation
At
e92c3c9, the local AVIF-enabled suite passed with 1,106 tests passed, 229 skipped, and no failures. The fork's Linux, Windows, macOS, and Android workflows also passed at that revision.Additional checks cover builds without item inspection, JPEG-only builds with exceptions disabled, malformed MPF associations, and focused ASan/UBSan tests. Sanitizer validation did not instrument libheif, and LeakSanitizer was unavailable locally.
Alpha coverage includes primary-alpha routing and SDR RGBA decode, plus a generated gain-map-side alpha regression. Reinstating blanket alpha rejection locally makes the new test fail. The gain-map-side test verifies routing, not decoded alpha fidelity. Real mixed-codec alpha and a comprehensive malformed-alpha graph matrix were not tested.
Performance
Warm-call measurements on arm64 macOS, using the final AVIF-only release build:
These are medians of five 1,000-call batch averages after warmup, excluding file I/O and pixel decoding. They are not end-to-end loader measurements or worst-case bounds. JPEG inspection still scans encoded bytes, and container parsing can allocate memory; avoiding a full-stream copy does not make the operation allocation-free or constant-time.
The release version is left unchanged for maintainers to decide.