Skip to main content

AdaptFromUnclamped

Trait AdaptFromUnclamped 

Source
pub trait AdaptFromUnclamped<T>: Sized {
    type Scalar;

    // Required method
    fn adapt_from_unclamped_with<M>(input: T) -> Self
       where M: LmsToXyz<Self::Scalar> + XyzToLms<Self::Scalar>;

    // Provided method
    fn adapt_from_unclamped(input: T) -> Self
       where Bradford: LmsToXyz<Self::Scalar> + XyzToLms<Self::Scalar> { ... }
}
Expand description

A trait for unchecked conversion of one color from another via chromatic adaptation.

See FromColor, TryFromColor and FromColorUnclamped for when there’s no need for chromatic adaptation.

Some conversions require the reference white point to be changed, while maintaining the appearance of the color. This is called “chromatic adaptation” or “white balancing”, and typically involves converting the color to the Lms color space. This trait defaults to using the Bradford matrix as part of the process, but other options are available in lms::matrix.

The adaptation_matrix function offers more options and control. This trait can be a convenient alternative when the source and destination white points are statically known.

Required Associated Types§

Source

type Scalar

The number type that’s used as the color’s components.

Required Methods§

Source

fn adapt_from_unclamped_with<M>(input: T) -> Self
where M: LmsToXyz<Self::Scalar> + XyzToLms<Self::Scalar>,

Adapt a color of type T into a color of type Self, using the custom matrix M.

use palette::{
    Xyz, white_point::{A, C}, lms::matrix::VonKries,
    chromatic_adaptation::AdaptFromUnclamped,
};

let input = Xyz::<A, f32>::new(0.315756, 0.162732, 0.015905);

//Will convert Xyz<A, f32> to Xyz<C, f32> using von Kries chromatic adaptation:
let output = Xyz::<C, f32>::adapt_from_unclamped_with::<VonKries>(input);

Provided Methods§

Source

fn adapt_from_unclamped(input: T) -> Self
where Bradford: LmsToXyz<Self::Scalar> + XyzToLms<Self::Scalar>,

Adapt a color of type T into a color of type Self, using the Bradford matrix.

use palette::{
    Xyz, white_point::{A, C},
    chromatic_adaptation::AdaptFromUnclamped,
};

let input = Xyz::<A, f32>::new(0.315756, 0.162732, 0.015905);

//Will convert Xyz<A, f32> to Xyz<C, f32> using Bradford chromatic adaptation:
let output = Xyz::<C, f32>::adapt_from_unclamped(input);

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§

Source§

impl<T, Wp1, Wp2> AdaptFromUnclamped<Xyz<Wp1, T>> for Xyz<Wp2, T>
where T: Zero + Arithmetics + Clone, Wp1: WhitePoint<T> + HasXyzMeta<XyzMeta = Wp1>, Wp2: WhitePoint<T> + HasXyzMeta<XyzMeta = Wp2>,