1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
/**
* Test that gdImageCrop() retains transparency
*
* We create an image with transparent pixels, crop the image, and check whether
* all pixels are identical to the respective source image.
*
* See <https://github.com/libgd/libgd/issues/432>
*/
#include "gd.h"
#include "gdtest.h"
#define WIDTH 10
#define HEIGHT 10
#define XOFF 1
#define YOFF 1
int main()
{
gdImagePtr src, dst;
gdRect crop = {XOFF, YOFF, WIDTH-XOFF-1, HEIGHT-YOFF-1};
int i, j;
src = gdImageCreateTrueColor(WIDTH, HEIGHT);
gdImageAlphaBlending(src, gdEffectReplace);
gdImageFilledRectangle(src, 0, 0, WIDTH-1, HEIGHT-1,
gdTrueColorAlpha(gdRedMax, gdGreenMax, gdBlueMax, gdAlphaMax));
dst = gdImageCrop(src, &crop);
gdTestAssert(dst != NULL);
for (i = 0; i < gdImageSX(dst); i++) {
for (j = 0; j < gdImageSY(dst); j++) {
gdTestAssert(gdImageGetPixel(dst, i, j) == gdImageGetPixel(src, i+XOFF, j+YOFF));
}
}
gdImageDestroy(src);
gdImageDestroy(dst);
return gdNumFailures();
}
|