mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-13 17:25:49 +03:00
Allow rawmode None to return the palette in the current mode
This commit is contained in:
parent
852859476b
commit
6be87277f7
|
@ -25,9 +25,10 @@ def test_palette_rawmode():
|
|||
im = Image.new("P", (1, 1))
|
||||
im.putpalette((1, 2, 3))
|
||||
|
||||
rgb = im.getpalette("RGB")
|
||||
assert len(rgb) == 256 * 3
|
||||
assert rgb[:3] == [1, 2, 3]
|
||||
for rawmode in ("RGB", None):
|
||||
rgb = im.getpalette(rawmode)
|
||||
assert len(rgb) == 256 * 3
|
||||
assert rgb[:3] == [1, 2, 3]
|
||||
|
||||
# Convert the RGB palette to RGBA
|
||||
rgba = im.getpalette("RGBA")
|
||||
|
@ -41,6 +42,7 @@ def test_palette_rawmode():
|
|||
assert len(rgb) == 256 * 3
|
||||
assert rgb[:3] == [1, 2, 3]
|
||||
|
||||
rgba = im.getpalette("RGBA")
|
||||
assert len(rgba) == 256 * 4
|
||||
assert rgba[:4] == [1, 2, 3, 4]
|
||||
for rawmode in ("RGBA", None):
|
||||
rgba = im.getpalette(rawmode)
|
||||
assert len(rgba) == 256 * 4
|
||||
assert rgba[:4] == [1, 2, 3, 4]
|
||||
|
|
|
@ -1405,7 +1405,8 @@ class Image:
|
|||
"""
|
||||
Returns the image palette as a list.
|
||||
|
||||
:param rawmode: The mode in which to return the palette.
|
||||
:param rawmode: The mode in which to return the palette. ``None`` will
|
||||
return the palette in its current mode.
|
||||
:returns: A list of color values [r, g, b, ...], or None if the
|
||||
image has no palette.
|
||||
"""
|
||||
|
@ -1415,6 +1416,8 @@ class Image:
|
|||
mode = self.im.getpalettemode()
|
||||
except ValueError:
|
||||
return None # no palette
|
||||
if rawmode is None:
|
||||
rawmode = mode
|
||||
return list(self.im.getpalette(mode, rawmode))
|
||||
|
||||
def getpixel(self, xy):
|
||||
|
|
Loading…
Reference in New Issue
Block a user