diff options
author | Christoph M. Becker <cmbecker69@gmx.de> | 2016-10-08 10:14:59 +0200 |
---|---|---|
committer | Christoph M. Becker <cmbecker69@gmx.de> | 2016-10-08 10:22:04 +0200 |
commit | 59cd8eb723cfdcd5a23267ec54f23c0da9466404 (patch) | |
tree | 24ee26737d05918e7d4ccac4293968632b3ce224 /ext/standard/image.c | |
parent | 9c1c8be7a2a677b1c2f893f7384efe41900fa087 (diff) | |
download | php-git-59cd8eb723cfdcd5a23267ec54f23c0da9466404.tar.gz |
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>
Diffstat (limited to 'ext/standard/image.c')
-rw-r--r-- | ext/standard/image.c | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/ext/standard/image.c b/ext/standard/image.c index 10386c3da0..9de78d4a2b 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; } |