Test for alpha preservation in ImageEnhance, #899

This commit is contained in:
wiredfool 2014-09-18 08:49:13 -07:00
parent 758c893067
commit 5ea966d869

View File

@ -22,6 +22,34 @@ class TestImageEnhance(PillowTestCase):
ImageEnhance.Sharpness(im).enhance(0.5)
def _half_transparent_image(self):
# returns an image, half transparent, half solid
im = hopper('RGB')
transparent = Image.new('L', im.size, 0)
solid = Image.new('L', (im.size[0]//2, im.size[1]), 255)
transparent.paste(solid, (0,0))
im.putalpha(transparent)
return im
def _check_alpha(self,im, original, op, amount):
self.assertEqual(im.getbands(), original.getbands())
self.assert_image_equal(im.split()[-1], original.split()[-1],
"Diff on %s: %s" % (op, amount))
def test_alpha(self):
# Issue https://github.com/python-pillow/Pillow/issues/899
# Is alpha preserved through image enhancement?
original = self._half_transparent_image()
for op in ['Color', 'Brightness', 'Contrast', 'Sharpness']:
for amount in [0,0.5,1.0]:
self._check_alpha(getattr(ImageEnhance,op)(original).enhance(amount),
original, op, amount)
if __name__ == '__main__':
unittest.main()