summaryrefslogtreecommitdiff
path: root/tests/gif/bug00181.c
blob: 27d6481175e1d648c02451829a2f9e810f061d3b (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <stdio.h>
#include "gd.h"
#include "gdtest.h"

int main()
{
	gdImagePtr im, im2, im3;
	FILE *fp;
	int black, trans;
	int error = 0;

	/* GIFEncode */
	im = gdImageCreate(100, 100);
        if (!im) {
                gdTestErrorMsg("Cannot create image.\n");
                return 1;
        }
	im->interlace = 1;
	fp = fopen("bug00181.gif", "wb");
	if (!fp) {
		gdTestErrorMsg("Cannot open <%s> for writing.\n", "bug00181.gif");
		return 1;
	}
	gdImageGif(im, fp);
	gdImageDestroy(im);
	fclose(fp);

	fp = fopen("bug00181.gif", "rb");
	if (!fp) {
		gdTestErrorMsg("Cannot open <%s> for reading.\n", "bug00181.gif");
		return 1;
	}
	im = gdImageCreateFromGif(fp);
	fclose(fp);
        if (!im) {
                gdTestErrorMsg("Cannot create image from <%s>\n", "bug00181.gif");
                return 1;
        }
	error = !im->interlace;
	gdImageDestroy(im);

	if (error) return error;

	/* GIFAnimEncode */
	im = gdImageCreate(100, 100);
	im->interlace = 1;
	gdImageColorAllocate(im, 255, 255, 255); /* allocate white for background color */
	black = gdImageColorAllocate(im, 0, 0, 0);
	trans = gdImageColorAllocate(im, 1, 1, 1);
	gdImageRectangle(im, 0, 0, 10, 10, black);
	fp = fopen("bug00181a.gif", "wb");
	if (!fp) {
		gdTestErrorMsg("Cannot open <%s> for writing.\n", "bug00181a.gif");
		return 1;
	}
	gdImageGifAnimBegin(im, fp, 1, 3);
	gdImageGifAnimAdd(im, fp, 0, 0, 0, 100, 1, NULL);
	im2 = gdImageCreate(100, 100);
	im2->interlace = 1;
	(void)gdImageColorAllocate(im2, 255, 255, 255);
	gdImagePaletteCopy (im2, im);
	gdImageRectangle(im2, 0, 0, 15, 15, black);
	gdImageColorTransparent (im2, trans);
	gdImageGifAnimAdd(im2, fp, 0, 0, 0, 100, 1, im);
	im3 = gdImageCreate(100, 100);
	im3->interlace = 1;
	(void)gdImageColorAllocate(im3, 255, 255, 255);
	gdImagePaletteCopy (im3, im);
	gdImageRectangle(im3, 0, 0, 15, 20, black);
	gdImageColorTransparent (im3, trans);
	gdImageGifAnimAdd(im3, fp, 0, 0, 0, 100, 1, im2);
	gdImageGifAnimEnd(fp);
	fclose(fp);
	gdImageDestroy(im);
	gdImageDestroy(im2);
	gdImageDestroy(im3);

	fp = fopen("bug00181a.gif", "rb");
	if (!fp) {
		gdTestErrorMsg("Cannot open <%s> for reading.\n", "bug00181a.gif");
		return 1;
	}
	im = gdImageCreateFromGif(fp);
	fclose(fp);
        if (!im) {
                gdTestErrorMsg("Cannot create image from <%s>\n", "bug00181a.gif");
                return 1;
        }
	error = !im->interlace;
	gdImageDestroy(im);

	return error;
}