diff options
author | Germano Cavalcante <germano.costa@ig.com.br> | 2017-03-24 10:06:30 +0300 |
---|---|---|
committer | Germano Cavalcante <germano.costa@ig.com.br> | 2017-03-24 10:06:30 +0300 |
commit | d23459f5164092fb59cd952da6ddd8c0d23170d4 (patch) | |
tree | dc4ca556d04bbe2189a6d0749922f6dc0ba9b8d5 /source | |
parent | bc0b5d611c8bac1923f06dbcf9945e97c223b7c2 (diff) |
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.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/intern/customdata.c | 23 |
1 files changed, 10 insertions, 13 deletions
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) |