summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPierre Joye <pierre.php@gmail.com>2021-08-25 09:48:09 +0700
committerGitHub <noreply@github.com>2021-08-25 09:48:09 +0700
commita24e96f01989bf9ca05a08d33862a08d6f4c4ed6 (patch)
tree74daa07aaa30d4c226da1f3da11ec8e166357eb3
parentdd6c6c6410b3b572ecdd522e85aa049113677020 (diff)
parent49ecef1bf4c1982831e1a39f00ab437ed03e2a2e (diff)
downloadlibgd-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.c20
-rw-r--r--tests/gdimagecopyresampled/basic_alpha_exp.pngbin2668 -> 2691 bytes
-rw-r--r--tests/gdimagecopyresampled/basic_exp.pngbin2144 -> 2104 bytes
-rw-r--r--tests/gdimagecopyresampled/bug00201_exp.pngbin11853 -> 9412 bytes
4 files changed, 6 insertions, 14 deletions
diff --git a/src/gd.c b/src/gd.c
index aea8015..51d87d1 100644
--- a/src/gd.c
+++ b/src/gd.c
@@ -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
index 29dfc27..4bfda78 100644
--- a/tests/gdimagecopyresampled/basic_alpha_exp.png
+++ b/tests/gdimagecopyresampled/basic_alpha_exp.png
Binary files differ
diff --git a/tests/gdimagecopyresampled/basic_exp.png b/tests/gdimagecopyresampled/basic_exp.png
index dccc2f9..0afa1b1 100644
--- a/tests/gdimagecopyresampled/basic_exp.png
+++ b/tests/gdimagecopyresampled/basic_exp.png
Binary files differ
diff --git a/tests/gdimagecopyresampled/bug00201_exp.png b/tests/gdimagecopyresampled/bug00201_exp.png
index 9ffe155..92fa30e 100644
--- a/tests/gdimagecopyresampled/bug00201_exp.png
+++ b/tests/gdimagecopyresampled/bug00201_exp.png
Binary files differ