com php-src: Add VP8X support to getimagesize() and friends: ext/standard/image.c ext/standard/tests/image/getimagesize.phpt
ext/standard/tests/image/image_type_to_mime_type.phpt ext/standard/tests/image/test12pix.webp
| From: | Christoph Michael Becker | Date: | Sat, 08 Oct 2016 13:06:07 +0000 |
| Subject: | com php-src: Add VP8X support to getimagesize() and friends: ext/standard/image.c ext/standard/tests/image/getimagesize.phpt ext/standard/tests/image/image_type_to_mime_type.phpt ext/standard/tests/image/test12pix.webp |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94867@lists.php.net to get a copy of this message | ||
Commit: 1d977e55d9781c5205e147a1998044d0cbb9e634
Author: Christoph M. Becker <cmbecker69@gmx.de> Sat, 8 Oct 2016 15:04:35 +0200
Parents: 5540aba2583f9ebaddcd404a2679d95660708558
Branches: PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=1d977e55d9781c5205e147a1998044d0cbb9e634
Log:
Add VP8X support to getimagesize() and friends
This ammends commit 14d4ee93 to also add support for the extended
WebP format, according to
<https://developers.google..com/speed/webp/docs/riff_container>.
Changed paths:
M ext/standard/image.c
M ext/standard/tests/image/getimagesize.phpt
M ext/standard/tests/image/image_type_to_mime_type.phpt
A ext/standard/tests/image/test12pix.webp
Diff:
diff --git a/ext/standard/image.c b/ext/standard/image.c
index 9de78d4..994fec1 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 98eb963..19b355e 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 b22f6e0..4ae5680 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 0000000..c87da24
Binary files /dev/null and b/ext/standard/tests/image/test12pix.webp differ