Skip to content

unpremultiply

Divides the color channels by the alpha, the inverse of premultiply. A fully transparent color (alpha 0) holds no color, so it gives transparent black. Channels are clamped to 255 and rounded to 8 bits.

use helpers4::color::unpremultiply;

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 unpremultiply(color: Rgba) -> Rgba
ParameterTypeDescription
colorRgbaThe premultiplied color.

Rgba — The straight color, with the same alpha.

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

assert_eq!(unpremultiply(Rgba::new(100, 50, 25, 128)), Rgba::new(199, 100, 50, 128));
assert_eq!(unpremultiply(Rgba::new(9, 9, 9, 0)), Rgba::new(0, 0, 0, 0));

src/color/unpremultiply.rs