Internalize gdImageScale*() and gdImageRotate*() helpers

This is basically a port of the "Small code cleanup" commit[1].

We can now drop the superfluous checks for zero width/height.  These
have been introduced as fix for bug 72337[2], while the same issue had
a simpler fix for upstream[3], because the helper functions already
were internal.

[1] <e054be7d82>
[2] <https://bugs.php.net/72337>
[3] <77309c419c>
This commit is contained in:
Christoph M. Becker 2025-01-03 12:10:32 +01:00
parent 11d701a6ab
commit f55d6cc110
No known key found for this signature in database
GPG key ID: D66C9593118BCCB6
4 changed files with 52 additions and 55 deletions

View file

@ -22,6 +22,10 @@ PHP 8.5 INTERNALS UPGRADE NOTES
3. Module changes
========================
- ext/gd
. The gdImageScale*() and gdImageRotate*() helpers are now internal in the
bundled libgd, like they have been in external libgd as of gd-2.1.1.
- ext/libxml
. The refcount APIs now return an `unsigned int` instead of an `int`.

View file

@ -718,11 +718,6 @@ void gdImageCopyResized(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int
substituted automatically. */
void gdImageCopyResampled(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH);
gdImagePtr gdImageRotate90(gdImagePtr src, int ignoretransparent);
gdImagePtr gdImageRotate180(gdImagePtr src, int ignoretransparent);
gdImagePtr gdImageRotate270(gdImagePtr src, int ignoretransparent);
gdImagePtr gdImageRotateInterpolated(const gdImagePtr src, const float angle, int bgcolor);
gdImagePtr gdImageClone(gdImagePtr src);
void gdImageSetBrush(gdImagePtr im, gdImagePtr brush);
@ -882,17 +877,8 @@ gdImagePtr gdImageCropThreshold(gdImagePtr im, const unsigned int color, const f
int gdImageSetInterpolationMethod(gdImagePtr im, gdInterpolationMethod id);
gdInterpolationMethod gdImageGetInterpolationMethod(gdImagePtr im);
gdImagePtr gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, const unsigned int new_height);
gdImagePtr gdImageScaleBicubic(gdImagePtr src_img, const unsigned int new_width, const unsigned int new_height);
gdImagePtr gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, const unsigned int height);
gdImagePtr gdImageScaleNearestNeighbour(gdImagePtr im, const unsigned int width, const unsigned int height);
gdImagePtr gdImageScaleTwoPass(const gdImagePtr pOrigImage, const unsigned int uOrigWidth, const unsigned int uOrigHeight, const unsigned int uNewWidth, const unsigned int uNewHeight);
gdImagePtr gdImageScale(const gdImagePtr src, const unsigned int new_width, const unsigned int new_height);
gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, const int bgColor);
gdImagePtr gdImageRotateBilinear(gdImagePtr src, const float degrees, const int bgColor);
gdImagePtr gdImageRotateBicubicFixed(gdImagePtr src, const float degrees, const int bgColor);
gdImagePtr gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor);
gdImagePtr gdImageRotateInterpolated(const gdImagePtr src, const float angle, int bgcolor);
typedef enum {

View file

@ -10,5 +10,11 @@
#define MAX3(a,b,c) ((a)<(b)?(MAX(b,c)):(MAX(a,c)))
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
#endif
/* Internal prototypes: */
/* gd_rotate.c */
gdImagePtr gdImageRotate90(gdImagePtr src, int ignoretransparent);
gdImagePtr gdImageRotate180(gdImagePtr src, int ignoretransparent);
gdImagePtr gdImageRotate270(gdImagePtr src, int ignoretransparent);
#endif

View file

@ -67,14 +67,31 @@ TODO:
# include <emmintrin.h>
#endif
#ifndef MIN
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
#define MIN3(a,b,c) ((a)<(b)?(MIN(a,c)):(MIN(b,c)))
#ifndef MAX
#define MAX(a,b) ((a)<(b)?(b):(a))
#endif
#define MAX3(a,b,c) ((a)<(b)?(MAX(b,c)):(MAX(a,c)))
static gdImagePtr gdImageScaleBilinear(gdImagePtr im,
const unsigned int new_width,
const unsigned int new_height);
static gdImagePtr gdImageScaleBicubicFixed(gdImagePtr src,
const unsigned int width,
const unsigned int height);
static gdImagePtr gdImageScaleNearestNeighbour(gdImagePtr im,
const unsigned int width, const unsigned int height);
static gdImagePtr gdImageScaleTwoPass(const gdImagePtr pOrigImage,
const unsigned int uOrigWidth,
const unsigned int uOrigHeight,
const unsigned int uNewWidth,
const unsigned int uNewHeight);
static gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src,
const float degrees,
const int bgColor);
static gdImagePtr gdImageRotateBilinear(gdImagePtr src,
const float degrees,
const int bgColor);
static gdImagePtr gdImageRotateBicubicFixed(gdImagePtr src,
const float degrees,
const int bgColor);
static gdImagePtr gdImageRotateGeneric(gdImagePtr src,
const float degrees,
const int bgColor);
/* only used here, let do a generic fixed point integers later if required by other
part of GD */
@ -1045,16 +1062,13 @@ static inline int _gdScaleVert (const gdImagePtr pSrc, const unsigned int src_wi
return 1;
}
gdImagePtr gdImageScaleTwoPass(const gdImagePtr src, const unsigned int src_width, const unsigned int src_height, const unsigned int new_width, const unsigned int new_height)
static gdImagePtr
gdImageScaleTwoPass(const gdImagePtr src, const unsigned int src_width, const unsigned int src_height, const unsigned int new_width, const unsigned int new_height)
{
gdImagePtr tmp_im;
gdImagePtr dst;
int scale_pass_res;
if (new_width == 0 || new_height == 0) {
return NULL;
}
/* Convert to truecolor if it isn't; this code requires it. */
if (!src->trueColor) {
gdImagePaletteToTrueColor(src);
@ -1094,7 +1108,8 @@ gdImagePtr gdImageScaleTwoPass(const gdImagePtr src, const unsigned int src_widt
Integer only implementation, good to have for common usages like pre scale very large
images before using another interpolation methods for the last step.
*/
gdImagePtr gdImageScaleNearestNeighbour(gdImagePtr im, const unsigned int width, const unsigned int height)
static gdImagePtr
gdImageScaleNearestNeighbour(gdImagePtr im, const unsigned int width, const unsigned int height)
{
const unsigned long new_width = MAX(1, width);
const unsigned long new_height = MAX(1, height);
@ -1108,10 +1123,6 @@ gdImagePtr gdImageScaleNearestNeighbour(gdImagePtr im, const unsigned int width,
unsigned long dst_offset_y = 0;
unsigned int i;
if (new_width == 0 || new_height == 0) {
return NULL;
}
dst_img = gdImageCreateTrueColor(new_width, new_height);
if (dst_img == NULL) {
@ -1165,10 +1176,6 @@ static gdImagePtr gdImageScaleBilinearPalette(gdImagePtr im, const unsigned int
gdImagePtr new_img;
const int transparent = im->transparent;
if (new_width == 0 || new_height == 0) {
return NULL;
}
new_img = gdImageCreateTrueColor(new_width, new_height);
if (new_img == NULL) {
return NULL;
@ -1266,10 +1273,6 @@ static gdImagePtr gdImageScaleBilinearTC(gdImagePtr im, const unsigned int new_w
long i;
gdImagePtr new_img;
if (new_width == 0 || new_height == 0) {
return NULL;
}
new_img = gdImageCreateTrueColor(new_width, new_height);
if (!new_img){
return NULL;
@ -1340,7 +1343,8 @@ static gdImagePtr gdImageScaleBilinearTC(gdImagePtr im, const unsigned int new_w
return new_img;
}
gdImagePtr gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, const unsigned int new_height)
static gdImagePtr
gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, const unsigned int new_height)
{
if (im->trueColor) {
return gdImageScaleBilinearTC(im, new_width, new_height);
@ -1349,7 +1353,8 @@ gdImagePtr gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, con
}
}
gdImagePtr gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, const unsigned int height)
static gdImagePtr
gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, const unsigned int height)
{
const long new_width = MAX(1, width);
const long new_height = MAX(1, height);
@ -1368,10 +1373,6 @@ gdImagePtr gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, co
unsigned int dst_offset_y = 0;
long i;
if (new_width == 0 || new_height == 0) {
return NULL;
}
/* impact perf a bit, but not that much. Implementation for palette
images can be done at a later point.
*/
@ -1628,7 +1629,8 @@ static int gdRotatedImageSize(gdImagePtr src, const float angle, gdRectPtr bbox)
return GD_TRUE;
}
gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, const int bgColor)
static gdImagePtr
gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, const int bgColor)
{
float _angle = ((float) (-degrees / 180.0f) * (float)M_PI);
const int src_w = gdImageSX(src);
@ -1650,10 +1652,6 @@ gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, co
new_width = bbox.width;
new_height = bbox.height;
if (new_width == 0 || new_height == 0) {
return NULL;
}
dst = gdImageCreateTrueColor(new_width, new_height);
if (!dst) {
return NULL;
@ -1685,7 +1683,8 @@ gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, co
return dst;
}
gdImagePtr gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor)
static gdImagePtr
gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor)
{
float _angle = ((float) (-degrees / 180.0f) * (float)M_PI);
const int src_w = gdImageSX(src);
@ -1751,7 +1750,8 @@ gdImagePtr gdImageRotateGeneric(gdImagePtr src, const float degrees, const int b
return dst;
}
gdImagePtr gdImageRotateBilinear(gdImagePtr src, const float degrees, const int bgColor)
static gdImagePtr
gdImageRotateBilinear(gdImagePtr src, const float degrees, const int bgColor)
{
float _angle = (float)((- degrees / 180.0f) * M_PI);
const unsigned int src_w = gdImageSX(src);
@ -1866,7 +1866,8 @@ gdImagePtr gdImageRotateBilinear(gdImagePtr src, const float degrees, const int
return dst;
}
gdImagePtr gdImageRotateBicubicFixed(gdImagePtr src, const float degrees, const int bgColor)
static gdImagePtr
gdImageRotateBicubicFixed(gdImagePtr src, const float degrees, const int bgColor)
{
const float _angle = (float)((- degrees / 180.0f) * M_PI);
const int src_w = gdImageSX(src);