Add earlier catching of wrong channels count

This commit is contained in:
Alexander 2018-04-12 12:40:40 +03:00
parent bdd8dc40f6
commit daa8e7dacd
2 changed files with 5 additions and 0 deletions

View File

@ -254,6 +254,9 @@ class TestColorLut3DFilter(PillowTestCase):
with self.assertRaisesRegexp(ValueError, "should have a length of 3"):
ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8)
with self.assertRaisesRegexp(ValueError, "Only 3 or 4 output"):
ImageFilter.Color3DLUT((2, 2, 2), [[1, 1]] * 8, channels=2)
def test_convert_table(self):
lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)
self.assertEqual(tuple(lut.size), (2, 2, 2))

View File

@ -326,6 +326,8 @@ class Color3DLUT(MultibandFilter):
name = "Color 3D LUT"
def __init__(self, size, table, channels=3, target_mode=None, **kwargs):
if channels not in (3, 4):
raise ValueError("Only 3 or 4 output channels are supported")
self.size = size = self._check_size(size)
self.channels = channels
self.mode = target_mode