Improved conversion from RGB to RGBa, LA and La #7888
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#7209 has started support from RGB to RGBa and La, but doesn't consider transparency.
When Pillow converts from RGB to RGBA, if there is an
info["transparency"]
entry, the pixels matching that value have their alpha channel set to zero.This PR adds support for converting from RGB to RGBa in a similar way, except that the matching pixels have all channels set to zero, because the alpha is premultiplied, and zero alpha means every channel should be zero.
https://pillow.readthedocs.io/en/stable/handbook/concepts.html#modes
Currently in
ImagingConvertTransparent
, the image is being converted from an image that may or may not be RGB, and the RGB transparency relates to the final image. From RGB to LA, the original image is RGB and the final image is not. So that additional path has been added.Now that RGB to LA works with transparency, converting from RGB to La is similar, except like 1 it premultiplies the values for transparent pixels so that the channels are all zero.