Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

putpalette() rawmode may be modes that can be unpacked to RGB #5634

Merged
merged 1 commit into from
Aug 13, 2021

Conversation

radarhere
Copy link
Member

Resolves #1280 by better documenting the range of raw modes that im.putpalette() can accept. It does not only accept RGB or RGBA, but also any raw mode that can be unpacked to RGB.

This means that the limit for the length of data is not just 768 or 1024. Since the limit is the number of channels multiplied by 256, for "R", it is 256.

>>> from PIL import Image
>>> im = Image.new("L", (1, 1))
>>> im.putpalette((1,)*256, "R")
>>> im.putpalette((1,)*257, "R")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "PIL/Image.py", line 1776, in putpalette
    self.load()  # install new palette
  File "PIL/Image.py", line 838, in load
    palette_length = self.im.putpalette(mode, arr)
ValueError: invalid palette size

@hugovk hugovk merged commit ea4263c into python-pillow:master Aug 13, 2021
@radarhere radarhere deleted the putpalette branch August 13, 2021 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs not providing required information for setting image palletes
2 participants