2023-12-21 14:13:31 +03:00
|
|
|
from __future__ import annotations
|
2024-01-20 14:23:03 +03:00
|
|
|
|
2013-10-16 09:01:30 +04:00
|
|
|
from PIL import Image
|
|
|
|
|
2019-07-06 23:40:53 +03:00
|
|
|
|
2024-01-27 07:19:43 +03:00
|
|
|
def test_white() -> None:
|
2019-11-04 01:18:55 +03:00
|
|
|
with Image.open("Tests/images/lab.tif") as i:
|
|
|
|
i.load()
|
2013-10-16 09:01:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
assert i.mode == "LAB"
|
2013-10-16 09:01:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
assert i.getbands() == ("L", "A", "B")
|
2013-10-16 09:01:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
k = i.getpixel((0, 0))
|
2013-10-16 09:01:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
L = i.getdata(0)
|
|
|
|
a = i.getdata(1)
|
|
|
|
b = i.getdata(2)
|
2013-10-16 09:01:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
assert k == (255, 128, 128)
|
2013-10-16 09:01:30 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
assert list(L) == [255] * 100
|
|
|
|
assert list(a) == [128] * 100
|
|
|
|
assert list(b) == [128] * 100
|
2013-10-16 09:01:30 +04:00
|
|
|
|
|
|
|
|
2024-01-27 07:19:43 +03:00
|
|
|
def test_green() -> None:
|
2019-11-04 01:18:55 +03:00
|
|
|
# l= 50 (/100), a = -100 (-128 .. 128) b=0 in PS
|
|
|
|
# == RGB: 0, 152, 117
|
|
|
|
with Image.open("Tests/images/lab-green.tif") as i:
|
|
|
|
k = i.getpixel((0, 0))
|
|
|
|
assert k == (128, 28, 128)
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2019-11-04 01:18:55 +03:00
|
|
|
|
2024-01-27 07:19:43 +03:00
|
|
|
def test_red() -> None:
|
2019-11-04 01:18:55 +03:00
|
|
|
# l= 50 (/100), a = 100 (-128 .. 128) b=0 in PS
|
|
|
|
# == RGB: 255, 0, 124
|
|
|
|
with Image.open("Tests/images/lab-red.tif") as i:
|
|
|
|
k = i.getpixel((0, 0))
|
|
|
|
assert k == (128, 228, 128)
|