Merge pull request #5579 from radarhere/simplified

This commit is contained in:
Hugo van Kemenade 2021-07-05 17:19:17 +03:00 committed by GitHub
commit b057f5f40f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1832,18 +1832,16 @@ class Image:
if source_palette is None: if source_palette is None:
if self.mode == "P": if self.mode == "P":
self.load() self.load()
real_source_palette = self.im.getpalette("RGB")[:768] source_palette = self.im.getpalette("RGB")[:768]
else: # L-mode else: # L-mode
real_source_palette = bytearray(i // 3 for i in range(768)) source_palette = bytearray(i // 3 for i in range(768))
else:
real_source_palette = source_palette
palette_bytes = b"" palette_bytes = b""
new_positions = [0] * 256 new_positions = [0] * 256
# pick only the used colors from the palette # pick only the used colors from the palette
for i, oldPosition in enumerate(dest_map): 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 new_positions[oldPosition] = i
# replace the palette color id of all pixel with the new id # replace the palette color id of all pixel with the new id