Pillow/Tests/test_imageops.py

86 lines
2.3 KiB
Python
Raw Normal View History

2014-07-07 21:03:50 +04:00
from helper import unittest, PillowTestCase, lena
from PIL import ImageOps
2014-06-10 13:10:47 +04:00
class TestImageOps(PillowTestCase):
2014-06-10 13:10:47 +04:00
class Deformer:
def getmesh(self, im):
x, y = im.size
return [((0, 0, x, y), (0, 0, x, 0, x, y, y, 0))]
2014-06-10 13:10:47 +04:00
deformer = Deformer()
2014-06-10 13:10:47 +04:00
def test_sanity(self):
2014-06-10 13:10:47 +04:00
ImageOps.autocontrast(lena("L"))
ImageOps.autocontrast(lena("RGB"))
2014-06-10 13:10:47 +04:00
ImageOps.autocontrast(lena("L"), cutoff=10)
ImageOps.autocontrast(lena("L"), ignore=[0, 255])
2014-06-10 13:10:47 +04:00
ImageOps.colorize(lena("L"), (0, 0, 0), (255, 255, 255))
ImageOps.colorize(lena("L"), "black", "white")
2014-06-10 13:10:47 +04:00
ImageOps.crop(lena("L"), 1)
ImageOps.crop(lena("RGB"), 1)
2014-06-10 13:10:47 +04:00
ImageOps.deform(lena("L"), self.deformer)
ImageOps.deform(lena("RGB"), self.deformer)
2014-06-10 13:10:47 +04:00
ImageOps.equalize(lena("L"))
ImageOps.equalize(lena("RGB"))
2014-06-10 13:10:47 +04:00
ImageOps.expand(lena("L"), 1)
ImageOps.expand(lena("RGB"), 1)
ImageOps.expand(lena("L"), 2, "blue")
ImageOps.expand(lena("RGB"), 2, "blue")
2014-06-10 13:10:47 +04:00
ImageOps.fit(lena("L"), (128, 128))
ImageOps.fit(lena("RGB"), (128, 128))
2014-06-10 13:10:47 +04:00
ImageOps.flip(lena("L"))
ImageOps.flip(lena("RGB"))
2014-06-10 13:10:47 +04:00
ImageOps.grayscale(lena("L"))
ImageOps.grayscale(lena("RGB"))
2014-06-10 13:10:47 +04:00
ImageOps.invert(lena("L"))
ImageOps.invert(lena("RGB"))
2014-06-10 13:10:47 +04:00
ImageOps.mirror(lena("L"))
ImageOps.mirror(lena("RGB"))
2014-06-10 13:10:47 +04:00
ImageOps.posterize(lena("L"), 4)
ImageOps.posterize(lena("RGB"), 4)
2014-06-10 13:10:47 +04:00
ImageOps.solarize(lena("L"))
ImageOps.solarize(lena("RGB"))
2014-06-10 13:10:47 +04:00
def test_1pxfit(self):
# Division by zero in equalize if image is 1 pixel high
newimg = ImageOps.fit(lena("RGB").resize((1, 1)), (35, 35))
self.assertEqual(newimg.size, (35, 35))
2014-06-10 13:10:47 +04:00
newimg = ImageOps.fit(lena("RGB").resize((1, 100)), (35, 35))
self.assertEqual(newimg.size, (35, 35))
2014-06-10 13:10:47 +04:00
newimg = ImageOps.fit(lena("RGB").resize((100, 1)), (35, 35))
self.assertEqual(newimg.size, (35, 35))
2014-06-10 13:10:47 +04:00
def test_pil163(self):
# Division by zero in equalize if < 255 pixels in image (@PIL163)
2014-06-10 13:10:47 +04:00
i = lena("RGB").resize((15, 16))
ImageOps.equalize(i.convert("L"))
ImageOps.equalize(i.convert("P"))
ImageOps.equalize(i.convert("RGB"))
if __name__ == '__main__':
unittest.main()
# End of file