Skip to content

Conversation

@radarhere
Copy link
Member

@radarhere radarhere commented Feb 14, 2022

When converting P to PA, Pillow currently sets the A value from the palette.

static void
p2pa(UINT8 *out, const UINT8 *in, int xsize, const UINT8 *palette) {
int x;
for (x = 0; x < xsize; x++, in++) {
const UINT8 *rgba = &palette[in[0]];
*out++ = in[0];
*out++ = in[0];
*out++ = in[0];
*out++ = rgba[3];
}
}

If the palette is in RGBA mode, that makes sense. However, if the palette is in RGB mode, then that doesn't make sense, and leads to this.

from PIL import Image
Image.open("Tests/images/hopper.png").convert("P").convert("PA").save("out.tiff")

out.tiff.zip

Instead, this PR checks the palette mode, and fills the alpha channel with 255 if the palette is RGB.

@hugovk hugovk merged commit 0aca22e into python-pillow:main Feb 17, 2022
@radarhere radarhere deleted the p2pa branch February 17, 2022 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants