2014-09-05 14:03:56 +04:00
|
|
|
from helper import unittest, PillowTestCase, hopper
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-03-26 20:12:51 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImagePoint(PillowTestCase):
|
2013-07-01 02:42:19 +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
|
|
|
|
2017-09-01 14:05:40 +03:00
|
|
|
self.assertRaises(ValueError, im.point, list(range(256)))
|
2014-06-10 13:10:47 +04:00
|
|
|
im.point(list(range(256))*3)
|
|
|
|
im.point(lambda x: x)
|
2013-12-11 04:05:05 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im = im.convert("I")
|
2017-09-01 14:05:40 +03:00
|
|
|
self.assertRaises(ValueError, im.point, list(range(256)))
|
2014-06-10 13:10:47 +04:00
|
|
|
im.point(lambda x: x*1)
|
|
|
|
im.point(lambda x: x+1)
|
|
|
|
im.point(lambda x: x*1+1)
|
2017-09-01 14:05:40 +03:00
|
|
|
self.assertRaises(TypeError, im.point, lambda x: x-1)
|
|
|
|
self.assertRaises(TypeError, im.point, lambda x: x/1)
|
2013-12-11 04:05:05 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_16bit_lut(self):
|
|
|
|
""" Tests for 16 bit -> 8 bit lut for converting I->L images
|
|
|
|
see https://github.com/python-pillow/Pillow/issues/440
|
2014-07-24 01:31:49 +04:00
|
|
|
"""
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper("I")
|
2014-06-10 13:10:47 +04:00
|
|
|
im.point(list(range(256))*256, 'L')
|
|
|
|
|
2014-07-29 08:49:11 +04:00
|
|
|
def test_f_lut(self):
|
|
|
|
""" Tests for floating point lut of 8bit gray image """
|
2014-09-05 14:03:56 +04:00
|
|
|
im = hopper('L')
|
2014-07-29 08:49:11 +04:00
|
|
|
lut = [0.5 * float(x) for x in range(256)]
|
|
|
|
|
|
|
|
out = im.point(lut, 'F')
|
|
|
|
|
|
|
|
int_lut = [x//2 for x in range(256)]
|
|
|
|
self.assert_image_equal(out.convert('L'), im.point(int_lut, 'L'))
|
2014-08-28 15:44:19 +04:00
|
|
|
|
2017-01-28 06:02:22 +03:00
|
|
|
def test_f_mode(self):
|
2017-09-01 14:05:40 +03:00
|
|
|
im = hopper('F')
|
|
|
|
self.assertRaises(ValueError, im.point, None)
|
2017-01-28 06:02:22 +03:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|