diff options
author | pajoye <none@none> | 2007-10-07 19:41:52 +0000 |
---|---|---|
committer | pajoye <none@none> | 2007-10-07 19:41:52 +0000 |
commit | 8fe1fe254dfc17db33c56937fd4dc2f1e22b9f1c (patch) | |
tree | a235f95f2613d12421af882ba83598c9b143c332 /examples/tgaread.c | |
parent | 74ba7ee645cad3a54213f3f58d22004e26be3b9e (diff) | |
download | libgd-8fe1fe254dfc17db33c56937fd4dc2f1e22b9f1c.tar.gz |
- #122, initial TGA support (read only)
Diffstat (limited to 'examples/tgaread.c')
-rw-r--r-- | examples/tgaread.c | 52 |
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); + } +} |