mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +03:00
improve CoreResampleAccuracy test. Use all bands configurations
This commit is contained in:
parent
8180b0f4c3
commit
a1b12f792a
|
@ -35,7 +35,7 @@ class TestImagingResampleVulnerability(PillowTestCase):
|
|||
|
||||
|
||||
class TestImagingCoreResampleAccuracy(PillowTestCase):
|
||||
def make_case(self, size, color):
|
||||
def make_case(self, mode, size, color):
|
||||
"""Makes a sample image with two dark and two bright squares.
|
||||
For example:
|
||||
e0 e0 1f 1f
|
||||
|
@ -50,7 +50,7 @@ class TestImagingCoreResampleAccuracy(PillowTestCase):
|
|||
rectangle = ImageDraw.Draw(i).rectangle
|
||||
rectangle((0, 0, size[0] // 2 - 1, size[1] // 2 - 1), bright)
|
||||
rectangle((size[0] // 2, size[1] // 2, size[0], size[1]), bright)
|
||||
return i
|
||||
return i.convert(mode)
|
||||
|
||||
def make_sample(self, data, size):
|
||||
"""Restores a sample image from given data string which contains
|
||||
|
@ -70,17 +70,16 @@ class TestImagingCoreResampleAccuracy(PillowTestCase):
|
|||
return sample
|
||||
|
||||
def check_case(self, case, sample):
|
||||
for channel in case.split():
|
||||
s_px = sample.load()
|
||||
c_px = channel.load()
|
||||
for y in range(case.size[1]):
|
||||
for x in range(case.size[0]):
|
||||
if c_px[x, y] != s_px[x, y]:
|
||||
message = '\nHave: \n{}\n\nExpected: \n{}'.format(
|
||||
self.serialize_image(channel),
|
||||
self.serialize_image(sample),
|
||||
)
|
||||
self.assertEqual(s_px[x, y], c_px[x, y], message)
|
||||
s_px = sample.load()
|
||||
c_px = case.load()
|
||||
for y in range(case.size[1]):
|
||||
for x in range(case.size[0]):
|
||||
if c_px[x, y] != s_px[x, y]:
|
||||
message = '\nHave: \n{}\n\nExpected: \n{}'.format(
|
||||
self.serialize_image(case),
|
||||
self.serialize_image(sample),
|
||||
)
|
||||
self.assertEqual(s_px[x, y], c_px[x, y], message)
|
||||
|
||||
def serialize_image(self, image):
|
||||
s_px = image.load()
|
||||
|
@ -93,61 +92,67 @@ class TestImagingCoreResampleAccuracy(PillowTestCase):
|
|||
)
|
||||
|
||||
def test_reduce_bilinear(self):
|
||||
case = self.make_case((8, 8), 0xe1)
|
||||
data = ('e1 c9'
|
||||
'c9 b7')
|
||||
self.check_case(
|
||||
case.resize((4, 4), Image.BILINEAR),
|
||||
self.make_sample(data, (4, 4)))
|
||||
for mode in ['RGBX', 'RGB', 'L']:
|
||||
case = self.make_case(mode, (8, 8), 0xe1)
|
||||
case = case.resize((4, 4), Image.BILINEAR)
|
||||
data = ('e1 c9'
|
||||
'c9 b7')
|
||||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (4, 4)))
|
||||
|
||||
def test_reduce_bicubic(self):
|
||||
case = self.make_case((12, 12), 0xe1)
|
||||
data = ('e1 e3 d4'
|
||||
'e3 e5 d6'
|
||||
'd4 d6 c9')
|
||||
self.check_case(
|
||||
case.resize((6, 6), Image.BICUBIC),
|
||||
self.make_sample(data, (6, 6)))
|
||||
for mode in ['RGBX', 'RGB', 'L']:
|
||||
case = self.make_case(mode, (12, 12), 0xe1)
|
||||
case = case.resize((6, 6), Image.BICUBIC)
|
||||
data = ('e1 e3 d4'
|
||||
'e3 e5 d6'
|
||||
'd4 d6 c9')
|
||||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (6, 6)))
|
||||
|
||||
def test_reduce_lanczos(self):
|
||||
case = self.make_case((16, 16), 0xe1)
|
||||
data = ('e1 e0 e4 d7'
|
||||
'e0 df e3 d6'
|
||||
'e4 e3 e7 da'
|
||||
'd7 d6 d9 ce')
|
||||
self.check_case(
|
||||
case.resize((8, 8), Image.LANCZOS),
|
||||
self.make_sample(data, (8, 8)))
|
||||
for mode in ['RGBX', 'RGB', 'L']:
|
||||
case = self.make_case(mode, (16, 16), 0xe1)
|
||||
case = case.resize((8, 8), Image.LANCZOS)
|
||||
data = ('e1 e0 e4 d7'
|
||||
'e0 df e3 d6'
|
||||
'e4 e3 e7 da'
|
||||
'd7 d6 d9 ce')
|
||||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (8, 8)))
|
||||
|
||||
def test_enlarge_bilinear(self):
|
||||
case = self.make_case((2, 2), 0xe1)
|
||||
data = ('e1 b0'
|
||||
'b0 98')
|
||||
self.check_case(
|
||||
case.resize((4, 4), Image.BILINEAR),
|
||||
self.make_sample(data, (4, 4)))
|
||||
for mode in ['RGBX', 'RGB', 'L']:
|
||||
case = self.make_case(mode, (2, 2), 0xe1)
|
||||
case = case.resize((4, 4), Image.BILINEAR)
|
||||
data = ('e1 b0'
|
||||
'b0 98')
|
||||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (4, 4)))
|
||||
|
||||
def test_enlarge_bicubic(self):
|
||||
case = self.make_case((4, 4), 0xe1)
|
||||
data = ('e1 e5 ee b9'
|
||||
'e5 e9 f3 bc'
|
||||
'ee f3 fd c1'
|
||||
'b9 bc c1 a2')
|
||||
self.check_case(
|
||||
case.resize((8, 8), Image.BICUBIC),
|
||||
self.make_sample(data, (8, 8)))
|
||||
for mode in ['RGBX', 'RGB', 'L']:
|
||||
case = self.make_case(mode, (4, 4), 0xe1)
|
||||
case = case.resize((8, 8), Image.BICUBIC)
|
||||
data = ('e1 e5 ee b9'
|
||||
'e5 e9 f3 bc'
|
||||
'ee f3 fd c1'
|
||||
'b9 bc c1 a2')
|
||||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (8, 8)))
|
||||
|
||||
def test_enlarge_lanczos(self):
|
||||
case = self.make_case((6, 6), 0xe1)
|
||||
data = ('e1 e0 db ed f5 b8'
|
||||
'e0 df da ec f3 b7'
|
||||
'db db d6 e7 ee b5'
|
||||
'ed ec e6 fb ff bf'
|
||||
'f5 f4 ee ff ff c4'
|
||||
'b8 b7 b4 bf c4 a0')
|
||||
self.check_case(
|
||||
case.resize((12, 12), Image.LANCZOS),
|
||||
self.make_sample(data, (12, 12)))
|
||||
for mode in ['RGBX', 'RGB', 'L']:
|
||||
case = self.make_case(mode, (6, 6), 0xe1)
|
||||
case = case.resize((12, 12), Image.LANCZOS)
|
||||
data = ('e1 e0 db ed f5 b8'
|
||||
'e0 df da ec f3 b7'
|
||||
'db db d6 e7 ee b5'
|
||||
'ed ec e6 fb ff bf'
|
||||
'f5 f4 ee ff ff c4'
|
||||
'b8 b7 b4 bf c4 a0')
|
||||
for channel in case.split():
|
||||
self.check_case(channel, self.make_sample(data, (12, 12)))
|
||||
|
||||
|
||||
class CoreResampleConsistencyTest(PillowTestCase):
|
||||
|
|
Loading…
Reference in New Issue
Block a user