Skip to content

Commit

Permalink
Merge pull request #5579 from radarhere/simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Jul 5, 2021
2 parents d43d446 + 9688507 commit b057f5f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/PIL/Image.py
Expand Up @@ -1832,18 +1832,16 @@ def remap_palette(self, dest_map, source_palette=None):
if source_palette is None:
if self.mode == "P":
self.load()
real_source_palette = self.im.getpalette("RGB")[:768]
source_palette = self.im.getpalette("RGB")[:768]
else: # L-mode
real_source_palette = bytearray(i // 3 for i in range(768))
else:
real_source_palette = source_palette
source_palette = bytearray(i // 3 for i in range(768))

palette_bytes = b""
new_positions = [0] * 256

# pick only the used colors from the palette
for i, oldPosition in enumerate(dest_map):
palette_bytes += real_source_palette[oldPosition * 3 : oldPosition * 3 + 3]
palette_bytes += source_palette[oldPosition * 3 : oldPosition * 3 + 3]
new_positions[oldPosition] = i

# replace the palette color id of all pixel with the new id
Expand Down

0 comments on commit b057f5f

Please sign in to comment.