cvs: php4 /ext/standard/ image.c

[email protected] ("Rasmus Lerdorf") Sun, 04 Jun 2000 18:29:15 -0000
Newsgroups php.version4
Message-ID <cvsrasmus960143355@cvsserver>
rasmus		Sun Jun  4 11:29:15 2000 EDT

  Modified files:
    /php4/ext/standard	image.c 
  Log:
  @ Add SWF support to getimagesize() function (Derick Rethans)
  Add SWF support to getimagesize() function
  
  
Index: php4/ext/standard/image.c
diff -u php4/ext/standard/image.c:1.18 php4/ext/standard/image.c:1.19
--- php4/ext/standard/image.c:1.18	Thu May 18 08:34:35 2000
+++ php4/ext/standard/image.c	Sun Jun  4 11:29:15 2000
@@ -15,7 +15,7 @@
    | Authors: Rasmus Lerdorf                                              |
    +----------------------------------------------------------------------+
  */
-/* $Id: image.c,v 1.18 2000/05/18 15:34:35 zeev Exp $ */
+/* $Id: image.c,v 1.19 2000/06/04 18:29:15 rasmus Exp $ */
 /* 
  * Based on Daniel Schmitt's imageinfo.c which carried the following
  * Copyright notice.
@@ -56,6 +56,8 @@
 {(char) 0x89, (char) 0x50, (char) 0x4e,
  (char) 0x47, (char) 0x0d, (char) 0x0a,
  (char) 0x1a, (char) 0x0a};
+const char php_sig_swf[3] =
+{'F', 'W', 'S'};
 
 /* return info as a struct, to make expansion easier */
 
@@ -92,6 +94,36 @@
 
 }
 
+static unsigned long int php_swf_get_bits (unsigned char* buffer, int pos, int count)
+{
+	unsigned int loop;
+	unsigned long int result = 0;
+	
+	for (loop = pos; loop < pos + count; loop++)
+	{
+		result = result + 
+			((((buffer[loop / 8]) >> (7 - (loop % 8))) & 0x01) << (count - (loop - pos) - 1));
+	}
+	return result;
+}
+
+static struct gfxinfo *php_handle_swf (FILE* fp)
+{
+	struct gfxinfo *result = NULL;
+	unsigned char bits;
+	unsigned char a[32];
+	
+	result = (struct gfxinfo *) ecalloc (1, sizeof (struct gfxinfo));
+	fseek(fp, 8, SEEK_SET);
+	fread(a,sizeof(a),1,fp);
+	bits = php_swf_get_bits (a, 0, 5);
+	result->width = (php_swf_get_bits (a, 5 + bits, bits) -
+		php_swf_get_bits (a, 5, bits)) / 20;
+	result->height = (php_swf_get_bits (a, 5 + (3 * bits), bits) -
+		php_swf_get_bits (a, 5 + (2 * bits), bits)) / 20;
+	return result;
+}
+
 /* routine to handle PNG files. - even easier */
 static struct gfxinfo *php_handle_png(FILE *fp)
 {
@@ -365,6 +397,9 @@
 		} else {
 			php_error(E_WARNING, "PNG file corrupted by ASCII conversion");
 		}
+	} else if (!memcmp(filetype, php_sig_swf, 3)) {
+		result = php_handle_swf(fp);
+		itype = 4;
 	}
 	fclose(fp);
 	if (result) {