[Bf-blender-cvs] [d23459f516] master: Fix T51038: `layerInterp_mloopcol` was casting instead of rounding the interpolated RGBA channels
Germano Cavalcante
noreply at git.blender.org
Fri Mar 24 08:06:57 CET 2017
Commit: d23459f5164092fb59cd952da6ddd8c0d23170d4
Author: Germano Cavalcante
Date: Fri Mar 24 04:06:30 2017 -0300
Branches: master
https://developer.blender.org/rBd23459f5164092fb59cd952da6ddd8c0d23170d4
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.
===================================================================
M source/blender/blenkernel/intern/customdata.c
===================================================================
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index c9f0b8ec9c..aca332f4bf 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)
More information about the Bf-blender-cvs
mailing list