pub trait Desaturate {
type Scalar;
// Required methods
fn desaturate(self, factor: Self::Scalar) -> Self;
fn desaturate_fixed(self, amount: Self::Scalar) -> Self;
}
Expand description
Operator for decreasing the saturation (or chroma) of a color.
The trait’s functions are split into two groups of functions: relative and fixed/absolute.
The relative function, desaturate
, scales the
saturation towards the minimum saturation value. This means that for a color
with 50% saturation, if desaturate(0.5)
is applied to it, the color will
scale halfway to the minimum value of 0% resulting in a new saturation value
of 25%.
The fixed or absolute function,
desaturate_fixed
, decreases the saturation
by an amount that is independent of the current saturation of the color. So
for a color with 50% saturation, if desaturate_fixed(0.5)
is applied to
it, the color will have 50% saturation removed from its saturation value
resulting in a new value of 0%.
See also DesaturateAssign
, Saturate
and SaturateAssign
.
use approx::assert_relative_eq;
use palette::{Hsv, Desaturate};
let a = Hsv::new_srgb(0.0, 0.5, 1.0);
assert_relative_eq!(a.desaturate(0.5).saturation, 0.25);
assert_relative_eq!(a.desaturate_fixed(0.5).saturation, 0.0);
Required Associated Types§
Required Methods§
sourcefn desaturate(self, factor: Self::Scalar) -> Self
fn desaturate(self, factor: Self::Scalar) -> Self
Scale the color towards the minimum saturation by factor
, a value
ranging from 0.0
to 1.0
.
use approx::assert_relative_eq;
use palette::{Hsv, Desaturate};
let color = Hsv::new_srgb(0.0, 0.5, 0.5);
assert_relative_eq!(color.desaturate(0.5).saturation, 0.25);
sourcefn desaturate_fixed(self, amount: Self::Scalar) -> Self
fn desaturate_fixed(self, amount: Self::Scalar) -> Self
Increase the saturation by amount
, a value ranging from 0.0
to
1.0
.
use approx::assert_relative_eq;
use palette::{Hsv, Desaturate};
let color = Hsv::new_srgb(0.0, 0.4, 0.5);
assert_relative_eq!(color.desaturate_fixed(0.2).saturation, 0.2);