com php-src: Fix #70102: imagecreatefromwebm() shifts colors: ext/gd/libgd/webpimg.c ext/gd/tests/bug70102.phpt
| From: | Christoph Michael Becker | Date: | Sun, 19 Jul 2015 20:33:54 +0000 |
| Subject: | com php-src: Fix #70102: imagecreatefromwebm() shifts colors: ext/gd/libgd/webpimg.c ext/gd/tests/bug70102.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-88048@lists.php.net to get a copy of this message | ||
Commit: a31fe58d8005ff47f8f6ad095dcd4fb3a2f0aae9
Author: Christoph M. Becker <cmb@php.net> Sun, 19 Jul 2015 22:21:56 +0200
Parents: d3958b32caf606a2710436f8c80df58152e3b160
Branches: PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a31fe58d8005ff47f8f6ad095dcd4fb3a2f0aae9
Log:
Fix #70102: imagecreatefromwebm() shifts colors
libgd internally uses ARGB format, so we have to decode to ARGB instead of
RGBA.
Bugs:
https://bugs.php.net/70102
Changed paths:
M ext/gd/libgd/webpimg.c
A ext/gd/tests/bug70102.phpt
Diff:
diff --git a/ext/gd/libgd/webpimg.c b/ext/gd/libgd/webpimg.c
index 6ce991f..f287e54 100644
--- a/ext/gd/libgd/webpimg.c
+++ b/ext/gd/libgd/webpimg.c
@@ -57,21 +57,21 @@ static inline int clip(float v, int a, int b) {
return (v > b) ? b : (v < 0) ? 0 : (int)(v);
}
enum {
- COLOR_RED = 0,
- COLOR_GREEN = 1,
- COLOR_BLUE = 2,
- ALPHA_CHANNEL = 3
+ COLOR_RED = 1,
+ COLOR_GREEN = 2,
+ COLOR_BLUE = 3,
+ ALPHA_CHANNEL = 0
};
-/* endian neutral extractions of RGBA from a 32 bit pixel */
+/* endian neutral extractions of ARGB from a 32 bit pixel */
static const uint32 RED_SHIFT =
- 8 * (sizeof(uint32) - 1 - COLOR_RED); /* 24 */
+ 8 * (sizeof(uint32) - 1 - COLOR_RED); /* 16 */
static const uint32 GREEN_SHIFT =
- 8 * (sizeof(uint32) - 1 - COLOR_GREEN); /* 16 */
+ 8 * (sizeof(uint32) - 1 - COLOR_GREEN); /* 8 */
static const uint32 BLUE_SHIFT =
- 8 * (sizeof(uint32) - 1 - COLOR_BLUE); /* 8 */
+ 8 * (sizeof(uint32) - 1 - COLOR_BLUE); /* 0 */
static const uint32 ALPHA_SHIFT =
- 8 * (sizeof(uint32) - 1 - ALPHA_CHANNEL); /* 0 */
+ 8 * (sizeof(uint32) - 1 - ALPHA_CHANNEL); /* 24 */
static inline int GetRed(const uint32* rgba) {
return gdTrueColorGetRed(*rgba);
diff --git a/ext/gd/tests/bug70102.phpt b/ext/gd/tests/bug70102.phpt
new file mode 100644
index 0000000..b82c757
--- /dev/null
+++ b/ext/gd/tests/bug70102.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Bug #70102 (imagecreatefromwebm() shifts colors)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+if (!function_exists('imagewebp') || !function_exists('imagecreatefromwebp'))
+ die('skip WebP support not available');
+?>
+--FILE--
+<?php
+$filename = __DIR__ . '/bug70102.webp';
+
+$im = imagecreatetruecolor(8, 8);
+$white = imagecolorallocate($im, 255, 255, 255);
+var_dump($white & 0xffffff);
+imagefilledrectangle($im, 0, 0, 7, 7, $white);
+imagewebp($im, $filename);
+imagedestroy($im);
+
+$im = imagecreatefromwebp($filename);
+$color = imagecolorat($im, 4, 4);
+var_dump($color & 0xffffff);
+?>
+--CLEAN--
+<?php
+unlink(__DIR__ . '/bug70102.webp');
+?>
+--EXPECT--
+int(16777215)
+int(16777215)