1 /**
2  * Regression test for <https://github.com/libgd/libgd/issues/329>
3  *
4  * We're testing that for truecolor as well as palette images after
5  * GD_BILINEAR_FIXED scaling the corner pixels of the scaled image have the
6  * expected color.
7  */
8 
9 #include <string.h>
10 #include "gd.h"
11 #include "gdtest.h"
12 
test(const char * mode)13 static void test(const char *mode)
14 {
15 	gdImagePtr src, dst;
16 	int expected, actual;
17 
18 	if (strcmp(mode, "palette")) {
19 		src = gdImageCreateTrueColor(100, 100);
20 		expected = gdTrueColorAlpha(255, 255, 255, gdAlphaOpaque);
21 		gdImageFilledRectangle(src, 0,0, 99,99, expected);
22 	} else {
23 		src = gdImageCreate(100, 100);
24 		gdImageColorAllocate(src, 255, 255, 255);
25 		expected = gdImageGetTrueColorPixel(src, 49, 49);
26 	}
27 
28 	gdImageSetInterpolationMethod(src, GD_BILINEAR_FIXED);
29 	dst = gdImageScale(src, 200, 200);
30 
31 	actual = gdImageGetPixel(dst, 0, 0);
32 	gdTestAssertMsg(actual == expected, "%s: wrong color; expected %x, but got %x", mode, expected, actual);
33 	actual = gdImageGetPixel(dst, 0, 199);
34 	gdTestAssertMsg(actual == expected, "%s: wrong color; expected %x, but got %x", mode, expected, actual);
35 	actual = gdImageGetPixel(dst, 199, 199);
36 	gdTestAssertMsg(actual == expected, "%s: wrong color; expected %x, but got %x", mode, expected, actual);
37 	actual = gdImageGetPixel(dst, 199, 0);
38 	gdTestAssertMsg(actual == expected, "%s: wrong color; expected %x, but got %x", mode, expected, actual);
39 
40 	gdImageDestroy(src);
41 	gdImageDestroy(dst);
42 }
43 
main()44 int main()
45 {
46 	test("palette");
47 	test("truecolor");
48 
49 	return gdNumFailures();
50 }
51