mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Convert getcolor input to RGBA if that is the palette mode
This commit is contained in:
parent
4d36feefc7
commit
3b9792ab74
|
@ -23,8 +23,12 @@ def test_getcolor():
|
|||
test_map = {}
|
||||
for i in range(256):
|
||||
test_map[palette.getcolor((i, i, i))] = i
|
||||
|
||||
assert len(test_map) == 256
|
||||
|
||||
# Colors can be converted between RGB and RGBA
|
||||
rgba_palette = ImagePalette.ImagePalette("RGBA")
|
||||
assert rgba_palette.getcolor((0, 0, 0)) == rgba_palette.getcolor((0, 0, 0, 255))
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
palette.getcolor((1, 2, 3))
|
||||
|
||||
|
|
|
@ -105,6 +105,8 @@ class ImagePalette:
|
|||
if self.rawmode:
|
||||
raise ValueError("palette contains raw palette data")
|
||||
if isinstance(color, tuple):
|
||||
if self.mode == "RGBA" and len(color) == 3:
|
||||
color += (255,)
|
||||
try:
|
||||
return self.colors[color]
|
||||
except KeyError as e:
|
||||
|
|
Loading…
Reference in New Issue
Block a user