Skip to content

How does PA -> P conversion work? #6506

Answered by radarhere
Yay295 asked this question in Q&A
Discussion options

You must be logged in to vote

You are correct that PA is not directly converted to P in the C layer at the moment. When support is missing for a direct conversion, the Python layer instead converts first to the base mode, and then to the destination mode.

Pillow/src/PIL/Image.py

Lines 1034 to 1040 in 87ecd01

try:
im = self.im.convert(mode, dither)
except ValueError:
try:
# normalize source image and try again
im = self.im.convert(getmodebase(self.mode))
im = im.convert(mode, dither)

So it goes PA to RGB, and then RGB to P.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@radarhere
Comment options

Answer selected by Yay295
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants