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 @@ -290,6 +290,18 @@ def test_p2pa_palette() -> None:
assert im_pa.getpalette() == im.getpalette()


def test_pa2p_palette() -> None:
im_pa = Image.frombytes("PA", (2, 1), bytes([0, 255, 1, 255]))
im_pa.putpalette(bytes([255, 0, 0, 7, 0, 255, 0, 9]), "RGBA")

im_pa.putalpha(Image.frombytes("L", (2, 1), bytes([240, 220])))
assert im_pa.get_flattened_data() == ((0, 240), (1, 220)) # Matches the alpha band

im_p = im_pa.convert("P")
assert im_p.im.getpalettemode() == "RGB"
assert im_p.im.getpalette("RGB") == bytes([255, 0, 0, 0, 255, 0])


rgb2xyz_matrix = (
0.412453, 0.357580, 0.180423, 0,
0.212671, 0.715160, 0.072169, 0,
Expand Down
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