diff options
author | Rasmus Lerdorf <rasmus@php.net> | 2000-06-04 18:29:15 +0000 |
---|---|---|
committer | Rasmus Lerdorf <rasmus@php.net> | 2000-06-04 18:29:15 +0000 |
commit | 7eec1997ef3e27f47f29a0334ec7c1a10e783a23 (patch) | |
tree | c30fb9477a13c775d119f5d2a70b22d2d2a82051 | |
parent | 8aa6d9cb35db1afc63b17ca0f792873c33542a1d (diff) | |
download | php-git-7eec1997ef3e27f47f29a0334ec7c1a10e783a23.tar.gz |
@ Add SWF support to getimagesize() function (Derick Rethans)
Add SWF support to getimagesize() function
-rw-r--r-- | ext/standard/image.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/ext/standard/image.c b/ext/standard/image.c index 392bb71dcd..266c3d3b1f 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -56,6 +56,8 @@ const char php_sig_png[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 php_read4(FILE *fp) } +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 @@ PHP_FUNCTION(getimagesize) } 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) { |