Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove cHRM check to accomodate ACES AP1 #579

Closed
wants to merge 1 commit into from

Conversation

jbowler
Copy link
Contributor

@jbowler jbowler commented Sep 4, 2024

ACES AP1 has a red endpoint with a negative Z, this triggers the checks
in libpng that ensure that x, y and z (chromaticities) are all >=0.
This removes the checks on the sign of the chromaticities since it is
valid to use negative values for any of them and converts the "internal"
error code return to external (because the internal cases correspond to
negative x, y or z.)

Signed-off-by: John Bowler jbowler@acm.org

ACES AP1 has a red endpoint with a negative Z, this triggers the checks
in libpng that ensure that x, y and z (chromaticities) are all >=0.
This removes the checks on the sign of the chromaticities since it is
valid to use negative values for any of them and converts the "internal"
error code return to external (because the internal cases correspond to
negative x, y or z.)

Signed-off-by: John Bowler <jbowler@acm.org>
@jbowler
Copy link
Contributor Author

jbowler commented Sep 4, 2024

REVIEW REQUIRED: @mbechard

@jbowler
Copy link
Contributor Author

jbowler commented Sep 4, 2024

@fuzzers: please review this with fuzzed cHRM values.

@jbowler
Copy link
Contributor Author

jbowler commented Sep 4, 2024

@mm2 the original (way, way back; 10, 15 years) issue was produced by a PNG with a cHRM which had colinear (IRC) rgb xy points. This was before any of the checks and caused issues somewhere (it was a long time ago), possibly CIEXYZ with NaN values. Somehow the result was a crash in lcms (possibly the author of the bug passed signalling NaN values in; I don't remember lcms supporting endpoints specified as chromaticities.)

This change should retain the check on colinear values but will allow cHRM chunks which result in CIEXYZ triples (to use the Windows terminology) with negative Z values, at least for the ACES AP1 and AP0 colour spaces.

@jbowler
Copy link
Contributor Author

jbowler commented Sep 4, 2024

If verified this closes #578

@mm2
Copy link

mm2 commented Sep 4, 2024

@mm2 the original (way, way back; 10, 15 years) issue was produced by a PNG with a cHRM which had colinear (IRC) rgb xy points. This was before any of the checks and caused issues somewhere (it was a long time ago), possibly CIEXYZ with NaN values. Somehow the result was a crash in lcms (possibly the author of the bug passed signalling NaN values in; I don't remember lcms supporting endpoints specified as chromaticities.)

Thanks for let me know. FYI, ICC addressed use of negative XYZ many years ago
https://color.org/technotes/Guidelines_on_the_use_of_negative_PCSXYZ_values.pdf

@mbechard
Copy link

mbechard commented Sep 4, 2024

Yep, looks good to me and I'm able to write->read a PNG using AP1 primaries.

@jbowler
Copy link
Contributor Author

jbowler commented Sep 6, 2024

ICC addressed use of negative XYZ many years ago

Yes; negative XYZ were always meaningful. Unfortunately the original PNG spec defined the chromaticity values as "unsigned". This doesn't arise in the adaptation case because the negatives come from the adaptation and it doesn't arise with ACES AP1 (that was just my over-enthusiastic error checks). It does arise in PNG with AP0 because the red y value is negative and significantly so; the rounding hack I suggested to @mbechard won't help.

@ctruta; this really needs to go into libpng16; it's an unexploded bomb that only hasn't been reported before because no one (apparently) has generated PNG files with the ACES chromaticities. That's going to change as a side effect of the W3C initiatives; these will make PNG more appropriate to video workflows and will, indirectly, encourage the use of wide gamut colour spaces.

It is a bug fix, nope, not security but then surely neither are changes to parts of the build system that have never worked?

I suspect @mbechard might support me in pushing for this.

@mbechard
Copy link

mbechard commented Sep 7, 2024

Yes for sure. Although I'm currently defaulting to ICC profiles if they are available, I think that will go away for the more common color spaces (ACES/DCI-P3/Rec2020) as they are easily defined and manipulated with matrices, which allows them to be done on the GPU. This will be important for high-res image sequence playback where I suspect running the image through an ICC transform on the CPU will end up being the bottleneck for playback performance. Being able to use the cHRM instead of ICC will be optimal in the future, when it's appropriate.

@ctruta ctruta self-requested a review September 7, 2024 10:03
Copy link
Member

@ctruta ctruta left a comment

Choose a reason for hiding this comment

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

👍

@ctruta
Copy link
Member

ctruta commented Sep 7, 2024

@ctruta; this really needs to go into libpng16

Done.
@jbowler: off-topic: if you believe that other pending PRs need to go into libpng16 also, please let me know before we turn it into a maintenance-only branch.

@ctruta ctruta closed this Sep 7, 2024
@jbowler
Copy link
Contributor Author

jbowler commented Sep 7, 2024

if you believe that other pending PRs need to go into libpng16 also, please let me know before we turn it into a maintenance-only branch.

The only one that I'm aware of which you haven't checked in to libpng16 is #557

I'll keep looking.

@ctruta
Copy link
Member

ctruta commented Sep 8, 2024

The only one that I'm aware of which you haven't checked in to libpng16 is #557

Ha! Good catch.

I'll keep looking.

Thank you @jbowler.

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.

4 participants