Skip to content

Commit

Permalink
Copy palette when converting from P to PA
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Aug 13, 2022
1 parent 92b0f2c commit 29f30ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Tests/test_image_convert.py
Expand Up @@ -236,6 +236,12 @@ def test_p2pa_alpha():
assert im_a.getpixel((x, y)) == alpha


def test_p2pa_palette():
with Image.open("Tests/images/tiny.png") as im:
im_pa = im.convert("PA")
assert im_pa.getpalette() == im.getpalette()


def test_matrix_illegal_conversion():
# Arrange
im = hopper("CMYK")
Expand Down
4 changes: 4 additions & 0 deletions src/libImaging/Convert.c
Expand Up @@ -1233,6 +1233,10 @@ frompalette(Imaging imOut, Imaging imIn, const char *mode) {
if (!imOut) {
return NULL;
}
if (strcmp(mode, "PA") == 0) {
ImagingPaletteDelete(imOut->palette);
imOut->palette = ImagingPaletteDuplicate(imIn->palette);
}

ImagingSectionEnter(&cookie);
for (y = 0; y < imIn->ysize; y++) {
Expand Down

0 comments on commit 29f30ef

Please sign in to comment.