use core::marker::PhantomData;
use crate::{num::Real, white_point::Any, xyz::meta::HasXyzMeta, Mat3};
pub trait HasLmsMatrix {
type LmsMatrix;
}
pub trait XyzToLms<T> {
fn xyz_to_lms_matrix() -> Mat3<T>;
}
pub trait LmsToXyz<T> {
fn lms_to_xyz_matrix() -> Mat3<T>;
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct WithLmsMatrix<M, Matrix>(pub PhantomData<(M, Matrix)>);
impl<M, Matrix> HasXyzMeta for WithLmsMatrix<M, Matrix>
where
M: HasXyzMeta,
{
type XyzMeta = M::XyzMeta;
}
impl<M, Matrix> HasLmsMatrix for WithLmsMatrix<M, Matrix> {
type LmsMatrix = Matrix;
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct VonKries;
impl<T> XyzToLms<T> for VonKries
where
T: Real,
{
#[rustfmt::skip]
#[inline]
fn xyz_to_lms_matrix() -> Mat3<T> {
[
T::from_f64( 0.4002400), T::from_f64(0.7076000), T::from_f64(-0.0808100),
T::from_f64(-0.2263000), T::from_f64(1.1653200), T::from_f64( 0.0457000),
T::from_f64( 0.0000000), T::from_f64(0.0000000), T::from_f64( 0.9182200),
]
}
}
impl<T> LmsToXyz<T> for VonKries
where
T: Real,
{
#[rustfmt::skip]
#[inline]
fn lms_to_xyz_matrix() -> Mat3<T> {
[
T::from_f64(1.8599364), T::from_f64(-1.1293816), T::from_f64( 0.2198974),
T::from_f64(0.3611914), T::from_f64( 0.6388125), T::from_f64(-0.0000064),
T::from_f64(0.0000000), T::from_f64( 0.0000000), T::from_f64( 1.0890636),
]
}
}
impl HasXyzMeta for VonKries {
type XyzMeta = Any;
}
impl HasLmsMatrix for VonKries {
type LmsMatrix = Self;
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Bradford;
impl<T> XyzToLms<T> for Bradford
where
T: Real,
{
#[rustfmt::skip]
#[inline]
fn xyz_to_lms_matrix() -> Mat3<T> {
[
T::from_f64( 0.8951000), T::from_f64( 0.2664000), T::from_f64(-0.1614000),
T::from_f64(-0.7502000), T::from_f64( 1.7135000), T::from_f64( 0.0367000),
T::from_f64( 0.0389000), T::from_f64(-0.0685000), T::from_f64( 1.0296000),
]
}
}
impl<T> LmsToXyz<T> for Bradford
where
T: Real,
{
#[rustfmt::skip]
#[inline]
fn lms_to_xyz_matrix() -> Mat3<T> {
[
T::from_f64( 0.9869929), T::from_f64(-0.1470543), T::from_f64(0.1599627),
T::from_f64( 0.4323053), T::from_f64( 0.5183603), T::from_f64(0.0492912),
T::from_f64(-0.0085287), T::from_f64( 0.0400428), T::from_f64(0.9684867),
]
}
}
impl HasXyzMeta for Bradford {
type XyzMeta = Any;
}
impl HasLmsMatrix for Bradford {
type LmsMatrix = Self;
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct UnitMatrix;
impl<T> XyzToLms<T> for UnitMatrix
where
T: Real,
{
#[rustfmt::skip]
#[inline]
fn xyz_to_lms_matrix() -> Mat3<T> {
[
T::from_f64(1.0000000), T::from_f64(0.0000000), T::from_f64(0.0000000),
T::from_f64(0.0000000), T::from_f64(1.0000000), T::from_f64(0.0000000),
T::from_f64(0.0000000), T::from_f64(0.0000000), T::from_f64(1.0000000),
]
}
}
impl<T> LmsToXyz<T> for UnitMatrix
where
T: Real,
{
#[rustfmt::skip]
#[inline]
fn lms_to_xyz_matrix() -> Mat3<T> {
[
T::from_f64(1.0000000), T::from_f64(0.0000000), T::from_f64(0.0000000),
T::from_f64(0.0000000), T::from_f64(1.0000000), T::from_f64(0.0000000),
T::from_f64(0.0000000), T::from_f64(0.0000000), T::from_f64(1.0000000),
]
}
}
impl HasXyzMeta for UnitMatrix {
type XyzMeta = Any;
}
impl HasLmsMatrix for UnitMatrix {
type LmsMatrix = Self;
}