mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-04 05:34:36 +03:00
Convert opaque RGBA color to RGB if that is the palette mode
This commit is contained in:
parent
3b9792ab74
commit
f3451aefc6
|
@ -29,6 +29,8 @@ def test_getcolor():
|
|||
rgba_palette = ImagePalette.ImagePalette("RGBA")
|
||||
assert rgba_palette.getcolor((0, 0, 0)) == rgba_palette.getcolor((0, 0, 0, 255))
|
||||
|
||||
assert palette.getcolor((0, 0, 0)) == palette.getcolor((0, 0, 0, 255))
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
palette.getcolor((1, 2, 3))
|
||||
|
||||
|
|
|
@ -105,8 +105,12 @@ 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,)
|
||||
if self.mode == "RGB":
|
||||
if len(color) == 4 and color[3] == 255:
|
||||
color = color[:3]
|
||||
elif self.mode == "RGBA":
|
||||
if len(color) == 3:
|
||||
color += (255,)
|
||||
try:
|
||||
return self.colors[color]
|
||||
except KeyError as e:
|
||||
|
|
Loading…
Reference in New Issue
Block a user