Skip to content

Only load new palette in putpalette() if it contains raw data - #10035

Open
radarhere wants to merge 2 commits into
python-pillow:mainfrom
radarhere:putpalette_load
Open

radarhere wants to merge 2 commits into
python-pillow:mainfrom
radarhere:putpalette_load

Conversation

@radarhere

Copy link
Copy Markdown
Member

At the end of putpalette(), there is

self.load() # install new palette

If we take 'install' to mean 'copy into C', in terms of our big picture, there's no reason why that needs to be done. Every time Pillow goes to access C image data, load() is called first, so that copying could be lazily deferred.

What it is doing of immediate consequence is decoding the palette data from the raw mode into the mode. So this PR changes load() to only run if the palette data needs decoding.

At the same time, I will continue the principle of #10002 by not assigning a RGBA rawmode to an RGBA palette in putpalette(), and similarly for CMYK. So RGBA and CMYK raw mode palettes can have their load() operations lazily deferred as well.

This branch has not been deployed

No deployments
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.

1 participant