Skip to content

Commit e4df0cb

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix libgd 223: gdImageRotateGeneric() does not properly interpolate
2 parents 47f1cae + 12e4ee4 commit e4df0cb

File tree

3 files changed

+30
-16
lines changed

3 files changed

+30
-16
lines changed

ext/gd/libgd/gd_interpolation.c

+4-16
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,8 @@ static int getPixelInterpolateWeight(gdImagePtr im, const double x, const double
755755
*/
756756
int getPixelInterpolated(gdImagePtr im, const double x, const double y, const int bgColor)
757757
{
758-
const int xi=(int)((x) < 0 ? x - 1: x);
759-
const int yi=(int)((y) < 0 ? y - 1: y);
758+
const int xi=(int)(x);
759+
const int yi=(int)(y);
760760
int yii;
761761
int i;
762762
double kernel, kernel_cache_y;
@@ -1702,13 +1702,6 @@ gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor)
17021702
int new_width, new_height;
17031703
gdRect bbox;
17041704

1705-
const gdFixed f_slop_y = f_sin;
1706-
const gdFixed f_slop_x = f_cos;
1707-
const gdFixed f_slop = f_slop_x > 0 && f_slop_y > 0 ?
1708-
(f_slop_x > f_slop_y ? gd_divfx(f_slop_y, f_slop_x) : gd_divfx(f_slop_x, f_slop_y))
1709-
: 0;
1710-
1711-
17121705
if (bgColor < 0) {
17131706
return NULL;
17141707
}
@@ -1734,15 +1727,10 @@ gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor)
17341727
long m = gd_fxtoi(f_m);
17351728
long n = gd_fxtoi(f_n);
17361729

1737-
if ((n <= 0) || (m <= 0) || (m >= src_h) || (n >= src_w)) {
1730+
if (m < -1 || n < -1 || m >= src_h || n >= src_w ) {
17381731
dst->tpixels[dst_offset_y][dst_offset_x++] = bgColor;
1739-
} else if ((n <= 1) || (m <= 1) || (m >= src_h - 1) || (n >= src_w - 1)) {
1740-
register int c = getPixelInterpolated(src, n, m, bgColor);
1741-
c = c | (( gdTrueColorGetAlpha(c) + ((int)(127* gd_fxtof(f_slop)))) << 24);
1742-
1743-
dst->tpixels[dst_offset_y][dst_offset_x++] = _color_blend(bgColor, c);
17441732
} else {
1745-
dst->tpixels[dst_offset_y][dst_offset_x++] = getPixelInterpolated(src, n, m, bgColor);
1733+
dst->tpixels[dst_offset_y][dst_offset_x++] = getPixelInterpolated(src, gd_fxtod(f_n), gd_fxtod(f_m), bgColor);
17461734
}
17471735
}
17481736
dst_offset_y++;

ext/gd/tests/gd223.phpt

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
libgd bug 223 (gdImageRotateGeneric() does not properly interpolate)
3+
--EXTENSIONS--
4+
gd
5+
--SKIPIF--
6+
<?php
7+
if (!GD_BUNDLED) die("skip only for bundled libgd");
8+
?>
9+
--FILE--
10+
<?php
11+
require_once __DIR__ . "/func.inc";
12+
13+
$im = imagecreatetruecolor(64, 64);
14+
for ($j = 0; $j < 64; $j++) {
15+
for ($i = 0; $i < 64; $i++) {
16+
imagesetpixel($im, $i, $j, ($i % 2 || $j % 2) ? 0x000000 : 0xffffff);
17+
}
18+
}
19+
20+
imagesetinterpolation($im, IMG_BICUBIC);
21+
$im = imagerotate($im, 45, 0xff0000);
22+
23+
test_image_equals_file(__DIR__ . "/gd223.png", $im);
24+
?>
25+
--EXPECT--
26+
The images are equal.

ext/gd/tests/gd223.png

9.49 KB
Loading

0 commit comments

Comments
 (0)