From 1d977e55d9781c5205e147a1998044d0cbb9e634 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sat, 8 Oct 2016 15:04:35 +0200 Subject: [PATCH] Add VP8X support to getimagesize() and friends This ammends commit 14d4ee93 to also add support for the extended WebP format, according to . --- ext/standard/image.c | 38 +++++++++++------- ext/standard/tests/image/getimagesize.phpt | 17 +++++++- .../tests/image/image_type_to_mime_type.phpt | 4 +- ext/standard/tests/image/test12pix.webp | Bin 0 -> 2494 bytes 4 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 ext/standard/tests/image/test12pix.webp 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 0000000000000000000000000000000000000000..c87da2423fb6562f7df5bf03a801d296666ceb5c GIT binary patch literal 2494 zcmcJRc~n!!9>?e2>>&XH1V|)sSt46NcG;Cg!VW1Qt0*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