File: tgaread.c

package info (click to toggle)
libgd2 2.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 10,360 kB
  • sloc: ansic: 48,194; sh: 5,603; cpp: 1,298; makefile: 323; perl: 225; tcl: 45
file content (51 lines) | stat: -rw-r--r-- 884 bytes parent folder | download | duplicates (2)
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
/*
 * You can fetch a set of samples TIFF images here:
 * ftp://ftp.remotesensing.org/pub/libtiff/
 * (pics-x.y.z.tar.gz)
 */

#include <gd.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
	gdImagePtr im;
	FILE *fp;
	char path[4][2048];
	int i;
	char dst[2048];

	sprintf(path[0], "noIconAlpha.tga");
	sprintf(path[1], "noIcon.tga");

	for (i = 0; i < 2; i++) {
		printf("opening %s\n", path[i]);
		fp = fopen(path[i], "rb");
		if (!fp) {
			printf("failed, cannot open file\n");
			return 1;
		}

		im = gdImageCreateFromTga(fp);
		fclose(fp);
		if (!im) {
			fprintf(stderr, "Can't load TIFF image %s\n", path[i]);
			return 1;
		}


		sprintf(dst, "%i.png", i);

		fp = fopen(dst, "wb");
		if (!fp) {
			fprintf(stderr, "Can't save png image fromtiff.png\n");
			gdImageDestroy(im);
			return 1;
		}
		gdImagePng(im, fp);
		fclose(fp);
		gdImageDestroy(im);
	}
	return 0;
}