mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 10:46:16 +03:00
Fixed remapping to palette with duplicate entries
This commit is contained in:
parent
ad7be550aa
commit
e7fab6abf4
|
@ -1087,6 +1087,19 @@ def test_palette_save_P(tmp_path):
|
||||||
assert_image_equal(reloaded, im)
|
assert_image_equal(reloaded, im)
|
||||||
|
|
||||||
|
|
||||||
|
def test_palette_save_duplicate_entries(tmp_path):
|
||||||
|
im = Image.new("P", (1, 2))
|
||||||
|
im.putpixel((0, 1), 1)
|
||||||
|
|
||||||
|
im.putpalette((0, 0, 0, 0, 0, 0))
|
||||||
|
|
||||||
|
out = str(tmp_path / "temp.gif")
|
||||||
|
im.save(out, palette=[0, 0, 0, 0, 0, 0, 1, 1, 1])
|
||||||
|
|
||||||
|
with Image.open(out) as reloaded:
|
||||||
|
assert reloaded.convert("RGB").getpixel((0, 1)) == (0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
def test_palette_save_all_P(tmp_path):
|
def test_palette_save_all_P(tmp_path):
|
||||||
frames = []
|
frames = []
|
||||||
colors = ((255, 0, 0), (0, 255, 0))
|
colors = ((255, 0, 0), (0, 255, 0))
|
||||||
|
|
|
@ -523,6 +523,8 @@ def _normalize_palette(im, palette, info):
|
||||||
index = im.palette.colors[source_color]
|
index = im.palette.colors[source_color]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
index = None
|
index = None
|
||||||
|
if index in used_palette_colors:
|
||||||
|
index = None
|
||||||
used_palette_colors.append(index)
|
used_palette_colors.append(index)
|
||||||
for i, index in enumerate(used_palette_colors):
|
for i, index in enumerate(used_palette_colors):
|
||||||
if index is None:
|
if index is None:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user