Skip to content

Commit a24e96f

Browse files
authored
Merge pull request #735 from libgd/bug/661
fix #661, restore correct clamping, fixing alpha artifacts (these ones ar…
2 parents dd6c6c6 + 49ecef1 commit a24e96f

File tree

4 files changed

+6
-14
lines changed

4 files changed

+6
-14
lines changed

src/gd.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3539,20 +3539,12 @@ BGD_DECLARE(void) gdImageCopyResampled (gdImagePtr dst,
35393539
green /= alpha_sum;
35403540
blue /= alpha_sum;
35413541
}
3542-
/* Clamping to allow for rounding errors above */
3543-
if (red > 255.0) {
3544-
red = 255.0;
3545-
}
3546-
if (green > 255.0) {
3547-
green = 255.0;
3548-
}
3549-
if (blue > 255.0f) {
3550-
blue = 255.0;
3551-
}
3552-
if (alpha > gdAlphaMax) {
3553-
alpha = gdAlphaMax;
3554-
}
3555-
gdImageSetPixel(dst, x, y, gdTrueColorAlpha ((int) red, (int) green, (int) blue, (int) alpha));
3542+
/* Round up closest next channel value and clamp to max channel value */
3543+
red = red >= 255.5 ? 255 : red+0.5;
3544+
blue = blue >= 255.5 ? 255 : blue+0.5;
3545+
green = green >= 255.5 ? 255 : green+0.5;
3546+
alpha = alpha >= gdAlphaMax+0.5 ? 255 : alpha+0.5;
3547+
gdImageSetPixel(dst, x, y, gdTrueColorAlpha ((int)red, (int)green, (int)blue, (int)alpha));
35563548
}
35573549
}
35583550
}
23 Bytes
Loading
-40 Bytes
Loading
-2.38 KB
Loading

0 commit comments

Comments
 (0)