Make _make_gamma_lut() public

This commit is contained in:
hugovk 2014-07-19 01:45:57 +03:00
parent 17223001df
commit 3c39a44f6e
2 changed files with 20 additions and 1 deletions

View File

@ -134,7 +134,7 @@ def _make_linear_lut(black, white):
return lut
def _make_gamma_lut(exp, mode="RGB"):
def make_gamma_lut(exp):
lut = []
for i in range(256):
lut.append(int(((i / 255.0) ** exp) * 255.0 + 0.5))

View File

@ -44,6 +44,25 @@ class TestImagePalette(PillowTestCase):
self.assertIsInstance(p, ImagePalette)
self.assertEqual(p.palette, palette.tobytes())
def test_make_gamma_lut(self):
# Arrange
from PIL.ImagePalette import make_gamma_lut
exp = 5
# Act
lut = make_gamma_lut(exp)
# Assert
self.assertIsInstance(lut, list)
self.assertEqual(len(lut), 256)
# Check a few values
self.assertEqual(lut[0], 0)
self.assertEqual(lut[63], 0)
self.assertEqual(lut[127], 8)
self.assertEqual(lut[191], 60)
self.assertEqual(lut[255], 255)
if __name__ == '__main__':
unittest.main()