2021-05-12 17:28:06 +11:00
|
|
|
"""test of core functions """
|
|
|
|
|
|
|
|
import floatimg
|
2021-05-11 22:53:41 +11:00
|
|
|
|
|
|
|
|
|
|
|
def test_create():
|
|
|
|
width = 640
|
|
|
|
height = 480
|
2021-05-12 17:28:06 +11:00
|
|
|
img = floatimg.create(width, height, floatimg.RGB)
|
2021-05-11 22:53:41 +11:00
|
|
|
assert img.width == width
|
|
|
|
assert img.height == height
|
2021-05-12 17:28:06 +11:00
|
|
|
assert img.type_id == floatimg.RGB
|
2021-05-11 22:53:41 +11:00
|
|
|
|
2021-05-12 17:28:06 +11:00
|
|
|
img = floatimg.create_rgb(width, height)
|
2021-05-11 22:53:41 +11:00
|
|
|
|
2021-05-12 17:28:06 +11:00
|
|
|
assert img.type_id == floatimg.RGB
|
2021-05-11 22:53:41 +11:00
|
|
|
# TODO inspect RVB
|
|
|
|
|
|
|
|
|
|
|
|
def test_clone():
|
2021-05-12 17:28:06 +11:00
|
|
|
width = 5
|
|
|
|
height = 5
|
|
|
|
img = floatimg.create(width, height, floatimg.RGB)
|
2021-05-12 22:57:49 +11:00
|
|
|
img.fill((127.0, 127.0, 127.0))
|
2021-05-12 17:28:06 +11:00
|
|
|
|
|
|
|
# clone without copying pixel values
|
2021-05-12 22:57:49 +11:00
|
|
|
img2 = img.clone(False)
|
2021-05-11 22:53:41 +11:00
|
|
|
assert img.width == img2.width
|
|
|
|
assert img.height == img2.height
|
|
|
|
assert img.type_id == img2.type_id
|
|
|
|
# TODO inspect RVB and do pixel per pixel comparison
|
2021-05-12 17:28:06 +11:00
|
|
|
for y in range(height):
|
|
|
|
for x in range(width):
|
2021-05-12 22:57:49 +11:00
|
|
|
assert img.get(x, y) != img2.get(x, y)
|
2021-05-12 17:28:06 +11:00
|
|
|
|
2021-05-12 22:57:49 +11:00
|
|
|
img2 = img.clone(True)
|
2021-05-12 17:28:06 +11:00
|
|
|
assert img.width == img2.width
|
|
|
|
assert img.height == img2.height
|
|
|
|
assert img.type_id == img2.type_id
|
|
|
|
# TODO inspect RVB and do pixel per pixel comparison
|
|
|
|
for y in range(height):
|
|
|
|
for x in range(width):
|
2021-05-12 22:57:49 +11:00
|
|
|
assert img.get(x, y) == img2.get(x, y)
|
2021-05-11 22:53:41 +11:00
|
|
|
|
|
|
|
|
|
|
|
def test_rgb_constant():
|
|
|
|
width = 5
|
|
|
|
height = 5
|
|
|
|
color = [127.0, 127.0, 127.0]
|
2021-05-12 17:28:06 +11:00
|
|
|
img = floatimg.create_rgb(width, height)
|
2021-05-12 22:57:49 +11:00
|
|
|
img.fill(color)
|
2021-05-11 22:53:41 +11:00
|
|
|
for y in range(height):
|
|
|
|
for x in range(width):
|
2021-05-12 22:57:49 +11:00
|
|
|
assert img.get(x, y) == color
|
|
|
|
|
2021-05-12 17:28:06 +11:00
|
|
|
|
|
|
|
def test_copy_data():
|
|
|
|
width = 5
|
|
|
|
height = 5
|
|
|
|
color = [127.0, 127.0, 127.0]
|
|
|
|
img = floatimg.create_rgb(width, height)
|
2021-05-12 22:57:49 +11:00
|
|
|
img.fill(color)
|
2021-05-12 17:28:06 +11:00
|
|
|
|
|
|
|
img2 = floatimg.create_rgb(width, height)
|
2021-05-12 22:57:49 +11:00
|
|
|
img2.fill((64.0, 64.0, 64.0))
|
2021-05-12 17:28:06 +11:00
|
|
|
|
|
|
|
img.copy_data(img2)
|
|
|
|
|
|
|
|
for y in range(height):
|
|
|
|
for x in range(width):
|
2021-05-12 22:57:49 +11:00
|
|
|
assert img.get(x, y) == img2.get(x, y)
|
2021-05-12 17:28:06 +11:00
|
|
|
|
|
|
|
|
|
|
|
def test_clear():
|
|
|
|
width, height = 5, 5
|
|
|
|
color = [127.0, 127.0, 127.0]
|
|
|
|
img = floatimg.create_rgb(width, height)
|
2021-05-12 22:57:49 +11:00
|
|
|
img.fill(color)
|
2021-05-12 17:28:06 +11:00
|
|
|
img.clear()
|
|
|
|
for y in range(height):
|
|
|
|
for x in range(width):
|
2021-05-12 22:57:49 +11:00
|
|
|
assert img.get(x, y) == [0.0, 0.0, 0.0]
|
2021-05-12 17:28:06 +11:00
|
|
|
|
|
|
|
|
|
|
|
def test_str_type():
|
|
|
|
width, height = 5, 5
|
|
|
|
img = floatimg.create_rgb(width, height)
|
|
|
|
assert img.str_type == "rgb"
|
|
|
|
|
|
|
|
|
|
|
|
def test__str__():
|
|
|
|
width, height = 5, 5
|
|
|
|
img = floatimg.create_rgb(width, height)
|
|
|
|
img_str = str(img)
|
|
|
|
assert " width=5 " in img_str
|
|
|
|
assert " height=5 " in img_str
|
|
|
|
assert " type=rgb>" in img_str
|
|
|
|
|
|
|
|
|
|
|
|
def test_put_rgb():
|
|
|
|
width, height = 5, 5
|
|
|
|
img = floatimg.create_rgb(width, height)
|
2021-05-12 22:57:49 +11:00
|
|
|
assert img.get(0, 0) == [0.0, 0.0, 0.0]
|
|
|
|
img.put(0, 0, (127.0, 127.0, 127.0))
|
|
|
|
assert img.get(0, 0) == [127.0, 127.0, 127.0]
|
2021-05-13 04:50:27 +11:00
|
|
|
|
|
|
|
|
|
|
|
def test_add():
|
|
|
|
width, height = 5, 5
|
|
|
|
img = floatimg.create_rgb(width, height)
|
|
|
|
color = (32.0, 32.0, 32.0)
|
|
|
|
img.put(0, 0, color)
|
|
|
|
img.add(0, 0, color)
|
|
|
|
assert img.get(0, 0) == [64.0, 64.0, 64.0]
|
2021-05-14 15:40:38 +11:00
|
|
|
|
|
|
|
|
|
|
|
def test_op_add():
|
|
|
|
width, height = 5, 5
|
|
|
|
img = floatimg.create_rgb(width, height)
|
|
|
|
color = (32.0, 32.0, 32.0)
|
|
|
|
img.fill(color)
|
|
|
|
img2 = floatimg.create_rgb(width, height)
|
|
|
|
img2.fill(color)
|
|
|
|
img3 = img + img2
|
|
|
|
for y in range(height):
|
|
|
|
for x in range(width):
|
|
|
|
assert img3.get(x, y) == [64.0, 64.0, 64.0]
|
|
|
|
|
|
|
|
|
|
|
|
def test_op_sub():
|
|
|
|
width, height = 5, 5
|
|
|
|
img = floatimg.create_rgb(width, height)
|
|
|
|
color = (32.0, 32.0, 32.0)
|
|
|
|
img.fill(color)
|
|
|
|
img2 = floatimg.create_rgb(width, height)
|
|
|
|
img2.fill(color)
|
|
|
|
img3 = img - img2
|
|
|
|
for y in range(height):
|
|
|
|
for x in range(width):
|
|
|
|
assert img3.get(x, y) == [0.0, 0.0, 0.0]
|
|
|
|
|
|
|
|
|
|
|
|
def test_op_mul():
|
|
|
|
width, height = 5, 5
|
|
|
|
img = floatimg.create_rgb(width, height)
|
|
|
|
color = (32.0, 32.0, 32.0)
|
|
|
|
img.fill(color)
|
|
|
|
img2 = floatimg.create_rgb(width, height)
|
|
|
|
img2.fill((2.0, 2.0, 2.0))
|
|
|
|
img3 = img * img2
|
|
|
|
for y in range(height):
|
|
|
|
for x in range(width):
|
|
|
|
assert img3.get(x, y) == [64.0, 64.0, 64.0]
|
|
|
|
|
|
|
|
def test_op_min():
|
|
|
|
width, height = 5, 5
|
|
|
|
img = floatimg.create_rgb(width, height)
|
|
|
|
img.fill((32.0, 0.0, 32.0))
|
|
|
|
|
|
|
|
img2 = floatimg.create_rgb(width, height)
|
|
|
|
img2.fill((0.0, 32.0, 0.0))
|
|
|
|
img3 = img.min(img2)
|
|
|
|
for y in range(height):
|
|
|
|
for x in range(width):
|
|
|
|
assert img3.get(x, y) == [0.0, 0.0, 0.0]
|
|
|
|
|
|
|
|
|
|
|
|
def test_op_max():
|
|
|
|
width, height = 5, 5
|
|
|
|
img = floatimg.create_rgb(width, height)
|
|
|
|
img.fill((32.0, 0.0, 32.0))
|
|
|
|
|
|
|
|
img2 = floatimg.create_rgb(width, height)
|
|
|
|
img2.fill((0.0, 32.0, 0.0))
|
|
|
|
img3 = img.max(img2)
|
|
|
|
for y in range(height):
|
|
|
|
for x in range(width):
|
|
|
|
assert img3.get(x, y) == [32.0, 32.0, 32.0]
|