More tests

This commit is contained in:
Alexander 2018-03-26 22:29:50 +03:00
parent b30b2a280f
commit 5f0b7ee73e
2 changed files with 66 additions and 3 deletions

View File

@ -19,7 +19,6 @@ class TestColorLut3DCoreAPI(PillowTestCase):
b / float(size3D-1) if size3D != 1 else 0,
r / float(size1D-1) if size1D != 1 else 0,
g / float(size2D-1) if size2D != 1 else 0,
b / float(size3D-1) if size3D != 1 else 0,
][:channels]
for b in range(size3D)
for g in range(size2D)
@ -42,7 +41,7 @@ class TestColorLut3DCoreAPI(PillowTestCase):
with self.assertRaisesRegexp(ValueError, "table_channels"):
im.im.color_lut_3d('RGB', Image.LINEAR,
*self.generate_unit_table(6, 3))
*self.generate_unit_table(5, 3))
with self.assertRaisesRegexp(ValueError, "table_channels"):
im.im.color_lut_3d('RGB', Image.LINEAR,
@ -60,6 +59,14 @@ class TestColorLut3DCoreAPI(PillowTestCase):
im.im.color_lut_3d('RGB', Image.LINEAR,
*self.generate_unit_table(3, (66, 3, 3)))
with self.assertRaisesRegexp(ValueError, r"size1D \* size2D \* size3D"):
im.im.color_lut_3d('RGB', Image.LINEAR,
3, 2, 2, 2, [0, 0, 0] * 7)
with self.assertRaisesRegexp(ValueError, r"size1D \* size2D \* size3D"):
im.im.color_lut_3d('RGB', Image.LINEAR,
3, 2, 2, 2, [0, 0, 0] * 9)
def test_correct_arguments(self):
im = Image.new('RGB', (10, 10), 0)
@ -124,6 +131,63 @@ class TestColorLut3DCoreAPI(PillowTestCase):
im.im.color_lut_3d('RGBA', Image.LINEAR,
*self.generate_unit_table(4, 3))
def test_units(self):
g = Image.linear_gradient('L')
im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),
g.transpose(Image.ROTATE_180)])
# Fast test with small cubes
for size in [2, 3, 5, 7, 11, 16, 17]:
self.assert_image_equal(im, im._new(
im.im.color_lut_3d('RGB', Image.LINEAR,
*self.generate_unit_table(3, size))))
# Not so fast
self.assert_image_equal(im, im._new(
im.im.color_lut_3d('RGB', Image.LINEAR,
*self.generate_unit_table(3, (2, 2, 65)))))
def test_channels_order(self):
g = Image.linear_gradient('L')
im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),
g.transpose(Image.ROTATE_180)])
# Reverse channels by splitting and using table
self.assert_image_equal(
Image.merge('RGB', im.split()[::-1]),
im._new(im.im.color_lut_3d('RGB', Image.LINEAR,
3, 2, 2, 2, [
0, 0, 0, 0, 0, 1,
0, 1, 0, 0, 1, 1,
1, 0, 0, 1, 0, 1,
1, 1, 0, 1, 1, 1,
])))
def test_overflow(self):
g = Image.linear_gradient('L')
im = Image.merge('RGB', [g, g.transpose(Image.ROTATE_90),
g.transpose(Image.ROTATE_180)])
transformed = im._new(im.im.color_lut_3d('RGB', Image.LINEAR,
3, 2, 2, 2,
[
-1, -1, -1, 2, -1, -1,
-1, 2, -1, 2, 2, -1,
-1, -1, 2, 2, -1, 2,
-1, 2, 2, 2, 2, 2,
])).load()
self.assertEqual(transformed[0, 0], (0, 0, 255))
self.assertEqual(transformed[50, 50], (0, 0, 255))
self.assertEqual(transformed[255, 0], (0, 255, 255))
self.assertEqual(transformed[205, 50], (0, 255, 255))
self.assertEqual(transformed[0, 255], (255, 0, 0))
self.assertEqual(transformed[50, 205], (255, 0, 0))
self.assertEqual(transformed[255, 255], (255, 255, 0))
self.assertEqual(transformed[205, 205], (255, 255, 0))
if __name__ == '__main__':
unittest.main()

View File

@ -740,7 +740,6 @@ _prepare_lut_table(PyObject* table, Py_ssize_t table_size)
} else {
prepared[i] = table_data[i] * (255 << PRECISION_BITS) + 0.5;
}
// printf("%f, %d ", table_data[i], prepared[i]);
}
#undef PRECISION_BITS