From 6f69379fdcd3f095cb3ab8a73d8079e6e7554df5 Mon Sep 17 00:00:00 2001 From: "neiljp (Neil Pilgrim)" Date: Sun, 20 Aug 2017 18:39:40 -0700 Subject: [PATCH] Image.remap_palette: Tweak to improve typing. --- PIL/Image.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index 96bd66b2e..c94c8b47e 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -1624,16 +1624,18 @@ class Image(object): if source_palette is None: if self.mode == "P": - source_palette = self.im.getpalette("RGB")[:768] + real_source_palette = self.im.getpalette("RGB")[:768] else: # L-mode - source_palette = bytearray(i//3 for i in range(768)) + real_source_palette = bytearray(i//3 for i in range(768)) + else: + real_source_palette = source_palette palette_bytes = b"" new_positions = [0]*256 # pick only the used colors from the palette for i, oldPosition in enumerate(dest_map): - palette_bytes += source_palette[oldPosition*3:oldPosition*3+3] + palette_bytes += real_source_palette[oldPosition*3:oldPosition*3+3] new_positions[oldPosition] = i # replace the palette color id of all pixel with the new id