jpegrutils: set use_base_cg for Apple gain maps - #483
pateltejas wants to merge 1 commit into
Conversation
The Apple decode path in getMetadataFromXMP() returns early without setting use_base_cg, so it stays false. Decoding is unaffected, but re-encoding the decoded base image, gain map and metadata (e.g. to resize an Apple HDR JPEG) then fails in encodeJPEGR with "ICC marker in gainmap jpeg is missing": use_base_cg == false tells the encoder the gain map lives in an alternate color space and must carry its own ICC profile, which Apple gain-map images do not. Apple applies the gain map in the base image's color space, so set use_base_cg = true, matching the ISO and Adobe XMP paths. Test: decodeApple now asserts use_base_cg for both Apple fixtures (it fails without this change).
|
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. |
|
Thanks for fixing this, looks like a good PR. Did you just close it due to the CLA requirement? Or did you have some other concern? Would it be worth adding a round-trip test that re-encodes the base image and gain map with the decoded metadata, then checks that the result decodes successfully? That would cover the transcode failure directly. Just a suggestion, not something I’d hold up the fix over. |
The Apple decode path in
getMetadataFromXMP()(added in #385) returns early without settinguse_base_cg, so it staysfalse.Decoding is unaffected. But re-encoding the decoded base image, gain map, and metadata through
uhdr_enc_set_compressed_image+uhdr_enc_set_gainmap_imagefails inJpegR::encodeJPEGR:use_base_cg == falsetells the encoder the gain map is applied in an alternate color space and must carry its own ICC profile. Apple gain-map images don't have one. Apple applies the gain map in the base image's color space, souse_base_cgshould betrue, which is what the ISO and Adobe XMP paths already set.In practice this shows up when an app resizes an Apple HDR JPEG while preserving its gain map (for example ImageMagick's
UHDR:coder): the transcode fails instead of producing a smaller Ultra HDR JPEG.Decoded output doesn't change. Apple gain-map images carry no ICC, so
applyGainMapresolves the gain map's gamut to the base's, and both gamut-conversion paths are identity whichever wayuse_base_cgis set. I confirmed that decoding both Apple fixtures to linear HDR gives byte-identical output with and without this change. Only the encode check is affected.Test
JpegRTest.decodeApplenow also assertsuse_base_cgfor both Apple fixtures (apple_gainmap_old.jpg,apple_gainmap_new.jpg). It fails on both without this change and passes with it. The fullultrahdr_unit_testsuite passes (1093 tests).Related discussion: #365.