From 2912d78b945ba915297ec2f1fd38dd104c06a279 Mon Sep 17 00:00:00 2001 From: askmeaboutloom Date: Sat, 29 Jul 2023 07:54:34 +0200 Subject: [PATCH] Avoid colors tending toward black when smudging By adding a fudge factor. Not too sure why it happens in the first place, since we round things properly, but this seems to be a fix for anything going wrong in that regard. Maybe just an artifact of the algorithm or caused by the inaccuracy of the 8 bit protocol that we have to compensate for. --- extern/drawdance/libengine/dpengine/layer_content.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/extern/drawdance/libengine/dpengine/layer_content.c b/extern/drawdance/libengine/dpengine/layer_content.c index b40192a49..c4f984e9a 100644 --- a/extern/drawdance/libengine/dpengine/layer_content.c +++ b/extern/drawdance/libengine/dpengine/layer_content.c @@ -415,9 +415,12 @@ static DP_UPixelFloat sample_dab_color(DP_LayerContent *lc, DP_BrushStamp stamp) alpha /= weight; // Unpremultiply, clamp against rounding error. - red = CLAMP(red / alpha, 0.0f, 1.0f); - green = CLAMP(green / alpha, 0.0f, 1.0f); - blue = CLAMP(blue / alpha, 0.0f, 1.0f); + // The fudge factor avoids smudging causing the color to tend toward black. + // Not entirely sure why that happens, but fudging fixes it, so whatever. + float fudge = 0.005f; + red = CLAMP(red / alpha + fudge, 0.0f, 1.0f); + green = CLAMP(green / alpha + fudge, 0.0f, 1.0f); + blue = CLAMP(blue / alpha + fudge, 0.0f, 1.0f); return (DP_UPixelFloat){ .b = blue,