summaryrefslogtreecommitdiff
path: root/examples/tgaread.c
diff options
context:
space:
mode:
authorpajoye <none@none>2007-10-07 19:41:52 +0000
committerpajoye <none@none>2007-10-07 19:41:52 +0000
commit8fe1fe254dfc17db33c56937fd4dc2f1e22b9f1c (patch)
treea235f95f2613d12421af882ba83598c9b143c332 /examples/tgaread.c
parent74ba7ee645cad3a54213f3f58d22004e26be3b9e (diff)
downloadlibgd-8fe1fe254dfc17db33c56937fd4dc2f1e22b9f1c.tar.gz
- #122, initial TGA support (read only)
Diffstat (limited to 'examples/tgaread.c')
-rw-r--r--examples/tgaread.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/examples/tgaread.c b/examples/tgaread.c
new file mode 100644
index 0000000..909b184
--- /dev/null
+++ b/examples/tgaread.c
@@ -0,0 +1,52 @@
+/* $Id$ */
+/*
+ * 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[3][2048];
+ int i;
+ char dst[2048];
+
+ sprintf(path[0], "noIcon.tga");
+ sprintf(path[1], "noIcon.sgi");
+ sprintf(path[2], "noIcon.pic");
+
+ 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);
+ }
+}