Conversation
| with Image.open("Tests/images/tiny.png") as im: | ||
| im_pa = im.convert("PA") | ||
| assert im_pa.getpalette() == im.getpalette() | ||
| assert im_pa.getpalette(None) == im.getpalette() |
There was a problem hiding this comment.
What's the reason for this None? 🤔
There was a problem hiding this comment.
It's returning the palette in the current palette mode, rather than the default of RGB - https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.getpalette
There was a problem hiding this comment.
Right, and .getpalette() calls load no matter what. 👍
|
With this, my test from #9834 fails: |
|
Yes, your test fails because you are accessing the core image directly - |
|
Ah yeah, that was it. assert im_p.palette.mode == "RGB"
print(im_p.im.getpalettemode())
im_p.load()
print(im_p.im.getpalettemode())prints out RGBA and RGB. ... Matter of separate discussion (and I'm surprised if no one's thought about it or discussed before), but I wonder if |
Alternative to #9834
#9834 found that after converting an image to P or PA with the WEB palette, the Python palette was updated, but the C palette was not. It solves the problem by
load()ing the Python palette into C at once (viaputpalette()).This PR instead just marks the Python palette as dirty, and the loading of the palette into C is lazily deferred until a future
load()call.