Skip to content

Commit f55d6cc

Browse files
committed
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] <libgd/libgd@e054be7> [2] <https://bugs.php.net/72337> [3] <libgd/libgd@77309c4>
1 parent 11d701a commit f55d6cc

File tree

4 files changed

+52
-55
lines changed

4 files changed

+52
-55
lines changed

UPGRADING.INTERNALS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ PHP 8.5 INTERNALS UPGRADE NOTES
2222
3. Module changes
2323
========================
2424

25+
- ext/gd
26+
. The gdImageScale*() and gdImageRotate*() helpers are now internal in the
27+
bundled libgd, like they have been in external libgd as of gd-2.1.1.
28+
2529
- ext/libxml
2630
. The refcount APIs now return an `unsigned int` instead of an `int`.
2731

ext/gd/libgd/gd.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -718,11 +718,6 @@ void gdImageCopyResized(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int
718718
substituted automatically. */
719719
void gdImageCopyResampled(gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH);
720720

721-
gdImagePtr gdImageRotate90(gdImagePtr src, int ignoretransparent);
722-
gdImagePtr gdImageRotate180(gdImagePtr src, int ignoretransparent);
723-
gdImagePtr gdImageRotate270(gdImagePtr src, int ignoretransparent);
724-
gdImagePtr gdImageRotateInterpolated(const gdImagePtr src, const float angle, int bgcolor);
725-
726721
gdImagePtr gdImageClone(gdImagePtr src);
727722

728723
void gdImageSetBrush(gdImagePtr im, gdImagePtr brush);
@@ -882,17 +877,8 @@ gdImagePtr gdImageCropThreshold(gdImagePtr im, const unsigned int color, const f
882877
int gdImageSetInterpolationMethod(gdImagePtr im, gdInterpolationMethod id);
883878
gdInterpolationMethod gdImageGetInterpolationMethod(gdImagePtr im);
884879

885-
gdImagePtr gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, const unsigned int new_height);
886-
gdImagePtr gdImageScaleBicubic(gdImagePtr src_img, const unsigned int new_width, const unsigned int new_height);
887-
gdImagePtr gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, const unsigned int height);
888-
gdImagePtr gdImageScaleNearestNeighbour(gdImagePtr im, const unsigned int width, const unsigned int height);
889-
gdImagePtr gdImageScaleTwoPass(const gdImagePtr pOrigImage, const unsigned int uOrigWidth, const unsigned int uOrigHeight, const unsigned int uNewWidth, const unsigned int uNewHeight);
890880
gdImagePtr gdImageScale(const gdImagePtr src, const unsigned int new_width, const unsigned int new_height);
891881

892-
gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, const int bgColor);
893-
gdImagePtr gdImageRotateBilinear(gdImagePtr src, const float degrees, const int bgColor);
894-
gdImagePtr gdImageRotateBicubicFixed(gdImagePtr src, const float degrees, const int bgColor);
895-
gdImagePtr gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor);
896882
gdImagePtr gdImageRotateInterpolated(const gdImagePtr src, const float angle, int bgcolor);
897883

