summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Joye <pajoye@php.net>2004-11-20 13:34:52 +0000
committerPierre Joye <pajoye@php.net>2004-11-20 13:34:52 +0000
commit3775b781975370efa561b690cfee0bf376c21313 (patch)
tree7138d5b1cec3632c9f133e6858b905207499a63b
parentbe6160f0f95363bee3c6b9346fb94adce8e6640f (diff)
downloadphp-git-3775b781975370efa561b690cfee0bf376c21313.tar.gz
- Fix #30229, imagerectangle draw the corners twice, making it useless
with alpha channel. Fix it to work well with thick>1 as well, both filled and wired rectangle
-rw-r--r--ext/gd/libgd/gd.c82
1 files changed, 70 insertions, 12 deletions
diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c
index 93a70bff86..c82ac31c00 100644
--- a/ext/gd/libgd/gd.c
+++ b/ext/gd/libgd/gd.c
@@ -2029,24 +2029,72 @@ void gdImageRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
{
int x1h = x1, x1v = x1, y1h = y1, y1v = y1, x2h = x2, x2v = x2, y2h = y2, y2v = y2;
int thick = im->thick;
+ int half1 = 1;
+ int t;
+ if (y2 < y1) {
+ t=y1;
+ y1 = y2;
+ y2 = t;
+
+ t = x1;
+ x1 = x2;
+ x2 = t;
+ }
+
+ x1h = x1; x1v = x1; y1h = y1; y1v = y1; x2h = x2; x2v = x2; y2h = y2; y2v = y2;
if (thick > 1) {
- int half = thick / 2;
- int half1 = thick - half;
+ int cx, cy, x1ul, y1ul, x2lr, y2lr;
+ int half = thick >> 1;
+ half1 = thick - half;
+ x1ul = x1 - half;
+ y1ul = y1 - half;
+
+ x2lr = x2 + half;
+ y2lr = y2 + half;
- if (y1 < y2) {
- y1v = y1h - half;
- y2v = y2h + half1 - 1;
- } else {
- y1v = y1h + half1 - 1;
- y2v = y2h - half;
+ cy = y1ul + thick;
+ while (cy-- > y1ul) {
+ cx = x1ul - 1;
+ while (cx++ < x2lr) {
+ gdImageSetPixel(im, cx, cy, color);
+ }
+ }
+
+ cy = y2lr - thick;
+ while (cy++ < y2lr) {
+ cx = x1ul - 1;
+ while (cx++ < x2lr) {
+ gdImageSetPixel(im, cx, cy, color);
+ }
+ }
+
+ cy = y1ul + thick - 1;
+ while (cy++ < y2lr -thick) {
+ cx = x1ul - 1;
+ while (cx++ < x1ul + thick) {
+ gdImageSetPixel(im, cx, cy, color);
+ }
+ }
+
+ cy = y1ul + thick - 1;
+ while (cy++ < y2lr -thick) {
+ cx = x2lr - thick - 1;
+ while (cx++ < x2lr) {
+ gdImageSetPixel(im, cx, cy, color);
+ }
}
+
+ return;
+ } else {
+ y1v = y1h + 1;
+ y2v = y2h - 1;
+ gdImageLine(im, x1h, y1h, x2h, y1h, color);
+ gdImageLine(im, x1h, y2h, x2h, y2h, color);
+ gdImageLine(im, x1v, y1v, x1v, y2v, color);
+ gdImageLine(im, x2v, y1v, x2v, y2v, color);
}
- gdImageLine(im, x1h, y1h, x2h, y1h, color);
- gdImageLine(im, x1h, y2h, x2h, y2h, color);
- gdImageLine(im, x1v, y1v, x1v, y2v, color);
- gdImageLine(im, x2v, y1v, x2v, y2v, color);
}
void gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color)
@@ -2069,6 +2117,16 @@ void gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int
if (y1 > gdImageSY(im)) {
y1 = gdImageSY(im);
}
+ if (y2 < y1) {
+ int t;
+ t=y1;
+ y1 = y2;
+ y2 = t;
+
+ t = x1;
+ x1 = x2;
+ x2 = t;
+ }
for (y = y1; (y <= y2); y++) {
for (x = x1; (x <= x2); x++) {