alphaBlend method Null safety
Blend the foreground
color over background
color and store the color
in result
.
Implementation
static void alphaBlend(
Vector4 foreground, Vector4 background, Vector4 result) {
final a = foreground.a + (1.0 - foreground.a) * background.a;
final factor = 1.0 / a;
final r = factor *
(foreground.a * foreground.r +
(1.0 - foreground.a) * background.a * background.r);
final g = factor *
(foreground.a * foreground.g +
(1.0 - foreground.a) * background.a * background.g);
final b = factor *
(foreground.a * foreground.b +
(1.0 - foreground.a) * background.a * background.b);
result.setValues(r, g, b, a);
}