Repository navigation
Update transparency when quantizing - #10720
mh-masum6875 wants to merge 2 commits into
Conversation
|
Could we cover palette images with a byte-valued alpha table before dropping it here? On Pillow 13.0.0, a 3-pixel P image with a white/gray/black palette, indices |
|
Good catch, thanks. I reproduced it, your example lost its alpha with my change. Leaving the bytes as they were doesn't work in general though, the palette order usually moves and the old table then points at the wrong colors. I pushed a commit that carries each color's alpha over to its new position, plus tests for your case and one where the order changes. One limit: if quantizing merges colors, those come out opaque. |
Changes proposed in this pull request:
quantize()copiesinfo["transparency"]to the new P image unchanged. For an RGB image that's an RGB tuple, so the result can't be converted to RGBA or saved as GIF. For L and P images, it's an index into the old values, so the wrong palette entry is transparent, or none at all.quantize(palette=...)on an L image is unchanged, as the pixel values are kept as the palette indexes there.I only ran this against the 13.0.0 wheel with the change applied on top, as I don't have a C toolchain set up here.