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