summaryrefslogtreecommitdiff
path: root/ext/gd
diff options
context:
space:
mode:
Diffstat (limited to 'ext/gd')
-rw-r--r--ext/gd/libgd/gd.c67
-rw-r--r--ext/gd/libgd/xbm.c2
-rw-r--r--ext/gd/tests/bug43475.phpt59
-rw-r--r--ext/gd/tests/bug43475.pngbin0 -> 4697 bytes
-rw-r--r--ext/gd/tests/bug53640.phpt2
-rw-r--r--ext/gd/tests/bug64641.phpt38
-rw-r--r--ext/gd/tests/bug64641.pngbin0 -> 1404 bytes
-rw-r--r--ext/gd/tests/imagecolorallocatealpha_basic.phpt2
-rw-r--r--ext/gd/tests/imagefilledarc_basic.phpt2
-rw-r--r--ext/gd/tests/imagefilledarc_variation1.phpt2
-rw-r--r--ext/gd/tests/imagefilledarc_variation2.phpt2
-rw-r--r--ext/gd/tests/imagegammacorrect_basic.phpt2
-rw-r--r--ext/gd/tests/imagegammacorrect_variation1.phpt2
-rw-r--r--ext/gd/tests/imagetruecolortopalette_basic.phpt2
14 files changed, 170 insertions, 12 deletions
diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c
index 17b0a1091b..bb2f9c23aa 100644
--- a/ext/gd/libgd/gd.c
+++ b/ext/gd/libgd/gd.c
@@ -1053,11 +1053,13 @@ void gdImageAABlend (gdImagePtr im)
}
}
+static void _gdImageFilledHRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color);
+
static void gdImageHLine(gdImagePtr im, int y, int x1, int x2, int col)
{
if (im->thick > 1) {
int thickhalf = im->thick >> 1;
- gdImageFilledRectangle(im, x1, y - thickhalf, x2, y + im->thick - thickhalf - 1, col);
+ _gdImageFilledHRectangle(im, x1, y - thickhalf, x2, y + im->thick - thickhalf - 1, col);
} else {
if (x2 < x1) {
int t = x2;
@@ -2122,10 +2124,53 @@ void gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
}
}
-void gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
+static void _gdImageFilledHRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
{
int x, y;
+ if (x1 == x2 && y1 == y2) {
+ gdImageSetPixel(im, x1, y1, color);
+ return;
+ }
+
+ if (x1 > x2) {
+ x = x1;
+ x1 = x2;
+ x2 = x;
+ }
+
+ if (y1 > y2) {
+ y = y1;
+ y1 = y2;
+ y2 = y;
+ }
+
+ if (x1 < 0) {
+ x1 = 0;
+ }
+
+ if (x2 >= gdImageSX(im)) {
+ x2 = gdImageSX(im) - 1;
+ }
+
+ if (y1 < 0) {
+ y1 = 0;
+ }
+
+ if (y2 >= gdImageSY(im)) {
+ y2 = gdImageSY(im) - 1;
+ }
+
+ for (x = x1; (x <= x2); x++) {
+ for (y = y1; (y <= y2); y++) {
+ gdImageSetPixel (im, x, y, color);
+ }
+ }
+}
+
+static void _gdImageFilledVRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
+{
+ int x, y;
if (x1 == x2 && y1 == y2) {
gdImageSetPixel(im, x1, y1, color);
@@ -2167,6 +2212,11 @@ void gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int
}
}
+void gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
+{
+ _gdImageFilledVRectangle(im, x1, y1, x2, y2, color);
+}
+
void gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h)
{
int c;
@@ -2669,6 +2719,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/libgd/xbm.c b/ext/gd/libgd/xbm.c
index d127a1d4ff..b351814abb 100644
--- a/ext/gd/libgd/xbm.c
+++ b/ext/gd/libgd/xbm.c
@@ -210,7 +210,7 @@ void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out)
if (gdImageGetPixel(image, x, y) == fg) {
c |= b;
}
- if ((b == 128) || (x == sx && y == sy)) {
+ if ((b == 128) || (x == sx - 1)) {
b = 1;
if (p) {
gdCtxPrintf(out, ", ");
diff --git a/ext/gd/tests/bug43475.phpt b/ext/gd/tests/bug43475.phpt
new file mode 100644
index 0000000000..b29b9800a5
--- /dev/null
+++ b/ext/gd/tests/bug43475.phpt
@@ -0,0 +1,59 @@
+--TEST--
+Bug #43475 (Thick styled lines have scrambled patterns)
+--SKIPIF--
+<?php
+ if (!extension_loaded('gd')) die("skip gd extension not available\n");
+?>
+--FILE--
+<?php
+require_once __DIR__ . '/similarity.inc';
+
+function setStyleAndThickness($im, $color, $thickness)
+{
+ $style = array();
+ $i = 0;
+ while ($i < 16 * $thickness) {
+ $style[$i++] = $color;
+ }
+ while ($i < 20 * $thickness) {
+ $style[$i++] = IMG_COLOR_TRANSPARENT;
+ }
+ while ($i < 28 * $thickness) {
+ $style[$i++] = $color;
+ }
+ while ($i < 32 * $thickness) {
+ $style[$i++] = IMG_COLOR_TRANSPARENT;
+ }
+ imagesetstyle($im, $style);
+ imagesetthickness($im, $thickness);
+}
+
+$im = imagecreate(800, 800);
+imagecolorallocate($im, 255, 255, 255);
+$black = imagecolorallocate($im, 0, 0, 0);
+
+setStyleAndThickness($im, $black, 1);
+imageline($im, 50, 250, 550, 250, IMG_COLOR_STYLED);
+imageline($im, 550, 250, 550, 750, IMG_COLOR_STYLED);
+imageline($im, 550, 750, 50, 250, IMG_COLOR_STYLED);
+
+setStyleAndThickness($im, $black, 2);
+imageline($im, 100, 200, 600, 200, IMG_COLOR_STYLED);
+imageline($im, 600, 200, 600, 700, IMG_COLOR_STYLED);
+imageline($im, 600, 700, 100, 200, IMG_COLOR_STYLED);
+
+setStyleAndThickness($im, $black, 4);
+imageline($im, 150, 150, 650, 150, IMG_COLOR_STYLED);
+imageline($im, 650, 150, 650, 650, IMG_COLOR_STYLED);
+imageline($im, 650, 650, 150, 150, IMG_COLOR_STYLED);
+
+setStyleAndThickness($im, $black, 6);
+imageline($im, 200, 100, 700, 100, IMG_COLOR_STYLED);
+imageline($im, 700, 100, 700, 600, IMG_COLOR_STYLED);
+imageline($im, 700, 600, 200, 100, IMG_COLOR_STYLED);
+
+$ex = imagecreatefrompng(__DIR__ . '/bug43475.png');
+var_dump(calc_image_dissimilarity($ex, $im) < 1e-5);
+?>
+--EXPECT--
+bool(true)
diff --git a/ext/gd/tests/bug43475.png b/ext/gd/tests/bug43475.png
new file mode 100644
index 0000000000..774270f63d
--- /dev/null
+++ b/ext/gd/tests/bug43475.png
Binary files differ
diff --git a/ext/gd/tests/bug53640.phpt b/ext/gd/tests/bug53640.phpt
index a16b7c24c0..ee875de19a 100644
--- a/ext/gd/tests/bug53640.phpt
+++ b/ext/gd/tests/bug53640.phpt
@@ -12,8 +12,6 @@ $white = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 2, 2, 6, 6, $white);
imagexbm($im, NULL);
?>
---XFAIL--
-Padding is not implemented yet
--EXPECT--
#define image_width 9
#define image_height 9
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--
+<?php
+if (!extension_loaded('gd')) die("skip gd extension not available\n");
+?>
+--FILE--
+<?php
+require_once __DIR__ . '/similarity.inc';
+
+$im = imagecreatetruecolor(640, 480);
+
+$points = array(
+ 100, 100,
+ 100, 200,
+ 100, 300
+);
+imagefilledpolygon($im, $points, 3, 0xFFFF00);
+
+$points = array(
+ 300, 200,
+ 400, 200,
+ 500, 200
+);
+imagefilledpolygon($im, $points, 3, 0xFFFF00);
+
+$ex = imagecreatefrompng(__DIR__ . '/bug64641.png');
+if (($diss = calc_image_dissimilarity($ex, $im)) < 1e-5) {
+ echo "IDENTICAL";
+} else {
+ echo "DISSIMILARITY: $diss";
+}
+imagedestroy($ex);
+
+imagedestroy($im);
+?>
+--EXPECT--
+IDENTICAL
diff --git a/ext/gd/tests/bug64641.png b/ext/gd/tests/bug64641.png
new file mode 100644
index 0000000000..8376262d2f
--- /dev/null
+++ b/ext/gd/tests/bug64641.png
Binary files differ
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