898884
typedef enum {

ext/gd/libgd/gd_intern.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@
1010
#define MAX3(a,b,c) ((a)<(b)?(MAX(b,c)):(MAX(a,c)))
1111
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
1212

13-
#endif
13+
/* Internal prototypes: */
14+
15+
/* gd_rotate.c */
16+
gdImagePtr gdImageRotate90(gdImagePtr src, int ignoretransparent);
17+
gdImagePtr gdImageRotate180(gdImagePtr src, int ignoretransparent);
18+
gdImagePtr gdImageRotate270(gdImagePtr src, int ignoretransparent);
1419

20+
#endif

ext/gd/libgd/gd_interpolation.c

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,31 @@
6767
# include <emmintrin.h>
6868
#endif
6969

70-
#ifndef MIN
71-
#define MIN(a,b) ((a)<(b)?(a):(b))
72-
#endif
73-
#define MIN3(a,b,c) ((a)<(b)?(MIN(a,c)):(MIN(b,c)))
74-
#ifndef MAX
75-
#define MAX(a,b) ((a)<(b)?(b):(a))
76-
#endif
77-
#define MAX3(a,b,c) ((a)<(b)?(MAX(b,c)):(MAX(a,c)))
70+
static gdImagePtr gdImageScaleBilinear(gdImagePtr im,
71+
const unsigned int new_width,
72+
const unsigned int new_height);
73+
static gdImagePtr gdImageScaleBicubicFixed(gdImagePtr src,
74+
const unsigned int width,
75+
const unsigned int height);
76+
static gdImagePtr gdImageScaleNearestNeighbour(gdImagePtr im,
77+
const unsigned int width, const unsigned int height);
78+
static gdImagePtr gdImageScaleTwoPass(const gdImagePtr pOrigImage,
79+
const unsigned int uOrigWidth,
80+
const unsigned int uOrigHeight,
81+
const unsigned int uNewWidth,
82+
const unsigned int uNewHeight);
83+
static gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src,
84+
const float degrees,
85+
const int bgColor);
86+
static gdImagePtr gdImageRotateBilinear(gdImagePtr src,
87+
const float degrees,
88+
const int bgColor);
89+
static gdImagePtr gdImageRotateBicubicFixed(gdImagePtr src,
90+
const float degrees,
91+
const int bgColor);
92+
static gdImagePtr gdImageRotateGeneric(gdImagePtr src,
93+
const float degrees,
94+
const int bgColor);
7895

7996
/* only used here, let do a generic fixed point integers later if required by other
8097
part of GD */
@@ -1045,16 +1062,13 @@ static inline int _gdScaleVert (const gdImagePtr pSrc, const unsigned int src_wi
10451062
return 1;
10461063
}
10471064

