From: Christoph M. Becker Date: Sat, 8 Oct 2016 13:04:35 +0000 (+0200) Subject: Add VP8X support to getimagesize() and friends X-Git-Tag: php-7.1.0RC4~78 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1d977e55d9781c5205e147a1998044d0cbb9e634;p=php Add VP8X support to getimagesize() and friends This ammends commit 14d4ee93 to also add support for the extended WebP format, according to . --- diff --git a/ext/standard/image.c b/ext/standard/image.c index 9de78d4a2b..994fec1068 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -1129,21 +1129,19 @@ static struct gfxinfo *php_handle_webp(php_stream * stream) struct gfxinfo *result = NULL; const char sig[3] = {'V', 'P', '8'}; unsigned char buf[18]; - int lossless; + char format; if (php_stream_read(stream, (char *) buf, 18) != 18) return NULL; - /* simple WebP only */ if (memcmp(buf, sig, 3)) { return NULL; } switch (buf[3]) { case ' ': - lossless = 0; - break; case 'L': - lossless = 1; + case 'X': + format = buf[3]; break; default: return NULL; @@ -1151,18 +1149,28 @@ static struct gfxinfo *php_handle_webp(php_stream * stream) result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo)); - if (lossless) { - result->width = buf[9] + ((buf[10] & 0x3F) << 8) + 1; - result->height = (buf[10] >> 6) + (buf[11] << 2) + ((buf[12] & 0xF) << 10) + 1; - } else { - result->width = (buf[14]) + ((buf[15] & 0x3F) << 8); - result->height = (buf[16]) + ((buf[17] & 0x3F) << 8); + switch (format) { + case ' ': + result->width = (buf[14]) + ((buf[15] & 0x3F) << 8); + result->height = (buf[16]) + ((buf[17] & 0x3F) << 8); + break; + case 'L': + result->width = buf[9] + ((buf[10] & 0x3F) << 8) + 1; + result->height = (buf[10] >> 6) + (buf[11] << 2) + ((buf[12] & 0xF) << 10) + 1; + break; + case 'X': + result->width = buf[12] + (buf[13] << 8) + (buf[14] << 16) + 1; + result->height = buf[15] + (buf[16] << 8) + (buf[17] << 16) + 1; + break; } result->bits = 8; /* always 1 byte */ - if (lossless) { - result->channels = 4; /* always ARGB */ - } else { - result->channels = 3; /* always YUV */ + switch (format) { + case ' ': + result->channels = 3; /* always YUV */ + break; + case 'L': + result->channels = 4; /* always ARGB */ + break; } return result; diff --git a/ext/standard/tests/image/getimagesize.phpt b/ext/standard/tests/image/getimagesize.phpt index 98eb963f3d..19b355e92e 100644 --- a/ext/standard/tests/image/getimagesize.phpt +++ b/ext/standard/tests/image/getimagesize.phpt @@ -23,7 +23,7 @@ GetImageSize() var_dump($result); ?> --EXPECT-- -array(15) { +array(16) { ["test-1pix.bmp"]=> array(6) { [0]=> @@ -39,6 +39,21 @@ array(15) { ["mime"]=> string(14) "image/x-ms-bmp" } + ["test12pix.webp"]=> + array(6) { + [0]=> + int(4) + [1]=> + int(3) + [2]=> + int(18) + [3]=> + string(20) "width="4" height="3"" + ["bits"]=> + int(8) + ["mime"]=> + string(10) "image/webp" + } ["test1bpix.bmp"]=> array(6) { [0]=> diff --git a/ext/standard/tests/image/image_type_to_mime_type.phpt b/ext/standard/tests/image/image_type_to_mime_type.phpt index b22f6e030d..4ae5680238 100644 --- a/ext/standard/tests/image/image_type_to_mime_type.phpt +++ b/ext/standard/tests/image/image_type_to_mime_type.phpt @@ -25,9 +25,11 @@ image_type_to_mime_type() var_dump($result); ?> --EXPECT-- -array(15) { +array(16) { ["test-1pix.bmp"]=> string(14) "image/x-ms-bmp" + ["test12pix.webp"]=> + string(10) "image/webp" ["test1bpix.bmp"]=> string(14) "image/x-ms-bmp" ["test1pix.bmp"]=> diff --git a/ext/standard/tests/image/test12pix.webp b/ext/standard/tests/image/test12pix.webp new file mode 100644 index 0000000000..c87da2423f Binary files /dev/null and b/ext/standard/tests/image/test12pix.webp differ