From 2657c0dec0ffb8fad660949be4714572211c4148 Mon Sep 17 00:00:00 2001 From: Eric Soroos Date: Fri, 7 Nov 2014 14:47:23 -0800 Subject: [PATCH] Test for endianness issues in stretch --- Tests/test_imaging_stretch.py | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/Tests/test_imaging_stretch.py b/Tests/test_imaging_stretch.py index a9858eff5..52548e3dc 100644 --- a/Tests/test_imaging_stretch.py +++ b/Tests/test_imaging_stretch.py @@ -39,6 +39,73 @@ class TestImagingStretch(PillowTestCase): self.assertEqual(r.mode, "RGB") self.assertEqual(r.size, (764, 414)) + def test_endianess(self): + # Make an image with one colored pixel, in one channel. + # When stretched, that channel should be the same as a GS image. + # Other channels should be unaffected. + # The R and A channels should not swap, which is indicitive of + # an endianess issues + + im = Image.new('L', (2,2), 0) + im.putpixel((1,1),128) + + blank = Image.new('L', (4,4), 0) + alpha = Image.new('L', (4,4), 255) + + for f in [Image.BILINEAR, Image.BICUBIC, Image.ANTIALIAS]: + + im_r = Image.new('RGBA', (2,2), (0,0,0,255)) + im_r.putpixel((1,1),(128,0,0,255)) + + target = im._new(im.im.stretch((4,4), f)) + stretched = im_r._new(im_r.im.stretch((4,4),f)) + + self.assert_image_equal(stretched.split()[0],target) + self.assert_image_equal(stretched.split()[1],blank) + self.assert_image_equal(stretched.split()[2],blank) + self.assert_image_equal(stretched.split()[3],alpha) + + + im_r = Image.new('RGB', (2,2), (0,0,0)) + im_r.putpixel((1,1),(128,0,0)) + + target = im._new(im.im.stretch((4,4), f)) + stretched = im_r._new(im_r.im.stretch((4,4),f)) + + #print " ".join(hex(ord(s)) for s in stretched.split()[0].tobytes()) + #print " ".join(hex(ord(s)) for s in stretched.split()[1].tobytes()) + #print " ".join(hex(ord(s)) for s in stretched.split()[2].tobytes()) + + #print " ".join(hex(ord(s)) for s in target.tobytes()) + + #print + + self.assert_image_equal(stretched.split()[0],target, 'rxRGB R channel fail') + self.assert_image_equal(stretched.split()[1],blank, 'rxRGB G channel fail') + self.assert_image_equal(stretched.split()[2],blank, 'rxRGB B channel fail') + + + im_g = Image.new('RGBA', (2,2), (0,0,0,255)) + im_g.putpixel((1,1),(0,128,0,255)) + + stretched = im_g._new(im_g.im.stretch((4,4),f)) + + self.assert_image_equal(stretched.split()[0],blank) + self.assert_image_equal(stretched.split()[1],target) + self.assert_image_equal(stretched.split()[2],blank) + self.assert_image_equal(stretched.split()[3],alpha) + + + im_g = Image.new('RGB', (2,2), (0,0,0)) + im_g.putpixel((1,1),(0,128,0)) + + target = im._new(im.im.stretch((4,4), f)) + stretched = im_g._new(im_g.im.stretch((4,4),f)) + + self.assert_image_equal(stretched.split()[0],blank, 'gxRGB R channel fail') + self.assert_image_equal(stretched.split()[1],target, 'gxRGB G channel fail') + self.assert_image_equal(stretched.split()[2],blank, 'gxRGB B channel fail') + if __name__ == '__main__': unittest.main()