From d23459f5164092fb59cd952da6ddd8c0d23170d4 Mon Sep 17 00:00:00 2001 From: Germano Cavalcante Date: Fri, 24 Mar 2017 04:06:30 -0300 Subject: Fix T51038: `layerInterp_mloopcol` was casting instead of rounding the interpolated RGBA channels Casting to int truncates a floating-point number, that is, it loose the fractional part. --- source/blender/blenkernel/intern/customdata.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'source') diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index c9f0b8ec9ca..aca332f4bf5 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -805,18 +805,15 @@ static void layerInterp_mloopcol( const float *sub_weights, int count, void *dest) { MLoopCol *mc = dest; - int i; - const float *sub_weight; struct { float a; float r; float g; float b; - } col; - col.a = col.r = col.g = col.b = 0; + } col = {0}; - sub_weight = sub_weights; - for (i = 0; i < count; ++i) { + const float *sub_weight = sub_weights; + for (int i = 0; i < count; ++i) { float weight = weights ? weights[i] : 1; const MLoopCol *src = sources[i]; if (sub_weights) { @@ -833,19 +830,19 @@ static void layerInterp_mloopcol( col.a += src->a * weight; } } - + + /* delay writing to the destination incase dest is in sources */ + mc->r = iroundf(col.r); + mc->g = iroundf(col.g); + mc->b = iroundf(col.b); + mc->a = iroundf(col.a); + /* Subdivide smooth or fractal can cause problems without clamping * although weights should also not cause this situation */ CLAMP(col.a, 0.0f, 255.0f); CLAMP(col.r, 0.0f, 255.0f); CLAMP(col.g, 0.0f, 255.0f); CLAMP(col.b, 0.0f, 255.0f); - - /* delay writing to the destination incase dest is in sources */ - mc->r = (int)col.r; - mc->g = (int)col.g; - mc->b = (int)col.b; - mc->a = (int)col.a; } static int layerMaxNum_mloopcol(void) -- cgit v1.2.3