Ensure Image and core palettes are in sync after PA conversion - #9834
Ensure Image and core palettes are in sync after PA conversion#9834akx wants to merge 3 commits into
Conversation
| im.putalpha(Image.frombytes("L", (2, 1), bytes([240, 220]))) | ||
| assert im.get_flattened_data() == ((0, 240), (1, 220)) # Matches the alpha band |
There was a problem hiding this comment.
| im.putalpha(Image.frombytes("L", (2, 1), bytes([240, 220]))) | |
| assert im.get_flattened_data() == ((0, 240), (1, 220)) # Matches the alpha band |
These lines don't appear relevant.
There was a problem hiding this comment.
They're meant to show the palette alpha isn't used.
There was a problem hiding this comment.
I consider it pretty foundational that the palette doesn't affect pixel values (without conversion). I'm not sure it needs to be tested here? We already have
Pillow/Tests/test_image_putalpha.py
Lines 28 to 33 in abb8ba0
There was a problem hiding this comment.
That test_image_putalpha segment doesn't seem to really cover the contents of the palette.
I don't see how having this here really hurts?
| from . import ImagePalette | ||
|
|
||
| new_im.palette = ImagePalette.ImagePalette("RGB", im.getpalette("RGB")) | ||
| new_im.palette.dirty = True | ||
| new_im.load() |
There was a problem hiding this comment.
| from . import ImagePalette | |
| new_im.palette = ImagePalette.ImagePalette("RGB", im.getpalette("RGB")) | |
| new_im.palette.dirty = True | |
| new_im.load() | |
| new_im.putpalette(im.getpalette()) |
There was a problem hiding this comment.
Applied but with explicit "RGB" + comment.
There was a problem hiding this comment.
Out of curiosity, why explicit "RGB"?
There was a problem hiding this comment.
Because then you don't need to look up getpalette()'s definition to find out that the default is in fact "RGB", and not something that's inferred from im, as I would've initially assumed.
(Or, IOW, Explicit Is Better Than Implicit.)
…s dropped) Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
While working on #9833, I noticed that an RGBA palette's alphas would be "resurrected" if you converted from PA to P (which retains the RGBA palette in the core im object even if the
ImagePalettewrapper is recreated), and then to RGBA.With this, the "zombie" alpha from the RGBA doesn't appear anymore.
I would suspect this is more the Do What I Mean behavior, because an RGBA palette's alpha values weren't "visible" in a PA image anyway.