2023-12-21 14:13:31 +03:00
|
|
|
from __future__ import annotations
|
2024-01-20 14:23:03 +03:00
|
|
|
|
2020-02-12 19:29:19 +03:00
|
|
|
import pytest
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2020-02-12 19:29:19 +03:00
|
|
|
from .helper import assert_image_equal, hopper
|
2014-03-26 20:12:51 +04:00
|
|
|
|
2012-10-16 00:26:38 +04:00
|
|
|
|
2020-02-12 19:29:19 +03:00
|
|
|
def test_sanity():
|
|
|
|
im = hopper()
|
2013-12-11 04:05:05 +04:00
|
|
|
|
2020-02-12 19:29:19 +03:00
|
|
|
with pytest.raises(ValueError):
|
|
|
|
im.point(list(range(256)))
|
|
|
|
im.point(list(range(256)) * 3)
|
|
|
|
im.point(lambda x: x)
|
2022-04-07 01:58:57 +03:00
|
|
|
im.point(lambda x: x * 1.2)
|
2013-12-11 04:05:05 +04:00
|
|
|
|
2020-02-12 19:29:19 +03:00
|
|
|
im = im.convert("I")
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
im.point(list(range(256)))
|
|
|
|
im.point(lambda x: x * 1)
|
|
|
|
im.point(lambda x: x + 1)
|
2022-05-03 02:01:23 +03:00
|
|
|
im.point(lambda x: x - 1)
|
2020-02-12 19:29:19 +03:00
|
|
|
im.point(lambda x: x * 1 + 1)
|
2022-05-01 08:58:44 +03:00
|
|
|
im.point(lambda x: 0.1 + 0.2 * x)
|
|
|
|
im.point(lambda x: -x)
|
|
|
|
im.point(lambda x: x - 0.5)
|
|
|
|
im.point(lambda x: 1 - x / 2)
|
|
|
|
im.point(lambda x: (2 + x) / 3)
|
|
|
|
im.point(lambda x: 0.5)
|
2022-05-03 02:01:23 +03:00
|
|
|
im.point(lambda x: x / 1)
|
2022-05-03 23:53:50 +03:00
|
|
|
im.point(lambda x: x + x)
|
2020-02-12 19:29:19 +03:00
|
|
|
with pytest.raises(TypeError):
|
2022-05-01 08:58:44 +03:00
|
|
|
im.point(lambda x: x * x)
|
2022-05-03 23:53:50 +03:00
|
|
|
with pytest.raises(TypeError):
|
|
|
|
im.point(lambda x: x / x)
|
2020-02-12 19:29:19 +03:00
|
|
|
with pytest.raises(TypeError):
|
2022-05-01 08:58:44 +03:00
|
|
|
im.point(lambda x: 1 / x)
|
|
|
|
with pytest.raises(TypeError):
|
|
|
|
im.point(lambda x: x // 2)
|
2014-06-10 13:10:47 +04:00
|
|
|
|
2014-07-29 08:49:11 +04:00
|
|
|
|
2020-02-12 19:29:19 +03:00
|
|
|
def test_16bit_lut():
|
2020-08-31 00:37:17 +03:00
|
|
|
"""Tests for 16 bit -> 8 bit lut for converting I->L images
|
|
|
|
see https://github.com/python-pillow/Pillow/issues/440
|
|
|
|
"""
|
2020-02-12 19:29:19 +03:00
|
|
|
im = hopper("I")
|
|
|
|
im.point(list(range(256)) * 256, "L")
|
2014-07-29 08:49:11 +04:00
|
|
|
|
2014-08-28 15:44:19 +04:00
|
|
|
|
2020-02-12 19:29:19 +03:00
|
|
|
def test_f_lut():
|
2021-08-12 14:50:09 +03:00
|
|
|
"""Tests for floating point lut of 8bit gray image"""
|
2020-02-12 19:29:19 +03:00
|
|
|
im = hopper("L")
|
|
|
|
lut = [0.5 * float(x) for x in range(256)]
|
|
|
|
|
|
|
|
out = im.point(lut, "F")
|
|
|
|
|
|
|
|
int_lut = [x // 2 for x in range(256)]
|
|
|
|
assert_image_equal(out.convert("L"), im.point(int_lut, "L"))
|
|
|
|
|
|
|
|
|
|
|
|
def test_f_mode():
|
|
|
|
im = hopper("F")
|
|
|
|
with pytest.raises(ValueError):
|
|
|
|
im.point(None)
|