From 26663dd90baf0df449422ad1bb05404cf6b528de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Wallk=C3=B6tter?= Date: Sat, 2 Apr 2022 18:12:46 +0200 Subject: [PATCH] BUG: handle PIL paletts with <256 color palettes --- imageio/plugins/pillow_legacy.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imageio/plugins/pillow_legacy.py b/imageio/plugins/pillow_legacy.py index a70c733a5..f578876b2 100644 --- a/imageio/plugins/pillow_legacy.py +++ b/imageio/plugins/pillow_legacy.py @@ -671,7 +671,8 @@ def _palette_is_grayscale(pil_image): elif pil_image.info.get("transparency", None): # see issue #475 return False # get palette as an array with R, G, B columns - palette = np.asarray(pil_image.getpalette()).reshape((256, 3)) + # Note: starting in pillow 9.1 palettes may have less than 256 entries + palette = np.asarray(pil_image.getpalette()).reshape((-1, 3)) # Not all palette colors are used; unused colors have junk values. start, stop = pil_image.getextrema() valid_palette = palette[start : stop + 1]