Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure image is opaque after converting P to PA with RGB palette #6052

Merged
merged 2 commits into from
Feb 17, 2022

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.

src/libImaging/Convert.c Outdated Show resolved Hide resolved
@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.

None yet

3 participants