diff options
author | Pierre Joye <pierre.php@gmail.com> | 2021-08-25 09:48:09 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-25 09:48:09 +0700 |
commit | a24e96f01989bf9ca05a08d33862a08d6f4c4ed6 (patch) | |
tree | 74daa07aaa30d4c226da1f3da11ec8e166357eb3 | |
parent | dd6c6c6410b3b572ecdd522e85aa049113677020 (diff) | |
parent | 49ecef1bf4c1982831e1a39f00ab437ed03e2a2e (diff) | |
download | libgd-a24e96f01989bf9ca05a08d33862a08d6f4c4ed6.tar.gz |
Merge pull request #735 from libgd/bug/661
fix #661, restore correct clamping, fixing alpha artifacts (these ones ar…
-rw-r--r-- | src/gd.c | 20 | ||||
-rw-r--r-- | tests/gdimagecopyresampled/basic_alpha_exp.png | bin | 2668 -> 2691 bytes | |||
-rw-r--r-- | tests/gdimagecopyresampled/basic_exp.png | bin | 2144 -> 2104 bytes | |||
-rw-r--r-- | tests/gdimagecopyresampled/bug00201_exp.png | bin | 11853 -> 9412 bytes |
4 files changed, 6 insertions, 14 deletions
@@ -3539,20 +3539,12 @@ BGD_DECLARE(void) gdImageCopyResampled (gdImagePtr dst, green /= alpha_sum; blue /= alpha_sum; } - /* Clamping to allow for rounding errors above */ - if (red > 255.0) { - red = 255.0; - } - if (green > 255.0) { - green = 255.0; - } - if (blue > 255.0f) { - blue = 255.0; - } - if (alpha > gdAlphaMax) { - alpha = gdAlphaMax; - } - gdImageSetPixel(dst, x, y, gdTrueColorAlpha ((int) red, (int) green, (int) blue, (int) alpha)); + /* Round up closest next channel value and clamp to max channel value */ + red = red >= 255.5 ? 255 : red+0.5; + blue = blue >= 255.5 ? 255 : blue+0.5; + green = green >= 255.5 ? 255 : green+0.5; + alpha = alpha >= gdAlphaMax+0.5 ? 255 : alpha+0.5; + gdImageSetPixel(dst, x, y, gdTrueColorAlpha ((int)red, (int)green, (int)blue, (int)alpha)); } } } diff --git a/tests/gdimagecopyresampled/basic_alpha_exp.png b/tests/gdimagecopyresampled/basic_alpha_exp.png Binary files differindex 29dfc27..4bfda78 100644 --- a/tests/gdimagecopyresampled/basic_alpha_exp.png +++ b/tests/gdimagecopyresampled/basic_alpha_exp.png diff --git a/tests/gdimagecopyresampled/basic_exp.png b/tests/gdimagecopyresampled/basic_exp.png Binary files differindex dccc2f9..0afa1b1 100644 --- a/tests/gdimagecopyresampled/basic_exp.png +++ b/tests/gdimagecopyresampled/basic_exp.png diff --git a/tests/gdimagecopyresampled/bug00201_exp.png b/tests/gdimagecopyresampled/bug00201_exp.png Binary files differindex 9ffe155..92fa30e 100644 --- a/tests/gdimagecopyresampled/bug00201_exp.png +++ b/tests/gdimagecopyresampled/bug00201_exp.png |