Debian Codegraph @

examples/tgaread.c

raw
1 /*
2 * You can fetch a set of samples TIFF images here:
3 * ftp://ftp.remotesensing.org/pub/libtiff/
4 * (pics-x.y.z.tar.gz)
5 */
6
7 #include <gd.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10
11 int main()
12 {
13 gdImagePtr im;
14 FILE *fp;
15 char path[4][2048];
16 int i;
17 char dst[2048];
18
19 sprintf(path[0], "noIconAlpha.tga");
20 sprintf(path[1], "noIcon.tga");
21
22 for (i = 0; i < 2; i++) {
23 printf("opening %s\n", path[i]);
24 fp = fopen(path[i], "rb");
25 if (!fp) {
26 printf("failed, cannot open file\n");
27 return 1;
28 }
29
30 im = gdImageCreateFromTga(fp);
31 fclose(fp);
32 if (!im) {
33 fprintf(stderr, "Can't load TIFF image %s\n", path[i]);
34 return 1;
35 }
36
37
38 sprintf(dst, "%i.png", i);
39
40 fp = fopen(dst, "wb");
41 if (!fp) {
42 fprintf(stderr, "Can't save png image fromtiff.png\n");
43 gdImageDestroy(im);
44 return 1;
45 }
46 gdImagePng(im, fp);
47 fclose(fp);
48 gdImageDestroy(im);
49 }
50 return 0;
51 }