Skip to content

ImagePalette: loading a translucent RGBA color into an RGB palette will break the palette #6652

@jsbueno

Description

@jsbueno

This is a minor thing:

In PIL/ImagePalette.py, we have

if len(color) == 4 and color[3] == 255:
color = color[:3]

And then, this color is consumed in line 151, always assuming it is 3-bytes long (and having 4 would make colors from that point on "out of sync") . I was about to send a small PR raising value error in the unchecked case:

   if len(color) == 4 and color[3] < 255:
          raise ValueError(...)

But then, why not just truncate the alpha away, and always use the RGB value if an RGBA color is added to an RGB palette?
Can we do that?

(the sole purpose of this issue is to ask this question - I should submit fix + test afterwards)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions