Skip to content

premultiply

Multiplies the color channels by the alpha, the form a renderer composites with (a translucent color then adds to what is underneath without a further multiplication). Channels are rounded to 8 bits, so unpremultiply gives back the original only approximately for translucent colors, and not at all for alpha 0.

use helpers4::color::premultiply;

Cargo feature color (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features color

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.11", default-features = false, features = ["color"] }
pub fn premultiply(color: Rgba) -> Rgba
ParameterTypeDescription
colorRgbaThe straight color.

Rgba — The premultiplied color, with the same alpha.

use helpers4::color::{premultiply, Rgba};

assert_eq!(premultiply(Rgba::new(200, 100, 50, 128)), Rgba::new(100, 50, 25, 128));
assert_eq!(premultiply(Rgba::new(200, 100, 50, 255)), Rgba::new(200, 100, 50, 255));

src/color/premultiply.rs