Gamut

Trait Gamut 

Source
pub trait Gamut: Sized {
    // Required methods
    fn in_gamut(&self) -> bool;
    fn clamp_to_gamut(&self) -> Self;
    fn map_to_gamut(self) -> Self;
}
Expand description

Whether a colour is within the natural bounds of its colour space, and the ability to produce a naively clamped version or a perceptually gamut-mapped version.

CSS Color 4 12.1 and 13.1 state that out-of-gamut values must be preserved through intermediate computations. Gamut mapping (reducing to displayable range) only happens at “actual-value” / display time. This trait lets callers query and map when appropriate.

Required Methods§

Source

fn in_gamut(&self) -> bool

Returns true if all colour channels are within the natural bounds of this colour space. Alpha is not considered — it is always clamped on construction.

Source

fn clamp_to_gamut(&self) -> Self

Returns a copy with all colour channels naively clamped to the natural bounds.

This is simple per-channel clipping for fast but less perceptually pleasing results.

Source

fn map_to_gamut(self) -> Self

Perceptually maps this colour into gamut.

For RGB-based colour spaces this should use the ray trace algorithm in CSS Color 4 13.2, to casting a ray from an achromatic anchor toward the out-of-gamut colour and finding the intersection with the gamut’s RGB cube via the slab method.

Reference: https://facelessuser.github.io/coloraide/gamut/#ray-tracing-chroma-reduction CSS Color 4 spec: https://drafts.csswg.org/css-color-4/#pseudo-raytrace

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§