Skip to content

Commit 307565d

Browse files
committed
ext/gd: porting gdImageClone to the bundled libgd version.
close GH-15640
1 parent eb89233 commit 307565d

File tree

3 files changed

+89
-0
lines changed

3 files changed

+89
-0
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ PHP NEWS
99
. Fixed bug GH-13988 (Storing DOMElement consume 4 times more memory in
1010
PHP 8.1 than in PHP 8.0). (nielsdos)
1111

12+
- GD:
13+
. Added gdImageClone to bundled libgd. (David Carlier)
14+
1215
27 Aug 2024, PHP 8.4.0beta4
1316

1417
- Core:

ext/gd/libgd/gd.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,90 @@ void gdImageAABlend (gdImagePtr im)
968968

969969
static void _gdImageFilledHRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color);
970970

971+
gdImagePtr gdImageClone (gdImagePtr src) {
972+
gdImagePtr dst;
973+
register int i, x;
974+
975+
if (src->trueColor) {
976+
dst = gdImageCreateTrueColor(src->sx , src->sy);
977+
} else {
978+
dst = gdImageCreate(src->sx , src->sy);
979+
}
980+
981+
if (dst == NULL) {
982+
return NULL;
983+
}
984+
985+
if (src->trueColor == 0) {
986+
dst->colorsTotal = src->colorsTotal;
987+
for (i = 0; i < gdMaxColors; i++) {
988+
dst->red[i] = src->red[i];
989+
dst->green[i] = src->green[i];
990+
dst->blue[i] = src->blue[i];
991+
dst->alpha[i] = src->alpha[i];
992+
dst->open[i] = src->open[i];
993+
}
994+
for (i = 0; i < src->sy; i++) {
995+
for (x = 0; x < src->sx; x++) {
996+
dst->pixels[i][x] = src->pixels[i][x];
997+
}
998+
}
999+
} else {
1000+
for (i = 0; i < src->sy; i++) {
1001+
for (x = 0; x < src->sx; x++) {
1002+
dst->tpixels[i][x] = src->tpixels[i][x];
1003+
}
1004+
}
1005+
}
1006+
1007+
dst->interlace = src->interlace;
1008+
1009+
dst->alphaBlendingFlag = src->alphaBlendingFlag;
1010+
dst->saveAlphaFlag = src->saveAlphaFlag;
1011+
dst->AA = src->AA;
1012+
dst->AA_color = src->AA_color;
1013+
dst->AA_dont_blend = src->AA_dont_blend;
1014+
1015+
dst->cx1 = src->cx1;
1016+
dst->cy1 = src->cy1;
1017+
dst->cx2 = src->cx2;
1018+
dst->cy2 = src->cy2;
1019+
1020+
dst->res_x = src->res_x;
1021+
dst->res_y = src->res_y;
1022+
1023+
dst->interpolation_id = src->interpolation_id;
1024+
dst->interpolation = src->interpolation;
1025+
1026+
if (src->brush) {
1027+
dst->brush = gdImageClone(src->brush);
1028+
}
1029+
1030+
if (src->tile) {
1031+
dst->tile = gdImageClone(src->tile);
1032+
}
1033+
1034+
if (src->style) {
1035+
gdImageSetStyle(dst, src->style, src->styleLength);
1036+
dst->stylePos = src->stylePos;
1037+
}
1038+
1039+
for (i = 0; i < gdMaxColors; i++) {
1040+
dst->brushColorMap[i] = src->brushColorMap[i];
1041+
dst->tileColorMap[i] = src->tileColorMap[i];
1042+
}
1043+
1044+
if (src->polyAllocated > 0 && overflow2(sizeof(int), src->polyAllocated) == 0) {
1045+
dst->polyInts = gdMalloc (sizeof (int) * src->polyAllocated);
1046+
dst->polyAllocated = src->polyAllocated;
1047+
for (i = 0; i < src->polyAllocated; i++) {
1048+
dst->polyInts[i] = src->polyInts[i];
1049+
}
1050+
}
1051+
1052+
return dst;
1053+
}
1054+
9711055
static void gdImageHLine(gdImagePtr im, int y, int x1, int x2, int col)
9721056
{
9731057
if (im->thick > 1) {

ext/gd/libgd/gd.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,8 @@ gdImagePtr gdImageRotate180(gdImagePtr src, int ignoretransparent);
723723
gdImagePtr gdImageRotate270(gdImagePtr src, int ignoretransparent);
724724
gdImagePtr gdImageRotateInterpolated(const gdImagePtr src, const float angle, int bgcolor);
725725

726+
gdImagePtr gdImageClone(gdImagePtr src);
727+
726728
void gdImageSetBrush(gdImagePtr im, gdImagePtr brush);
727729
void gdImageSetTile(gdImagePtr im, gdImagePtr tile);
728730
void gdImageSetAntiAliased(gdImagePtr im, int c);

0 commit comments

Comments
 (0)