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
67
68
69
70
71
72
73
74
75
76
|
#include "gd.h"
#include "gdtest.h"
#define SRC_WIDTH 80
#define SRC_HEIGHT 42
#define DEST_WIDTH 200
#define DEST_HEIGHT 200
/* Create an image and fill it with true transparency */
gdImagePtr blank_image(int width, int height)
{
gdImagePtr img;
int c;
img = gdImageCreateTrueColor(width, height);
gdImageAlphaBlending(img, 0);
c = gdImageColorAllocateAlpha(img, 255, 0, 255, 127);
gdImageFilledRectangle(img, 0, 0, width-1, height-1, c);
return img;
}
/* Merge layers on top of each other */
gdImagePtr flatten(gdImagePtr *layers, int layer_count, int width, int height)
{
gdImagePtr img;
int i;
img = blank_image(width,height);
gdImageAlphaBlending(img, 1);
for (i = 0; i < layer_count; i++) {
gdImageCopy(img, layers[i], 0,0, 0,0, width,height);
}
gdImageSaveAlpha(img, 1);
return img;
}
int main()
{
gdImagePtr layers[2], background, logo_source, logo, scaled_logo, img;
FILE *fp;
// Rounding issue, won't fix as it only happens on mingw 32bit.
// __aarch64__/graviton. It fails within the CI while outside is 100% success over 100s builds&runs
#if defined(__MINGW32__) || defined(__aarch64__) || defined(_M_ARM64)
return 77;
#endif
background = blank_image(DEST_WIDTH,DEST_HEIGHT);
fp = gdTestFileOpen2("gdimagecopyresampled", "bug00201_src.png");
logo_source = gdImageCreateFromPng(fp);
fclose(fp);
logo = blank_image(SRC_WIDTH,SRC_HEIGHT);
gdImageAlphaBlending(logo, 0);
gdImageCopy(logo, logo_source, 0,0, 0,0, SRC_WIDTH,SRC_HEIGHT);
gdImageDestroy(logo_source);
scaled_logo = blank_image(DEST_WIDTH,DEST_HEIGHT);
gdImageAlphaBlending(scaled_logo, 0);
gdImageCopyResampled(scaled_logo, logo, 0,0, 0,0, 200,105, SRC_WIDTH,SRC_HEIGHT);
gdImageDestroy(logo);
layers[0] = background;
layers[1] = scaled_logo;
img = flatten(layers, 2, DEST_WIDTH, DEST_HEIGHT);
gdImageDestroy(background);
gdImageDestroy(scaled_logo);
gdAssertImageEqualsToFile("gdimagecopyresampled/bug00201_exp.png", img);
gdImageDestroy(img);
return gdNumFailures();
}
|