diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 692497d186f..b726aab10cd 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -3025,7 +3025,7 @@ PHP_FUNCTION(imagegammacorrect) zval *IM; gdImagePtr im; int i; - double input, output; + double input, output, gamma; if (zend_parse_parameters(ZEND_NUM_ARGS(), "rdd", &IM, &input, &output) == FAILURE) { return; @@ -3036,6 +3036,8 @@ PHP_FUNCTION(imagegammacorrect) RETURN_FALSE; } + gamma = input / output; + if ((im = (gdImagePtr)zend_fetch_resource(Z_RES_P(IM), "Image", le_gd)) == NULL) { RETURN_FALSE; } @@ -3048,9 +3050,9 @@ PHP_FUNCTION(imagegammacorrect) c = gdImageGetPixel(im, x, y); gdImageSetPixel(im, x, y, gdTrueColorAlpha( - (int) ((pow((pow((gdTrueColorGetRed(c) / 255.0), input)), 1.0 / output) * 255) + .5), - (int) ((pow((pow((gdTrueColorGetGreen(c) / 255.0), input)), 1.0 / output) * 255) + .5), - (int) ((pow((pow((gdTrueColorGetBlue(c) / 255.0), input)), 1.0 / output) * 255) + .5), + (int) ((pow((gdTrueColorGetRed(c) / 255.0), gamma) * 255) + .5), + (int) ((pow((gdTrueColorGetGreen(c) / 255.0), gamma) * 255) + .5), + (int) ((pow((gdTrueColorGetBlue(c) / 255.0), gamma) * 255) + .5), gdTrueColorGetAlpha(c) ) ); @@ -3060,9 +3062,9 @@ PHP_FUNCTION(imagegammacorrect) } for (i = 0; i < gdImageColorsTotal(im); i++) { - im->red[i] = (int)((pow((pow((im->red[i] / 255.0), input)), 1.0 / output) * 255) + .5); - im->green[i] = (int)((pow((pow((im->green[i] / 255.0), input)), 1.0 / output) * 255) + .5); - im->blue[i] = (int)((pow((pow((im->blue[i] / 255.0), input)), 1.0 / output) * 255) + .5); + im->red[i] = (int)((pow((im->red[i] / 255.0), gamma) * 255) + .5); + im->green[i] = (int)((pow((im->green[i] / 255.0), gamma) * 255) + .5); + im->blue[i] = (int)((pow((im->blue[i] / 255.0), gamma) * 255) + .5); } RETURN_TRUE; diff --git a/ext/gd/tests/imagegammacorrect_variation2.phpt b/ext/gd/tests/imagegammacorrect_variation2.phpt new file mode 100644 index 00000000000..4a317b5d906 --- /dev/null +++ b/ext/gd/tests/imagegammacorrect_variation2.phpt @@ -0,0 +1,72 @@ +--TEST-- +Apply imagegammacorrect() to a step wedge +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECT-- +palette gamma (1, 2): The images are equal. +truecolor gamma (1, 2): The images are equal. +palette gamma (1, 1): The images are equal. +truecolor gamma (1, 1): The images are equal. +palette gamma (2, 1): The images are equal. +truecolor gamma (2, 1): The images are equal. +===DONE=== diff --git a/ext/gd/tests/imagegammacorrect_variation2_1_1.png b/ext/gd/tests/imagegammacorrect_variation2_1_1.png new file mode 100644 index 00000000000..517010b42ff Binary files /dev/null and b/ext/gd/tests/imagegammacorrect_variation2_1_1.png differ diff --git a/ext/gd/tests/imagegammacorrect_variation2_1_2.png b/ext/gd/tests/imagegammacorrect_variation2_1_2.png new file mode 100644 index 00000000000..9b9d7f04a6c Binary files /dev/null and b/ext/gd/tests/imagegammacorrect_variation2_1_2.png differ diff --git a/ext/gd/tests/imagegammacorrect_variation2_2_1.png b/ext/gd/tests/imagegammacorrect_variation2_2_1.png new file mode 100644 index 00000000000..f7384be913a Binary files /dev/null and b/ext/gd/tests/imagegammacorrect_variation2_2_1.png differ