2014-07-07 21:03:50 +04:00
|
|
|
from helper import unittest, PillowTestCase, lena
|
2012-10-16 00:26:38 +04:00
|
|
|
|
|
|
|
from PIL import Image
|
|
|
|
|
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
class TestImageGetProjection(PillowTestCase):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
def test_sanity(self):
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
im = lena()
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
projection = im.getprojection()
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
self.assertEqual(len(projection), 2)
|
|
|
|
self.assertEqual(len(projection[0]), im.size[0])
|
|
|
|
self.assertEqual(len(projection[1]), im.size[1])
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2014-06-10 13:10:47 +04:00
|
|
|
# 8-bit image
|
|
|
|
im = Image.new("L", (10, 10))
|
|
|
|
self.assertEqual(im.getprojection()[0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
|
|
|
|
self.assertEqual(im.getprojection()[1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
|
|
|
|
im.paste(255, (2, 4, 8, 6))
|
|
|
|
self.assertEqual(im.getprojection()[0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0])
|
|
|
|
self.assertEqual(im.getprojection()[1], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0])
|
|
|
|
|
|
|
|
# 32-bit image
|
|
|
|
im = Image.new("RGB", (10, 10))
|
|
|
|
self.assertEqual(im.getprojection()[0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
|
|
|
|
self.assertEqual(im.getprojection()[1], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
|
|
|
|
im.paste(255, (2, 4, 8, 6))
|
|
|
|
self.assertEqual(im.getprojection()[0], [0, 0, 1, 1, 1, 1, 1, 1, 0, 0])
|
|
|
|
self.assertEqual(im.getprojection()[1], [0, 0, 0, 0, 1, 1, 0, 0, 0, 0])
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
unittest.main()
|
|
|
|
|
|
|
|
# End of file
|