Open
Conversation
197g
reviewed
Apr 7, 2026
Member
197g
left a comment
There was a problem hiding this comment.
Just a question, integer arithmetic with fixed divisors sounds preferable in either case—most of the time at least.
Comment on lines
+563
to
+565
| (((255 - c) * k_inv) / 255) as u8, | ||
| (((255 - m) * k_inv) / 255) as u8, | ||
| (((255 - y) * k_inv) / 255) as u8, |
Member
There was a problem hiding this comment.
It's making a good point that as used floor semantics but wouldn't we prefer rounding here? Then a bias term for 127 should be added here before.
Contributor
Author
There was a problem hiding this comment.
Thank you! Adding a bias term is mathematically more accurate for rounding, but it again introduced pixel differences when testing against libtiff (which uses truncation by default). I have added another test case for this specific truncation behavior:
CMYK: [1, 1, 1, 128]with intermediate values(255 - c) = 254andk_inv = 127- New logic without bias term:
(254 * 127) / 255 = 32258 / 255 = 126(integer division naturally truncates to 126) - With bias term:
(254 * 127 + 127) / 255 = 32385 / 255 = 127(rounds up to 127)
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.
This PR replaces floating-point arithmetic with pure integer arithmetic for CMYK-to-RGB conversion in the TIFF decoder. Fixes Precision Errors:
tiff/testsuite/cmyk_u8_edge_case.tif(edge case with a 1x1 pixel with CMYK [0, 0, 0, 65]) to test this