Fix JPEG segment ordering per JFIF and CIPA DC-007 standards#394
Open
minatoAI wants to merge 1 commit into
Open
Fix JPEG segment ordering per JFIF and CIPA DC-007 standards#394minatoAI wants to merge 1 commit into
minatoAI wants to merge 1 commit into
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. |
The appendGainMap function built JPEG output with incorrect marker ordering: - JFIF (APP0) was written after XMP, ISO, MPF and ICC segments (must be the first APP marker after SOI per JFIF spec) - MPF was written before JFIF and ICC, far from SOS (must be placed right before SOS per CIPA DC-007) This caused platforms like Xiaohongshu to fail HDR recognition because their decoders follow the standard marker ordering. Fix: 1. Extract APP0(JFIF) from the base JPEG data and write it right after SOI 2. Parse the base JPEG marker segments (DQT, SOF, DHT) and write them before MPF 3. Write MPF right before SOS per CIPA DC-007 4. Write SOS + compressed data after MPF Also: - Added rdf:about="" attribute and hdrgm:OplusScale field to the gain map XMP metadata block (required by Android Ultra HDR specification) - Added -DWITH_CRT_DLL=ON to turbojpeg ExternalProject for MSVC compatibility - When BUILD_FOR_WINUI is defined, skip the forced /MT CRT override
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
appendGainMapfunction builds JPEG output with incorrect APP marker ordering:This causes HDR decoders that follow the standard ordering (e.g., Xiaohongshu/小红书) to fail to recognize the Ultra HDR gain map.
Changes
lib/src/jpegr.cpp: Extract APP0(JFIF) from the base JPEG data and write it immediately after SOI. Parse the base JPEG marker segments (DQT, SOF, DHT) and write them before MPF. Write MPF right before SOS per CIPA DC-007.
lib/src/jpegrutils.cpp: Add
rdf:about=""attribute andhdrgm:OplusScale="-1"field to the gain map XMP metadata block, matching the Android Ultra HDR specification (developer.android.com/media/platform/hdr-image-format).CMakeLists.txt: Add
-DWITH_CRT_DLL=ONto turbojpeg's ExternalProject CMAKE_ARGS when building on MSVC, to prevent CRT mismatch when the parent project uses dynamic CRT (/MD).Testing
Verified that the fix produces a JPEG segment order identical to camera-captured Ultra HDR images (e.g., OPPO Find X8 Ultra), and the reordered file is correctly recognized as HDR by the Xiaohongshu platform.