From cb2fc7ec900adfe026788bc9f6b29aca34a2eaf3 Mon Sep 17 00:00:00 2001 From: askmeaboutloom Date: Tue, 1 Aug 2023 21:29:40 +0200 Subject: [PATCH] Don't truncate color sampling mask to 8 bits It's a 15 bit mask, so this was nonsense. Fixes the issues with smudge colors going lighter or darker that required a fudge factor to be applied. --- extern/drawdance/libengine/dpengine/layer_content.c | 9 +++------ extern/drawdance/libengine/dpengine/paint.c | 5 +++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/extern/drawdance/libengine/dpengine/layer_content.c b/extern/drawdance/libengine/dpengine/layer_content.c index 43a133e1d..12fb1849c 100644 --- a/extern/drawdance/libengine/dpengine/layer_content.c +++ b/extern/drawdance/libengine/dpengine/layer_content.c @@ -416,12 +416,9 @@ static DP_UPixelFloat sample_dab_color(DP_LayerContent *lc, DP_BrushStamp stamp, alpha /= weight; // Unpremultiply, clamp against rounding error. - // 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); + red = CLAMP(red / alpha, 0.0f, 1.0f); + green = CLAMP(green / alpha, 0.0f, 1.0f); + blue = CLAMP(blue / alpha, 0.0f, 1.0f); return (DP_UPixelFloat){ .b = blue, diff --git a/extern/drawdance/libengine/dpengine/paint.c b/extern/drawdance/libengine/dpengine/paint.c index 48f14c3e7..197daa588 100644 --- a/extern/drawdance/libengine/dpengine/paint.c +++ b/extern/drawdance/libengine/dpengine/paint.c @@ -1059,8 +1059,9 @@ DP_BrushStamp DP_paint_color_sampling_stamp_make(uint16_t *data, int diameter, for (int x = 0; x < diameter; ++x) { double dist = (DP_square_double(x - radius) + yy) * lut_scale; int i = DP_double_to_int(dist); - *d = i < CLASSIC_LUT_SIZE ? DP_float_to_uint8(DP_BIT15 * lut[i]) - : 0; + *d = i < CLASSIC_LUT_SIZE + ? DP_float_to_uint16(DP_BIT15 * lut[i]) + : 0; ++d; } }