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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include "gd.h"
#include "gdtest.h"
int main()
{
gdImagePtr src, dst;
int r, g, b;
void *p;
int size = 0;
int status = 0;
CuTestImageResult result = {0, 0};
src = gdImageCreate(100, 100);
if (src == NULL) {
printf("could not create src\n");
return 1;
}
r = gdImageColorAllocate(src, 0xFF, 0, 0);
g = gdImageColorAllocate(src, 0, 0xFF, 0);
b = gdImageColorAllocate(src, 0, 0, 0xFF);
gdImageFilledRectangle(src, 0, 0, 99, 99, r);
gdImageRectangle(src, 20, 20, 79, 79, g);
gdImageEllipse(src, 70, 25, 30, 20, b);
#define OUTPUT_GD(x) do { \
FILE *fp; \
\
fp = fopen("gd_im2im_" #x ".gd", "wb"); \
if (fp) { \
gdImageGd(x, fp); \
fclose(fp); \
} \
} while (0)
OUTPUT_GD(src);
p = gdImageGdPtr(src, &size);
if (p == NULL) {
status = 1;
printf("p is null\n");
goto door0;
}
if (size <= 0) {
status = 1;
printf("size is non-positive\n");
goto door1;
}
dst = gdImageCreateFromGdPtr(size, p);
if (dst == NULL) {
status = 1;
printf("could not create dst\n");
goto door1;
}
OUTPUT_GD(dst);
gdTestImageDiff(src, dst, NULL, &result);
if (result.pixels_changed > 0) {
status = 1;
printf("pixels changed: %d\n", result.pixels_changed);
}
gdImageDestroy(dst);
door1:
gdFree(p);
door0:
gdImageDestroy(src);
return status;
}
|