mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
Use first index for repeated color
This commit is contained in:
parent
450382f574
commit
7005e66f00
|
@ -155,6 +155,12 @@ def test_trns_RGB(tmp_path):
|
||||||
assert "transparency" not in im_p.info
|
assert "transparency" not in im_p.info
|
||||||
im_p.save(f)
|
im_p.save(f)
|
||||||
|
|
||||||
|
im = Image.new("RGB", (1, 1))
|
||||||
|
im.info["transparency"] = im.getpixel((0, 0))
|
||||||
|
im_p = im.convert("P", palette=Image.ADAPTIVE)
|
||||||
|
assert im_p.info["transparency"] == im_p.getpixel((0, 0))
|
||||||
|
im_p.save(f)
|
||||||
|
|
||||||
|
|
||||||
def test_gif_with_rgba_palette_to_p():
|
def test_gif_with_rgba_palette_to_p():
|
||||||
# See https://github.com/python-pillow/Pillow/issues/2433
|
# See https://github.com/python-pillow/Pillow/issues/2433
|
||||||
|
|
|
@ -53,10 +53,12 @@ class ImagePalette:
|
||||||
self._palette = palette
|
self._palette = palette
|
||||||
|
|
||||||
mode_len = len(self.mode)
|
mode_len = len(self.mode)
|
||||||
self.colors = {
|
self.colors = {}
|
||||||
tuple(self.palette[i : i + mode_len]): i // mode_len
|
for i in range(0, len(self.palette), mode_len):
|
||||||
for i in range(0, len(self.palette), mode_len)
|
color = tuple(self.palette[i : i + mode_len])
|
||||||
}
|
if color in self.colors:
|
||||||
|
continue
|
||||||
|
self.colors[color] = i // mode_len
|
||||||
|
|
||||||
def copy(self):
|
def copy(self):
|
||||||
new = ImagePalette()
|
new = ImagePalette()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user