compositeOver static method
Alpha-composites foreground over an opaque background, returning
the resulting opaque color. Returns foreground unchanged if it is
already opaque.
Implementation
static Color compositeOver(Color foreground, Color background) {
final alpha = foreground.a;
if (alpha >= 1.0) return foreground;
final inverse = 1.0 - alpha;
return Color.from(
alpha: 1.0,
red: foreground.r * alpha + background.r * inverse,
green: foreground.g * alpha + background.g * inverse,
blue: foreground.b * alpha + background.b * inverse,
);
}