com php-src: Add VP8L 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/test3llpix.webp
| From: | Christoph Michael Becker | Date: | Sat, 08 Oct 2016 08:22:04 +0000 |
| Subject: | com php-src: Add VP8L 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/test3llpix.webp |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94865@lists.php.net to get a copy of this message | ||
Commit: 59cd8eb723cfdcd5a23267ec54f23c0da9466404
Author: Christoph M. Becker <cmbecker69@gmx.de> Sat, 8 Oct 2016 10:14:59 +0200
Parents: 9c1c8be7a2a677b1c2f893f7384efe41900fa087
Branches: PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=59cd8eb723cfdcd5a23267ec54f23c0da9466404
Log:
Add VP8L support to getimagesize() and friends
This ammends commit 14d4ee93 to also add support for simple lossless
WebP, according to
<https://chromium.googlesource..com/webm/libwebp/+/master/doc/webp-lossless-bitstream-spec.txt>
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/test3llpix.webp
Diff:
diff --git a/ext/standard/image.c b/ext/standard/image.c
index 10386c3..9de78d4 100644
--- a/ext/standard/image.c
+++ b/ext/standard/image.c
@@ -1127,22 +1127,43 @@ static struct gfxinfo *php_handle_ico(php_stream * stream)
static struct gfxinfo *php_handle_webp(php_stream * stream)
{
struct gfxinfo *result = NULL;
- const char sig[4] = {'V', 'P', '8', ' '};
+ const char sig[3] = {'V', 'P', '8'};
unsigned char buf[18];
+ int lossless;
if (php_stream_read(stream, (char *) buf, 18) != 18)
return NULL;
- if (memcmp(buf, sig, 4)) { /* simple lossy WebP only */
+ /* simple WebP only */
+ if (memcmp(buf, sig, 3)) {
return NULL;
}
+ switch (buf[3]) {
+ case ' ':
+ lossless = 0;
+ break;
+ case 'L':
+ lossless = 1;
+ break;
+ default:
+ return NULL;
+ }
result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
-
- result->width = (buf[14]) + ((buf[15] & 0x3F) << 8);
- result->height = (buf[16]) + ((buf[17] & 0x3F) << 8);
+
+ 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);
+ }
result->bits = 8; /* always 1 byte */
- result->channels = 3; /* always YUV */
+ if (lossless) {
+ result->channels = 4; /* always ARGB */
+ } else {
+ result->channels = 3; /* always YUV */
+ }
return result;
}
diff --git a/ext/standard/tests/image/getimagesize.phpt b/ext/standard/tests/image/getimagesize.phpt
index e088322..98eb963 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(14) {
+array(15) {
["test-1pix.bmp"]=>
array(6) {
[0]=>
@@ -137,6 +137,23 @@ array(14) {
["mime"]=>
string(9) "image/gif"
}
+ ["test3llpix.webp"]=>
+ array(7) {
+ [0]=>
+ int(1)
+ [1]=>
+ int(3)
+ [2]=>
+ int(18)
+ [3]=>
+ string(20) "width="1" height="3""
+ ["bits"]=>
+ int(8)
+ ["channels"]=>
+ int(4)
+ ["mime"]=>
+ string(10) "image/webp"
+ }
["test3pix.webp"]=>
array(7) {
[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 492c843..b22f6e0 100644
--- a/ext/standard/tests/image/image_type_to_mime_type.phpt
+++ b/ext/standard/tests/image/image_type_to_mime_type.phpt
@@ -25,7 +25,7 @@ image_type_to_mime_type()
var_dump($result);
?>
--EXPECT--
-array(14) {
+array(15) {
["test-1pix.bmp"]=>
string(14) "image/x-ms-bmp"
["test1bpix.bmp"]=>
@@ -40,6 +40,8 @@ array(14) {
string(10) "image/jpeg"
["test2pix.gif"]=>
string(9) "image/gif"
+ ["test3llpix.webp"]=>
+ string(10) "image/webp"
["test3pix.webp"]=>
string(10) "image/webp"
["test4pix.gif"]=>
diff --git a/ext/standard/tests/image/test3llpix.webp b/ext/standard/tests/image/test3llpix..webp
new file mode 100644
index 0000000..2243a1b
Binary files /dev/null and b/ext/standard/tests/image/test3llpix.webp differ