]> granicus.if.org Git - php/commitdiff
Add VP8X support to getimagesize() and friends
authorChristoph M. Becker <cmbecker69@gmx.de>
Sat, 8 Oct 2016 13:04:35 +0000 (15:04 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Sat, 8 Oct 2016 13:06:07 +0000 (15:06 +0200)
This ammends commit 14d4ee93 to also add support for the extended
WebP format, according to
<https://developers.google.com/speed/webp/docs/riff_container>.

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 [new file with mode: 0644]

index 9de78d4a2b4d4ea0f673044334607d2f77bb8a10..994fec106866b2f2d0e3083d282e52c7e931832b 100644 (file)
@@ -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;
index 98eb963f3df574d6517e9bf95dda93447da60e03..19b355e92e8812387861a7d4a7b4f9e28c2146de 100644 (file)
@@ -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]=>
index b22f6e030d3784e97fd6a5a135032d53d2dfb2ab..4ae56802389a807379def7176eee9e1c1b91c4bf 100644 (file)
@@ -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 (file)
index 0000000..c87da24
Binary files /dev/null and b/ext/standard/tests/image/test12pix.webp differ