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

Mismatch alpha channel when converting "P" to "PA" compared to "P" to "RGBA" #6336

Closed
RedShy opened this issue May 27, 2022 · 1 comment · Fixed by #6337
Closed

Mismatch alpha channel when converting "P" to "PA" compared to "P" to "RGBA" #6336

RedShy opened this issue May 27, 2022 · 1 comment · Fixed by #6337

Comments

@RedShy
Copy link
Contributor

RedShy commented May 27, 2022

What did you do?

I opened a PNG "P" image and converted it to "PA" and "RGBA".

What did you expect to happen?

The alpha channel for every pixel is the same for the "PA" and "RGBA" conversion

What actually happened?

The alpha channel in the "PA" image is different from the "RGBA" image

What are your OS, Python and Pillow versions?

  • OS: Microsoft Windows 10.0.19043 Pro
  • Python: 3.10.4
  • Pillow: 9.1.1
def output(bytes):
    return ''.join(['\\x%02x' % b for b in bytes])

assert Image.open("tiny.png").mode == "P"

img_PA = Image.open("tiny.png").convert("PA")
img_RGBA = Image.open("tiny.png").convert("RGBA")

print(output(img_PA.tobytes()[slice(1, None, 2)]))   # \x00\x00\xff\xff\x00\x00\xd0\xb7\x00\x00\x38\x00\x00\x00\x15\xc0
print(output(img_RGBA.tobytes()[slice(3, None, 4)])) # \x00\x00\xff\xff\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00\xff\xff

The tiny image used:
tiny

I added PR #6337 that should resolve the issue

@Lucas-C
Copy link
Contributor

Lucas-C commented May 27, 2022

Thank you for reporting this and submitting a PR @RedShy 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants