alphaBlend method

void alphaBlend (
  1. Vector4 foreground,
  2. Vector4 background,
  3. Vector4 result
)

Blend the foreground color over background color and store the color in result.

Implementation

static void alphaBlend(
    Vector4 foreground, Vector4 background, Vector4 result) {
  final double a = foreground.a + (1.0 - foreground.a) * background.a;
  final double factor = 1.0 / a;

  final double r = factor *
      (foreground.a * foreground.r +
          (1.0 - foreground.a) * background.a * background.r);
  final double g = factor *
      (foreground.a * foreground.g +
          (1.0 - foreground.a) * background.a * background.g);
  final double b = factor *
      (foreground.a * foreground.b +
          (1.0 - foreground.a) * background.a * background.b);

  result.setValues(r, g, b, a);
}