From 4b4275059fd3d7f0840d238a92d8cd0cfe3292eb Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 19 Jun 2016 13:54:55 +0200 Subject: [PATCH] Fix #64641: imagefilledpolygon doesn't draw horizontal line As has been reported, 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. That has also been fixed in libgd with . --- ext/gd/libgd/gd.c | 13 ++++++ ext/gd/tests/bug64641.phpt | 38 ++++++++++++++++++ ext/gd/tests/bug64641.png | Bin 0 -> 1404 bytes .../tests/imagecolorallocatealpha_basic.phpt | 2 +- ext/gd/tests/imagefilledarc_basic.phpt | 2 +- ext/gd/tests/imagefilledarc_variation1.phpt | 2 +- ext/gd/tests/imagefilledarc_variation2.phpt | 2 +- ext/gd/tests/imagegammacorrect_basic.phpt | 2 +- .../tests/imagegammacorrect_variation1.phpt | 2 +- .../tests/imagetruecolortopalette_basic.phpt | 2 +- 10 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 ext/gd/tests/bug64641.phpt create mode 100644 ext/gd/tests/bug64641.png diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c index 89c7dbdd58..7ba4e0c911 100644 --- a/ext/gd/libgd/gd.c +++ b/ext/gd/libgd/gd.c @@ -2717,6 +2717,19 @@ void gdImageFilledPolygon (gdImagePtr im, gdPointPtr p, int n, int c) 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 */ if (miny < 0) { diff --git a/ext/gd/tests/bug64641.phpt b/ext/gd/tests/bug64641.phpt new file mode 100644 index 0000000000..d8dae9a4d3 --- /dev/null +++ b/ext/gd/tests/bug64641.phpt @@ -0,0 +1,38 @@ +--TEST-- +Bug #64641 (imagefilledpolygon doesn't draw horizontal line) +--SKIPIF-- + +--FILE-- + +--EXPECT-- +IDENTICAL diff --git a/ext/gd/tests/bug64641.png b/ext/gd/tests/bug64641.png new file mode 100644 index 0000000000000000000000000000000000000000..8376262d2f5351e6f0ebf03b110d423bfed2ed2b GIT binary patch literal 1404 zcmeAS@N?(olHy`uVBq!ia0y~yU}|7sV0^&A1Qgk|*?Ths1FN&Ai(^Q|oVPbFayA$U zusSM#yI-Vp=s=QD@WJ1^T6gOKRSr>5mwT>?kzx0a*NhAWN{nm`4Ghc<4h@V73I`Yj z1QHlHI1CtASR@#jn0Oc%N2O^OEDu()A9(p}jrfL@hObyRbUAY#(2Bb-8U+KG^oD4L d9-PkpaFkoco4vO<+vhaMfu62@F6*2UngGSqk1hZJ literal 0 HcmV?d00001 diff --git a/ext/gd/tests/imagecolorallocatealpha_basic.phpt b/ext/gd/tests/imagecolorallocatealpha_basic.phpt index 720c50098a..bdc417387f 100644 --- a/ext/gd/tests/imagecolorallocatealpha_basic.phpt +++ b/ext/gd/tests/imagecolorallocatealpha_basic.phpt @@ -26,5 +26,5 @@ var_dump(md5(base64_encode($imgsrc))); var_dump($corA); ?> --EXPECT-- -string(32) "b856a0b1a15efe0f79551ebbb5651fe8" +string(32) "2a6424e4cb4e1b7391dfff74bf136bde" int(842163455) \ No newline at end of file diff --git a/ext/gd/tests/imagefilledarc_basic.phpt b/ext/gd/tests/imagefilledarc_basic.phpt index 9ff9bd3716..3357dd75aa 100644 --- a/ext/gd/tests/imagefilledarc_basic.phpt +++ b/ext/gd/tests/imagefilledarc_basic.phpt @@ -25,4 +25,4 @@ ob_end_clean(); echo md5(base64_encode($img)); ?> --EXPECT-- -894f394c7f2e2364642ef27fea6bfc33 +beffeaf5231adaaff1f21a2108fb6f7e diff --git a/ext/gd/tests/imagefilledarc_variation1.phpt b/ext/gd/tests/imagefilledarc_variation1.phpt index 2dec1ead2c..2254b0910f 100644 --- a/ext/gd/tests/imagefilledarc_variation1.phpt +++ b/ext/gd/tests/imagefilledarc_variation1.phpt @@ -25,4 +25,4 @@ ob_end_clean(); echo md5(base64_encode($img)); ?> --EXPECT-- -b77bbb8207e5adbebfcc8bd1c4074305 +b467492b806001c3720b3f18cfbde5b0 diff --git a/ext/gd/tests/imagefilledarc_variation2.phpt b/ext/gd/tests/imagefilledarc_variation2.phpt index 5c8ffba001..57686ab64c 100644 --- a/ext/gd/tests/imagefilledarc_variation2.phpt +++ b/ext/gd/tests/imagefilledarc_variation2.phpt @@ -25,4 +25,4 @@ ob_end_clean(); echo md5(base64_encode($img)); ?> --EXPECT-- -b8b572812b3c85678f6c38c4ecca7619 +cfad369fc6d863785d3c95b4b4788225 diff --git a/ext/gd/tests/imagegammacorrect_basic.phpt b/ext/gd/tests/imagegammacorrect_basic.phpt index b568728e71..33d6b1ad6c 100644 --- a/ext/gd/tests/imagegammacorrect_basic.phpt +++ b/ext/gd/tests/imagegammacorrect_basic.phpt @@ -29,4 +29,4 @@ if ($gamma){ echo md5(base64_encode($img)); ?> --EXPECT-- -30639772903913594bc665743e1b9ab8 +e79553115df689ea5df18a4636380569 diff --git a/ext/gd/tests/imagegammacorrect_variation1.phpt b/ext/gd/tests/imagegammacorrect_variation1.phpt index cda96c6287..7a321f89d8 100644 --- a/ext/gd/tests/imagegammacorrect_variation1.phpt +++ b/ext/gd/tests/imagegammacorrect_variation1.phpt @@ -29,4 +29,4 @@ if ($gamma){ echo md5(base64_encode($img)); ?> --EXPECT-- -7716c0905ae08bd84b4d6cba8969a42e +b017b1ddc8bda00e82aa8cbfb54c35d4 diff --git a/ext/gd/tests/imagetruecolortopalette_basic.phpt b/ext/gd/tests/imagetruecolortopalette_basic.phpt index b0a0394b55..3bd0d3102e 100644 --- a/ext/gd/tests/imagetruecolortopalette_basic.phpt +++ b/ext/gd/tests/imagetruecolortopalette_basic.phpt @@ -28,4 +28,4 @@ echo md5(base64_encode($img)); ?> --EXPECT-- bool(true) -0843f63ab2f9fddedd69b0b421686bc5 \ No newline at end of file +1d41787ff70aa0c7eea5ee9304afa36b \ No newline at end of file -- 2.40.0