Skip to content

Ignore putpalette rawmode if data is an ImagePalette - #10032

Open
radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:rawmode
Open

radarhere wants to merge 1 commit into
python-pillow:mainfrom
radarhere:rawmode

Conversation

@radarhere

Copy link
Copy Markdown
Member

If an ImagePalette is passed to putpalette(),

Pillow/src/PIL/Image.py

Lines 2135 to 2138 in 7d67d37

def putpalette(
self,
data: ImagePalette.ImagePalette | bytes | Sequence[int],
rawmode: str = "RGB",

then the rawmode from the palette is used.

Pillow/src/PIL/Image.py

Lines 2163 to 2164 in 7d67d37

if isinstance(data, ImagePalette.ImagePalette):
palette = ImagePalette.raw(data.rawmode or "RGB", data.palette)

But only at first? Later, the rawmode argument is used.

Pillow/src/PIL/Image.py

Lines 2169 to 2172 in 7d67d37

if rawmode.startswith("CMYK"):
self.palette.mode = "CMYK"
elif "A" in rawmode:
self.palette.mode = "RGBA"

If an ImagePalette is passed to putpalette(), let's be simple and consistent and ignore rawmode.

When considering this, you might wonder if the documentation lays out a different expectation. The answer is no - it doesn't even mention that you can pass an ImagePalette in. See https://pillow.readthedocs.io/en/latest/reference/Image.html#PIL.Image.Image.putpalette

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