| 1 | //! Defines the tristimulus values of the CIE Illuminants. |
| 2 | //! |
| 3 | //! White point is the reference white or target white as seen by a standard |
| 4 | //! observer under a standard illuminant. For example, photographs taken indoors |
| 5 | //! may be lit by incandescent lights, which are relatively orange compared to |
| 6 | //! daylight. Defining "white" as daylight will give unacceptable results when |
| 7 | //! attempting to color-correct a photograph taken with incandescent lighting. |
| 8 | |
| 9 | use crate::{num::Real, Xyz}; |
| 10 | |
| 11 | /// Represents an unspecified reference white point. |
| 12 | /// |
| 13 | /// Some color spaces (such as `Xyz` and `Yxy`) or operations don't necessarily |
| 14 | /// need a known intended white point. `Any` may be used as a placeholder type |
| 15 | /// in those situations. |
| 16 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 17 | pub struct Any; |
| 18 | |
| 19 | /// WhitePoint defines the Xyz color co-ordinates for a given white point. |
| 20 | /// |
| 21 | /// A white point (often referred to as reference white or target white in |
| 22 | /// technical documents) is a set of tristimulus values or chromaticity |
| 23 | /// coordinates that serve to define the color "white" in image capture, |
| 24 | /// encoding, or reproduction. |
| 25 | /// |
| 26 | /// Custom white points can be easily defined on an empty struct with the |
| 27 | /// tristimulus values and can be used in place of the ones defined in this |
| 28 | /// library. |
| 29 | pub trait WhitePoint<T>: 'static { |
| 30 | /// Get the Xyz chromaticity co-ordinates for the white point. |
| 31 | fn get_xyz() -> Xyz<Any, T>; |
| 32 | } |
| 33 | |
| 34 | /// CIE standard illuminant A |
| 35 | /// |
| 36 | /// CIE standard illuminant A is intended to represent typical, domestic, |
| 37 | /// tungsten-filament lighting. Its relative spectral power distribution is that |
| 38 | /// of a Planckian radiator at a temperature of approximately 2856 K. Uses the |
| 39 | /// CIE 1932 2° Standard Observer |
| 40 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 41 | pub struct A; |
| 42 | impl<T: Real> WhitePoint<T> for A { |
| 43 | #[inline] |
| 44 | fn get_xyz() -> Xyz<Any, T> { |
| 45 | Xyz::new(T::from_f64(1.09850), T::from_f64(1.0), T::from_f64(0.35585)) |
| 46 | } |
| 47 | } |
| 48 | /// CIE standard illuminant B |
| 49 | /// |
| 50 | /// CIE standard illuminant B represents noon sunlight, with a correlated color |
| 51 | /// temperature (CCT) of 4874 K Uses the CIE 1932 2° Standard Observer |
| 52 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 53 | pub struct B; |
| 54 | impl<T: Real> WhitePoint<T> for B { |
| 55 | #[inline] |
| 56 | fn get_xyz() -> Xyz<Any, T> { |
| 57 | Xyz::new(T::from_f64(0.99072), T::from_f64(1.0), T::from_f64(0.85223)) |
| 58 | } |
| 59 | } |
| 60 | /// CIE standard illuminant C |
| 61 | /// |
| 62 | /// CIE standard illuminant C represents the average day light with a CCT of |
| 63 | /// 6774 K Uses the CIE 1932 2° Standard Observer |
| 64 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 65 | pub struct C; |
| 66 | impl<T: Real> WhitePoint<T> for C { |
| 67 | #[inline] |
| 68 | fn get_xyz() -> Xyz<Any, T> { |
| 69 | Xyz::new(T::from_f64(0.98074), T::from_f64(1.0), T::from_f64(1.18232)) |
| 70 | } |
| 71 | } |
| 72 | /// CIE D series standard illuminant - D50 |
| 73 | /// |
| 74 | /// D50 White Point is the natural daylight with a color temperature of around |
| 75 | /// 5000K for 2° Standard Observer. |
| 76 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 77 | pub struct D50; |
| 78 | impl<T: Real> WhitePoint<T> for D50 { |
| 79 | #[inline] |
| 80 | fn get_xyz() -> Xyz<Any, T> { |
| 81 | Xyz::new(T::from_f64(0.96422), T::from_f64(1.0), T::from_f64(0.82521)) |
| 82 | } |
| 83 | } |
| 84 | /// CIE D series standard illuminant - D55 |
| 85 | /// |
| 86 | /// D55 White Point is the natural daylight with a color temperature of around |
| 87 | /// 5500K for 2° Standard Observer. |
| 88 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 89 | pub struct D55; |
| 90 | impl<T: Real> WhitePoint<T> for D55 { |
| 91 | #[inline] |
| 92 | fn get_xyz() -> Xyz<Any, T> { |
| 93 | Xyz::new(T::from_f64(0.95682), T::from_f64(1.0), T::from_f64(0.92149)) |
| 94 | } |
| 95 | } |
| 96 | /// CIE D series standard illuminant - D65 |
| 97 | /// |
| 98 | /// D65 White Point is the natural daylight with a color temperature of 6500K |
| 99 | /// for 2° Standard Observer. |
| 100 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 101 | pub struct D65; |
| 102 | impl<T: Real> WhitePoint<T> for D65 { |
| 103 | #[inline] |
| 104 | fn get_xyz() -> Xyz<Any, T> { |
| 105 | Xyz::new(T::from_f64(0.95047), T::from_f64(1.0), T::from_f64(1.08883)) |
| 106 | } |
| 107 | } |
| 108 | /// CIE D series standard illuminant - D75 |
| 109 | /// |
| 110 | /// D75 White Point is the natural daylight with a color temperature of around |
| 111 | /// 7500K for 2° Standard Observer. |
| 112 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 113 | pub struct D75; |
| 114 | impl<T: Real> WhitePoint<T> for D75 { |
| 115 | #[inline] |
| 116 | fn get_xyz() -> Xyz<Any, T> { |
| 117 | Xyz::new(T::from_f64(0.94972), T::from_f64(1.0), T::from_f64(1.22638)) |
| 118 | } |
| 119 | } |
| 120 | /// CIE standard illuminant E |
| 121 | /// |
| 122 | /// CIE standard illuminant E represents the equal energy radiator |
| 123 | /// Uses the CIE 1932 2° Standard Observer |
| 124 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 125 | pub struct E; |
| 126 | impl<T: Real> WhitePoint<T> for E { |
| 127 | #[inline] |
| 128 | fn get_xyz() -> Xyz<Any, T> { |
| 129 | Xyz::new(T::from_f64(1.0), T::from_f64(1.0), T::from_f64(1.0)) |
| 130 | } |
| 131 | } |
| 132 | /// CIE fluorescent illuminant series - F2 |
| 133 | /// |
| 134 | /// F2 represents a semi-broadband fluorescent lamp for 2° Standard Observer. |
| 135 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 136 | pub struct F2; |
| 137 | impl<T: Real> WhitePoint<T> for F2 { |
| 138 | #[inline] |
| 139 | fn get_xyz() -> Xyz<Any, T> { |
| 140 | Xyz::new(T::from_f64(0.99186), T::from_f64(1.0), T::from_f64(0.67393)) |
| 141 | } |
| 142 | } |
| 143 | /// CIE fluorescent illuminant series - F7 |
| 144 | /// |
| 145 | /// F7 represents a broadband fluorescent lamp for 2° Standard Observer. |
| 146 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 147 | pub struct F7; |
| 148 | impl<T: Real> WhitePoint<T> for F7 { |
| 149 | #[inline] |
| 150 | fn get_xyz() -> Xyz<Any, T> { |
| 151 | Xyz::new(T::from_f64(0.95041), T::from_f64(1.0), T::from_f64(1.08747)) |
| 152 | } |
| 153 | } |
| 154 | /// CIE fluorescent illuminant series - F11 |
| 155 | /// |
| 156 | /// F11 represents a narrowband fluorescent lamp for 2° Standard Observer. |
| 157 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 158 | pub struct F11; |
| 159 | impl<T: Real> WhitePoint<T> for F11 { |
| 160 | #[inline] |
| 161 | fn get_xyz() -> Xyz<Any, T> { |
| 162 | Xyz::new(T::from_f64(1.00962), T::from_f64(1.0), T::from_f64(0.64350)) |
| 163 | } |
| 164 | } |
| 165 | /// CIE D series standard illuminant - D50 |
| 166 | /// |
| 167 | /// D50 White Point is the natural daylight with a color temperature of around |
| 168 | /// 5000K for 10° Standard Observer. |
| 169 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 170 | pub struct D50Degree10; |
| 171 | impl<T: Real> WhitePoint<T> for D50Degree10 { |
| 172 | #[inline] |
| 173 | fn get_xyz() -> Xyz<Any, T> { |
| 174 | Xyz::new(T::from_f64(0.9672), T::from_f64(1.0), T::from_f64(0.8143)) |
| 175 | } |
| 176 | } |
| 177 | /// CIE D series standard illuminant - D55 |
| 178 | /// |
| 179 | /// D55 White Point is the natural daylight with a color temperature of around |
| 180 | /// 5500K for 10° Standard Observer. |
| 181 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 182 | pub struct D55Degree10; |
| 183 | impl<T: Real> WhitePoint<T> for D55Degree10 { |
| 184 | #[inline] |
| 185 | fn get_xyz() -> Xyz<Any, T> { |
| 186 | Xyz::new(T::from_f64(0.958), T::from_f64(1.0), T::from_f64(0.9093)) |
| 187 | } |
| 188 | } |
| 189 | /// CIE D series standard illuminant - D65 |
| 190 | /// |
| 191 | /// D65 White Point is the natural daylight with a color temperature of 6500K |
| 192 | /// for 10° Standard Observer. |
| 193 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 194 | pub struct D65Degree10; |
| 195 | impl<T: Real> WhitePoint<T> for D65Degree10 { |
| 196 | #[inline] |
| 197 | fn get_xyz() -> Xyz<Any, T> { |
| 198 | Xyz::new(T::from_f64(0.9481), T::from_f64(1.0), T::from_f64(1.073)) |
| 199 | } |
| 200 | } |
| 201 | /// CIE D series standard illuminant - D75 |
| 202 | /// |
| 203 | /// D75 White Point is the natural daylight with a color temperature of around |
| 204 | /// 7500K for 10° Standard Observer. |
| 205 | #[derive(Copy, Clone, Debug, PartialEq, Eq)] |
| 206 | pub struct D75Degree10; |
| 207 | impl<T: Real> WhitePoint<T> for D75Degree10 { |
| 208 | #[inline] |
| 209 | fn get_xyz() -> Xyz<Any, T> { |
| 210 | Xyz::new(T::from_f64(0.94416), T::from_f64(1.0), T::from_f64(1.2064)) |
| 211 | } |
| 212 | } |