Fix #300: gdImageClone() assigns res_y = res_x
We fix the obvious typo in gdImageClone(), add a regression test and improve related documentation.master
parent
2fe471d5d4
commit
4b840e8216
19
src/gd.c
19
src/gd.c
|
@ -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;
|
||||
|
|
12
src/gd.h
12
src/gd.h
|
@ -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
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ if (BUILD_TEST)
|
|||
gd
|
||||
gd2
|
||||
gdimagearc
|
||||
gdimageclone
|
||||
gdimagecolorclosest
|
||||
gdimagecolordeallocate
|
||||
gdimagecolorexact
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
/bug00300
|
|
@ -0,0 +1,5 @@
|
|||
LIST(APPEND TESTS_FILES
|
||||
bug00300
|
||||
)
|
||||
|
||||
ADD_GD_TESTS()
|
|
@ -0,0 +1,5 @@
|
|||
libgd_test_programs += \
|
||||
gdimageclone/bug00300
|
||||
|
||||
EXTRA_DIST += \
|
||||
gdimagearc/CMakeLists.txt
|
|
@ -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();
|
||||
}
|
Loading…
Reference in New Issue