Fix #319: gdImageRotateInterpolated can have wrong background color
We backport the fix for <https://bugs.php.net/65070>, and also the fix for <https://bugs.php.net/70976> which was introduced by fixing 65070.master
parent
ddf3b493f1
commit
65d40f5aa5
6
src/gd.c
6
src/gd.c
|
@ -4385,6 +4385,12 @@ BGD_DECLARE(int) gdImagePaletteToTrueColor(gdImagePtr src)
|
|||
src->pixels = NULL;
|
||||
src->alphaBlendingFlag = 0;
|
||||
src->saveAlphaFlag = 1;
|
||||
|
||||
if (src->transparent >= 0) {
|
||||
const unsigned char c = src->transparent;
|
||||
src->transparent = gdTrueColorAlpha(src->red[c], src->green[c], src->blue[c], src->alpha[c]);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
clean_on_error:
|
||||
|
|
|
@ -1686,13 +1686,6 @@ gdImageRotateNearestNeighbour(gdImagePtr src, const float degrees,
|
|||
gdRect bbox;
|
||||
int new_height, new_width;
|
||||
|
||||
/* impact perf a bit, but not that much. Implementation for palette
|
||||
images can be done at a later point.
|
||||
*/
|
||||
if (src->trueColor == 0) {
|
||||
gdImagePaletteToTrueColor(src);
|
||||
}
|
||||
|
||||
gdRotatedImageSize(src, degrees, &bbox);
|
||||
new_width = bbox.width;
|
||||
new_height = bbox.height;
|
||||
|
@ -1750,13 +1743,6 @@ gdImageRotateGeneric(gdImagePtr src, const float degrees, const int bgColor)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* impact perf a bit, but not that much. Implementation for palette
|
||||
images can be done at a later point.
|
||||
*/
|
||||
if (src->trueColor == 0) {
|
||||
gdImagePaletteToTrueColor(src);
|
||||
}
|
||||
|
||||
if (src->interpolation == NULL) {
|
||||
gdImageSetInterpolationMethod(src, GD_DEFAULT);
|
||||
}
|
||||
|
@ -1807,6 +1793,16 @@ BGD_DECLARE(gdImagePtr) gdImageRotateInterpolated(const gdImagePtr src, const fl
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* impact perf a bit, but not that much. Implementation for palette
|
||||
images can be done at a later point.
|
||||
*/
|
||||
if (src->trueColor == 0) {
|
||||
if (bgcolor < gdMaxColors) {
|
||||
bgcolor = gdTrueColorAlpha(src->red[bgcolor], src->green[bgcolor], src->blue[bgcolor], src->alpha[bgcolor]);
|
||||
}
|
||||
gdImagePaletteToTrueColor(src);
|
||||
}
|
||||
|
||||
/* 0 && 90 degrees multiple rotation, 0 rotation simply clones the return image and convert it
|
||||
to truecolor, as we must return truecolor image. */
|
||||
switch (angle_rounded) {
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
/bug00067
|
||||
/php_bug_64898
|
||||
/php_bug_65070
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
LIST(APPEND TESTS_FILES
|
||||
bug00067
|
||||
php_bug_64898
|
||||
php_bug_65070
|
||||
)
|
||||
|
||||
ADD_GD_TESTS()
|
||||
|
|
|
@ -5,7 +5,8 @@ endif
|
|||
|
||||
if HAVE_LIBPNG
|
||||
libgd_test_programs += \
|
||||
gdimagerotate/php_bug_64898
|
||||
gdimagerotate/php_bug_64898 \
|
||||
gdimagerotate/php_bug_65070
|
||||
endif
|
||||
|
||||
EXTRA_DIST += \
|
||||
|
@ -25,4 +26,6 @@ EXTRA_DIST += \
|
|||
gdimagerotate/bug00067_180_exp.png \
|
||||
gdimagerotate/php_bug_64898.png \
|
||||
gdimagerotate/php_bug_64898_exp.png \
|
||||
gdimagerotate/php_bug_65070.gif \
|
||||
gdimagerotate/php_bug_65070_exp.png \
|
||||
gdimagerotate/remirh128.png
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
#include "gd.h"
|
||||
#include "gdtest.h"
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
gdImagePtr src, dst;
|
||||
FILE *fp;
|
||||
int black;
|
||||
char *path;
|
||||
|
||||
fp = gdTestFileOpen2("gdimagerotate", "php_bug_65070.gif");
|
||||
src = gdImageCreateFromGif(fp);
|
||||
fclose(fp);
|
||||
|
||||
black = gdImageColorAllocateAlpha(src, 0, 0, 0, 0);
|
||||
dst = gdImageRotateInterpolated(src, 30.0, black);
|
||||
|
||||
path = gdTestFilePath2("gdimagerotate", "php_bug_65070_exp.png");
|
||||
gdAssertImageEqualsToFile(path, dst);
|
||||
gdFree(path);
|
||||
|
||||
gdImageDestroy(src);
|
||||
gdImageDestroy(dst);
|
||||
|
||||
return gdNumFailures();
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 8.2 KiB |
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
Loading…
Reference in New Issue