Add repr for Color3DLUT

This commit is contained in:
Alexander 2018-04-12 11:54:54 +03:00
parent fb1d25417e
commit 75c76d91e1
2 changed files with 22 additions and 1 deletions

View File

@ -1,5 +1,7 @@
from __future__ import division
from array import array
from PIL import Image, ImageFilter
from helper import unittest, PillowTestCase
@ -264,8 +266,18 @@ class TestColorLut3DFilter(PillowTestCase):
self.assertEqual(lut.table, list(range(24)))
lut = ImageFilter.Color3DLUT((2, 2, 2), [(0, 1, 2, 3)] * 8,
channels=4)
channels=4)
def test_repr(self):
lut = ImageFilter.Color3DLUT(2, [0, 1, 2] * 8)
self.assertEqual(repr(lut),
"<Color3DLUT from list size=2x2x2 channels=3>")
lut = ImageFilter.Color3DLUT(
(3, 4, 5), array('f', [0, 0, 0, 0] * (3 * 4 * 5)),
channels=4, target_mode='YCbCr', _copy_table=False)
self.assertEqual(repr(lut),
"<Color3DLUT from array size=3x4x5 channels=4 target_mode=YCbCr>")
class TestGenerateColorLut3D(PillowTestCase):
def test_wrong_channels_count(self):

View File

@ -442,6 +442,15 @@ class Color3DLUT(MultibandFilter):
target_mode=target_mode or self.mode,
_copy_table=False)
def __repr__(self):
r = ["{0} from {1}".format(self.__class__.__name__,
self.table.__class__.__name__)]
r.append("size={0}x{1}x{2}".format(*self.size))
r.append("channels={0}".format(self.channels))
if self.mode:
r.append("target_mode={0}".format(self.mode))
return "<{}>".format(" ".join(r))
def filter(self, image):
from . import Image