ext/gd: porting gdImageClone to the bundled libgd version.

close GH-15640
This commit is contained in:
David Carlier 2024-08-29 19:33:11 +01:00
parent eb89233800
commit 307565d577
No known key found for this signature in database
GPG Key ID: 8486F847B4B94EF1
3 changed files with 89 additions and 0 deletions

3
NEWS
View File

@ -9,6 +9,9 @@ PHP NEWS
. Fixed bug GH-13988 (Storing DOMElement consume 4 times more memory in
PHP 8.1 than in PHP 8.0). (nielsdos)
- GD:
. Added gdImageClone to bundled libgd. (David Carlier)
27 Aug 2024, PHP 8.4.0beta4
- Core:

View File

@ -968,6 +968,90 @@ void gdImageAABlend (gdImagePtr im)
static void _gdImageFilledHRectangle (gdImagePtr im, int x1, int y1, int x2, int y2, int color);
gdImagePtr gdImageClone (gdImagePtr src) {
gdImagePtr dst;
register int i, x;
if (src->trueColor) {
dst = gdImageCreateTrueColor(src->sx , src->sy);
} else {
dst = gdImageCreate(src->sx , src->sy);
}
if (dst == NULL) {
return NULL;
}
if (src->trueColor == 0) {
dst->colorsTotal = src->colorsTotal;
for (i = 0; i < gdMaxColors; i++) {
dst->red[i] = src->red[i];
dst->green[i] = src->green[i];
dst->blue[i] = src->blue[i];
dst->alpha[i] = src->alpha[i];
dst->open[i] = src->open[i];
}
for (i = 0; i < src->sy; i++) {
for (x = 0; x < src->sx; x++) {
dst->pixels[i][x] = src->pixels[i][x];
}
}
} else {
for (i = 0; i < src->sy; i++) {
for (x = 0; x < src->sx; x++) {
dst->tpixels[i][x] = src->tpixels[i][x];
}
}
}
dst->interlace = src->interlace;
dst->alphaBlendingFlag = src->alphaBlendingFlag;
dst->saveAlphaFlag = src->saveAlphaFlag;
dst->AA = src->AA;
dst->AA_color = src->AA_color;
dst->AA_dont_blend = src->AA_dont_blend;
dst->cx1 = src->cx1;
dst->cy1 = src->cy1;
dst->cx2 = src->cx2;
dst->cy2 = src->cy2;
dst->res_x = src->res_x;
dst->res_y = src->res_y;
dst->interpolation_id = src->interpolation_id;
dst->interpolation = src->interpolation;
if (src->brush) {
dst->brush = gdImageClone(src->brush);
}
if (src->tile) {
dst->tile = gdImageClone(src->tile);
}
if (src->style) {
gdImageSetStyle(dst, src->style, src->styleLength);
dst->stylePos = src->stylePos;
}
for (i = 0; i < gdMaxColors; i++) {
dst->brushColorMap[i] = src->brushColorMap[i];
dst->tileColorMap[i] = src->tileColorMap[i];
}
if (src->polyAllocated > 0 && overflow2(sizeof(int), src->polyAllocated) == 0) {
dst->polyInts = gdMalloc (sizeof (int) * src->polyAllocated);
dst->polyAllocated = src->polyAllocated;
for (i = 0; i < src->polyAllocated; i++) {
dst->polyInts[i] = src->polyInts[i];
}
}
return dst;
}
static void gdImageHLine(gdImagePtr im, int y, int x1, int x2, int col)
{
if (im->thick > 1) {

View File

@ -723,6 +723,8 @@ 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);
void gdImageSetTile(gdImagePtr im, gdImagePtr tile);
void gdImageSetAntiAliased(gdImagePtr im, int c);