2014-09-05 14:03:56 +04:00
|
|
|
from helper import unittest, PillowTestCase, hopper
|
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):
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper()
|
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-09-05 14:03:56 +04:00
|
|
|
im = hopper()
|
|
|
|
im = im.quantize(palette=hopper("P"))
|
2014-06-10 13:10:47 +04:00
|
|
|
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):
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper()
|
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):
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper('RGBA')
|
2014-06-10 13:10:47 +04:00
|
|
|
im.quantize()
|
|
|
|
self.assertRaises(Exception, lambda: im.quantize(method=0))
|
|
|
|
|
2015-08-22 16:03:11 +03:00
|
|
|
def test_quantize(self):
|
|
|
|
im = Image.open('Tests/images/caption_6_33_22.png')
|
|
|
|
im.convert('RGB').quantize().convert('RGB')
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
# End of file
|