mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-28 19:06:18 +03:00
Image.remap_palette: Tweak to improve typing.
This commit is contained in:
parent
72b3e6819d
commit
6f69379fdc
|
@ -1624,16 +1624,18 @@ class Image(object):
|
||||||
|
|
||||||
if source_palette is None:
|
if source_palette is None:
|
||||||
if self.mode == "P":
|
if self.mode == "P":
|
||||||
source_palette = self.im.getpalette("RGB")[:768]
|
real_source_palette = self.im.getpalette("RGB")[:768]
|
||||||
else: # L-mode
|
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""
|
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 += source_palette[oldPosition*3:oldPosition*3+3]
|
palette_bytes += real_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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user