From 76e96e92cb7bd57b16afaab0dbdfda4cfbe81d3b Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Thu, 3 Jan 2019 15:13:40 +0100 Subject: [PATCH] nitpicker: avoid color bleeding This patch improves the output of opaque pixels in the presence of an alpha channel by adding a special case for the maximum alpha value. Fixes #2831 --- repos/os/include/nitpicker_gfx/texture_painter.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/repos/os/include/nitpicker_gfx/texture_painter.h b/repos/os/include/nitpicker_gfx/texture_painter.h index 74bf7bdab..471a61ef0 100644 --- a/repos/os/include/nitpicker_gfx/texture_painter.h +++ b/repos/os/include/nitpicker_gfx/texture_painter.h @@ -98,13 +98,15 @@ struct Texture_painter * Copy texture with alpha blending */ for (j = clipped.h(); j--; src += src_w, alpha += src_w, dst += dst_w) - for (i = clipped.w(), s = src, a = alpha, d = dst; i--; s++, d++, a++) - if (*a) - *d = PT::mix(*d, *s, *a); + for (i = clipped.w(), s = src, a = alpha, d = dst; i--; s++, d++, a++) { + unsigned char const alpha_value = *a; + if (__builtin_expect(alpha_value != 0, true)) + *d = PT::mix(*d, *s, alpha_value + 1); + } break; case MIXED: - + for (j = clipped.h(); j--; src += src_w, dst += dst_w) for (i = clipped.w(), s = src, d = dst; i--; s++, d++) *d = PT::avr(mix_pixel, *s);