Skip to content

Commit 77faf6d

Browse files
committed
Internalize gdImageScale*() and gdImageRotate*() helpers
This is basically a port of the "Small code cleanup" commit[1]. [1] <libgd/libgd@e054be7>
1 parent 2dfe927 commit 77faf6d

File tree

3 files changed

+48
-31
lines changed

3 files changed

+48
-31
lines changed

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 & 16 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,7 +1062,8 @@ 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;
@@ -1094,7 +1112,8 @@ gdImagePtr gdImageScaleTwoPass(const gdImagePtr src, const unsigned int src_widt
10941112
Integer only implementation, good to have for common usages like pre scale very large
10951113
images before using another interpolation methods for the last step.
10961114
*/
1097-
gdImagePtr gdImageScaleNearestNeighbour(gdImagePtr im, const unsigned int width, const unsigned int height)
1115+
static gdImagePtr
1116+
gdImageScaleNearestNeighbour(gdImagePtr im, const unsigned int width, const unsigned int height)
10981117
{
10991118
const unsigned long new_width = MAX(1, width);
11001119
const unsigned long new_height = MAX(1, height);
@@ -1340,7 +1359,8 @@ static gdImagePtr gdImageScaleBilinearTC(gdImagePtr im, const unsigned int new_w
13401359
return new_img;
13411360
}
13421361

1343-
gdImagePtr gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, const unsigned int new_height)
1362+
static gdImagePtr
1363+
gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, const unsigned int new_height)
13441364
{
13451365
if (im->trueColor) {
13461366
return gdImageScaleBilinearTC(im, new_width, new_height);
@@ -1349,7 +1369,8 @@ gdImagePtr gdImageScaleBilinear(gdImagePtr im, const unsigned int new_width, con
13491369
}
13501370
}
13511371

1352-
gdImagePtr gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, const unsigned int height)
1372+
static gdImagePtr
1373+
gdImageScaleBicubicFixed(gdImagePtr src, const unsigned int width, const unsigned int height)
13531374
{
13541375
const long new_width = MAX(1, width);
13551376
const long new_height = MAX(1, height);
@@ -1628,7 +1649,8 @@ static int gdRotatedImageSize(gdImagePtr src, const float angle, gdRectPtr bbox)
16281649
return GD_TRUE;
16291650
}
16301651

1631-
gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, const int bgColor)
1652+
static gdImagePtr
1653+
gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, const int bgColor)
16321654
{
16331655
float _angle = ((float) (-degrees / 180.0f) * (float)M_PI);
16341656
const int src_w = gdImageSX(src);
@@ -1685,7 +1707,8 @@ gdImagePtr gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees, co
16851707
return dst;
16861708
}
16871709

1688-
gdImagePtr gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor)
1710+
static gdImagePtr
1711+
gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor)
16891712
{
16901713
float _angle = ((float) (-degrees / 180.0f) * (float)M_PI);
16911714
const int src_w = gdImageSX(src);
@@ -1751,7 +1774,8 @@ gdImagePtr gdImageRotateGeneric(gdImagePtr src, const float degrees, const int b
17511774
return dst;
17521775
}
17531776

1754-
gdImagePtr gdImageRotateBilinear(gdImagePtr src, const float degrees, const int bgColor)
1777+
static gdImagePtr
1778+
gdImageRotateBilinear(gdImagePtr src, const float degrees, const int bgColor)
17551779
{
17561780
float _angle = (float)((- degrees / 180.0f) * M_PI);
17571781
const unsigned int src_w = gdImageSX(src);
@@ -1866,7 +1890,8 @@ gdImagePtr gdImageRotateBilinear(gdImagePtr src, const float degrees, const int
18661890
return dst;
18671891
}
18681892

1869-
gdImagePtr gdImageRotateBicubicFixed(gdImagePtr src, const float degrees, const int bgColor)
1893+
static gdImagePtr
1894+
gdImageRotateBicubicFixed(gdImagePtr src, const float degrees, const int bgColor)
18701895
{
18711896
const float _angle = (float)((- degrees / 180.0f) * M_PI);
18721897
const int src_w = gdImageSX(src);

0 commit comments

Comments
 (0)