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

Fix P -> PA conversion #6337

Merged
merged 5 commits into from Jun 1, 2022
Merged

Conversation

RedShy
Copy link
Contributor

@RedShy RedShy commented May 27, 2022

Resolves #6336

I fixed the function p2pa() in the file Convert.c by multiplying in[0] with 4 like other similar conversion functions do in the same source file.
I also added a test to cover the conversion "P" -> "PA".

@Lucas-C
Copy link
Contributor

Lucas-C commented May 27, 2022

Great, precise fix!

Looks legitimate to me.

Have you checked that the transparency of the resulting image can be seen with some image viewer ? (a web browser or your OS default one)

@RedShy
Copy link
Contributor Author

RedShy commented May 27, 2022

Have you checked that the transparency of the resulting image can be seen with some image viewer ? (a web browser or your OS default one)

Yes. I ran this code with and without the fix I added

Image.open("black.png").convert("PA").convert("RGBA").save("converted.png")

The original image is half black, half transparent
orig_black
Without the fix, the resulting image is all transparent:
old_black
With the fix the image is like the original: half transparent and half black
new_black

@radarhere
Copy link
Member

Some history.

#3728 added p2pa with in[0] * 4.
During the release of Pillow 6.0.0 though, this function caused a problem. Part of the fix was to change it to in[0]. I made that change without being able to iteratively test the fix myself though, so it is believable that that line did not actually need changing to fix Pillow 6.0.0.

@hugovk hugovk merged commit 37c6423 into python-pillow:main Jun 1, 2022
@radarhere radarhere changed the title Fix "P"->"PA" image conversion Fix P -> PA conversion Jun 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mismatch alpha channel when converting "P" to "PA" compared to "P" to "RGBA"
4 participants