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.
This commit is contained in:
Germano Cavalcante 2017-03-24 04:06:30 -03:00
parent bc0b5d611c
commit d23459f516
Notes: blender-bot 2023-02-14 07:07:16 +01:00
Referenced by commit a6f74453b6, Fix unreported: inaccuracy of interpolation of custom color layers due to float truncation
Referenced by issue #51038, Decimate causes errors with vertex colour data
1 changed files with 10 additions and 13 deletions

View File

@ -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)