From 5e897341c6c5c1f0fdb8d95ca7e3643dc7e89d77 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 30 Sep 2013 21:21:53 -0700 Subject: [PATCH 1/6] Added mesh transform test --- Tests/test_image_transform.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Tests/test_image_transform.py b/Tests/test_image_transform.py index 7d4b6d9b3..73d98e721 100644 --- a/Tests/test_image_transform.py +++ b/Tests/test_image_transform.py @@ -2,4 +2,15 @@ from tester import * from PIL import Image -success() +def test_quad(): + # one simple quad transform, equivalent to scale & crop upper left quad + im = lena('RGB') + (w,h) = im.size + transformed = im.transform(im.size, Image.QUAD, + (0,0,0,h/2, + w/2,h/2,w/2,0), # ul -> ccw around quad + Image.BILINEAR) + + scaled = im.resize((w*2, h*2), Image.BILINEAR).crop((0,0,w,h)) + + assert_image_equal(transformed, scaled, 10) From 2241f744d99302681cbf9aed67136a38d9e28eed Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 30 Sep 2013 21:57:19 -0700 Subject: [PATCH 2/6] extents test --- Tests/test_image_transform.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Tests/test_image_transform.py b/Tests/test_image_transform.py index 73d98e721..0de86dc16 100644 --- a/Tests/test_image_transform.py +++ b/Tests/test_image_transform.py @@ -2,6 +2,19 @@ from tester import * from PIL import Image +def test_extent(): + im = lena('RGB') + (w,h) = im.size + transformed = im.transform(im.size, Image.EXTENT, + (0,0, + w/2,h/2), # ul -> lr + Image.BILINEAR) + + + scaled = im.resize((w*2, h*2), Image.BILINEAR).crop((0,0,w,h)) + + assert_image_similar(transformed, scaled, 10) # undone -- precision? + def test_quad(): # one simple quad transform, equivalent to scale & crop upper left quad im = lena('RGB') From 2afdc3776d07718eb42f0b59f11b22578235cec2 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 30 Sep 2013 22:01:23 -0700 Subject: [PATCH 3/6] quad test, with blank space test --- Tests/test_image_transform.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/Tests/test_image_transform.py b/Tests/test_image_transform.py index 0de86dc16..79cb11d5b 100644 --- a/Tests/test_image_transform.py +++ b/Tests/test_image_transform.py @@ -26,4 +26,33 @@ def test_quad(): scaled = im.resize((w*2, h*2), Image.BILINEAR).crop((0,0,w,h)) - assert_image_equal(transformed, scaled, 10) + assert_image_equal(transformed, scaled) + +def test_mesh(): + # this should be a checkerboard of halfsized lenas in ul, lr + im = lena('RGBA') + (w,h) = im.size + transformed = im.transform(im.size, Image.MESH, + [((0,0,w/2,h/2), # box + (0,0,0,h, + w,h,w,0)), # ul -> ccw around quad + ((w/2,h/2,w,h), # box + (0,0,0,h, + w,h,w,0))], # ul -> ccw around quad + Image.BILINEAR) + + scaled = im.resize((w/2, h/2), Image.BILINEAR) + + checker = Image.new('RGBA', im.size) + checker.paste(scaled, (0,0)) + checker.paste(scaled, (w/2,h/2)) + + assert_image_equal(transformed, checker) + + # now, check to see that the extra area is (0,0,0,0) + blank = Image.new('RGBA', (w/2,h/2), (0,0,0,0)) + + assert_image_equal(blank, transformed.crop((w/2,0,w,h/2))) + assert_image_equal(blank, transformed.crop((0,h/2,w/2,h))) + + From 46c58560baf01bc490b0c98de71ff38703961bb6 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 30 Sep 2013 22:10:19 -0700 Subject: [PATCH 4/6] adding memset test --- Tests/test_image_transform.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/Tests/test_image_transform.py b/Tests/test_image_transform.py index 79cb11d5b..3a9a3f51f 100644 --- a/Tests/test_image_transform.py +++ b/Tests/test_image_transform.py @@ -41,6 +41,8 @@ def test_mesh(): w,h,w,0))], # ul -> ccw around quad Image.BILINEAR) + transformed.save('transformed.png') + scaled = im.resize((w/2, h/2), Image.BILINEAR) checker = Image.new('RGBA', im.size) @@ -51,8 +53,30 @@ def test_mesh(): # now, check to see that the extra area is (0,0,0,0) blank = Image.new('RGBA', (w/2,h/2), (0,0,0,0)) - + assert_image_equal(blank, transformed.crop((w/2,0,w,h/2))) assert_image_equal(blank, transformed.crop((0,h/2,w/2,h))) +def test_blank_fill(): + # attempting to hit + # https://github.com/python-imaging/Pillow/issues/254 reported + # + # issue is that transforms with transparent overflow area + # contained junk from previous images, especially on systems with + # constrained memory. So, attempt to fill up memory with a + # pattern, free it, and then run the mesh test again. Using a 1Mp + # image with 4 bands, for 4 megs of data allocated, x 64. OMM (64 + # bit 12.04 VM with 512 megs available, this fails with Pillow < + # a0eaf06cc5f62a6fb6de556989ac1014ff3348ea + # + # Running by default, but I'd totally understand not doing it in + # the future + + foo = [Image.new('RGBA',(1024,1024), (a,a,a,a)) + for a in range(1,65)] + + # Yeah. Watch some JIT optimize this out. + foo = None + + test_mesh() From 7546e1fb178118bf638e2186b94701d4db6ffb4c Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 30 Sep 2013 22:32:50 -0700 Subject: [PATCH 5/6] Py3. sigh --- Tests/test_image_transform.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Tests/test_image_transform.py b/Tests/test_image_transform.py index 3a9a3f51f..56a0d9d71 100644 --- a/Tests/test_image_transform.py +++ b/Tests/test_image_transform.py @@ -7,7 +7,7 @@ def test_extent(): (w,h) = im.size transformed = im.transform(im.size, Image.EXTENT, (0,0, - w/2,h/2), # ul -> lr + w//2,h//2), # ul -> lr Image.BILINEAR) @@ -20,8 +20,8 @@ def test_quad(): im = lena('RGB') (w,h) = im.size transformed = im.transform(im.size, Image.QUAD, - (0,0,0,h/2, - w/2,h/2,w/2,0), # ul -> ccw around quad + (0,0,0,h//2, + w//2,h//2,w//2,0), # ul -> ccw around quad Image.BILINEAR) scaled = im.resize((w*2, h*2), Image.BILINEAR).crop((0,0,w,h)) @@ -33,29 +33,29 @@ def test_mesh(): im = lena('RGBA') (w,h) = im.size transformed = im.transform(im.size, Image.MESH, - [((0,0,w/2,h/2), # box + [((0,0,w//2,h//2), # box (0,0,0,h, w,h,w,0)), # ul -> ccw around quad - ((w/2,h/2,w,h), # box + ((w//2,h//2,w,h), # box (0,0,0,h, w,h,w,0))], # ul -> ccw around quad Image.BILINEAR) transformed.save('transformed.png') - scaled = im.resize((w/2, h/2), Image.BILINEAR) + scaled = im.resize((w//2, h//2), Image.BILINEAR) checker = Image.new('RGBA', im.size) checker.paste(scaled, (0,0)) - checker.paste(scaled, (w/2,h/2)) + checker.paste(scaled, (w//2,h//2)) assert_image_equal(transformed, checker) # now, check to see that the extra area is (0,0,0,0) - blank = Image.new('RGBA', (w/2,h/2), (0,0,0,0)) + blank = Image.new('RGBA', (w//2,h//2), (0,0,0,0)) - assert_image_equal(blank, transformed.crop((w/2,0,w,h/2))) - assert_image_equal(blank, transformed.crop((0,h/2,w/2,h))) + assert_image_equal(blank, transformed.crop((w//2,0,w,h//2))) + assert_image_equal(blank, transformed.crop((0,h//2,w//2,h))) def test_blank_fill(): From a0d7e72cbbe07670bd313716c91f459e6413d705 Mon Sep 17 00:00:00 2001 From: wiredfool Date: Mon, 30 Sep 2013 22:47:22 -0700 Subject: [PATCH 6/6] don't write the test image --- Tests/test_image_transform.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_image_transform.py b/Tests/test_image_transform.py index 56a0d9d71..31516d978 100644 --- a/Tests/test_image_transform.py +++ b/Tests/test_image_transform.py @@ -41,7 +41,7 @@ def test_mesh(): w,h,w,0))], # ul -> ccw around quad Image.BILINEAR) - transformed.save('transformed.png') + #transformed.save('transformed.png') scaled = im.resize((w//2, h//2), Image.BILINEAR)