1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
use std::fmt::Debug;
use crate::math::FloatNumber;
/// The white point representation.
///
/// See the following for more details:
/// [White point - Wikipedia](https://en.wikipedia.org/wiki/White_point)
pub trait WhitePoint: Copy + Clone + Debug + Default + PartialEq {
/// Returns the X component of the white point.
///
/// # Type Parameters
/// * `T` - The floating point type.
///
/// # Returns
/// The X component of the white point.
#[must_use]
fn x<T>() -> T
where
T: FloatNumber;
/// Returns the Y component of the white point.
///
/// # Type Parameters
/// * `T` - The floating point type.
///
/// # Returns
/// The Y component of the white point.
#[must_use]
fn y<T>() -> T
where
T: FloatNumber;
/// Returns the Z component of the white point.
///
/// # Type Parameters
/// * `T` - The floating point type.
///
/// # Returns
/// The Z component of the white point.
#[must_use]
fn z<T>() -> T
where
T: FloatNumber;
}
/// The D50 white point representation.
///
/// This is commonly used in color science and is the default white point for many color spaces, including CIE L*a*b* and CIE L*C*h*.
///
/// See the following for more details:
/// [Illuminant D50](https://en.wikipedia.org/wiki/Illuminant_D50)
#[derive(Copy, Clone, Debug, Default, PartialEq)]
pub struct D50;
impl D50 {
const X: f64 = 0.964_22;
const Y: f64 = 1.0;
const Z: f64 = 0.825_21;
}
impl WhitePoint for D50 {
#[inline]
fn x<T>() -> T
where
T: FloatNumber,
{
T::from_f64(Self::X)
}
#[inline]
fn y<T>() -> T
where
T: FloatNumber,
{
T::from_f64(Self::Y)
}
#[inline]
fn z<T>() -> T
where
T: FloatNumber,
{
T::from_f64(Self::Z)
}
}
/// The D65 white point representation.
///
/// This is commonly used in color science and is the default white point for many color spaces, including sRGB and Adobe RGB.
///
/// See the following for more details:
/// [Illuminant D65](https://en.wikipedia.org/wiki/Illuminant_D65)
#[derive(Copy, Clone, Debug, Default, PartialEq)]
pub struct D65;
impl D65 {
const X: f64 = 0.950_47;
const Y: f64 = 1.0;
const Z: f64 = 1.088_83;
}
impl WhitePoint for D65 {
#[inline]
fn x<T>() -> T
where
T: FloatNumber,
{
T::from_f64(Self::X)
}
#[inline]
fn y<T>() -> T
where
T: FloatNumber,
{
T::from_f64(Self::Y)
}
#[inline]
fn z<T>() -> T
where
T: FloatNumber,
{
T::from_f64(Self::Z)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_d50() {
let x: f64 = D50::x();
assert_eq!(x, D50::X);
let y: f64 = D50::y();
assert_eq!(y, D50::Y);
let z: f64 = D50::z();
assert_eq!(z, D50::Z);
}
#[test]
fn test_d65() {
let x: f64 = D65::x();
assert_eq!(x, D65::X);
let y: f64 = D65::y();
assert_eq!(y, D65::Y);
let z: f64 = D65::z();
assert_eq!(z, D65::Z);
}
}