Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions ext/gd/libgd/gd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions ext/gd/libgd/gd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading