1
from __future__ import annotations
5
from .helper import assert_image_equal, hopper
8
def test_sanity() -> None:
11
with pytest.raises(ValueError):
12
im.point(list(range(256)))
13
im.point(list(range(256)) * 3)
15
im.point(lambda x: x * 1.2)
18
with pytest.raises(ValueError):
19
im.point(list(range(256)))
20
im.point(lambda x: x * 1)
21
im.point(lambda x: x + 1)
22
im.point(lambda x: x - 1)
23
im.point(lambda x: x * 1 + 1)
24
im.point(lambda x: 0.1 + 0.2 * x)
25
im.point(lambda x: -x)
26
im.point(lambda x: x - 0.5)
27
im.point(lambda x: 1 - x / 2)
28
im.point(lambda x: (2 + x) / 3)
29
im.point(lambda x: 0.5)
30
im.point(lambda x: x / 1)
31
im.point(lambda x: x + x)
32
with pytest.raises(TypeError):
33
im.point(lambda x: x * x)
34
with pytest.raises(TypeError):
35
im.point(lambda x: x / x)
36
with pytest.raises(TypeError):
37
im.point(lambda x: 1 / x)
38
with pytest.raises(TypeError):
39
im.point(lambda x: x // 2)
42
def test_16bit_lut() -> None:
43
"""Tests for 16 bit -> 8 bit lut for converting I->L images
44
see https://github.com/python-pillow/Pillow/issues/440
47
im.point(list(range(256)) * 256, "L")
50
def test_f_lut() -> None:
51
"""Tests for floating point lut of 8bit gray image"""
53
lut = [0.5 * float(x) for x in range(256)]
55
out = im.point(lut, "F")
57
int_lut = [x // 2 for x in range(256)]
58
assert_image_equal(out.convert("L"), im.point(int_lut, "L"))
61
def test_f_mode() -> None:
63
with pytest.raises(ValueError):