From 2a305b38b76f3a3ab0a91cbffb43f675f95917c4 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 2 Oct 2016 20:27:58 +0200 Subject: [PATCH] Implement request #33066: Add GD Image Function gdImageOpenPolygon() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gdImageOpenPolygon() has been introduced with líbgd 2.0.29, so we finally add a PHP binding for it, and port the respective libgd functionality to PHP's bundled libgd. --- ext/gd/gd.c | 31 ++++++++++++++++++++--- ext/gd/libgd/gd.c | 12 ++++++++- ext/gd/libgd/gd.h | 1 + ext/gd/php_gd.h | 1 + ext/gd/tests/imageopenpolygon.png | Bin 0 -> 1325 bytes ext/gd/tests/imageopenpolygon_basic.phpt | 29 +++++++++++++++++++++ 6 files changed, 69 insertions(+), 5 deletions(-) create mode 100644 ext/gd/tests/imageopenpolygon.png create mode 100644 ext/gd/tests/imageopenpolygon_basic.phpt diff --git a/ext/gd/gd.c b/ext/gd/gd.c index f8569779baa..caac3a994dc 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -578,6 +578,13 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagepolygon, 0) ZEND_ARG_INFO(0, col) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO(arginfo_imageopenpolygon, 0) + ZEND_ARG_INFO(0, im) + ZEND_ARG_INFO(0, points) /* ARRAY_INFO(0, points, 0) */ + ZEND_ARG_INFO(0, num_pos) + ZEND_ARG_INFO(0, col) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO(arginfo_imagefilledpolygon, 0) ZEND_ARG_INFO(0, im) ZEND_ARG_INFO(0, points) /* ARRAY_INFO(0, points, 0) */ @@ -938,6 +945,7 @@ const zend_function_entry gd_functions[] = { PHP_FE(imageline, arginfo_imageline) PHP_FE(imageloadfont, arginfo_imageloadfont) PHP_FE(imagepolygon, arginfo_imagepolygon) + PHP_FE(imageopenpolygon, arginfo_imageopenpolygon) PHP_FE(imagerectangle, arginfo_imagerectangle) PHP_FE(imagesetpixel, arginfo_imagesetpixel) PHP_FE(imagestring, arginfo_imagestring) @@ -3346,6 +3354,7 @@ PHP_FUNCTION(imageinterlace) /* }}} */ /* {{{ php_imagepolygon + arg = -1 open polygon arg = 0 normal polygon arg = 1 filled polygon */ /* im, points, num_points, col */ @@ -3398,10 +3407,16 @@ static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled) gdImageSetAntiAliased(im, col); col = gdAntiAliased; } - if (filled) { - gdImageFilledPolygon(im, points, npoints, col); - } else { - gdImagePolygon(im, points, npoints, col); + switch (filled) { + case -1: + gdImageOpenPolygon(im, points, npoints, col); + break; + case 0: + gdImagePolygon(im, points, npoints, col); + break; + case 1: + gdImageFilledPolygon(im, points, npoints, col); + break; } efree(points); @@ -3417,6 +3432,14 @@ PHP_FUNCTION(imagepolygon) } /* }}} */ +/* {{{ proto bool imageopenpolygon(resource im, array point, int num_points, int col) + Draw a polygon */ +PHP_FUNCTION(imageopenpolygon) +{ + php_imagepolygon(INTERNAL_FUNCTION_PARAM_PASSTHRU, -1); +} +/* }}} */ + /* {{{ proto bool imagefilledpolygon(resource im, array point, int num_points, int col) Draw a filled polygon */ PHP_FUNCTION(imagefilledpolygon) diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c index afa8e287cce..b312c574c33 100644 --- a/ext/gd/libgd/gd.c +++ b/ext/gd/libgd/gd.c @@ -2605,6 +2605,17 @@ void gdImageCopyResampled (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, i } void gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c) +{ + if (n <= 0) { + return; + } + + + gdImageLine (im, p->x, p->y, p[n - 1].x, p[n - 1].y, c); + gdImageOpenPolygon (im, p, n, c); +} + +void gdImageOpenPolygon (gdImagePtr im, gdPointPtr p, int n, int c) { int i; int lx, ly; @@ -2615,7 +2626,6 @@ void gdImagePolygon (gdImagePtr im, gdPointPtr p, int n, int c) lx = p->x; ly = p->y; - gdImageLine(im, lx, ly, p[n - 1].x, p[n - 1].y, c); for (i = 1; i < n; i++) { p++; gdImageLine(im, lx, ly, p->x, p->y, c); diff --git a/ext/gd/libgd/gd.h b/ext/gd/libgd/gd.h index 4b6f86e28c3..85dbe9b7e07 100644 --- a/ext/gd/libgd/gd.h +++ b/ext/gd/libgd/gd.h @@ -493,6 +493,7 @@ typedef struct { } gdPoint, *gdPointPtr; void gdImagePolygon(gdImagePtr im, gdPointPtr p, int n, int c); +void gdImageOpenPolygon(gdImagePtr im, gdPointPtr p, int n, int c); void gdImageFilledPolygon(gdImagePtr im, gdPointPtr p, int n, int c); /* These functions still work with truecolor images, diff --git a/ext/gd/php_gd.h b/ext/gd/php_gd.h index 0b35423f888..a6a660184f1 100644 --- a/ext/gd/php_gd.h +++ b/ext/gd/php_gd.h @@ -174,6 +174,7 @@ PHP_FUNCTION(imageinterlace); PHP_FUNCTION(imageline); PHP_FUNCTION(imageloadfont); PHP_FUNCTION(imagepolygon); +PHP_FUNCTION(imageopenpolygon); PHP_FUNCTION(imagerectangle); PHP_FUNCTION(imagesetpixel); PHP_FUNCTION(imagestring); diff --git a/ext/gd/tests/imageopenpolygon.png b/ext/gd/tests/imageopenpolygon.png new file mode 100644 index 0000000000000000000000000000000000000000..33bcf3222331b392fb09ef12d8260005989748aa GIT binary patch literal 1325 zcmV+|1=9M7P)n`?65yfCTjV4*lU341 zfKx0YG==HU)dP5vrm+l~#xiIc%b;m2gQl?zn#M9{8q1(*EQ1tdF*DwlQr6Vezo@XK zs!_Y9nK|h<(e$j3m|0)>i6*3sh!9DwV7Lc1^-JqdsByPw-v#Y^%&Mnni42JsW*WWN zhujJYLlIHQb;9%9L8mZlwPl0v^>^E4RG?dhL4eU+E4kjxm)c*|dW=vN;8kzjt);o} zXezLz3$q>_g9f+4!%zTnQ8ri-TN=Y@U%O`{x<27o=UFDVA~Is&SpL{RdPOg>yK?|X zQnnkm0;g7N0l<>JdDgRJb}MTbN=z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