Pillow/Tests/test_image_getprojection.py

32 lines
1.2 KiB
Python
Raw Normal View History

from .helper import PillowTestCase, hopper
from PIL import Image
2014-06-10 13:10:47 +04:00
class TestImageGetProjection(PillowTestCase):
def test_sanity(self):
im = hopper()
2014-06-10 13:10:47 +04:00
projection = im.getprojection()
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])
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])