diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2016-06-17 13:14:39 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2016-06-20 14:16:23 +0200 |
commit | f9f10fa9d4a55a8a1aaf6aa89db61f764cd2fe98 (patch) | |
tree | 5dbd4b4cf23fce8b8ba8ddafea30b2731a452787 | |
parent | a61d9f3600f22893338df1cba0a31705d5e13579 (diff) | |
download | libgd-f9f10fa9d4a55a8a1aaf6aa89db61f764cd2fe98.tar.gz |
Fix PHP bug #64641: imagefilledpolygon doesn't draw horizontal line
As reported in <https://bugs.php.net/64641> 1-dimensional horizontal
filled polygons are not drawn at all. That is caused by the scanline
algorithm used for drawing filled polygons which skips the drawing of
horizontal edges, because that is normally not necessary. If, however,
the polygon consists of horizontal edges only, that obviously doesn't
work, so we add a special case handling.
-rw-r--r-- | src/gd.c | 13 | ||||
-rw-r--r-- | tests/gdimagefilledpolygon/.gitignore | 1 | ||||
-rw-r--r-- | tests/gdimagefilledpolygon/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/gdimagefilledpolygon/Makemodule.am | 6 | ||||
-rw-r--r-- | tests/gdimagefilledpolygon/php_bug_64641.c | 47 | ||||
-rw-r--r-- | tests/gdimagefilledpolygon/php_bug_64641.png | bin | 0 -> 1425 bytes |
6 files changed, 66 insertions, 2 deletions
@@ -3142,6 +3142,19 @@ BGD_DECLARE(void) gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int maxy = p[i].y; } } + /* necessary special case: horizontal line */ + if (n > 1 && miny == maxy) { + x1 = x2 = p[0].x; + for (i = 1; (i < n); i++) { + if (p[i].x < x1) { + x1 = p[i].x; + } else if (p[i].x > x2) { + x2 = p[i].x; + } + } + gdImageLine(im, x1, miny, x2, miny, c); + return; + } pmaxy = maxy; /* 2.0.16: Optimization by Ilia Chipitsine -- don't waste time offscreen */ /* 2.0.26: clipping rectangle is even better */ diff --git a/tests/gdimagefilledpolygon/.gitignore b/tests/gdimagefilledpolygon/.gitignore index 9caf98f..9826ed8 100644 --- a/tests/gdimagefilledpolygon/.gitignore +++ b/tests/gdimagefilledpolygon/.gitignore @@ -3,3 +3,4 @@ /gdimagefilledpolygon1 /gdimagefilledpolygon2 /gdimagefilledpolygon3 +/php_bug_64641 diff --git a/tests/gdimagefilledpolygon/CMakeLists.txt b/tests/gdimagefilledpolygon/CMakeLists.txt index 8180bb1..3147a5a 100644 --- a/tests/gdimagefilledpolygon/CMakeLists.txt +++ b/tests/gdimagefilledpolygon/CMakeLists.txt @@ -4,6 +4,7 @@ LIST(APPEND TESTS_FILES gdimagefilledpolygon2 gdimagefilledpolygon3 bug00100 + php_bug_64641 ) ADD_GD_TESTS() diff --git a/tests/gdimagefilledpolygon/Makemodule.am b/tests/gdimagefilledpolygon/Makemodule.am index 2dcded0..7a2f681 100644 --- a/tests/gdimagefilledpolygon/Makemodule.am +++ b/tests/gdimagefilledpolygon/Makemodule.am @@ -4,7 +4,8 @@ libgd_test_programs += \ gdimagefilledpolygon/gdimagefilledpolygon0 \ gdimagefilledpolygon/gdimagefilledpolygon1 \ gdimagefilledpolygon/gdimagefilledpolygon2 \ - gdimagefilledpolygon/gdimagefilledpolygon3 + gdimagefilledpolygon/gdimagefilledpolygon3 \ + gdimagefilledpolygon/php_bug_64641 endif EXTRA_DIST += \ @@ -13,4 +14,5 @@ EXTRA_DIST += \ gdimagefilledpolygon/gdimagefilledpolygon0.png \ gdimagefilledpolygon/gdimagefilledpolygon1.png \ gdimagefilledpolygon/gdimagefilledpolygon2.png \ - gdimagefilledpolygon/gdimagefilledpolygon3.png + gdimagefilledpolygon/gdimagefilledpolygon3.png \ + gdimagefilledpolygon/php_bug_64641.png diff --git a/tests/gdimagefilledpolygon/php_bug_64641.c b/tests/gdimagefilledpolygon/php_bug_64641.c new file mode 100644 index 0000000..baf8913 --- /dev/null +++ b/tests/gdimagefilledpolygon/php_bug_64641.c @@ -0,0 +1,47 @@ +/* + Test drawing of 1-dimensional filled polygons + + We're drawing a vertical and a horizontal 1-dimensional filled polygon, + which is supposed to result in a vertical and a horizontal line. + + See also <https://bugs.php.net/64641>. +*/ + +#include "gd.h" +#include "gdtest.h" + +int main() +{ + gdImagePtr im; + gdPointPtr points; + + im = gdImageCreateTrueColor(640, 480); + + points = (gdPointPtr)calloc(3, sizeof(gdPoint)); + gdTestAssert(points != NULL); + + /* vertical line */ + points[0].x = 100; + points[0].y = 100; + points[1].x = 100; + points[1].y = 200; + points[2].x = 100; + points[2].y = 300; + gdImageFilledPolygon(im, points, 3, 0xFFFF00); + + /* horizontal line */ + points[0].x = 300; + points[0].y = 200; + points[1].x = 400; + points[1].y = 200; + points[2].x = 500; + points[2].y = 200; + gdImageFilledPolygon(im, points, 3, 0xFFFF00); + + gdAssertImageEqualsToFile("gdimagefilledpolygon/php_bug_64641.png", im); + + free(points); + gdImageDestroy(im); + + return gdNumFailures(); +} diff --git a/tests/gdimagefilledpolygon/php_bug_64641.png b/tests/gdimagefilledpolygon/php_bug_64641.png Binary files differnew file mode 100644 index 0000000..62fb621 --- /dev/null +++ b/tests/gdimagefilledpolygon/php_bug_64641.png |