mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 12:17:14 +03:00
Merge pull request #6283 from radarhere/palette
Populate Python palette in fromarray()
This commit is contained in:
commit
5e0e1e4114
|
@ -80,3 +80,15 @@ def test_fromarray():
|
|||
with pytest.raises(TypeError):
|
||||
wrapped = Wrapper(test("L"), {"shape": (100, 128)})
|
||||
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:
|
||||
im = new(mode, (1, 1))
|
||||
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
|
||||
return im
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user