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
46
47
48
|
/**
* Test that gdImageCropAuto() crops left and right as well
*
* We test that an image with four unicolored quadrants, where either both left
* quadrants or both right quadrants have the same color, but the remaining
* quadrants have different colors, are treated identically by
* gdImageCropAuto(…, GD_CROP_SIDES).
*
* See <https://github.com/libgd/libgd/issues/486>
*/
#include "gd.h"
#include "gdtest.h"
int main()
{
gdImagePtr orig, croppedLeft, croppedRight;
int red, green, blue;
orig = gdImageCreateTrueColor(8, 8);
red = gdImageColorAllocate(orig, 255, 0, 0);
green = gdImageColorAllocate(orig, 0, 255, 0);
blue = gdImageColorAllocate(orig, 0, 0, 255);
gdImageFilledRectangle(orig, 0, 0, 3, 3, green); // tl
gdImageFilledRectangle(orig, 4, 0, 7, 3, red); // tr
gdImageFilledRectangle(orig, 0, 4, 3, 7, green); // bl
gdImageFilledRectangle(orig, 4, 4, 7, 7, blue); // br
croppedLeft = gdImageCropAuto(orig, GD_CROP_SIDES);
gdTestAssert(croppedLeft != NULL);
gdImageFilledRectangle(orig, 0, 0, 3, 3, red); // tl
gdImageFilledRectangle(orig, 4, 0, 7, 3, green); // tr
gdImageFilledRectangle(orig, 0, 4, 3, 7, blue); // bl
gdImageFilledRectangle(orig, 4, 4, 7, 7, green); // br
croppedRight = gdImageCropAuto(orig, GD_CROP_SIDES);
gdTestAssert(croppedRight != NULL);
gdAssertImageEquals(croppedRight, croppedLeft);
gdImageDestroy(orig);
gdImageDestroy(croppedLeft);
gdImageDestroy(croppedRight);
return gdNumFailures();
}
|