Skip to content

Conversation

@ferdnyc
Copy link
Contributor

@ferdnyc ferdnyc commented Mar 30, 2025

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practices as demonstrated in the repository.

Description

When losslessly encoding an image to JXL, attempt to retrieve any ICC profile set on the source image, and if one exists, apply it to the output JXL image instead of using JxlEncoderSetColorEncoding.

Fixes #8022

When losslessly encoding an image to JXL, attempt to retrieve any
ICC profile set on the source image, and if one exists, apply it
to the output JXL image instead of using JxlEncoderSetColorEncoding.

Fixes ImageMagick#8022
Comment on lines 1035 to 1048
basic_info.uses_original_profile=JXL_TRUE;
{
icc_profile = GetImageProfile(image, "icc");
if (icc_profile != (StringInfo *) NULL)
basic_info.uses_original_profile=JXL_TRUE;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The uses_original_profile flag is a hint for the JXL decoder, and has no real meaning if there's no profile attached to the encoded image. So, we only set it when we're also applying an ICC profile.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately it gets slightly more confusing.
basic_info.uses_original_profile should be true for lossless and false for lossy, as it controls when XYB is used internally instead of RGB. The naming could probably be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh! I didn't realize that at all, yeah. So it should still be set unconditionally if quality == 100, then, regardless of whether or not there's an ICC profile? My mistake for assuming otherwise, thanks.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I know it's confusing and we've had a few asking why files aren't working, only to see that flag set incorrectly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed now, though I wonder if I should also add a comment to the delegate code explaining the meaning of the flag. (I don't love the idea of documenting libjxl in ImageMagick's source, tho, that feels like it'll inevitably come back to bite me eventually.)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just thinking, I'll add a comment to libjxl. Though I think documenting it in the wrapper here can't hurt too. Since most will only see this instead of libjxl itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonnyawsom3 Well, if you're going to add something to the JXL documentation (even if just API documentation), I'd much rather the comment here just be something like,

/* Necessary for lossless decoding.
 * See: [url] 
 */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, it's only gonna be short anyway

Controls internal color space, separate to displayed color space.
True = RGB   False = XYB   VarDCT requires False, Lossless requires True

or something similar

@urban-warrior urban-warrior merged commit 815cc3a into ImageMagick:main Apr 5, 2025
8 checks passed
@ferdnyc ferdnyc deleted the jxl-preserve-icc branch April 5, 2025 16:09
This was referenced Jul 22, 2025
This was referenced Dec 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

JXL->JXL processing (to remove alpha channel) drops color profile

3 participants