Function unpremultiply
Converts a premultiplied result back to straight linear-light sRGB.
Alpha!(LinearSRgb!T) unpremultiply(T)(
Premultiplied!(LinearSRgb!T) value
) pure nothrow @nogc @safe;
Use this after compositing when a consumer needs straight alpha. For nonzero alpha, RGB coordinates are divided by alpha. At zero alpha the hidden straight RGB is unrecoverable, so the function returns transparent black.
Parameters
| Name | Description |
|---|---|
| value | Premultiplied linear-light sRGB value. |
Returns
The corresponding straight-alpha representation.
See Also
premultiply
Example
const premultiplied = Premultiplied!LinearSRgbf(
LinearSRgbf(0.25f, 0.625f, -0.125f),
0.5f
);
const straight = unpremultiply(premultiplied);
assert(straight .color == LinearSRgbf(0.5f, 1.25f, -0.25f));
assert(straight .alpha == 0.5f);
const transparent = unpremultiply(
Premultiplied!LinearSRgbf(
LinearSRgbf(1.0f, -2.0f, 3.0f),
0.0f
)
);
assert(transparent .color == LinearSRgbf(0.0f, 0.0f, 0.0f));
assert(transparent .alpha == 0.0f);