Repository navigation
Correct transparency when converting with matrix - #10468
Merged
radarhere merged 2 commits intoNov 9, 2026
Merged
Conversation
Member
|
You're pointing out that Pillow/src/libImaging/Matrix.c Line 52 in a26b63c and Line 1098 in a26b63c disagree. The C code has been there since PIL. The Python code was added in #3205 by me. I am inclined to believe that I made a mistake. |
radarhere
enabled auto-merge (squash)
November 9, 2026 09:05
radarhere
force-pushed
the
fix/matrix-transparency-rounding
branch
from
November 9, 2026 09:07
5298b68 to
eb58ce8
Compare
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.
Changes proposed in this pull request:
convert()is given a matrix, thetransparencycolor ininfois now calculated the same way as the pixels,m[0] * r + m[1] * g + m[2] * b + m[3] + 0.5. The Python helper hadm[3] * 0.5, so the offset was halved and the rounding term was lost, and the transparent color no longer matched the pixel it was meant to mark.With
(0.5, 0.5, 0, 0)the pixel is 128 and the transparency was 127.test_matrix_transparency, which checks that the transparency equals the converted pixel. On main it fails withassert 127 == 128andassert (123, 61, 100) == (123, 62, 101).test_matrix_xyzexpected(105, 54, 4), but the C conversion turns(255, 0, 0)into(105, 54, 5)with that matrix, so the expected value is updated to match.The full test suite passes locally, apart from
test_grab, which also fails on main here because of macOS screen capture permissions. pre-commit andtox -e mypypass.