Skip to content

Fix primary JPEG XMP merging across namespace prefixes and reencoding - #472

Closed
gregbenz wants to merge 6 commits into
google:feat/preserve-xmp-metadatafrom
gregbenz:codex/fix-jpeg-xmp-merge
Closed

gregbenz wants to merge 6 commits into
google:feat/preserve-xmp-metadatafrom
gregbenz:codex/fix-jpeg-xmp-merge

Conversation

@gregbenz

Copy link
Copy Markdown
Contributor

Preserve captions, keywords, rights, and other descriptive content in the supplied or selected XMP packet when encoding an Ultra HDR JPEG with UHDR_WRITE_XMP=ON, while updating its gain-map information to match the output.

Currently, equivalent RDF namespace prefixes can cause descriptive metadata to disappear even though encoding succeeds. Reusing existing XMP can also leave duplicate Container directories and an outdated gain-map length.

This uses the bundled XML reader to identify properties by namespace URI, preserve unrelated packet content, and replace the primary Container:Directory and hdrgm:Version properties with current generated metadata. It handles both explicitly supplied XMP and XMP inherited from a compressed base JPEG. No new dependency or public C API change is introduced.

Tests cover namespace aliases, inherited and explicit XMP, replacement of descriptive values, changed gain-map sizes, comments/CDATA, xpacket wrappers, unrelated RDF resources, and malformed or oversized input. Local synthetic JPEG files were also checked for preserved metadata values, correct directory lengths, and successful HDR decoding.

Local validation on macOS arm64: full CMake/CTest suites pass in dual, XMP-only, and ISO-only modes; all 11 focused ASan/UBSan tests pass. The inherited-XMP regression fails against the original feature-branch code.

Additional local checks exercised six real Adobe-origin XMP packets on small synthetic JPEG carriers: 48 operations across inherited input, explicit input, getter reuse with changed gain-map size, and replacement in dual and XMP-only modes. Independent checks verified retained properties, current directory lengths, and successful HDR decoding. Linux, Android, macOS, and Windows CI pass on the current commit.

ISO-only passthrough remains unchanged. JPEG extraction still selects the first standard XMP packet; descriptive content in later packets and Extended XMP are outside this change. Packets the bundled reader cannot safely merge return UHDR_CODEC_INVALID_PARAM instead of silently losing their contents.

Targets feat/preserve-xmp-metadata, following #471 and contributing to #469.

@gregbenz

gregbenz commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@DichenZhang1, thanks for incorporating this into feat/preserve-xmp-metadata. I checked the branch after #494 and confirmed that the merge handler and all seven regression cases from this PR are covered, including the ISO-only path. #494 also replaces the earlier size restriction with Extended XMP support.

Closing this as superseded by the feature branch.

@gregbenz gregbenz closed this Oct 3, 2026
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