diff --git a/PIL/ImagePalette.py b/PIL/ImagePalette.py index 67bf593e6..3b9e96172 100644 --- a/PIL/ImagePalette.py +++ b/PIL/ImagePalette.py @@ -17,6 +17,7 @@ # import array +import warnings from PIL import Image, ImageColor @@ -125,6 +126,26 @@ def raw(rawmode, data): # Factories def _make_linear_lut(black, white): + warnings.warn( + '_make_linear_lut() is deprecated. ' + 'Please call make_linear_lut() instead.', + DeprecationWarning, + stacklevel=2 + ) + return make_linear_lut(black, white) + + +def _make_gamma_lut(exp): + warnings.warn( + '_make_gamma_lut() is deprecated. ' + 'Please call make_gamma_lut() instead.', + DeprecationWarning, + stacklevel=2 + ) + return make_gamma_lut(exp) + + +def make_linear_lut(black, white): lut = [] if black == 0: for i in range(256): diff --git a/Tests/test_imagepalette.py b/Tests/test_imagepalette.py index af742edd1..8356b5d60 100644 --- a/Tests/test_imagepalette.py +++ b/Tests/test_imagepalette.py @@ -44,6 +44,34 @@ class TestImagePalette(PillowTestCase): self.assertIsInstance(p, ImagePalette) self.assertEqual(p.palette, palette.tobytes()) + def test_make_linear_lut(self): + # Arrange + from PIL.ImagePalette import make_linear_lut + black = 0 + white = 255 + + # Act + lut = make_linear_lut(black, white) + + # Assert + self.assertIsInstance(lut, list) + self.assertEqual(len(lut), 256) + # Check values + for i in range(0, len(lut)): + self.assertEqual(lut[i], i) + + def test_make_linear_lut_not_yet_implemented(self): + # Update after FIXME + # Arrange + from PIL.ImagePalette import make_linear_lut + black = 1 + white = 255 + + # Act + self.assertRaises( + NotImplementedError, + lambda: make_linear_lut(black, white)) + def test_make_gamma_lut(self): # Arrange from PIL.ImagePalette import make_gamma_lut @@ -62,6 +90,27 @@ class TestImagePalette(PillowTestCase): self.assertEqual(lut[191], 60) self.assertEqual(lut[255], 255) + def test_private_make_linear_lut_warning(self): + # Arrange + from PIL.ImagePalette import _make_linear_lut + black = 0 + white = 255 + + # Act / Assert + self.assert_warning( + DeprecationWarning, + lambda: _make_linear_lut(black, white)) + + def test_private_make_gamma_lut_warning(self): + # Arrange + from PIL.ImagePalette import _make_gamma_lut + exp = 5 + + # Act / Assert + self.assert_warning( + DeprecationWarning, + lambda: _make_gamma_lut(exp)) + if __name__ == '__main__': unittest.main()