cvs: gd /libgd/examples tiffread.c

[email protected] ("Pierre-Alain Joye") Sun, 07 Oct 2007 14:28:22 -0000
Newsgroups php.gd.cvs
Message-ID <cvspajoye1191767302@cvsserver>
pajoye		Sun Oct  7 14:28:22 2007 UTC

  Modified files:              
    /gd/libgd/examples	tiffread.c 
  Log:
  - update example
  
  
http://cvs.php.net/viewvc.cgi/gd/libgd/examples/tiffread.c?r1=1.1&r2=1.2&diff_format=u
Index: gd/libgd/examples/tiffread.c
diff -u gd/libgd/examples/tiffread.c:1.1 gd/libgd/examples/tiffread.c:1.2
--- gd/libgd/examples/tiffread.c:1.1	Thu Oct  4 19:47:41 2007
+++ gd/libgd/examples/tiffread.c	Sun Oct  7 14:28:22 2007
@@ -1,4 +1,10 @@
-/* $Id: tiffread.c,v 1.1 2007/10/04 19:47:41 pajoye Exp $ */
+/* $Id: tiffread.c,v 1.2 2007/10/07 14:28:22 pajoye Exp $ */
+/*
+ * 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>
@@ -6,33 +12,47 @@
 {
  	gdImagePtr im;
 	FILE *fp;
-	char path[2048];
+	char path[9][2048];
+	int i;
+	char dst[2048];
 
-//	sprintf(path, "/home/pierre/projects/gd/patches/tiff/images/cramps-tile.tif");
-	sprintf(path, "/home/pierre/projects/gd/patches/tiff/images/ycbcr-cat.tif");
+	sprintf(path[0], "cramps-tile.tif");
+	sprintf(path[1], "cramps.tif");
+	sprintf(path[2], "ycbcr-cat.tif");
+	sprintf(path[3], "jello.tif");
+	sprintf(path[4], "caspian.tif");
+	sprintf(path[5], "strike.tif");
+	sprintf(path[6], "off_luv24.tif");
+	sprintf(path[7], "off_l16.tif");
+	sprintf(path[8], "fax2d.tif");
 
-	printf("opening %s\n", path);
-	fp = fopen(path, "rb");
-	if (!fp) {
-		printf("failed, cannot open file\n");
-		return 1;
-	}
+	for (i = 0; i < 9; i++) {
+		printf("opening %s\n", path[i]);
+		fp = fopen(path[i], "rb");
+		if (!fp) {
+			printf("failed, cannot open file\n");
+			return 1;
+		}
+
+		im = gdImageCreateFromTiff(fp);
+		fclose(fp);
+		if (!im) {
+			fprintf(stderr, "Can't load TIFF image %s\n", path[i]);
+			return 1;
+		}
 
-	im = gdImageCreateFromTiff(fp);
-	fclose(fp);
-	if (!im) {
-		fprintf(stderr, "Can't load TIFF image %s\n", path);
-		return 1;
-	}
 
-	fp = fopen("fromtiff.png", "wb");
-	if (!fp) {
-		fprintf(stderr, "Can't save png image fromtiff.png\n");
+		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 1;
 	}
-
-	gdImagePng(im, fp);
-	fclose(fp);
-	gdImageDestroy(im);
 }