From 92eea7a9cc5022750e82ba07da96612bdea03f72 Mon Sep 17 00:00:00 2001 From: hugovk Date: Mon, 12 May 2014 17:32:04 +0300 Subject: [PATCH 01/11] Tests for ImageDraw --- Tests/images/imagedraw_arc.png | Bin 0 -> 284 bytes Tests/images/imagedraw_chord.png | Bin 0 -> 326 bytes Tests/images/imagedraw_ellipse.png | Bin 0 -> 491 bytes Tests/images/imagedraw_pieslice.png | Bin 0 -> 405 bytes Tests/test_imagedraw.py | 106 ++++++++++++++++++++++++++++ 5 files changed, 106 insertions(+) create mode 100644 Tests/images/imagedraw_arc.png create mode 100644 Tests/images/imagedraw_chord.png create mode 100644 Tests/images/imagedraw_ellipse.png create mode 100644 Tests/images/imagedraw_pieslice.png diff --git a/Tests/images/imagedraw_arc.png b/Tests/images/imagedraw_arc.png new file mode 100644 index 0000000000000000000000000000000000000000..b097743890cb1907122e53a98231e8887d791d12 GIT binary patch literal 284 zcmeAS@N?(olHy`uVBq!ia0vp^DIm3c2+)C>xpS`>3f5(Zs9FD75X*zkc7DBDk+omSCdxl;y1HgSsJzU zmEpZza$2#*Ruz7e8#YW!Ufg!%%NmQF_u8+!e@Xt)YcH*9vF6qLSDa@!ATD08i}~^A Vp2dg61W$kjJYD@<);T3K0RX^ebT$A0 literal 0 HcmV?d00001 diff --git a/Tests/images/imagedraw_chord.png b/Tests/images/imagedraw_chord.png new file mode 100644 index 0000000000000000000000000000000000000000..db3b35310235b1c7ab6e368d08f3bf89b9836777 GIT binary patch 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 literal 0 HcmV?d00001 diff --git a/Tests/images/imagedraw_ellipse.png b/Tests/images/imagedraw_ellipse.png new file mode 100644 index 0000000000000000000000000000000000000000..fb03fd148597a95bd4c446243b064e91561973ff GIT binary patch literal 491 zcmeAS@N?(olHy`uVBq!ia0vp^DImVh<$#e#iZH>9#NfrDIbrR>YpU ze7$YWlI^<={o3`zoN@0bj&rel?AHhzp0!dkZr|!Ur!TXt|4fOf{JhIYI({vYbH8n~ zc*b*c!6RReTsp#|>pefj$JfVGcADzSxpw-g5y}5e?m2%e=DqrGY51nd$yPnSC9%7v zEtR#4I=7B9`^|jce)dfVy-RF;Wee0^^mI+TdYdu*=+ur~iRGIwT?vrAreSw4a`C5x zryunVqRx7`>s@dDGT$MBb8F(-V);2!LqqKjtT#z;Ewn8;%yP&}VGRnQF@K7lS*QNm zSdk>^3}sWN-MWEb#G4)TthcJgG5d9|o^KVGt;09S8ivU?I=I@PlRl V%h(%|l_|GCVxF#kF6*2UngEBh-Om63 literal 0 HcmV?d00001 diff --git a/Tests/images/imagedraw_pieslice.png b/Tests/images/imagedraw_pieslice.png new file mode 100644 index 0000000000000000000000000000000000000000..1b2acff92ab9aa263ce85ceb1a37493d4cbef6cb GIT binary patch literal 405 zcmeAS@N?(olHy`uVBq!ia0vp^DImmi_QNfYxaH53Vj{XAGUgN#YVIFC)qlsvNwOXirup8(c8%OTW-&O7bl%x zb9aX7OqFSEUrq^oubqDX-&Cz>|MDXD^3Br?du+5*=-8*|9?s;GxrWbru1ff?+p^I{ zuQM|_H>Z5vnT=<_gy8GO{EpOZxvKrC)xJJ*r^PnPDO_VdQk8HsVzb8!n${V^hH)%9N+zbw06{%>NP@%}SSuANIouO%;tm~~G(Ovm Date: Mon, 12 May 2014 19:55:18 +0300 Subject: [PATCH 02/11] Make sure bounding box in ints (for Py3) --- Tests/test_imagedraw.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 11f4fcd91..9904457af 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -7,10 +7,10 @@ from PIL import ImageDraw w, h = 100, 100 # Bounding box points -x0 = w / 4 -x1 = x0 * 3 -y0 = h / 4 -y1 = x0 * 3 +x0 = int(w / 4) +x1 = int(x0 * 3) +y0 = int(h / 4) +y1 = int(x0 * 3) # Two kinds of bounding box bbox1 = [(x0, y0), (x1, y1)] From 6b274b4c5e22a06ad72a682f7cb80a8b541dd87b Mon Sep 17 00:00:00 2001 From: hugovk Date: Mon, 12 May 2014 21:45:16 +0300 Subject: [PATCH 03/11] More ImageDraw tests. Some may need redoing after issues #367 and #463 are sorted. --- Tests/images/imagedraw_line.png | Bin 0 -> 286 bytes Tests/images/imagedraw_point.png | Bin 0 -> 124 bytes Tests/images/imagedraw_polygon.png | Bin 0 -> 292 bytes Tests/images/imagedraw_rectangle.png | Bin 0 -> 228 bytes Tests/test_imagedraw.py | 88 +++++++++++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 Tests/images/imagedraw_line.png create mode 100644 Tests/images/imagedraw_point.png create mode 100644 Tests/images/imagedraw_polygon.png create mode 100644 Tests/images/imagedraw_rectangle.png diff --git a/Tests/images/imagedraw_line.png b/Tests/images/imagedraw_line.png new file mode 100644 index 0000000000000000000000000000000000000000..6d0e6994d861246c94a905d395b683775489ed09 GIT binary patch literal 286 zcmeAS@N?(olHy`uVBq!ia0vp^DIm(?a5DGbZ$zeim|1j!c@7cxq%qP7CDP~|u_;jC{;ef806_|%a9N^|HJI(rAL?`wsNYvBS&t;uc GLK6VpyB)Xy literal 0 HcmV?d00001 diff --git a/Tests/images/imagedraw_polygon.png b/Tests/images/imagedraw_polygon.png new file mode 100644 index 0000000000000000000000000000000000000000..5f160be76ceef3d85c7092a63d87e48115ec3303 GIT binary patch literal 292 zcmeAS@N?(olHy`uVBq!ia0vp^DImw+vGjmJT^EHnX^geT_FfuUkUHZNI{sZ}!Rk|0m4{9vEKINY9-e)hTs>plK zf0wzoVExtz&HLGxuB(RaJN`74*Yta-VVKvqS^Za|;!cOWF0GApUKv-OyfkS2(un&p zj{=rlZ%gGBt;+45%Ct8u`ENz%;hTHQ^s+5>T>lqgxjlUMmyq|u{M){)zW?9dcGH?U z5nB95tu}?MJNE0X`Nu0kH}|b+_D;=Tv)TLZmtXf^?!N!LuzFf(O0aa2sAg&W`hwcs f8mvISp@4!0|C_PVOkF`octGNwu6{1-oD!M-=- z>O8hT9}YG)8MEq~w&nw>0Rg?=IellJ-B`Bs_km6zUKttvYn|@ihKNQQ!h`vh`P05b c>}QaB%D Date: Mon, 12 May 2014 23:27:02 +0300 Subject: [PATCH 04/11] Test experimental floodfill() --- Tests/images/imagedraw_floodfill.png | Bin 0 -> 232 bytes Tests/test_imagedraw.py | 16 ++++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 Tests/images/imagedraw_floodfill.png diff --git a/Tests/images/imagedraw_floodfill.png b/Tests/images/imagedraw_floodfill.png new file mode 100644 index 0000000000000000000000000000000000000000..89376a0f01585431b6dfcdce1ab78d41ad1ae0c0 GIT binary patch literal 232 zcmeAS@N?(olHy`uVBq!ia0vp^DIm>$A6c=E^p z_-RJRvt}Gvu!@~0CVtOxMxZJnIFS6j;PtMyWbfxMrrtk$=Dg9r6Ysd~H!l?z(55Af ikWc^j+E5$nh9kTQ1uU8CSMGTP67Y2Ob6Mw<&;$VOggeUs literal 0 HcmV?d00001 diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 727275c2d..73617b97a 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -1,6 +1,7 @@ from tester import * from PIL import Image +from PIL import ImageColor from PIL import ImageDraw # Image size @@ -219,4 +220,19 @@ def test_rectangle2(): helper_rectangle(bbox2) +def test_floodfill(): + # Arrange + im = Image.new("RGB", (w, h)) + draw = ImageDraw.Draw(im) + draw.rectangle(bbox2, outline="yellow", fill="green") + centre_point = (int(w/2), int(h/2)) + + # Act + ImageDraw.floodfill(im, centre_point, ImageColor.getrgb("red")) + del draw + + # Assert + assert_image_equal(im, Image.open("Tests/images/imagedraw_floodfill.png")) + + # End of file From 5b55cb72d33c692f1677341311ec3df05dd0b500 Mon Sep 17 00:00:00 2001 From: hugovk Date: Mon, 12 May 2014 23:33:05 +0300 Subject: [PATCH 05/11] Test experimental floodfill with a border --- Tests/images/imagedraw_floodfill2.png | Bin 0 -> 212 bytes Tests/test_imagedraw.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 Tests/images/imagedraw_floodfill2.png diff --git a/Tests/images/imagedraw_floodfill2.png b/Tests/images/imagedraw_floodfill2.png new file mode 100644 index 0000000000000000000000000000000000000000..41b92fb75a032515147d1d63d27f45d61d85f69b GIT binary patch literal 212 zcmeAS@N?(olHy`uVBq!ia0vp^DIm?LEc!(!8PgVbG9L%=Jzf1= J);T3K0RX!!He~<+ literal 0 HcmV?d00001 diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 73617b97a..2a1f963c7 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -235,4 +235,21 @@ def test_floodfill(): assert_image_equal(im, Image.open("Tests/images/imagedraw_floodfill.png")) +def test_floodfill_border(): + # Arrange + im = Image.new("RGB", (w, h)) + draw = ImageDraw.Draw(im) + draw.rectangle(bbox2, outline="yellow", fill="green") + centre_point = (int(w/2), int(h/2)) + + # Act + ImageDraw.floodfill( + im, centre_point, ImageColor.getrgb("red"), + border=ImageColor.getrgb("black")) + del draw + + # Assert + assert_image_equal(im, Image.open("Tests/images/imagedraw_floodfill2.png")) + + # End of file From 60b25701332bb2056e3903761f456849186f046f Mon Sep 17 00:00:00 2001 From: hugovk Date: Tue, 13 May 2014 14:43:48 +0300 Subject: [PATCH 06/11] Test ImageDraw's bitmap() --- Tests/images/imagedraw_bitmap.png | Bin 0 -> 2127 bytes Tests/test_imagedraw.py | 14 ++++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 Tests/images/imagedraw_bitmap.png diff --git a/Tests/images/imagedraw_bitmap.png b/Tests/images/imagedraw_bitmap.png new file mode 100644 index 0000000000000000000000000000000000000000..05337b693928aa27ede94ddf8aa1b4afc534ff8c GIT binary patch literal 2127 zcmaKudr;Eb7RP^@CC6j=2+6DFBPgwlMoLPC*~KvN_(%>Tzgi>yS|CmJzIj7)3jly1xD)?4opSFZ%QtGL$W(A4S>o-O&f52I zJLT~to9+TKdYxQWVhSnOj}3*RMfSv zA}P78VqCOQF|G(jOiQIP6HZT*!n7Ts$w>}Jzb!e4(JHjY4GjB~4Or*qe}wM3JV7{j z4!!Vh(RB8a#Uxe!NxR$ZJA$uyH6?iG&kLV@O3CX7iT_l({La1S0dww9_2lSHzfhrR zr_ko@aACYzUcB_=h!KCyK0VfRPF!8!UR&q^Guv_5On}hE3?Ottp`GW0z;%I5f6IQy zzm%*!YQ*0^dhm{O^3t2-DM7%)(wu*iuY zgz3Mpt*t4gt-;bKl(XPI|A(iWM!Y0zPS?!0orDJ3m9mxG)>Tj<6q>$ry*+K?c@j8IPmnb7EPLe0KxPbdlZ{=UhV7T<6uV zoKAA9&6R|NBI8|{0WRELIA9&`)e?|NCSGUG9yKYRqqYp~bg*iG3yTPY@%Kn+>wSz} z`Y#hY;6iSFv_1yJZfq1qO1N-o;%K;VN=4Lk&zB|XmFYGx76&tIX?JmOxO~IO6^(AT(V@Mr4rt!#Z20$b zFJAMcq`|kq+{O7tu}>8mHyd=UT8b3qFy6+^+fEXkNM=m-ZVJekMQ)A;?_u3-ZjEd?99&~)b2uB&GpKkWrH$|-?6C2fG zqPq=RIFN7Zgy>hB!jUTVUmmx7EtN_Y3JcwBztjycEW|ig;PE4R>~Vu!tm6&l)a~%R zWp!Q}K!JrTk0Mh&KW;fmt>P$eVyr4ek!?h*-atKrQc_Zyy>@pY0n$H)$UA3OCZ3CZa;9xOuP-bsE6dHz zEz@#mmL#3Yn^MTUjdBp#rLb)1urjYY-5;BYvK38laP@%2;J z_4Na|qA66SrPizz9na<2)VcW)87eC&?zzjUs|n)rBmMc9`Q4Gpzj5NiU%^DD!{ z!{?o#G)r2EXWf|=4CqilpW_B16ZhT3%6PZ~BYHlam0PkA>TAhla!|Nq#a^l(@IsBP zi@2h?TG6DvvgQ4!#9)P7{%THD=RepkTg=MEW>vpMq?}-AL)BbMYpZMe#`DA& z84rdl@thefwhjmgVAZ>%d=B{vB?ju#QqXoFO+oy}GDQD<`&lvl%E_?8KYQOkOSU+c z7RA~pRsn$F`2%!yZyBK6ms<-H?8?rPNL`obnCc3I1$QLOY?=>pGcE7?Ka|Vm$3xmB zFkzkIxe*)s*keRFFKIBI8XqSDKs=IFKajmdN#?rSHfv~J4NX?#+`=CRM z^|Um*LmsuaJDKFKuB;GB6Yq9Cj$MS>U_txo{x)Dl|47V8;@b%OTZfW@r7E;xj2dvy zIt;!3e&L-;4R!0J*F5d$DEF+>%mBuF5xOdi6}6vv@wG!X5C%s%s!XKa<|xes^L(GQ z(kaxJRF`UT@zKEvUl^1mMYa&&?zMiwQd{AHGGSxmcf^S?#(F2dYVK-kDxyE)B&NpG zFn0@Joc)e^%)DR=Fwm8oL{Xxcu_ck-l0T5%czm#Q6VkbA4Jkj|HTK3{*A3IqnUrKE zSVmibv<5cw)1GRq>`pJNuKC}{{qN-cKawNf1ahkTB$z@01oSOf`bXk{5P{v B0-gW> literal 0 HcmV?d00001 diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 2a1f963c7..0a9366928 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -71,6 +71,20 @@ def test_arc2(): helper_arc(bbox2) +def test_bitmap(): + # Arrange + small = Image.open("Tests/images/pil123rgba.png").resize((50, 50)) + im = Image.new("RGB", (w, h)) + draw = ImageDraw.Draw(im) + + # Act + draw.bitmap((10, 10), small) + del draw + + # Assert + assert_image_equal(im, Image.open("Tests/images/imagedraw_bitmap.png")) + + def helper_chord(bbox): # Arrange im = Image.new("RGB", (w, h)) From 2662c38f5c5b7b4da8007f51c6020766d9e3f63f Mon Sep 17 00:00:00 2001 From: wiredfool Date: Tue, 20 May 2014 12:59:31 -0700 Subject: [PATCH 07/11] Updating docs to reflect current understanding --- docs/reference/ImageDraw.rst | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/docs/reference/ImageDraw.rst b/docs/reference/ImageDraw.rst index 68855eb5b..45be43057 100644 --- a/docs/reference/ImageDraw.rst +++ b/docs/reference/ImageDraw.rst @@ -91,9 +91,12 @@ Methods Draws an arc (a portion of a circle outline) between the start and end angles, inside the given bounding box. - :param xy: Four points to define the bounding box. Sequence of either - ``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``. - :param outline: Color to use for the outline. + :param xy: Four points to define the bounding box. Sequence of + ``[x0, y0, x1, y1]``. + :param start: Starting angle, in degrees. Angles are measured from + 3 o'clock, increasing clockwise. + :param end: Ending angle, in degrees. + :param fill: Color to use for the arc. .. py:method:: PIL.ImageDraw.Draw.bitmap(xy, bitmap, fill=None) @@ -111,8 +114,8 @@ Methods Same as :py:meth:`~PIL.ImageDraw.Draw.arc`, but connects the end points with a straight line. - :param xy: Four points to define the bounding box. Sequence of either - ``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``. + :param xy: Four points to define the bounding box. Sequence of + ``[x0, y0, x1, y1]``. :param outline: Color to use for the outline. :param fill: Color to use for the fill. @@ -144,8 +147,8 @@ Methods Same as arc, but also draws straight lines between the end points and the center of the bounding box. - :param xy: Four points to define the bounding box. Sequence of either - ``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``. + :param xy: Four points to define the bounding box. Sequence of + ``[x0, y0, x1, y1]``. :param outline: Color to use for the outline. :param fill: Color to use for the fill. From 35336e5afd5e3eb9ea2991eaf3b705877c49a173 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 24 May 2014 17:31:37 +0300 Subject: [PATCH 08/11] Test arc, chord, pieslice give TypeError when bounding box is [(x0, y0), (x1, y1)] --- Tests/test_imagedraw.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 0a9366928..21eca5038 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -62,9 +62,8 @@ def helper_arc(bbox): assert_image_equal(im, Image.open("Tests/images/imagedraw_arc.png")) -# FIXME -# def test_arc1(): -# helper_arc(bbox1) +def test_arc1(): + assert_exception(TypeError, lambda: helper_arc(bbox1)) def test_arc2(): @@ -98,9 +97,8 @@ def helper_chord(bbox): assert_image_equal(im, Image.open("Tests/images/imagedraw_chord.png")) -# FIXME -# def test_chord1(): -# helper_chord(bbox1) +def test_chord1(): + assert_exception(TypeError, lambda: helper_chord(bbox1)) def test_chord2(): @@ -162,9 +160,8 @@ def helper_pieslice(bbox): assert_image_equal(im, Image.open("Tests/images/imagedraw_pieslice.png")) -# FIXME -# def test_pieslice1(): -# helper_pieslice(bbox1) +def test_pieslice1(): + assert_exception(TypeError, lambda: helper_pieslice(bbox1)) def test_pieslice2(): From 8f92562ec353e7a2efeb96fb85aa5d76f3270492 Mon Sep 17 00:00:00 2001 From: hugovk Date: Sat, 24 May 2014 17:36:31 +0300 Subject: [PATCH 09/11] Remove old FIXME comment [CI skip] --- Tests/test_imagedraw.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 21eca5038..2e0cc07c0 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -53,7 +53,6 @@ def helper_arc(bbox): draw = ImageDraw.Draw(im) # Act - # FIXME Should docs note 0 degrees is at 3 o'clock? # FIXME Fill param should be named outline. draw.arc(bbox, 0, 180) del draw From ae37743ac743bc4f23cc7caa787a541fdb3e9651 Mon Sep 17 00:00:00 2001 From: hugovk Date: Tue, 27 May 2014 16:58:26 +0300 Subject: [PATCH 10/11] Both kinds of bounding box for arc, chord and pieslice. --- Tests/test_imagedraw.py | 6 +-- _imaging.c | 109 ++++++++++++++++++++++++++++++---------- 2 files changed, 86 insertions(+), 29 deletions(-) diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 2e0cc07c0..c47638a05 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -62,7 +62,7 @@ def helper_arc(bbox): def test_arc1(): - assert_exception(TypeError, lambda: helper_arc(bbox1)) + helper_arc(bbox1) def test_arc2(): @@ -97,7 +97,7 @@ def helper_chord(bbox): def test_chord1(): - assert_exception(TypeError, lambda: helper_chord(bbox1)) + helper_chord(bbox1) def test_chord2(): @@ -160,7 +160,7 @@ def helper_pieslice(bbox): def test_pieslice1(): - assert_exception(TypeError, lambda: helper_pieslice(bbox1)) + helper_pieslice(bbox1) def test_pieslice2(): diff --git a/_imaging.c b/_imaging.c index c47868b81..f8fd96f8a 100644 --- a/_imaging.c +++ b/_imaging.c @@ -2252,17 +2252,17 @@ void _font_text_asBytes(PyObject* encoded_string, unsigned char** text){ if (bytes) { *text = (unsigned char*)PyBytes_AsString(bytes); return; - } + } #if PY_VERSION_HEX < 0x03000000 /* likely case here is py2.x with an ordinary string. but this isn't defined in Py3.x */ if (PyString_Check(encoded_string)) { *text = (unsigned char *)PyString_AsString(encoded_string); - } + } #endif } - + static PyObject* _font_getmask(ImagingFontObject* self, PyObject* args) @@ -2336,7 +2336,7 @@ _font_getsize(ImagingFontObject* self, PyObject* args) return NULL; } - return Py_BuildValue("ii", textwidth(self, text), self->ysize); + return Py_BuildValue("ii", textwidth(self, text), self->ysize); } static struct PyMethodDef _font_methods[] = { @@ -2399,17 +2399,35 @@ _draw_ink(ImagingDrawObject* self, PyObject* args) static PyObject* _draw_arc(ImagingDrawObject* self, PyObject* args) { - int x0, y0, x1, y1; + double* xy; + int n; + + PyObject* data; int ink; int start, end; int op = 0; - if (!PyArg_ParseTuple(args, "(iiii)iii|i", - &x0, &y0, &x1, &y1, - &start, &end, &ink)) + if (!PyArg_ParseTuple(args, "Oiii|i", &data, &start, &end, &ink)) return NULL; - if (ImagingDrawArc(self->image->image, x0, y0, x1, y1, start, end, - &ink, op) < 0) + n = PyPath_Flatten(data, &xy); + if (n < 0) + return NULL; + if (n != 2) { + PyErr_SetString(PyExc_TypeError, + "coordinate list must contain exactly 2 coordinates" + ); + return NULL; + } + + n = ImagingDrawArc(self->image->image, + (int) xy[0], (int) xy[1], + (int) xy[2], (int) xy[3], + start, end, &ink, op + ); + + free(xy); + + if (n < 0) return NULL; Py_INCREF(Py_None); @@ -2455,15 +2473,35 @@ _draw_bitmap(ImagingDrawObject* self, PyObject* args) static PyObject* _draw_chord(ImagingDrawObject* self, PyObject* args) { - int x0, y0, x1, y1; + double* xy; + int n; + + PyObject* data; int ink, fill; int start, end; - if (!PyArg_ParseTuple(args, "(iiii)iiii", - &x0, &y0, &x1, &y1, &start, &end, &ink, &fill)) + if (!PyArg_ParseTuple(args, "Oiiii", + &data, &start, &end, &ink, &fill)) return NULL; - if (ImagingDrawChord(self->image->image, x0, y0, x1, y1, - start, end, &ink, fill, self->blend) < 0) + n = PyPath_Flatten(data, &xy); + if (n < 0) + return NULL; + if (n != 2) { + PyErr_SetString(PyExc_TypeError, + "coordinate list must contain exactly 2 coordinates" + ); + return NULL; + } + + n = ImagingDrawChord(self->image->image, + (int) xy[0], (int) xy[1], + (int) xy[2], (int) xy[3], + start, end, &ink, fill, self->blend + ); + + free(xy); + + if (n < 0) return NULL; Py_INCREF(Py_None); @@ -2492,8 +2530,8 @@ _draw_ellipse(ImagingDrawObject* self, PyObject* args) return NULL; } - n = ImagingDrawEllipse(self->image->image, - (int) xy[0], (int) xy[1], + n = ImagingDrawEllipse(self->image->image, + (int) xy[0], (int) xy[1], (int) xy[2], (int) xy[3], &ink, fill, self->blend ); @@ -2656,15 +2694,34 @@ _draw_outline(ImagingDrawObject* self, PyObject* args) static PyObject* _draw_pieslice(ImagingDrawObject* self, PyObject* args) { - int x0, y0, x1, y1; + double* xy; + int n; + + PyObject* data; int ink, fill; int start, end; - if (!PyArg_ParseTuple(args, "(iiii)iiii", - &x0, &y0, &x1, &y1, &start, &end, &ink, &fill)) + if (!PyArg_ParseTuple(args, "Oiiii", &data, &start, &end, &ink, &fill)) return NULL; - if (ImagingDrawPieslice(self->image->image, x0, y0, x1, y1, - start, end, &ink, fill, self->blend) < 0) + n = PyPath_Flatten(data, &xy); + if (n < 0) + return NULL; + if (n != 2) { + PyErr_SetString(PyExc_TypeError, + "coordinate list must contain exactly 2 coordinates" + ); + return NULL; + } + + n = ImagingDrawPieslice(self->image->image, + (int) xy[0], (int) xy[1], + (int) xy[2], (int) xy[3], + start, end, &ink, fill, self->blend + ); + + free(xy); + + if (n < 0) return NULL; Py_INCREF(Py_None); @@ -2738,9 +2795,9 @@ _draw_rectangle(ImagingDrawObject* self, PyObject* args) return NULL; } - n = ImagingDrawRectangle(self->image->image, + n = ImagingDrawRectangle(self->image->image, (int) xy[0], (int) xy[1], - (int) xy[2], (int) xy[3], + (int) xy[2], (int) xy[3], &ink, fill, self->blend ); @@ -3117,8 +3174,8 @@ _getattr_ptr(ImagingObject* self, void* closure) static PyObject* _getattr_unsafe_ptrs(ImagingObject* self, void* closure) { - return Py_BuildValue("(ss)(si)(si)(si)(si)(si)(sn)(sn)(sn)(sn)(sn)(si)(si)(sn)", - "mode", self->image->mode, + return Py_BuildValue("(ss)(si)(si)(si)(si)(si)(sn)(sn)(sn)(sn)(sn)(si)(si)(sn)", + "mode", self->image->mode, "type", self->image->type, "depth", self->image->depth, "bands", self->image->bands, From 4dcae4402cca5ed75e33c038778c291691095a7d Mon Sep 17 00:00:00 2001 From: Hugo Date: Tue, 27 May 2014 23:55:43 +0300 Subject: [PATCH 11/11] Add back the other bounding box [CI skip] --- docs/reference/ImageDraw.rst | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/reference/ImageDraw.rst b/docs/reference/ImageDraw.rst index 45be43057..30aa15a9b 100644 --- a/docs/reference/ImageDraw.rst +++ b/docs/reference/ImageDraw.rst @@ -91,11 +91,11 @@ Methods Draws an arc (a portion of a circle outline) between the start and end angles, inside the given bounding box. - :param xy: Four points to define the bounding box. Sequence of - ``[x0, y0, x1, y1]``. - :param start: Starting angle, in degrees. Angles are measured from + :param xy: Four points to define the bounding box. Sequence of + ``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``. + :param start: Starting angle, in degrees. Angles are measured from 3 o'clock, increasing clockwise. - :param end: Ending angle, in degrees. + :param end: Ending angle, in degrees. :param fill: Color to use for the arc. .. py:method:: PIL.ImageDraw.Draw.bitmap(xy, bitmap, fill=None) @@ -114,8 +114,8 @@ Methods Same as :py:meth:`~PIL.ImageDraw.Draw.arc`, but connects the end points with a straight line. - :param xy: Four points to define the bounding box. Sequence of - ``[x0, y0, x1, y1]``. + :param xy: Four points to define the bounding box. Sequence of + ``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``. :param outline: Color to use for the outline. :param fill: Color to use for the fill. @@ -148,7 +148,7 @@ Methods center of the bounding box. :param xy: Four points to define the bounding box. Sequence of - ``[x0, y0, x1, y1]``. + ``[(x0, y0), (x1, y1)]`` or ``[x0, y0, x1, y1]``. :param outline: Color to use for the outline. :param fill: Color to use for the fill.