Skip to content

Conversation

@radarhere
Copy link
Member

Address the problem raised in #7186

putpalette()'s strategy for attaching a palette to an image is to change the mode, set the palette, and then call load().

Pillow/src/PIL/Image.py

Lines 1918 to 1921 in 117618b

self.mode = "PA" if "A" in self.mode else "P"
self.palette = palette
self.palette.mode = "RGB"
self.load() # install new palette

We have been testing this with all of the valid modes.

However, the user found an error when calling putpalette() on an image directly after opening it, before load() is called. This means that L and LA images are attempted to be unpacked directly into P and PA images respectively, which Unpack.c doesn't currently support.

This PR fixes that.

@hugovk hugovk merged commit c62c514 into python-pillow:main Jun 13, 2023
@radarhere radarhere deleted the putpalette branch June 13, 2023 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants