2014-06-10 13:10:47 +04:00
|
|
|
from helper import unittest, PillowTestCase, tearDownModule, lena
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImageQuantize(PillowTestCase):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_sanity(self):
|
|
|
|
im = lena()
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im = im.quantize()
|
|
|
|
self.assert_image(im, "P", im.size)
|
2013-07-01 02:42:19 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im = lena()
|
|
|
|
im = im.quantize(palette=lena("P"))
|
|
|
|
self.assert_image(im, "P", im.size)
|
2013-03-11 23:33:04 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_octree_quantize(self):
|
|
|
|
im = lena()
|
2013-03-11 23:33:04 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im = im.quantize(100, Image.FASTOCTREE)
|
|
|
|
self.assert_image(im, "P", im.size)
|
2014-03-26 08:42:04 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
assert len(im.getcolors()) == 100
|
|
|
|
|
|
|
|
def test_rgba_quantize(self):
|
|
|
|
im = lena('RGBA')
|
|
|
|
im.quantize()
|
|
|
|
self.assertRaises(Exception, lambda: im.quantize(method=0))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
# End of file
|