1048-
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)
1065+
static gdImagePtr
1066+
gdImageScaleTwoPass(const gdImagePtr src, const unsigned int src_width, const unsigned int src_height, const unsigned int new_width, const unsigned int new_height)
10491067
{
10501068
gdImagePtr tmp_im;
10511069
gdImagePtr dst;
10521070
int scale_pass_res;
10531071

1054-
if (new_width == 0 || new_height == 0) {
1055-
return NULL;
1056-
}
1057-
10581072
/* Convert to truecolor if it isn't; this code requires it. */
10591073
if (!src->trueColor) {
10601074
gdImagePaletteToTrueColor(src);
@@ -1094,7 +1108,8 @@ gdImagePtr gdImageScaleTwoPass(const gdImagePtr src, const unsigned int src_widt
10941108
Integer only implementation, good to have for common usages like pre scale very large
10951109
images before using another interpolation methods for the last step.
10961110
*/
1097-
gdImagePtr gdImageScaleNearestNeighbour(gdImagePtr im, const unsigned int width, const unsigned int height)
1111+
static gdImagePtr
1112+
gdImageScaleNearestNeighbour(gdImagePtr im, const unsigned int width, const unsigned int height)
10981113
{
10991114
const unsigned long new_width = MAX(1, width);
11001115
const unsigned long new_height = MAX(1, height);
@@ -1108,10 +1123,6 @@ gdImagePtr gdImageScaleNearestNeighbour(gdImagePtr im, const unsigned int width,
11081123
unsigned long dst_offset_y = 0;
11091124
unsigned int i;
11101125

1111-
if (new_width == 0 || new_height == 0) {
1112-
return NULL;
1113-
}
1114-
11151126
dst_img = gdImageCreateTrueColor(new_width, new_height);
11161127

11171128
if (dst_img == NULL) {
@@ -1165,10 +1176,6 @@ static gdImagePtr gdImageScaleBilinearPalette(gdImagePtr im, const unsigned int
11651176
gdImagePtr new_img;
11661177
const int transparent = im->transparent;
11671178

1168-
if (new_width == 0 || new_height == 0) {
1169-
return NULL;
1170-
}
1171-
11721179
new_img = gdImageCreateTrueColor(new_width, new_height);
11731180
if (new_img == NULL) {
11741181
return NULL;
@@ -1266,10 +1273,6 @@ static gdImagePtr gdImageScaleBilinearTC(gdImagePtr im, const unsigned int new_w
12661273
long i;
12671274
gdImagePtr new_img;
12681275

1269-
if (new_width == 0 || new_height == 0) {
1270-
return NULL;
1271-
}
1272-
12731276
new_img = gdImageCreateTrueColor(new_width, new_height);
12741277
if (!new_img){
12751278
return NULL;
@@ -1340,7 +1343,8 @@ static gdImagePtr gdImageScaleBilinearTC(gdImagePtr im, const unsigned int new_w
13401343
return new_img;
13411344
}
13421345

1343-
gdImagePtr gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, const unsigned int new_height)
1346+
static gdImagePtr
1347+
gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, const unsigned int new_height)
13441348
{
13451349
if (im->trueColor) {
13461350
return gdImageScaleBilinearTC(im, new_width, new_height);
@@ -1349,7 +1353,8 @@ gdImagePtr gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, con
13491353
}
13501354
}
13511355

1352-
gdImagePtr gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, const unsigned int height)
1356+
static gdImagePtr
1357+
gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, const unsigned int height)
13531358
{
13541359
const long new_width = MAX(1, width);
13551360
const long new_height = MAX(1, height);
@@ -1368,10 +1373,6 @@ gdImagePtr gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, co
13681373
unsigned int dst_offset_y = 0;
13691374
long i;
13701375

1371-
if (new_width == 0 || new_height == 0) {
1372-
return NULL;
1373-
}
1374-
13751376
/* impact perf a bit, but not that much. Implementation for palette
13761377
images can be done at a later point.
13771378
*/
@@ -1628,7 +1629,8 @@ static int gdRotatedImageSize(gdImagePtr src, const float angle, gdRectPtr bbox)
16281629
return GD_TRUE;
16291630
}
16301631

1631-
gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, const int bgColor)
1632+
static gdImagePtr
1633+
gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, const int bgColor)
16321634
{
16331635
float _angle = ((float) (-degrees / 180.0f) * (float)M_PI);
16341636
const int src_w = gdImageSX(src);
@@ -1650,10 +1652,6 @@ gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, co
16501652
new_width = bbox.width;
16511653
new_height = bbox.height;
16521654

1653-
if (new_width == 0 || new_height == 0) {
1654-
return NULL;
1655-
}
1656-
16571655
dst = gdImageCreateTrueColor(new_width, new_height);
16581656
if (!dst) {
16591657
return NULL;
@@ -1685,7 +1683,8 @@ gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, co
16851683
return dst;
16861684
}
16871685

1688-
gdImagePtr gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor)
1686+
static gdImagePtr
1687+
gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor)
16891688
{
16901689
float _angle = ((float) (-degrees / 180.0f) * (float)M_PI);
16911690
const int src_w = gdImageSX(src);
@@ -1751,7 +1750,8 @@ gdImagePtr gdImageRotateGeneric(gdImagePtr src, const float degrees, const int b
17511750
return dst;
17521751
}
17531752

1754-
gdImagePtr gdImageRotateBilinear(gdImagePtr src, const float degrees, const int bgColor)
1753+
static gdImagePtr
1754+
gdImageRotateBilinear(gdImagePtr src, const float degrees, const int bgColor)
17551755
{
17561756
float _angle = (float)((- degrees / 180.0f) * M_PI);
17571757
const unsigned int src_w = gdImageSX(src);
@@ -1866,7 +1866,8 @@ gdImagePtr gdImageRotateBilinear(gdImagePtr src, const float degrees, const int
18661866
return dst;
18671867
}
18681868

1869-
gdImagePtr gdImageRotateBicubicFixed(gdImagePtr src, const float degrees, const int bgColor)
1869+
static gdImagePtr
1870+
gdImageRotateBicubicFixed(gdImagePtr src, const float degrees, const int bgColor)
18701871
{
18711872
const float _angle = (float)((- degrees / 180.0f) * M_PI);
18721873
const int src_w = gdImageSX(src);

0 commit comments

Comments
 (0)