From 5ea966d8698ff2adcff9b514f053babc7463450f Mon Sep 17 00:00:00 2001 From: wiredfool Date: Thu, 18 Sep 2014 08:49:13 -0700 Subject: [PATCH] Test for alpha preservation in ImageEnhance, #899 --- Tests/test_imageenhance.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Tests/test_imageenhance.py b/Tests/test_imageenhance.py index 5edf46b12..58042db85 100644 --- a/Tests/test_imageenhance.py +++ b/Tests/test_imageenhance.py @@ -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()