Fix #300: gdImageClone() assigns res_y = res_x

We fix the obvious typo in gdImageClone(), add a regression test and improve
related documentation.
master
Christoph M. Becker 2016-09-12 23:53:34 +02:00
parent 2fe471d5d4
commit 4b840e8216
8 changed files with 70 additions and 6 deletions

View File

@ -2711,7 +2711,7 @@ BGD_DECLARE(gdImagePtr) gdImageClone (gdImagePtr src) {
dst->cy2 = src->cy2;
dst->res_x = src->res_x;
dst->res_y = src->res_x;
dst->res_y = src->res_y;
dst->paletteQuantizationMethod = src->paletteQuantizationMethod;
dst->paletteQuantizationSpeed = src->paletteQuantizationSpeed;
@ -3818,9 +3818,20 @@ BGD_DECLARE(void) gdImageGetClip (gdImagePtr im, int *x1P, int *y1P, int *x2P, i
*y2P = im->cy2;
}
/*
Function: gdImageSetResolution
*/
/**
* Function: gdImageSetResolution
*
* Sets the resolution of an image.
*
* Parameters:
* im - The image.
* res_x - The horizontal resolution in DPI.
* res_y - The vertical resolution in DPI.
*
* See also:
* - <gdImageResolutionX>
* - <gdImageResolutionY>
*/
BGD_DECLARE(void) gdImageSetResolution(gdImagePtr im, const unsigned int res_x, const unsigned int res_y)
{
if (res_x > 0) im->res_x = res_x;

View File

@ -1303,22 +1303,30 @@ BGD_DECLARE(gdImagePtr) gdImageCopyGaussianBlurred(gdImagePtr src, int radius,
#define gdImageTrueColorPixel(im, x, y) (im)->tpixels[(y)][(x)]
/**
* Macro: gdImageResolution
* Macro: gdImageResolutionX
*
* Gets the horizontal resolution in DPI.
*
* Parameters:
* im - The image.
*
* See also:
* - <gdImageResolutionY>
* - <gdImageSetResolution>
*/
#define gdImageResolutionX(im) (im)->res_x
/**
* Macro: gdImageResolution
* Macro: gdImageResolutionY
*
* Gets the vertical resolution in DPI.
*
* Parameters:
* im - The image.
*
* See also:
* - <gdImageResolutionX>
* - <gdImageSetResolution>
*/
#define gdImageResolutionY(im) (im)->res_y

View File

@ -24,6 +24,7 @@ if (BUILD_TEST)
gd
gd2
gdimagearc
gdimageclone
gdimagecolorclosest
gdimagecolordeallocate
gdimagecolorexact

View File

@ -19,6 +19,7 @@ include freetype/Makemodule.am
include gd/Makemodule.am
include gd2/Makemodule.am
include gdimagearc/Makemodule.am
include gdimageclone/Makemodule.am
include gdimagecolorclosest/Makemodule.am
include gdimagecolordeallocate/Makemodule.am
include gdimagecolorexact/Makemodule.am

1
tests/gdimageclone/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/bug00300

View File

@ -0,0 +1,5 @@
LIST(APPEND TESTS_FILES
bug00300
)
ADD_GD_TESTS()

View File

@ -0,0 +1,5 @@
libgd_test_programs += \
gdimageclone/bug00300
EXTRA_DIST += \
gdimagearc/CMakeLists.txt

View File

@ -0,0 +1,32 @@
/**
* Regression test for <https://github.com/libgd/libgd/issues/300>
*
* We're testing that the resolution does not change when cloning.
*/
#include "gd.h"
#include "gdtest.h"
int main()
{
gdImagePtr im, clone;
im = gdImageCreate(8, 8);
gdImageSetResolution(im, 100, 50);
clone = gdImageClone(im);
gdTestAssertMsg(gdImageResolutionX(clone) == gdImageResolutionX(im),
"horizontal resolution doesn't match: expected %d, got %d\n",
gdImageResolutionX(im), gdImageResolutionX(clone));
gdTestAssertMsg(gdImageResolutionY(clone) == gdImageResolutionY(im),
"vertical resolution doesn't match: expected %d, got %d\n",
gdImageResolutionY(im), gdImageResolutionY(clone));
gdImageDestroy(clone);
gdImageDestroy(im);
return gdNumFailures();
}