Function sourceOver

Places a premultiplied linear-light source over a destination.

Premultiplied!(LinearSRgb!T) sourceOver(T)(
  Premultiplied!(LinearSRgb!T) source,
  Premultiplied!(LinearSRgb!T) destination
) pure nothrow @nogc @safe;

Use this for ordinary Porter-Duff source-over compositing after both colors have been converted to premultiplied linear-light sRGB. The operation does not validate or clamp alpha, clip RGB, gamut-map, convert color spaces, or infer a background.

Parameters

NameDescription
source Premultiplied foreground color.
destination Premultiplied background color.

Returns

The premultiplied source-over result.

Standards

Porter-Duff source-over compositing.

Example

import color.alpha : Alpha, premultiply;
import color.rgb : LinearSRgbf;

const source = premultiply(
    Alpha!LinearSRgbf(
        LinearSRgbf(0.0f, 0.0f, 1.0f),
        0.5f
    )
);

const destination = premultiply(
    Alpha!LinearSRgbf(
        LinearSRgbf(1.0f, 0.0f, 0.0f),
        1.0f
    )
);

const result = sourceOver(source, destination);

assert(result.color == LinearSRgbf(0.5f, 0.0f, 0.5f));
assert(result.alpha == 1.0f);