Skip to content

Commit d00987f

Browse files
committed
Implement LMS
1 parent 148f406 commit d00987f

File tree

11 files changed

+845
-52
lines changed

11 files changed

+845
-52
lines changed

palette/src/chromatic_adaptation.rs

+10-30
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
2727
use crate::{
2828
convert::{FromColorUnclamped, IntoColorUnclamped},
29+
lms::{
30+
self,
31+
meta::{LmsToXyz, XyzToLms},
32+
},
2933
matrix::{multiply_3x3, multiply_xyz, Mat3},
3034
num::{Arithmetics, Real, Zero},
3135
white_point::{Any, WhitePoint},
@@ -95,44 +99,20 @@ where
9599
match *self {
96100
Method::Bradford => {
97101
ConeResponseMatrices::<T> {
98-
ma: [
99-
T::from_f64(0.8951000), T::from_f64(0.2664000), T::from_f64(-0.1614000),
100-
T::from_f64(-0.7502000), T::from_f64(1.7135000), T::from_f64(0.0367000),
101-
T::from_f64(0.0389000), T::from_f64(-0.0685000), T::from_f64(1.0296000)
102-
],
103-
inv_ma: [
104-
T::from_f64(0.9869929), T::from_f64(-0.1470543), T::from_f64(0.1599627),
105-
T::from_f64(0.4323053), T::from_f64(0.5183603), T::from_f64(0.0492912),
106-
T::from_f64(-0.0085287), T::from_f64(0.0400428), T::from_f64(0.9684867)
107-
],
102+
ma: lms::meta::Bradford::xyz_to_lms_matrix(),
103+
inv_ma: lms::meta::Bradford::lms_to_xyz_matrix(),
108104
}
109105
}
110106
Method::VonKries => {
111107
ConeResponseMatrices::<T> {
112-
ma: [
113-
T::from_f64(0.4002400), T::from_f64(0.7076000), T::from_f64(-0.0808100),
114-
T::from_f64(-0.2263000), T::from_f64(1.1653200), T::from_f64(0.0457000),
115-
T::from_f64(0.0000000), T::from_f64(0.0000000), T::from_f64(0.9182200)
116-
],
117-
inv_ma: [
118-
T::from_f64(1.8599364), T::from_f64(-1.1293816), T::from_f64(0.2198974),
119-
T::from_f64(0.3611914), T::from_f64(0.6388125), T::from_f64(-0.0000064),
120-
T::from_f64(0.0000000), T::from_f64(0.0000000), T::from_f64(1.0890636)
121-
],
108+
ma: lms::meta::VonKries::xyz_to_lms_matrix(),
109+
inv_ma: lms::meta::VonKries::lms_to_xyz_matrix(),
122110
}
123111
}
124112
Method::XyzScaling => {
125113
ConeResponseMatrices::<T> {
126-
ma: [
127-
T::from_f64(1.0000000), T::from_f64(0.0000000), T::from_f64(0.0000000),
128-
T::from_f64(0.0000000), T::from_f64(1.0000000), T::from_f64(0.0000000),
129-
T::from_f64(0.0000000), T::from_f64(0.0000000), T::from_f64(1.0000000)
130-
],
131-
inv_ma: [
132-
T::from_f64(1.0000000), T::from_f64(0.0000000), T::from_f64(0.0000000),
133-
T::from_f64(0.0000000), T::from_f64(1.0000000), T::from_f64(0.0000000),
134-
T::from_f64(0.0000000), T::from_f64(0.0000000), T::from_f64(1.0000000)
135-
],
114+
ma: lms::meta::UnitMatrix::xyz_to_lms_matrix(),
115+
inv_ma: lms::meta::UnitMatrix::lms_to_xyz_matrix(),
136116
}
137117
}
138118
}

palette/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ pub mod hwb;
359359
pub mod lab;
360360
pub mod lch;
361361
pub mod lchuv;
362+
pub mod lms;
362363
pub mod luma;
363364
pub mod luv;
364365
mod luv_bounds;

palette/src/lms.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//! Types for the LMS color space.
2+
3+
#[allow(clippy::module_inception)]
4+
mod lms;
5+
6+
pub mod meta;
7+
8+
use crate::Alpha;
9+
10+
pub use self::lms::*;
11+
12+
/// LMS that uses the von Kries matrix.
13+
pub type VonKriesLms<M, T> = Lms<meta::WithLmsMatrix<M, meta::VonKries>, T>;
14+
15+
/// LMSA that uses the von Kries matrix.
16+
pub type VonKriesLmsa<M, T> = Alpha<Lms<meta::WithLmsMatrix<M, meta::VonKries>, T>, T>;
17+
18+
/// LMS that uses the Bradford matrix.
19+
pub type BradfordLms<M, T> = Lms<meta::WithLmsMatrix<M, meta::Bradford>, T>;
20+
21+
/// LMSA that uses the Bradford matrix.
22+
pub type BradfordLmsa<M, T> = Alpha<Lms<meta::WithLmsMatrix<M, meta::Bradford>, T>, T>;

0 commit comments

Comments
 (0)