From 63f05576b840c597f91414fd2ca6db8ca869e3e9 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 30 Apr 2013 06:07:42 +0000 Subject: More image painting fixes: * 2D image painting support for masking to limit the max contribution of a stroke to a pixel, to get it working compatible with projection painting. Not strictly a bugfix, but the inconsistency here was annoying. * Fix python errors in Texture Mask panel in image editor, was missing overlay options. * Clamp paint mask to 0..1 in case some texture exceeds it, this could give black pixels due to integer overflow. --- .../blenlib/intern/math_color_blend_inline.c | 30 ++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'source/blender/blenlib/intern') diff --git a/source/blender/blenlib/intern/math_color_blend_inline.c b/source/blender/blenlib/intern/math_color_blend_inline.c index 94a474da681..121750fe919 100644 --- a/source/blender/blenlib/intern/math_color_blend_inline.c +++ b/source/blender/blenlib/intern/math_color_blend_inline.c @@ -372,12 +372,17 @@ MINLINE void blend_color_erase_alpha_float(float dst[4], const float src1[4], co { if (src2[3] != 0.0f && src1[3] > 0.0f) { /* subtract alpha and remap RGB channels to match */ - const float alpha = max_ff(src1[3] - src2[3], 0.0f); - const float map_alpha = alpha / src1[3]; + float alpha = max_ff(src1[3] - src2[3], 0.0f); + float map_alpha; - dst[0] *= map_alpha; - dst[1] *= map_alpha; - dst[2] *= map_alpha; + if (alpha <= 0.0005f) + alpha = 0.0f; + + map_alpha = alpha / src1[3]; + + dst[0] = src1[0] * map_alpha; + dst[1] = src1[1] * map_alpha; + dst[2] = src1[2] * map_alpha; dst[3] = alpha; } else { @@ -393,12 +398,17 @@ MINLINE void blend_color_add_alpha_float(float dst[4], const float src1[4], cons { if (src2[3] != 0.0f && src1[3] < 1.0f) { /* add alpha and remap RGB channels to match */ - const float alpha = min_ff(src1[3] + src2[3], 1.0f); - const float map_alpha = (src1[3] > 0.0f) ? alpha / src1[3] : 1.0f; + float alpha = min_ff(src1[3] + src2[3], 1.0f); + float map_alpha; + + if (alpha >= 1.0f - 0.0005f) + alpha = 1.0f; + + map_alpha = (src1[3] > 0.0f) ? alpha / src1[3] : 1.0f; - dst[0] *= map_alpha; - dst[1] *= map_alpha; - dst[2] *= map_alpha; + dst[0] = src1[0] * map_alpha; + dst[1] = src1[1] * map_alpha; + dst[2] = src1[2] * map_alpha; dst[3] = alpha; } else { -- cgit v1.2.3