From f60095f9735d6b58763ab2d8b5dfd892a9d207e1 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 15 May 2017 15:22:38 +0300 Subject: [PATCH 01/12] Ignore test_images downloaded for tests --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 95ed4bac5..aa45f946f 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,9 @@ htmlcov/ nosetests.xml coverage.xml +# Test files +test_images + # Translations *.mo From 3db194476245eeafa2c78a7f680cff15082d776a Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 15 May 2017 17:09:29 +0300 Subject: [PATCH 02/12] Test drawing polygons with sloped and flat lines --- Tests/images/imagedraw_polygon_kite.png | Bin 0 -> 647 bytes Tests/test_imagedraw.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 Tests/images/imagedraw_polygon_kite.png diff --git a/Tests/images/imagedraw_polygon_kite.png b/Tests/images/imagedraw_polygon_kite.png new file mode 100644 index 0000000000000000000000000000000000000000..e48d6660fe2202e2deec1d5843beb4dfc39d4aec GIT binary patch literal 647 zcmV;20(kw2P)4PPC0GZ2i8AcR*IR=SQEnYFvb{Tj4{TTVmWKiz(qN~j#S=s zygs*#s!`5QN_$bIt)rjm<>=Ru$~h(JAI`n31E7#&S^t8nUm%RjtE`itkUv>XQ1y!? zaXFKv0t&g2H3X{uMloDIWa)xJ)@4nDst1w5Wm=XIP{^n(5m5Dj0=O*7vIYv-k|hqR z9()y-Az5ZYArrE;f~wzW375Vs`=F4ftYe_+H=W0&Cd&~hq##QLR6T)7T&HDu1clDY zQU_HwhwG3m*PzgLS*AdhP2k!qD+VaEOO{zsWuv&Z$O;Au3CnT;s%!|Cq^zi*kc=#M zpvwAj3CIc$3N6WU4XUgY*SxHIK%p5~VL+Aj;2M^7At*E;DZvI zy~ov%MNnmw^;7el_0b$6r6;8)XA`$$b>m;d?|MFGwPhg^<0ts%>HgnvKo+`|7_T}E zT+f=3g>EBu`<2q6Yw%05&?UsKzPmGe-%v&ticRd^JJJ(t9fW0}ki;%sMKiZPYnLn( ziP()R|EAZJZkL4u5W8-*^2$2+bFz?MVs|}ZvH0wcf-K~Yn2Cv=A-4X!p{6Y4g_y1R z?IR}gjI;?^$T%^h(~>17wXcIMS;!_aTeJDwIx)e$XpG82rihuCL{D?XWcSaqE(=*8 z=0+CkCnmnX57{^HbY!x>C h4l>3VV~nxDeF3HkH?Ycoy&M1l002ovPDHLkV1ib~E${#U literal 0 HcmV?d00001 diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 441a34a88..11e990bcb 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -30,6 +30,8 @@ BBOX2 = [X0, Y0, X1, Y1] POINTS1 = [(10, 10), (20, 40), (30, 30)] POINTS2 = [10, 10, 20, 40, 30, 30] +KITE_POINTS = [(10, 50), (70, 10), (90, 50), (70, 90), (10, 50)] + class TestImageDraw(PillowTestCase): @@ -267,6 +269,21 @@ class TestImageDraw(PillowTestCase): def test_polygon2(self): self.helper_polygon(POINTS2) + def test_polygon_kite(self): + # Test drawing lines of different gradients (dx>dy, dy>dx) and + # vertical (dx==0) and horizontal (dy==0) lines + # Arrange + im = Image.new("RGB", (W, H)) + draw = ImageDraw.Draw(im) + + # Act + draw.polygon(KITE_POINTS, fill="blue", outline="yellow") + del draw + + # Assert + self.assert_image_equal( + im, Image.open("Tests/images/imagedraw_polygon_kite.png")) + def helper_rectangle(self, bbox): # Arrange im = Image.new("RGB", (W, H)) From d4a350cd79e07578356f99276aaa9b662b4593b7 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 15 May 2017 18:04:33 +0300 Subject: [PATCH 03/12] Test chord in RGB and L modes --- Tests/images/imagedraw_chord.png | Bin 326 -> 0 bytes Tests/images/imagedraw_chord_RGB.png | Bin 0 -> 324 bytes Tests/test_imagedraw.py | 17 ++++++++++------- 3 files changed, 10 insertions(+), 7 deletions(-) delete mode 100644 Tests/images/imagedraw_chord.png create mode 100644 Tests/images/imagedraw_chord_RGB.png diff --git a/Tests/images/imagedraw_chord.png b/Tests/images/imagedraw_chord.png deleted file mode 100644 index db3b35310235b1c7ab6e368d08f3bf89b9836777..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 326 zcmeAS@N?(olHy`uVBq!ia0vp^DImUz33VYkl1=nX|dqBVT;otL=PqD@Cub z;$2<(Q7d|t+$rnTn(Kcp*>>*yf#>4CDh^JY@$Oe#xmVO0!f&cvEFGQ N0Z&&ymvv4FO#l*njdTD2 diff --git a/Tests/images/imagedraw_chord_RGB.png b/Tests/images/imagedraw_chord_RGB.png new file mode 100644 index 0000000000000000000000000000000000000000..af6fc766007870d6dd75c4e0b673415af90459a1 GIT binary patch literal 324 zcmeAS@N?(olHy`uVBq!ia0vp^DImiL4E4Qefit@`FJTWf4%EDt3lk&SPw>2k|{! L{an^LB{Ts5P4tBx literal 0 HcmV?d00001 diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 11e990bcb..66a92b01d 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -94,10 +94,11 @@ class TestImageDraw(PillowTestCase): self.assert_image_equal( im, Image.open("Tests/images/imagedraw_bitmap.png")) - def helper_chord(self, bbox, start, end): + def helper_chord(self, mode, bbox, start, end): # Arrange - im = Image.new("RGB", (W, H)) + im = Image.new(mode, (W, H)) draw = ImageDraw.Draw(im) + expected = "Tests/images/imagedraw_chord_{}.png".format(mode) # Act draw.chord(bbox, start, end, fill="red", outline="yellow") @@ -105,15 +106,17 @@ class TestImageDraw(PillowTestCase): # Assert self.assert_image_similar( - im, Image.open("Tests/images/imagedraw_chord.png"), 1) + im, Image.open(expected), 1) def test_chord1(self): - self.helper_chord(BBOX1, 0, 180) - self.helper_chord(BBOX1, 0.5, 180.4) + for mode in ["RGB", "L"]: + self.helper_chord(mode, BBOX1, 0, 180) + self.helper_chord(mode, BBOX1, 0.5, 180.4) def test_chord2(self): - self.helper_chord(BBOX2, 0, 180) - self.helper_chord(BBOX2, 0.5, 180.4) + for mode in ["RGB", "L"]: + self.helper_chord(mode, BBOX2, 0, 180) + self.helper_chord(mode, BBOX2, 0.5, 180.4) def helper_ellipse(self, bbox): # Arrange From de1f156fcda5572ff0c0ac0dc2f773fc4f41a7de Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 15 May 2017 18:13:36 +0300 Subject: [PATCH 04/12] Add test file --- Tests/images/imagedraw_chord_L.png | Bin 0 -> 257 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Tests/images/imagedraw_chord_L.png diff --git a/Tests/images/imagedraw_chord_L.png b/Tests/images/imagedraw_chord_L.png new file mode 100644 index 0000000000000000000000000000000000000000..a5a0078d042113d2b6eddb217c68bd678d2d451b GIT binary patch literal 257 zcmeAS@N?(olHy`uVBq!ia0vp^DIm-NBp5 Date: Mon, 15 May 2017 18:23:00 +0300 Subject: [PATCH 05/12] Test ellipse in RGB and L modes --- Tests/images/imagedraw_ellipse_L.png | Bin 0 -> 359 bytes ...draw_ellipse.png => imagedraw_ellipse_RGB.png} | Bin Tests/test_imagedraw.py | 13 ++++++++----- 3 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 Tests/images/imagedraw_ellipse_L.png rename Tests/images/{imagedraw_ellipse.png => imagedraw_ellipse_RGB.png} (100%) diff --git a/Tests/images/imagedraw_ellipse_L.png b/Tests/images/imagedraw_ellipse_L.png new file mode 100644 index 0000000000000000000000000000000000000000..e47e6e441c16afcc1edb2f7c2a715fd36469c096 GIT binary patch literal 359 zcmV-t0hs=YP)m&+JP z12C;W<_gD!v>jjv@;Dyk2vNXTkamoCV+_jk90SvS7<$r47y^J3MkbLABaDJ*hCz`@ zG(&p?q&W;=;!!xnm>kC`l6XN>TPVaVmV6rq@rxzgG>IRCd!5h9X%R@FBLE%ayOUf2 zsm&I>gCwc7g!%uWCxHYq5Hc4Z)%W)ym9v4k#m?@PiOf;unlM#dMitOvcxMcx_Q01##LUPo^@7rs&hJvn-&8Q)gS?d{$T( zYa?MUa5`bWxm&>{TcVXSc;B^gKC1saM^O|-Q4~d^^#U`BI$YHAaJK*e002ovPDHLk FV1jb^l;r>b literal 0 HcmV?d00001 diff --git a/Tests/images/imagedraw_ellipse.png b/Tests/images/imagedraw_ellipse_RGB.png similarity index 100% rename from Tests/images/imagedraw_ellipse.png rename to Tests/images/imagedraw_ellipse_RGB.png diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 66a92b01d..e9c82872d 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -118,10 +118,11 @@ class TestImageDraw(PillowTestCase): self.helper_chord(mode, BBOX2, 0, 180) self.helper_chord(mode, BBOX2, 0.5, 180.4) - def helper_ellipse(self, bbox): + def helper_ellipse(self, mode, bbox): # Arrange - im = Image.new("RGB", (W, H)) + im = Image.new(mode, (W, H)) draw = ImageDraw.Draw(im) + expected = "Tests/images/imagedraw_ellipse_{}.png".format(mode) # Act draw.ellipse(bbox, fill="green", outline="blue") @@ -129,13 +130,15 @@ class TestImageDraw(PillowTestCase): # Assert self.assert_image_similar( - im, Image.open("Tests/images/imagedraw_ellipse.png"), 1) + im, Image.open(expected), 1) def test_ellipse1(self): - self.helper_ellipse(BBOX1) + for mode in ["RGB", "L"]: + self.helper_ellipse(mode, BBOX1) def test_ellipse2(self): - self.helper_ellipse(BBOX2) + for mode in ["RGB", "L"]: + self.helper_ellipse(mode, BBOX2) def test_ellipse_edge(self): # Arrange From ae9181f0a4d3011335cb0a2890b0d0ff007d748c Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 15 May 2017 18:24:12 +0300 Subject: [PATCH 06/12] Test polygons in RGB and L modes --- Tests/images/imagedraw_polygon_kite_L.png | Bin 0 -> 499 bytes ...ite.png => imagedraw_polygon_kite_RGB.png} | Bin Tests/test_imagedraw.py | 20 ++++++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 Tests/images/imagedraw_polygon_kite_L.png rename Tests/images/{imagedraw_polygon_kite.png => imagedraw_polygon_kite_RGB.png} (100%) diff --git a/Tests/images/imagedraw_polygon_kite_L.png b/Tests/images/imagedraw_polygon_kite_L.png new file mode 100644 index 0000000000000000000000000000000000000000..241d86bf40d72676f7e2652e42a9d0bea15f9f9f GIT binary patch literal 499 zcmVFD&LA4 zzc)90)l2XT@Os*}lqI(e%94KuEGadKhe1u!FknR~NSq7`k_!VCl&r+hAS; z%U~uEFrcRl5;=oGB4R*C=_NZD^b#QhT1q3?#9*hS`A;6r&(G&eSft6er>lKW9{r^~ zm|bst_w9NNmp5QGeTDn=WR#%C>{%HvYy4D#7_()!a@}`X5|o%7JIG-#ypSNnY}nP0 z=aaPr4Mu;`nw%MLB?vI`)9>sY?~zc&s5=tV-ilK~2_xdy, dy>dx) and # vertical (dx==0) and horizontal (dy==0) lines - # Arrange - im = Image.new("RGB", (W, H)) - draw = ImageDraw.Draw(im) + for mode in ["RGB", "L"]: + # Arrange + im = Image.new(mode, (W, H)) + draw = ImageDraw.Draw(im) + expected = "Tests/images/imagedraw_polygon_kite_{}.png".format(mode) - # Act - draw.polygon(KITE_POINTS, fill="blue", outline="yellow") - del draw + # Act + draw.polygon(KITE_POINTS, fill="blue", outline="yellow") + del draw - # Assert - self.assert_image_equal( - im, Image.open("Tests/images/imagedraw_polygon_kite.png")) + # Assert + self.assert_image_equal( + im, Image.open(expected)) def helper_rectangle(self, bbox): # Arrange From 2968313bb61a595460181f4a9d14593c1448efc2 Mon Sep 17 00:00:00 2001 From: hugovk Date: Mon, 15 May 2017 21:17:33 +0300 Subject: [PATCH 07/12] Remove unrunnable code: ImagingDrawWideLine is only called (in _imaging.c) when (width <= 1) is false --- libImaging/Draw.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libImaging/Draw.c b/libImaging/Draw.c index ca26282be..72c1599be 100644 --- a/libImaging/Draw.c +++ b/libImaging/Draw.c @@ -605,11 +605,6 @@ ImagingDrawWideLine(Imaging im, int x0, int y0, int x1, int y1, DRAWINIT(); - if (width <= 1) { - draw->line(im, x0, y0, x1, y1, ink); - return 0; - } - dx = x1-x0; dy = y1-y0; if (dx == 0 && dy == 0) { From 5871b7a5ba483907a527907f32c5c52524b33df0 Mon Sep 17 00:00:00 2001 From: hugovk Date: Mon, 15 May 2017 21:32:54 +0300 Subject: [PATCH 08/12] Test drawing a wide "line" from one point to another just draws a single point --- Tests/images/imagedraw_wide_line_dot.png | Bin 0 -> 116 bytes Tests/test_imagedraw.py | 14 ++++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 Tests/images/imagedraw_wide_line_dot.png diff --git a/Tests/images/imagedraw_wide_line_dot.png b/Tests/images/imagedraw_wide_line_dot.png new file mode 100644 index 0000000000000000000000000000000000000000..d6f0e789c5dfe76ba193f53005bc35a82e306027 GIT binary patch literal 116 zcmeAS@N?(olHy`uVBq!ia0vp^DIme2O0uLsBt3u)enFlU0 Date: Mon, 15 May 2017 21:44:28 +0300 Subject: [PATCH 09/12] Test drawing a rectangle bigger than the image --- Tests/images/imagedraw_big_rectangle.png | Bin 0 -> 290 bytes Tests/test_imagedraw.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 Tests/images/imagedraw_big_rectangle.png diff --git a/Tests/images/imagedraw_big_rectangle.png b/Tests/images/imagedraw_big_rectangle.png new file mode 100644 index 0000000000000000000000000000000000000000..fa2370b28736b1ca060e8f6a8d4be89cd64e28c3 GIT binary patch literal 290 zcmeAS@N?(olHy`uVBq!ia0vp^DIm}q Date: Mon, 15 May 2017 22:58:51 +0300 Subject: [PATCH 10/12] Test limits of arc/ellipse's start and end --- Tests/images/imagedraw_arc_end_le_start.png | Bin 0 -> 218 bytes Tests/images/imagedraw_arc_no_loops.png | Bin 0 -> 384 bytes Tests/test_imagedraw.py | 33 ++++++++++++++++++-- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 Tests/images/imagedraw_arc_end_le_start.png create mode 100644 Tests/images/imagedraw_arc_no_loops.png diff --git a/Tests/images/imagedraw_arc_end_le_start.png b/Tests/images/imagedraw_arc_end_le_start.png new file mode 100644 index 0000000000000000000000000000000000000000..aee48e1c6bb7e6c04513e728aa43c61ab03c4657 GIT binary patch literal 218 zcmeAS@N?(olHy`uVBq!ia0vp^DImtq3>U{-hS)9CgZ-hT&vd#zJ4M3 z?)%ki-CqM{od|xkp-(%WE?Zx44>wDrPHyVk5-4*-sQhh>vqjpm6?loyK6JKsD zixZo<^YNxN4H1ohlYgqSsU5pjA1T}^D!>h~3Pzr~%Xt2l*A27h)1QEZJYD@<);T3K F0RYYuS9bsa literal 0 HcmV?d00001 diff --git a/Tests/images/imagedraw_arc_no_loops.png b/Tests/images/imagedraw_arc_no_loops.png new file mode 100644 index 0000000000000000000000000000000000000000..e45ad57a5c382d5b01f06a841cbe164acdf76fed GIT binary patch literal 384 zcmV-`0e}99P)w000000002D9oYeXwANmK;5hQ5 zCMWpa(Th56er&XyfuECqW9FZH_d~PC>owKH$|h;8U0$1Vf3S){6Wgt?3G>;cvT4&; zzOTs>Si7(J(N`@iEBCl@zXtto?mxWP@s(cIGJRDDIwC{=)38EQr#eagRVQNiB%?0y zT&r_fo%-f+WCbWIpl4at&cRd7R7GQTOyx8TP*#Al0+bb?tN>*NC@Vl&0iDaLc3)a8 z&mYyodFqfxS*hxri5@Fw8d6q;gR4S@TPg%yQ$E?1?B4OjpIlUG4?${L;V83BNmHlUzm!566$^ifX e00000OZf&4$QD(^?NrJD0000 Date: Mon, 15 May 2017 22:59:25 +0300 Subject: [PATCH 11/12] Remove unexposed and unused code --- libImaging/Draw.c | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/libImaging/Draw.c b/libImaging/Draw.c index 72c1599be..65ab34a66 100644 --- a/libImaging/Draw.c +++ b/libImaging/Draw.c @@ -1025,20 +1025,6 @@ ImagingOutlineCurve(ImagingOutline outline, float x1, float y1, return 0; } -int -ImagingOutlineCurve2(ImagingOutline outline, float cx, float cy, - float x3, float y3) -{ - /* add bezier curve based on three control points (as - in the Flash file format) */ - - return ImagingOutlineCurve( - outline, - (outline->x + cx + cx)/3, (outline->y + cy + cy)/3, - (cx + cx + x3)/3, (cy + cy + y3)/3, - x3, y3); -} - int ImagingOutlineClose(ImagingOutline outline) { From 08c72a1720501900caef086bfbd1b96f5564541f Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 16 May 2017 10:33:38 +0300 Subject: [PATCH 12/12] flake8 --- PIL/ImageDraw.py | 1 + Tests/test_imagedraw.py | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/PIL/ImageDraw.py b/PIL/ImageDraw.py index ddf669f78..71e29ee48 100644 --- a/PIL/ImageDraw.py +++ b/PIL/ImageDraw.py @@ -283,6 +283,7 @@ def Draw(im, mode=None): except AttributeError: return ImageDraw(im, mode) + # experimental access to the outline API try: Outline = Image.core.outline diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 0166818d2..2ca5d0882 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -136,8 +136,7 @@ class TestImageDraw(PillowTestCase): del draw # Assert - self.assert_image_similar( - im, Image.open(expected), 1) + self.assert_image_similar(im, Image.open(expected), 1) def test_chord1(self): for mode in ["RGB", "L"]: @@ -160,8 +159,7 @@ class TestImageDraw(PillowTestCase): del draw # Assert - self.assert_image_similar( - im, Image.open(expected), 1) + self.assert_image_similar(im, Image.open(expected), 1) def test_ellipse1(self): for mode in ["RGB", "L"]: @@ -313,15 +311,15 @@ class TestImageDraw(PillowTestCase): # Arrange im = Image.new(mode, (W, H)) draw = ImageDraw.Draw(im) - expected = "Tests/images/imagedraw_polygon_kite_{}.png".format(mode) + expected = "Tests/images/imagedraw_polygon_kite_{}.png".format( + mode) # Act draw.polygon(KITE_POINTS, fill="blue", outline="yellow") del draw # Assert - self.assert_image_equal( - im, Image.open(expected)) + self.assert_image_equal(im, Image.open(expected)) def helper_rectangle(self, bbox): # Arrange @@ -564,5 +562,6 @@ class TestImageDraw(PillowTestCase): # Assert self.assert_image_similar(im, Image.open(expected), 1) + if __name__ == '__main__': unittest.main()