Commit 4c3a772c authored by Ell's avatar Ell
Browse files

app: fix SRC_OVER composite mode

When the source alpha is zero, we don't calculate the blended color,
so `comp[b]` can be infinite or NaN, in which case the expression
`in[ALPHA] * (comp[b] - layer[b])` is NaN, rather than the expected
value of zero.
parent bed63c6b
......@@ -547,12 +547,13 @@ compfun_src_over (gfloat *in,
while (samples--)
{
gfloat new_alpha;
gfloat in_alpha = in[ALPHA];
gfloat layer_alpha = layer[ALPHA] * opacity;
if (mask)
layer_alpha *= *mask;
new_alpha = layer_alpha + (1.0f - layer_alpha) * in[ALPHA];
new_alpha = layer_alpha + (1.0f - layer_alpha) * in_alpha;
if (layer_alpha == 0.0f || new_alpha == 0.0f)
{
......@@ -560,13 +561,19 @@ compfun_src_over (gfloat *in,
out[GREEN] = in[GREEN];
out[BLUE] = in[BLUE];
}
else if (in_alpha == 0.0f)
{
out[RED] = layer[RED];
out[GREEN] = layer[GREEN];
out[BLUE] = layer[BLUE];
}
else
{
gfloat ratio = layer_alpha / new_alpha;
gint b;
for (b = RED; b < ALPHA; b++)
out[b] = ratio * (in[ALPHA] * (comp[b] - layer[b]) + layer[b] - in[b]) + in[b];
out[b] = ratio * (in_alpha * (comp[b] - layer[b]) + layer[b] - in[b]) + in[b];
}
out[ALPHA] = new_alpha;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment