Skip to content

Fixed calling putpalette() on L and LA images before load()#7187

Merged
hugovk merged 1 commit intopython-pillow:mainfrom
radarhere:putpalette
Jun 13, 2023
Merged

Fixed calling putpalette() on L and LA images before load()#7187
hugovk merged 1 commit intopython-pillow:mainfrom
radarhere:putpalette

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