summaryrefslogtreecommitdiff
path: root/Build/source/libs/gd/libgd-src/tests/gif/bug00006.c
blob: c80d3878e5b72e9a40a2931f344f38de378ab021 (plain)
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
#include <stdio.h>
#include "gd.h"
#include "gdtest.h"

int main()
{
	gdImagePtr im;
	FILE *fp;
	char *file;
	const int r = 255, g = 0, b = 0;
	int r_f,g_f,b_f, trans_c_f;
	int trans_c = gdTrueColorAlpha(r,g,b,0);
	int error = 0;

	im = gdImageCreateTrueColor(192, 36);
	if (im == NULL) {
		gdTestErrorMsg("Cannot create image\n");
		return 1;
	}

	gdImageColorTransparent(im, trans_c);
	gdImageFilledRectangle(im, 0,0, 192,36, trans_c);

	file = gdTestTempFile("bug0006.gif");
	fp = fopen(file, "wb");
	if (!fp) {
		gdTestErrorMsg("Cannot open <%s> for writing\n", file);
		return 1;
	}

	gdImageTrueColorToPaletteSetMethod(im, GD_QUANT_JQUANT, 0);
	gdImageTrueColorToPalette(im, 1, 256);

	gdImageGif(im,fp);
	fclose(fp);

	gdImageDestroy(im);

	fp = fopen(file, "rb");
	if (!fp) {
		gdTestErrorMsg("Cannot open <%s> for reading\n", file);
		return 1;
	}
	im = gdImageCreateFromGif(fp);
	fclose(fp);

	if (!im) {
		gdTestErrorMsg("Cannot create image from <%s>\n", file);
		return 1;
	}

	trans_c_f = gdImageGetTransparent(im);
	if (gdTestAssert(trans_c_f == 1)) {
		r_f = gdImageRed(im, trans_c_f);
		g_f = gdImageGreen(im, trans_c_f);
		b_f = gdImageBlue(im, trans_c_f);

		if (!gdTestAssert(r_f == r) || !gdTestAssert(g_f==g) || !gdTestAssert(b_f==b)) {
			error = 1;
		}
	} else {
		error = 1;
	}

	/* Destroy it */
	gdImageDestroy(im);
	return error;
}