Skip to content

Commit 31693e6

Browse files
akxradarhere
andcommitted
Ensure Image and core palettes are in sync after PA conversion (alphas dropped)
Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
1 parent 39c5152 commit 31693e6

2 files changed

Lines changed: 2 additions & 4 deletions

File tree

Tests/test_image_convert.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,6 @@ def test_matrix_identity() -> None:
359359
assert_image_equal(converted_im, im)
360360

361361

362-
@pytest.mark.xfail(reason="zombie colors from palette shouldn't reappear")
363362
def test_pa2p_truly_drops_alpha() -> None:
364363
im = Image.frombytes("P", (2, 1), bytes([0, 1])).convert("PA")
365364
im.putpalette(bytes([255, 0, 0, 7, 0, 255, 0, 9]), "RGBA")

src/PIL/Image.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,9 +1242,8 @@ def convert_transparency(
12421242

12431243
new_im = self._new(im)
12441244
if mode in ("P", "PA") and palette != Palette.ADAPTIVE:
1245-
from . import ImagePalette
1246-
1247-
new_im.palette = ImagePalette.ImagePalette("RGB", im.getpalette("RGB"))
1245+
# Install the original image's palette into the new copy
1246+
new_im.putpalette(im.getpalette("RGB"))
12481247
if delete_trns:
12491248
# crash fail if we leave a bytes transparency in an rgb/l mode.
12501249
del new_im.info["transparency"]

0 commit comments

Comments
 (0)