From 576e579925d205a44dd347fca3646f5c749a60a6 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Tue, 30 Apr 2013 16:07:52 +0000 Subject: More painting fixes: * 2D image painting with textures that contained alpha did not work correctly, had been broken for a while. * 2D image panels texture (mask) panels showed wrong buttons for texture overlay. * Texture map mode 3D now also uses masking, like Tiled and Stencil the texture does not move along with the brush so it works fine. * 2D image paint View mapping did not work correct, especially noticeable with Rake rotation. * Masking is now disabled for the smear tool, this can't really work because the original image is constantly changing and gave artifacts. --- .../blenlib/intern/math_color_blend_inline.c | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'source/blender/blenlib/intern/math_color_blend_inline.c') diff --git a/source/blender/blenlib/intern/math_color_blend_inline.c b/source/blender/blenlib/intern/math_color_blend_inline.c index 121750fe919..52947fcee08 100644 --- a/source/blender/blenlib/intern/math_color_blend_inline.c +++ b/source/blender/blenlib/intern/math_color_blend_inline.c @@ -242,6 +242,28 @@ MINLINE void blend_color_add_alpha_byte(unsigned char dst[4], const unsigned cha } } +MINLINE void blend_color_interpolate_byte(unsigned char dst[4], const unsigned char src1[4], const unsigned char src2[4], float ft) +{ + /* do color interpolation, but in premultiplied space so that RGB colors + * from zero alpha regions have no influence */ + const int t = (int)(255 * ft); + const int mt = 255 - t; + int tmp = (mt * src1[3] + t * src2[3]); + + if (tmp > 0) { + dst[0] = divide_round_i(mt * src1[0] * src1[3] + t * src2[0] * src2[3], tmp); + dst[1] = divide_round_i(mt * src1[1] * src1[3] + t * src2[1] * src2[3], tmp); + dst[2] = divide_round_i(mt * src1[2] * src1[3] + t * src2[2] * src2[3], tmp); + dst[3] = divide_round_i(tmp, 255); + } + else { + dst[0] = src1[0]; + dst[1] = src1[1]; + dst[2] = src1[2]; + dst[3] = src1[3]; + } +} + /* premultiplied alpha float blending modes */ MINLINE void blend_color_mix_float(float dst[4], const float src1[4], const float src2[4]) @@ -420,4 +442,15 @@ MINLINE void blend_color_add_alpha_float(float dst[4], const float src1[4], cons } } +MINLINE void blend_color_interpolate_float(float dst[4], const float src1[4], const float src2[4], float t) +{ + /* interpolation, colors are premultiplied so it goes fine */ + float mt = 1.0f - t; + + dst[0] = mt * src1[0] + t * src2[0]; + dst[1] = mt * src1[1] + t * src2[1]; + dst[2] = mt * src1[2] + t * src2[2]; + dst[3] = mt * src1[3] + t * src2[3]; +} + #endif /* __MATH_COLOR_BLEND_INLINE_C__ */ -- cgit v1.2.3