Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ImagePalette's palette argument expects different alignment since 8.3.0 #5595

@krukai

Description

@krukai

It seems that PIL.ImagePalette.ImagePalette's palette argument no longer expects a palette aligned by channels, but one color after the other, i.e. RGBRGBRGB rather than RRRGGGBBB as previously.

I assume this is an unintentional breaking change as it is neither specifically mentioned in the patch notes, nor was the documentation updated. I could not find any PR or bug report on this, either (unless I missed it - I am sorry if that's the case).

If this is a bug, I hope it can actually become a feature as I personally prefer the new ordering.

Example:

import PIL.Image
import PIL.ImagePalette

p = [0, 0, 0,
     255, 0, 0,
     0, 255, 0]

palette = PIL.ImagePalette.ImagePalette(mode='RGB', palette=p, size=len(p))

image = PIL.Image.new('P', (100, 100), 1)  # fill image with second color in the palette
image.putpalette(palette)

image.show()  # Gives a blue image on 8.2.0 and a red image since 8.3.0

assert image.getpalette()[:len(p)] == p, 'This assert succeeds in 8.3.0'

Cheers!

  • OS: Arch Linux
  • Python: 3.9
  • Pillow: 8.3.0+

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