diff --git a/src/gd.c b/src/gd.c index 4547936..c3a09d2 100644 --- a/src/gd.c +++ b/src/gd.c @@ -2258,6 +2258,101 @@ BGD_DECLARE(void) gdImageFilledRectangle (gdImagePtr im, int x1, int y1, int x2, } } +BGD_DECLARE(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[gdMaxColors] = src->red[gdMaxColors]; + dst->green[gdMaxColors] = src->green[gdMaxColors]; + dst->blue[gdMaxColors] = src->blue[gdMaxColors]; + dst->alpha[gdMaxColors] = src->alpha[gdMaxColors]; + dst->open[gdMaxColors] = src->open[gdMaxColors]; + } + for (i = 0; i < src->sy; i++) { + for (x = 0; x < src->sx; x++) { + dst->pixels[i][x] = dst->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]; + } + } + } + + if (src->styleLength > 0) { + dst->styleLength = src->styleLength; + dst->stylePos = src->stylePos; + for (i = 0; i < src->styleLength; i++) { + dst->style[i] = src->style[i]; + } + } + + 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_x; + + dst->paletteQuantizationMethod = src->paletteQuantizationMethod; + dst->paletteQuantizationSpeed = src->paletteQuantizationSpeed; + dst->paletteQuantizationMinQuality = src->paletteQuantizationMinQuality; + dst->paletteQuantizationMinQuality = src->paletteQuantizationMinQuality; + + 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); + } + + for (i = 0; i < gdMaxColors; i++) { + dst->brushColorMap[i] = src->brushColorMap[i]; + dst->tileColorMap[i] = src->tileColorMap[i]; + } + + if (src->polyAllocated > 0) { + dst->polyAllocated = src->polyAllocated; + for (i = 0; i < src->polyAllocated; i++) { + dst->polyInts[i] = src->polyInts[i]; + } + } + + return dst; +} + BGD_DECLARE(void) gdImageCopy (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX, int srcY, int w, int h) { diff --git a/src/gd.h b/src/gd.h index 69c38eb..7bcbabb 100644 --- a/src/gd.h +++ b/src/gd.h @@ -889,6 +889,8 @@ BGD_DECLARE(void) gdImageCopyRotated (gdImagePtr dst, int srcX, int srcY, int srcWidth, int srcHeight, int angle); +BGD_DECLARE(gdImagePtr) gdImageClone (gdImagePtr src); + BGD_DECLARE(void) gdImageSetBrush (gdImagePtr im, gdImagePtr brush); BGD_DECLARE(void) gdImageSetTile (gdImagePtr im, gdImagePtr tile); BGD_DECLARE(void) gdImageSetAntiAliased (gdImagePtr im, int c); diff --git a/src/gd_interpolation.c b/src/gd_interpolation.c index 8bb9ae1..de5b95e 100644 --- a/src/gd_interpolation.c +++ b/src/gd_interpolation.c @@ -2199,6 +2199,19 @@ BGD_DECLARE(gdImagePtr) gdImageRotateInterpolated(const gdImagePtr src, const fl /* no interpolation needed here */ switch (angle_rounded) { + + case 0: { + gdImagePtr dst = gdImageClone(src); + + if (dst == NULL) { + return NULL; + } + if (dst->trueColor == 0) { + gdImagePaletteToTrueColor(dst); + } + return dst; + } + case 9000: return gdImageRotate90(src, 0); case 18000: diff --git a/tests/gdimagerotate/bug00067.c b/tests/gdimagerotate/bug00067.c index 5d24172..24328a8 100644 --- a/tests/gdimagerotate/bug00067.c +++ b/tests/gdimagerotate/bug00067.c @@ -46,7 +46,7 @@ int main() exp = gdImageRotateInterpolated(im, angle, color); if (!exp) { - gdTestErrorMsg("rotating image failed.\n"); + gdTestErrorMsg("rotating image failed for %03d.\n", angle); gdImageDestroy(im); return 1; } diff --git a/tests/gdimagerotate/bug00067_000_exp.png b/tests/gdimagerotate/bug00067_000_exp.png index cb87846..d06b5fe 100644 Binary files a/tests/gdimagerotate/bug00067_000_exp.png and b/tests/gdimagerotate/bug00067_000_exp.png differ diff --git a/tests/gdimagerotate/bug00067_015_exp.png b/tests/gdimagerotate/bug00067_015_exp.png index c0b9b6e..a0f8ce2 100644 Binary files a/tests/gdimagerotate/bug00067_015_exp.png and b/tests/gdimagerotate/bug00067_015_exp.png differ diff --git a/tests/gdimagerotate/bug00067_030_exp.png b/tests/gdimagerotate/bug00067_030_exp.png index cdab559..aad7f4c 100644 Binary files a/tests/gdimagerotate/bug00067_030_exp.png and b/tests/gdimagerotate/bug00067_030_exp.png differ diff --git a/tests/gdimagerotate/bug00067_045_exp.png b/tests/gdimagerotate/bug00067_045_exp.png index 3747b5f..75916a5 100644 Binary files a/tests/gdimagerotate/bug00067_045_exp.png and b/tests/gdimagerotate/bug00067_045_exp.png differ diff --git a/tests/gdimagerotate/bug00067_060_exp.png b/tests/gdimagerotate/bug00067_060_exp.png index 178c202..f24364a 100644 Binary files a/tests/gdimagerotate/bug00067_060_exp.png and b/tests/gdimagerotate/bug00067_060_exp.png differ diff --git a/tests/gdimagerotate/bug00067_075_exp.png b/tests/gdimagerotate/bug00067_075_exp.png index 91b4eba..f8dcf44 100644 Binary files a/tests/gdimagerotate/bug00067_075_exp.png and b/tests/gdimagerotate/bug00067_075_exp.png differ diff --git a/tests/gdimagerotate/bug00067_105_exp.png b/tests/gdimagerotate/bug00067_105_exp.png index a6deb1d..2cf641d 100644 Binary files a/tests/gdimagerotate/bug00067_105_exp.png and b/tests/gdimagerotate/bug00067_105_exp.png differ diff --git a/tests/gdimagerotate/bug00067_120_exp.png b/tests/gdimagerotate/bug00067_120_exp.png index a4d07f1..1890f92 100644 Binary files a/tests/gdimagerotate/bug00067_120_exp.png and b/tests/gdimagerotate/bug00067_120_exp.png differ diff --git a/tests/gdimagerotate/bug00067_135_exp.png b/tests/gdimagerotate/bug00067_135_exp.png index 9fbf1d3..34ccb0a 100644 Binary files a/tests/gdimagerotate/bug00067_135_exp.png and b/tests/gdimagerotate/bug00067_135_exp.png differ diff --git a/tests/gdimagerotate/bug00067_150_exp.png b/tests/gdimagerotate/bug00067_150_exp.png index 6283143..330d030 100644 Binary files a/tests/gdimagerotate/bug00067_150_exp.png and b/tests/gdimagerotate/bug00067_150_exp.png differ diff --git a/tests/gdimagerotate/bug00067_165_exp.png b/tests/gdimagerotate/bug00067_165_exp.png index 567f3b4..df5b640 100644 Binary files a/tests/gdimagerotate/bug00067_165_exp.png and b/tests/gdimagerotate/bug00067_165_exp.png differ