Pillow

Форк
0
/
test_image_point.py 
64 строки · 1.6 Кб
1
from __future__ import annotations
2

3
import pytest
4

5
from .helper import assert_image_equal, hopper
6

7

8
def test_sanity() -> None:
9
    im = hopper()
10

11
    with pytest.raises(ValueError):
12
        im.point(list(range(256)))
13
    im.point(list(range(256)) * 3)
14
    im.point(lambda x: x)
15
    im.point(lambda x: x * 1.2)
16

17
    im = im.convert("I")
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)
40

41

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
45
    """
46
    im = hopper("I")
47
    im.point(list(range(256)) * 256, "L")
48

49

50
def test_f_lut() -> None:
51
    """Tests for floating point lut of 8bit gray image"""
52
    im = hopper("L")
53
    lut = [0.5 * float(x) for x in range(256)]
54

55
    out = im.point(lut, "F")
56

57
    int_lut = [x // 2 for x in range(256)]
58
    assert_image_equal(out.convert("L"), im.point(int_lut, "L"))
59

60

61
def test_f_mode() -> None:
62
    im = hopper("F")
63
    with pytest.raises(ValueError):
64
        im.point([])
65

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.