1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4 
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include "gd.h"
8 
9 /* A short program which converts a .png file into a .gd file, for
10    your convenience in creating images on the fly from a
11    basis image that must be loaded quickly. The .gd format
12    is not intended to be a general-purpose format. */
13 
14 int
main(int argc,char ** argv)15 main (int argc, char **argv)
16 {
17 	gdImagePtr im;
18 	gdImagePtr pal;
19 	FILE *in, *out;
20 	if (argc != 3) {
21 		fprintf(stderr, "Usage: gd2copypal palettefile.gd2 filename.gd2\n");
22 		exit (1);
23 	}
24 	in = fopen (argv[1], "rb");
25 	if (!in) {
26 		fprintf(stderr, "Palette file does not exist!\n");
27 		exit (1);
28 	}
29 	pal = gdImageCreateFromGd2 (in);
30 	fclose (in);
31 	if (!pal) {
32 		fprintf(stderr, "Palette is not in GD2 format!\n");
33 		exit (1);
34 	}
35 
36 	in = fopen (argv[2], "rb");
37 	if (!in) {
38 		fprintf(stderr, "Input file does not exist!\n");
39 		exit (1);
40 	}
41 	im = gdImageCreateFromGd2 (in);
42 	fclose (in);
43 	if (!im) {
44 		fprintf(stderr, "Input is not in GD2 format!\n");
45 		exit (1);
46 	}
47 
48 	gdImagePaletteCopy (im, pal);
49 
50 	out = fopen (argv[2], "wb");
51 	if (!out) {
52 		fprintf(stderr, "Output file cannot be written to!\n");
53 		gdImageDestroy (im);
54 		exit (1);
55 	}
56 	gdImageGd2 (im, out, 128, 2);
57 	fclose (out);
58 	gdImageDestroy (pal);
59 	gdImageDestroy (im);
60 
61 	return 0;
62 }
63