From 4e69b9c5531b3308725e023ce77e1574608451d4 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 4 Jan 2018 20:46:04 +1100 Subject: [PATCH 1/2] Skip outline if the draw operation fills with the same colour --- src/PIL/ImageDraw.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py index 89df27338..80a9f6023 100644 --- a/src/PIL/ImageDraw.py +++ b/src/PIL/ImageDraw.py @@ -138,7 +138,7 @@ class ImageDraw(object): ink, fill = self._getink(outline, fill) if fill is not None: self.draw.draw_chord(xy, start, end, fill, 1) - if ink is not None: + if ink is not None and ink != fill: self.draw.draw_chord(xy, start, end, ink, 0) def ellipse(self, xy, fill=None, outline=None): @@ -146,7 +146,7 @@ class ImageDraw(object): ink, fill = self._getink(outline, fill) if fill is not None: self.draw.draw_ellipse(xy, fill, 1) - if ink is not None: + if ink is not None and ink != fill: self.draw.draw_ellipse(xy, ink, 0) def line(self, xy, fill=None, width=0): @@ -161,7 +161,7 @@ class ImageDraw(object): ink, fill = self._getink(outline, fill) if fill is not None: self.draw.draw_outline(shape, fill, 1) - if ink is not None: + if ink is not None and ink != fill: self.draw.draw_outline(shape, ink, 0) def pieslice(self, xy, start, end, fill=None, outline=None): @@ -169,7 +169,7 @@ class ImageDraw(object): ink, fill = self._getink(outline, fill) if fill is not None: self.draw.draw_pieslice(xy, start, end, fill, 1) - if ink is not None: + if ink is not None and ink != fill: self.draw.draw_pieslice(xy, start, end, ink, 0) def point(self, xy, fill=None): @@ -183,7 +183,7 @@ class ImageDraw(object): ink, fill = self._getink(outline, fill) if fill is not None: self.draw.draw_polygon(xy, fill, 1) - if ink is not None: + if ink is not None and ink != fill: self.draw.draw_polygon(xy, ink, 0) def rectangle(self, xy, fill=None, outline=None): @@ -191,7 +191,7 @@ class ImageDraw(object): ink, fill = self._getink(outline, fill) if fill is not None: self.draw.draw_rectangle(xy, fill, 1) - if ink is not None: + if ink is not None and ink != fill: self.draw.draw_rectangle(xy, ink, 0) def _multiline_check(self, text): From 4d3339b70376a25158156130a27788fdde6bf114 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 5 Jan 2018 11:26:24 +1100 Subject: [PATCH 2/2] Added tests --- Tests/images/imagedraw_outline_chord_L.png | Bin 0 -> 212 bytes Tests/images/imagedraw_outline_chord_RGB.png | Bin 0 -> 259 bytes Tests/images/imagedraw_outline_ellipse_L.png | Bin 0 -> 290 bytes .../images/imagedraw_outline_ellipse_RGB.png | Bin 0 -> 378 bytes Tests/images/imagedraw_outline_pieslice_L.png | Bin 0 -> 266 bytes .../images/imagedraw_outline_pieslice_RGB.png | Bin 0 -> 340 bytes Tests/images/imagedraw_outline_polygon_L.png | Bin 0 -> 309 bytes .../images/imagedraw_outline_polygon_RGB.png | Bin 0 -> 393 bytes .../images/imagedraw_outline_rectangle_L.png | Bin 0 -> 125 bytes .../imagedraw_outline_rectangle_RGB.png | Bin 0 -> 212 bytes Tests/images/imagedraw_outline_shape_L.png | Bin 0 -> 263 bytes Tests/images/imagedraw_outline_shape_RGB.png | Bin 0 -> 316 bytes Tests/test_imagedraw.py | 41 ++++++++++++++++++ 13 files changed, 41 insertions(+) create mode 100644 Tests/images/imagedraw_outline_chord_L.png create mode 100644 Tests/images/imagedraw_outline_chord_RGB.png create mode 100644 Tests/images/imagedraw_outline_ellipse_L.png create mode 100644 Tests/images/imagedraw_outline_ellipse_RGB.png create mode 100644 Tests/images/imagedraw_outline_pieslice_L.png create mode 100644 Tests/images/imagedraw_outline_pieslice_RGB.png create mode 100644 Tests/images/imagedraw_outline_polygon_L.png create mode 100644 Tests/images/imagedraw_outline_polygon_RGB.png create mode 100644 Tests/images/imagedraw_outline_rectangle_L.png create mode 100644 Tests/images/imagedraw_outline_rectangle_RGB.png create mode 100644 Tests/images/imagedraw_outline_shape_L.png create mode 100644 Tests/images/imagedraw_outline_shape_RGB.png diff --git a/Tests/images/imagedraw_outline_chord_L.png b/Tests/images/imagedraw_outline_chord_L.png new file mode 100644 index 0000000000000000000000000000000000000000..9c20ad217141450ac3ffd9bc6e6a6ae6e9ea6aeb GIT binary patch literal 212 zcmeAS@N?(olHy`uVBq!ia0vp^DIm-NBp5yWGui7$e$$~yckOl^Z2bE%#>1V}nANd-;FQjjRdFu*)*UA1hi7_Ad zl>B|;_m1=Av(OO#_bORSSFN@F7<}qfT1=i-ta-hE+ikDlt7VUtl$ieN`Je6g`=99? z+m+#lQKeRrp~mMd&I(L@R4bl$BC_xAYBt5=bN-aDF)$psTJ~?Z(DfyH1+pN!Jzf1= J);T3K0RW^dR@wjn literal 0 HcmV?d00001 diff --git a/Tests/images/imagedraw_outline_chord_RGB.png b/Tests/images/imagedraw_outline_chord_RGB.png new file mode 100644 index 0000000000000000000000000000000000000000..9e9cb5af006f84b806867b586948cd1b21e668c3 GIT binary patch literal 259 zcmeAS@N?(olHy`uVBq!ia0vp^DImsV8LPK9oMvXgoV7CaQ=eTc7-)eiJ}~<9U@pyZkS}A z?YBW|Zm7bVrhB_G+MWc>3G3t24hJGrTi3{Qkas zk*s?Y&zgt7?t44ebY}SXxZ?E8zs~l>Jv+<8?pGd@`_ZPYeLE>!>hpP}%GfvGe!T0y qVis0&X!^-0`z2*w3n5NBuy-$G&o4H|_cdiRKq8*5elF{r5}E)|>1!?k literal 0 HcmV?d00001 diff --git a/Tests/images/imagedraw_outline_ellipse_L.png b/Tests/images/imagedraw_outline_ellipse_L.png new file mode 100644 index 0000000000000000000000000000000000000000..53b76b62b4210515d1dc2901d7b6fc59116ac085 GIT binary patch literal 290 zcmeAS@N?(olHy`uVBq!ia0vp^DIm-NBp5A0m|KGp8*o2aut|H!8*U{VQ;_tq~xSue{b)7#QE5%iKTOT$UNRNqW%)$m2rRnyit4Zk@Z>VkeA7@=s zH?o?QU%M;G+vmI*{|DQM)%GhdlXg)SKC&ew24b8@vT8jr(DqFt!C>3zCMszcS<|_y6tKO>1#*lz3%tFmJ;_esyMy# zAFFk7&(7+wcQ(o5H3$8}-gm@ip8fx9?FQpL`4z|9_nZWUDi9Q~KRzKBoyz#e9K`c< L^>bP0l+XkKcy*%w literal 0 HcmV?d00001 diff --git a/Tests/images/imagedraw_outline_pieslice_L.png b/Tests/images/imagedraw_outline_pieslice_L.png new file mode 100644 index 0000000000000000000000000000000000000000..92972d54cc927111bbf41eb7b793e277493f04f4 GIT binary patch literal 266 zcmeAS@N?(olHy`uVBq!ia0vp^DIm-NBp5b!~gswEzg%q zKMH)+k$h50pn8Vbk)SGp#cD3{OS6SSZ)WcN68K9kaLV3k*@8y#>+h;XHv3%9-tFli z=dAQ!_OeHer*3%2$=JyYChhrPs9IhAH)vVWFR{KelkTfCF5Mux{#4A`Hx=J?mL?xv zedXLb!=HD$)>Nkd(UJ!w#Kfx%vWm%ZX&Ot)Nb2YJ%d L)z4*}Q$iB}XDe~C literal 0 HcmV?d00001 diff --git a/Tests/images/imagedraw_outline_pieslice_RGB.png b/Tests/images/imagedraw_outline_pieslice_RGB.png new file mode 100644 index 0000000000000000000000000000000000000000..4be4fc4afbbf34a16d3278dd597362399de0ed76 GIT binary patch literal 340 zcmeAS@N?(olHy`uVBq!ia0vp^DIm&5H; z{@dSfz0e!R<9qB$;rUCw4<|7moCs781Kan`lY4Ndtm0DQ1wP|B7RP>76+EikxbIs3 zzqo(LOm6R8*2#AK*4j6wcGJYZ6?H5Pb-$!?ZQZWvp*o`9i@HNk8HC*}k~|g^seeAg zH77Y#XL_!V=$E3tseKWQ&o&nMFREMyKPBPFi`quD5e3+g`P!L3_gU?k8^i@}ll+ z_tNK8y**2-_gc9V a4ov0$CN31iGq1x9B8V+ZHr4o!2_x3LISRL{{F=aV--xaT)lN`S2 z@dRmX^;diu>+8-ZXzr%8@zO;drP75H9WrC(BHz8)&B?LfkaedPgQjARIPcE@0e_cs zyBGRtIpzAe-Q#k5dE$@#M+@QmdNRigLFl=ACF7Ud`XLHo5-y0C-!{qq_sP3SSDtguyUKhLrxanERCzpkvl6tx^<$`v0V_$^Pi>Zq=r#-7u zJ@>YI>EG{HrM%znEjnI$JSchn7f0reTfSA#>0J6NPV~Hd_tMtyrjp*Nd%NVUWxQ9v z%eI@gsru^G?Hx<^nCt8fo*r@QgRRujOQq{y-HF@yq&B{6qsZH<0XGe&ox8v1xtwqE z$xqc^dYATBZ%y6Wr@HxfQUB8YRi)Qr1iasOo7}(K7xC$b-1Q@uyx0G$nVod<@xEz4 im;En?hYbTmgYy1woJ>=gBP$PrL_J;oT-G@yGywpHPr0xF literal 0 HcmV?d00001 diff --git a/Tests/images/imagedraw_outline_rectangle_L.png b/Tests/images/imagedraw_outline_rectangle_L.png new file mode 100644 index 0000000000000000000000000000000000000000..b9c47018fb435b7916a92051c6e3b78046c1828f GIT binary patch literal 125 zcmeAS@N?(olHy`uVBq!ia0vp^DIm-NBp5?LEc!(!8PgVbG9L%=Jzf1= J);T3K0RX!!He~<+ literal 0 HcmV?d00001 diff --git a/Tests/images/imagedraw_outline_shape_L.png b/Tests/images/imagedraw_outline_shape_L.png new file mode 100644 index 0000000000000000000000000000000000000000..20ebef1578cf9c919e8d4e6094bf231a5abe6fcb GIT binary patch literal 263 zcmeAS@N?(olHy`uVBq!ia0vp^DIm-NBp5zi$2M z)W*M`SRXD_+qQh}&ybT(n2IJm(4VQ|x!%HYlF9L@_Z>d1og@-wpF1g`&QEBoMy7se z>ck^1p6;F+t5uXv1$};~`$j%>?T;_#U&yAeHlOWZD=TlY+h*~bY~P#K%d1asyj!!Y z=1@xLCzT?OV3RDJKX(nDRw#GowQh{svi-wXgJ&MroqBC6O~R+fTnPDWuCmpeZO%lsV=7B^-+ki&`2`Bz?O_zrmzLe!>j?5DgQu&X%Q~lo FCIBt_Yasvt literal 0 HcmV?d00001 diff --git a/Tests/images/imagedraw_outline_shape_RGB.png b/Tests/images/imagedraw_outline_shape_RGB.png new file mode 100644 index 0000000000000000000000000000000000000000..6fb6f623e4b01621b35cb6e939343f1386734036 GIT binary patch literal 316 zcmeAS@N?(olHy`uVBq!ia0vp^DImziq!6ST9>6{ZG7haGT> z+}x`@zq~r~^OvnNucS(BSiMH_*jDxAHSLQ3f8UIEd}Ab&pR~}0{V~76M&^_J_a0Qw zzp?T2eBZlwkDOz%`+arc`p&sFxf?h1`mgagcj$D+hD}YJ+Hr2?V&R&hU#rg@of>*J z`0w_IQ~eumy)XTGdCiXtZodqejBL$HynsGO1<$@QZZzczjaa`hA0*-F>gTe~DWM4f DE;olO literal 0 HcmV?d00001 diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index a79a75ca0..62b11e98c 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -572,6 +572,47 @@ class TestImageDraw(PillowTestCase): draw.textsize("\n") draw.textsize("test\n") + def test_same_color_outline(self): + # Prepare shape + x0, y0 = 5, 5 + x1, y1 = 5, 50 + x2, y2 = 95, 50 + x3, y3 = 95, 5 + + s = ImageDraw.Outline() + s.move(x0, y0) + s.curve(x1, y1, x2, y2, x3, y3) + s.line(x0, y0) + + # Begin + for mode in ["RGB", "L"]: + for fill, outline in [ + ["red", None], + ["red", "red"], + ["red", "#f00"] + ]: + for operation, args in { + 'chord':[BBOX1, 0, 180], + 'ellipse':[BBOX1], + 'shape':[s], + 'pieslice':[BBOX1, -90, 45], + 'polygon':[[(18, 30), (85, 30), (60, 72)]], + 'rectangle':[BBOX1] + }.items(): + # Arrange + im = Image.new(mode, (W, H)) + draw = ImageDraw.Draw(im) + + # Act + draw_method = getattr(draw, operation) + args += [fill, outline] + draw_method(*args) + + # Assert + expected = ("Tests/images/imagedraw_outline" + "_{}_{}.png".format(operation, mode)) + self.assert_image_similar(im, Image.open(expected), 1) + if __name__ == '__main__': unittest.main()