diff --git a/Tests/test_color_lut.py b/Tests/test_color_lut.py index 9477bea4f..336fa6c66 100644 --- a/Tests/test_color_lut.py +++ b/Tests/test_color_lut.py @@ -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)) diff --git a/src/PIL/ImageFilter.py b/src/PIL/ImageFilter.py index 6ba0ff6e7..6fcb3683f 100644 --- a/src/PIL/ImageFilter.py +++ b/src/PIL/ImageFilter.py @@ -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