mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-03-03 11:35:52 +03:00
Populate Python palette in fromarray()
This commit is contained in:
parent
134023796e
commit
ef8fd7f8b9
|
@ -80,3 +80,15 @@ def test_fromarray():
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
wrapped = Wrapper(test("L"), {"shape": (100, 128)})
|
wrapped = Wrapper(test("L"), {"shape": (100, 128)})
|
||||||
Image.fromarray(wrapped)
|
Image.fromarray(wrapped)
|
||||||
|
|
||||||
|
|
||||||
|
def test_fromarray_palette():
|
||||||
|
# Arrange
|
||||||
|
i = im.convert("L")
|
||||||
|
a = numpy.array(i)
|
||||||
|
|
||||||
|
# Act
|
||||||
|
out = Image.fromarray(a, "P")
|
||||||
|
|
||||||
|
# Assert that the Python and C palettes match
|
||||||
|
assert len(out.palette.colors) == len(out.im.getpalette()) / 3
|
||||||
|
|
|
@ -2838,6 +2838,10 @@ def frombuffer(mode, size, data, decoder_name="raw", *args):
|
||||||
if args[0] in _MAPMODES:
|
if args[0] in _MAPMODES:
|
||||||
im = new(mode, (1, 1))
|
im = new(mode, (1, 1))
|
||||||
im = im._new(core.map_buffer(data, size, decoder_name, 0, args))
|
im = im._new(core.map_buffer(data, size, decoder_name, 0, args))
|
||||||
|
if mode == "P":
|
||||||
|
from . import ImagePalette
|
||||||
|
|
||||||
|
im.palette = ImagePalette.ImagePalette("RGB", im.im.getpalette("RGB"))
|
||||||
im.readonly = 1
|
im.readonly = 1
|
||||||
return im
|
return im
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user