mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-06 13:15:48 +03:00
Limit quantized palette to number of colors
This commit is contained in:
parent
cc927343da
commit
ec198899f6
|
@ -77,6 +77,13 @@ def test_quantize_dither_diff():
|
||||||
assert dither.tobytes() != nodither.tobytes()
|
assert dither.tobytes() != nodither.tobytes()
|
||||||
|
|
||||||
|
|
||||||
|
def test_colors():
|
||||||
|
im = hopper()
|
||||||
|
colors = 2
|
||||||
|
converted = im.quantize(colors)
|
||||||
|
assert len(converted.palette.palette) == colors * len("RGB")
|
||||||
|
|
||||||
|
|
||||||
def test_transparent_colors_equal():
|
def test_transparent_colors_equal():
|
||||||
im = Image.new("RGBA", (1, 2), (0, 0, 0, 0))
|
im = Image.new("RGBA", (1, 2), (0, 0, 0, 0))
|
||||||
px = im.load()
|
px = im.load()
|
||||||
|
|
|
@ -1111,7 +1111,8 @@ class Image:
|
||||||
from . import ImagePalette
|
from . import ImagePalette
|
||||||
|
|
||||||
mode = im.im.getpalettemode()
|
mode = im.im.getpalettemode()
|
||||||
im.palette = ImagePalette.ImagePalette(mode, im.im.getpalette(mode, mode))
|
palette = im.im.getpalette(mode, mode)[: colors * len(mode)]
|
||||||
|
im.palette = ImagePalette.ImagePalette(mode, palette)
|
||||||
|
|
||||||
return im
|
return im
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user