palette

Trait Saturate

source
pub trait Saturate {
    type Scalar;

    // Required methods
    fn saturate(self, factor: Self::Scalar) -> Self;
    fn saturate_fixed(self, amount: Self::Scalar) -> Self;
}
Expand description

Operator for increasing 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, saturate, scales the saturation towards the maximum saturation value. This means that for a color with 50% saturation, if saturate(0.5) is applied to it, the color will scale halfway to the maximum value of 100% resulting in a new saturation value of 75%.

The fixed or absolute function, saturate_fixed, increases the saturation by an amount that is independent of the current saturation of the color. So for a color with 50% saturation, if saturate_fixed(0.5) is applied to it, the color will have 50% saturation added to its saturation value resulting in a new value of 100%.

See also SaturateAssign, Desaturate and DesaturateAssign.

use approx::assert_relative_eq;
use palette::{Hsv, Saturate};

let a = Hsv::new_srgb(0.0, 0.5, 1.0);

assert_relative_eq!(a.saturate(0.5).saturation, 0.75);
assert_relative_eq!(a.saturate_fixed(0.5).saturation, 1.0);

Required Associated Types§

source

type Scalar

The type of the saturation modifier.

Required Methods§

source

fn saturate(self, factor: Self::Scalar) -> Self

Scale the color towards the maximum saturation by factor, a value ranging from 0.0 to 1.0.

use approx::assert_relative_eq;
use palette::{Hsl, Saturate};

let color = Hsl::new_srgb(0.0, 0.5, 0.5);
assert_relative_eq!(color.saturate(0.5).saturation, 0.75);
source

fn saturate_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::{Hsl, Saturate};

let color = Hsl::new_srgb(0.0, 0.4, 0.5);
assert_relative_eq!(color.saturate_fixed(0.2).saturation, 0.6);

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<C: Saturate> Saturate for Alpha<C, C::Scalar>

source§

impl<S, T> Saturate for Hsl<S, T>

source§

impl<S, T> Saturate for Hsv<S, T>

source§

impl<T> Saturate for Cam16UcsJmh<T>

source§

impl<T> Saturate for Okhsl<T>

source§

impl<T> Saturate for Okhsv<T>

source§

impl<Wp, T> Saturate for Hsluv<Wp, T>

source§

impl<Wp, T> Saturate for Lch<Wp, T>

source§

impl<Wp, T> Saturate for Lchuv<Wp, T>