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

Opacity information is lost when reading a P mode image with transparency information #235

Open
alexwlchan opened this issue Apr 29, 2024 · 2 comments
Labels
fixed in upcoming release fix will arrive with next release

Comments

@alexwlchan
Copy link

Describe the bug

If you have a PNG image with mode P and a custom transparency value, opacity information is lost when you convert to HEIC.

Steps/Code to Reproduce

from PIL import Image, ImageDraw
from pillow_heif import register_heif_opener

register_heif_opener()

# Draw a basic checkerboard image
im = Image.new("P", size=(100, 100))

draw = ImageDraw.Draw(im)
draw.rectangle(xy=[(0, 0),   (50, 50)],   fill=255)
draw.rectangle(xy=[(50, 50), (100, 100)], fill=255)

# Save the image as a PNG, marking the 0'th colour in the palette as transparent
im.save("checkerboard.png", transparency=0)

# Open the image, then save it as an AVIF
opened_im = Image.open("checkerboard.png")
opened_im.save("checkerboard.heic", transparency=0)

Expected Results

An image with a simple 2×2 checkerboard pattern, with transparent squares in the bottom left and top right.

Actual Results

The HEIC is rendered as a solid black image, losing the transparency from the PNG.

Screenshot 2024-04-29 at 22 39 05

Versions

3.11.8 (v3.11.8:db85d51d3e, Feb  6 2024, 18:02:37) [Clang 13.0.0 (clang-1300.0.29.30)]
macOS-13.6.6-x86_64-i386-64bit
0.16.0
{'libheif': '1.17.6', 'HEIF': 'x265 HEVC encoder (3.4+31-6722fce1f)', 'AVIF': 'AOMedia Project AV1 Encoder 3.8.1', 'encoders': {'x265': 'x265 HEVC encoder (3.4+31-6722fce1f)', 'aom': 'AOMedia Project AV1 Encoder 3.8.1', 'mask': 'mask'}, 'decoders': {'libde265': 'libde265 HEVC decoder, version 1.0.15', 'aom': 'AOMedia Project AV1 Decoder 3.8.1'}}
@alexwlchan
Copy link
Author

alexwlchan commented Apr 29, 2024

Note: this may have a similar underlying cause/fix to fdintino/pillow-avif-plugin#48, which is where I originally spotted this issue.

@bigcat88
Copy link
Owner

bigcat88 commented May 8, 2024

Corrected the behaviour when the transparency is 0

Thank you for the bug report.

@bigcat88 bigcat88 added the fixed in upcoming release fix will arrive with next release label May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in upcoming release fix will arrive with next release
Projects
None yet
Development

No branches or pull requests

2 participants