From: Christoph M. Becker Date: Sun, 2 Oct 2016 17:06:59 +0000 (+0200) Subject: Add support for gdEffectMultiply X-Git-Tag: php-7.2.0alpha1~1217 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=82a8e57f37b9f28357c9ab9fc3df88bafd46ef62;p=php Add support for gdEffectMultiply gdLayerMultiply() has been introduced in libgd 2.1.1, and as such would have been already available for imagelayereffect() with a system libgd. We port the respective code to the bundled libgd, and also make IMG_EFFECT_MULTIPLY available to userland. --- diff --git a/UPGRADING b/UPGRADING index 055b313974..38250ed303 100644 --- a/UPGRADING +++ b/UPGRADING @@ -112,6 +112,9 @@ PHP 7.2 UPGRADE NOTES 10. New Global Constants ======================================== +- GD: + . IMG_EFFECT_MULTIPLY + - Standard: . PASSWORD_ARGON2_DEFAULT_MEMORY_COST . PASSWORD_ARGON2_DEFAULT_TIME_COST diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 6ff2a1c940..f8569779ba 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -1098,6 +1098,9 @@ PHP_MINIT_FUNCTION(gd) REGISTER_LONG_CONSTANT("IMG_EFFECT_ALPHABLEND", gdEffectAlphaBlend, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_EFFECT_NORMAL", gdEffectNormal, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_EFFECT_OVERLAY", gdEffectOverlay, CONST_CS | CONST_PERSISTENT); +#ifdef gdEffectMultiply + REGISTER_LONG_CONSTANT("IMG_EFFECT_MULTIPLY", gdEffectMultiply, CONST_CS | CONST_PERSISTENT); +#endif REGISTER_LONG_CONSTANT("IMG_CROP_DEFAULT", GD_CROP_DEFAULT, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT("IMG_CROP_TRANSPARENT", GD_CROP_TRANSPARENT, CONST_CS | CONST_PERSISTENT); diff --git a/ext/gd/libgd/gd.c b/ext/gd/libgd/gd.c index 5c3593ed1b..afa8e287cc 100644 --- a/ext/gd/libgd/gd.c +++ b/ext/gd/libgd/gd.c @@ -93,7 +93,6 @@ extern int gdSinT[]; static void gdImageBrushApply(gdImagePtr im, int x, int y); static void gdImageTileApply(gdImagePtr im, int x, int y); -static int gdLayerOverlay(int dst, int src); static int gdAlphaOverlayColor(int src, int dst, int max); int gdImageGetTrueColorPixel(gdImagePtr im, int x, int y); @@ -756,14 +755,15 @@ void gdImageSetPixel (gdImagePtr im, int x, int y, int color) im->tpixels[y][x] = color; break; case gdEffectAlphaBlend: - im->tpixels[y][x] = gdAlphaBlend(im->tpixels[y][x], color); - break; case gdEffectNormal: im->tpixels[y][x] = gdAlphaBlend(im->tpixels[y][x], color); break; case gdEffectOverlay : im->tpixels[y][x] = gdLayerOverlay(im->tpixels[y][x], color); break; + case gdEffectMultiply : + im->tpixels[y][x] = gdLayerMultiply(im->tpixels[y][x], color); + break; } } else { im->pixels[y][x] = color; @@ -2951,7 +2951,7 @@ void gdImageSaveAlpha (gdImagePtr im, int saveAlphaArg) im->saveAlphaFlag = saveAlphaArg; } -static int gdLayerOverlay (int dst, int src) +int gdLayerOverlay (int dst, int src) { int a1, a2; a1 = gdAlphaMax - gdTrueColorGetAlpha(dst); @@ -2984,6 +2984,28 @@ static int gdAlphaOverlayColor (int src, int dst, int max ) } } +int gdLayerMultiply (int dst, int src) +{ + int a1, a2, r1, r2, g1, g2, b1, b2; + a1 = gdAlphaMax - gdTrueColorGetAlpha(src); + a2 = gdAlphaMax - gdTrueColorGetAlpha(dst); + + r1 = gdRedMax - (a1 * (gdRedMax - gdTrueColorGetRed(src))) / gdAlphaMax; + r2 = gdRedMax - (a2 * (gdRedMax - gdTrueColorGetRed(dst))) / gdAlphaMax; + g1 = gdGreenMax - (a1 * (gdGreenMax - gdTrueColorGetGreen(src))) / gdAlphaMax; + g2 = gdGreenMax - (a2 * (gdGreenMax - gdTrueColorGetGreen(dst))) / gdAlphaMax; + b1 = gdBlueMax - (a1 * (gdBlueMax - gdTrueColorGetBlue(src))) / gdAlphaMax; + b2 = gdBlueMax - (a2 * (gdBlueMax - gdTrueColorGetBlue(dst))) / gdAlphaMax ; + + a1 = gdAlphaMax - a1; + a2 = gdAlphaMax - a2; + return ( ((a1*a2/gdAlphaMax) << 24) + + ((r1*r2/gdRedMax) << 16) + + ((g1*g2/gdGreenMax) << 8) + + ((b1*b2/gdBlueMax)) + ); +} + void gdImageSetClip (gdImagePtr im, int x1, int y1, int x2, int y2) { if (x1 < 0) { diff --git a/ext/gd/libgd/gd.h b/ext/gd/libgd/gd.h index 12832ded34..4b6f86e28c 100644 --- a/ext/gd/libgd/gd.h +++ b/ext/gd/libgd/gd.h @@ -92,6 +92,7 @@ void php_gd_error(const char *format, ...); #define gdEffectAlphaBlend 1 #define gdEffectNormal 2 #define gdEffectOverlay 3 +#define gdEffectMultiply 4 #define GD_TRUE 1 #define GD_FALSE 0 @@ -104,6 +105,8 @@ void php_gd_error(const char *format, ...); The resulting color is opaque. */ int gdAlphaBlend(int dest, int src); +int gdLayerOverlay(int dst, int src); +int gdLayerMultiply(int dest, int src); /** * Group: Transform