2019-02-03 18:34:53 +03:00
|
|
|
from .helper import PillowTestCase, hopper
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
from PIL import ImagePalette
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
class TestImagePutPalette(PillowTestCase):
|
|
|
|
def test_putpalette(self):
|
|
|
|
def palette(mode):
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper(mode).copy()
|
2019-06-13 18:54:24 +03:00
|
|
|
im.putpalette(list(range(256)) * 3)
|
2014-06-10 13:10:47 +04:00
|
|
|
p = im.getpalette()
|
|
|
|
if p:
|
|
|
|
return im.mode, p[:10]
|
|
|
|
return im.mode
|
2019-06-13 18:54:24 +03:00
|
|
|
|
2017-09-01 14:05:40 +03:00
|
|
|
self.assertRaises(ValueError, palette, "1")
|
2019-03-20 00:13:56 +03:00
|
|
|
for mode in ["L", "LA", "P", "PA"]:
|
2019-06-13 18:54:24 +03:00
|
|
|
self.assertEqual(
|
|
|
|
palette(mode),
|
|
|
|
("PA" if "A" in mode else "P", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
|
|
|
|
)
|
2017-09-01 14:05:40 +03:00
|
|
|
self.assertRaises(ValueError, palette, "I")
|
|
|
|
self.assertRaises(ValueError, palette, "F")
|
|
|
|
self.assertRaises(ValueError, palette, "RGB")
|
|
|
|
self.assertRaises(ValueError, palette, "RGBA")
|
|
|
|
self.assertRaises(ValueError, palette, "YCbCr")
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
def test_imagepalette(self):
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper("P")
|
2014-06-10 13:10:47 +04:00
|
|
|
im.putpalette(ImagePalette.negative())
|
|
|
|
im.putpalette(ImagePalette.random())
|
|
|
|
im.putpalette(ImagePalette.sepia())
|
|
|
|
im.putpalette(ImagePalette.wedge())
|