From daa8e7dacdfc7cbad9ccb1ae8e31dfb84af123c0 Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 12 Apr 2018 12:40:40 +0300 Subject: [PATCH] Add earlier catching of wrong channels count --- Tests/test_color_lut.py | 3 +++ src/PIL/ImageFilter.py | 2 ++ 2 files changed, 5 insertions(+) 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