Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Tests/test_image_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,15 @@ def test_matrix_identity() -> None:
# Assert
# No change
assert_image_equal(converted_im, im)


def test_pa2p_truly_drops_alpha() -> None:
im = Image.frombytes("P", (2, 1), bytes([0, 1])).convert("PA")
im.putpalette(bytes([255, 0, 0, 7, 0, 255, 0, 9]), "RGBA")
im.putalpha(Image.frombytes("L", (2, 1), bytes([240, 220])))
assert im.get_flattened_data() == ((0, 240), (1, 220)) # Matches the alpha band
im_p = im.convert("P")
assert im_p.palette is not None
assert im_p.im.getpalettemode() == im_p.palette.mode == "RGB"
rgba_data = im_p.convert("RGBA").get_flattened_data()
assert rgba_data == ((255, 0, 0, 255), (0, 255, 0, 255))
5 changes: 2 additions & 3 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1242,9 +1242,8 @@ def convert_transparency(

new_im = self._new(im)
if mode in ("P", "PA") and palette != Palette.ADAPTIVE:
from . import ImagePalette

new_im.palette = ImagePalette.ImagePalette("RGB", im.getpalette("RGB"))
# Install the original image's palette into the new copy
new_im.putpalette(im.getpalette("RGB"))
if delete_trns:
# crash fail if we leave a bytes transparency in an rgb/l mode.
del new_im.info["transparency"]
Expand Down
Loading