Pillow/Tests/test_format_lab.py

47 lines
1.1 KiB
Python
Raw Normal View History

from .helper import unittest, PillowTestCase
from PIL import Image
2014-06-10 13:10:47 +04:00
class TestFormatLab(PillowTestCase):
2014-06-10 13:10:47 +04:00
def test_white(self):
i = Image.open('Tests/images/lab.tif')
2014-06-10 13:10:47 +04:00
i.load()
2014-06-10 13:10:47 +04:00
self.assertEqual(i.mode, 'LAB')
2014-06-10 13:10:47 +04:00
self.assertEqual(i.getbands(), ('L', 'A', 'B'))
2014-06-10 13:10:47 +04:00
k = i.getpixel((0, 0))
self.assertEqual(k, (255, 128, 128))
2014-06-10 13:10:47 +04:00
L = i.getdata(0)
a = i.getdata(1)
b = i.getdata(2)
2014-06-10 13:10:47 +04:00
self.assertEqual(list(L), [255]*100)
self.assertEqual(list(a), [128]*100)
self.assertEqual(list(b), [128]*100)
2014-06-10 13:10:47 +04:00
def test_green(self):
# l= 50 (/100), a = -100 (-128 .. 128) b=0 in PS
# == RGB: 0, 152, 117
i = Image.open('Tests/images/lab-green.tif')
2014-06-10 13:10:47 +04:00
k = i.getpixel((0, 0))
self.assertEqual(k, (128, 28, 128))
def test_red(self):
# l= 50 (/100), a = 100 (-128 .. 128) b=0 in PS
# == RGB: 255, 0, 124
i = Image.open('Tests/images/lab-red.tif')
k = i.getpixel((0, 0))
self.assertEqual(k, (128, 228, 128))
if __name__ == '__main__':
unittest.main()