Merge branch 'PHP-8.3' into PHP-8.4

* PHP-8.3:
  Fix libgd 223: gdImageRotateGeneric() does not properly interpolate
This commit is contained in:
Christoph M. Becker 2025-01-06 20:38:18 +01:00
commit 12e4ee492b
No known key found for this signature in database
GPG key ID: D66C9593118BCCB6
4 changed files with 32 additions and 16 deletions

2
NEWS
View file

@ -10,6 +10,8 @@ PHP NEWS
transparency). (cmb) transparency). (cmb)
. Fixed bug GH-17373 (imagefttext() ignores clipping rect for palette . Fixed bug GH-17373 (imagefttext() ignores clipping rect for palette
images). (cmb) images). (cmb)
. Ported fix for libgd 223 (gdImageRotateGeneric() does not properly
interpolate). (cmb)
- Intl: - Intl:
. Fixed bug GH-11874 (intl causing segfault in docker images). (nielsdos) . Fixed bug GH-11874 (intl causing segfault in docker images). (nielsdos)

View file

@ -738,8 +738,8 @@ static int getPixelInterpolateWeight(gdImagePtr im, const double x, const double
*/ */
int getPixelInterpolated(gdImagePtr im, const double x, const double y, const int bgColor) int getPixelInterpolated(gdImagePtr im, const double x, const double y, const int bgColor)
{ {
const int xi=(int)((x) < 0 ? x - 1: x); const int xi=(int)(x);
const int yi=(int)((y) < 0 ? y - 1: y); const int yi=(int)(y);
int yii; int yii;
int i; int i;
double kernel, kernel_cache_y; double kernel, kernel_cache_y;
@ -1703,13 +1703,6 @@ gdImagePtr gdImageRotateGeneric(gdImagePtr src, const float degrees, const int b
int new_width, new_height; int new_width, new_height;
gdRect bbox; gdRect bbox;
const gdFixed f_slop_y = f_sin;
const gdFixed f_slop_x = f_cos;
const gdFixed f_slop = f_slop_x > 0 && f_slop_y > 0 ?
(f_slop_x > f_slop_y ? gd_divfx(f_slop_y, f_slop_x) : gd_divfx(f_slop_x, f_slop_y))
: 0;
if (bgColor < 0) { if (bgColor < 0) {
return NULL; return NULL;
} }
@ -1735,15 +1728,10 @@ gdImagePtr gdImageRotateGeneric(gdImagePtr src, const float degrees, const int b
long m = gd_fxtoi(f_m); long m = gd_fxtoi(f_m);
long n = gd_fxtoi(f_n); long n = gd_fxtoi(f_n);
if ((n <= 0) || (m <= 0) || (m >= src_h) || (n >= src_w)) { if (m < -1 || n < -1 || m >= src_h || n >= src_w ) {
dst->tpixels[dst_offset_y][dst_offset_x++] = bgColor; dst->tpixels[dst_offset_y][dst_offset_x++] = bgColor;
} else if ((n <= 1) || (m <= 1) || (m >= src_h - 1) || (n >= src_w - 1)) {
register int c = getPixelInterpolated(src, n, m, bgColor);
c = c | (( gdTrueColorGetAlpha(c) + ((int)(127* gd_fxtof(f_slop)))) << 24);
dst->tpixels[dst_offset_y][dst_offset_x++] = _color_blend(bgColor, c);
} else { } else {
dst->tpixels[dst_offset_y][dst_offset_x++] = getPixelInterpolated(src, n, m, bgColor); dst->tpixels[dst_offset_y][dst_offset_x++] = getPixelInterpolated(src, gd_fxtod(f_n), gd_fxtod(f_m), bgColor);
} }
} }
dst_offset_y++; dst_offset_y++;

26
ext/gd/tests/gd223.phpt Normal file
View file

@ -0,0 +1,26 @@
--TEST--
libgd bug 223 (gdImageRotateGeneric() does not properly interpolate)
--EXTENSIONS--
gd
--SKIPIF--
<?php
if (!GD_BUNDLED) die("skip only for bundled libgd");
?>
--FILE--
<?php
require_once __DIR__ . "/func.inc";
$im = imagecreatetruecolor(64, 64);
for ($j = 0; $j < 64; $j++) {
for ($i = 0; $i < 64; $i++) {
imagesetpixel($im, $i, $j, ($i % 2 || $j % 2) ? 0x000000 : 0xffffff);
}
}
imagesetinterpolation($im, IMG_BICUBIC);
$im = imagerotate($im, 45, 0xff0000);
test_image_equals_file(__DIR__ . "/gd223.png", $im);
?>
--EXPECT--
The images are equal.

BIN
ext/gd/tests/gd223.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB