@@ -5,7 +5,7 @@ use crate::{
5
5
num:: {
6
6
Abs , Arithmetics , Clamp , Exp , FromScalar , One , PartialCmp , Powf , Real , Signum , Sqrt , Zero ,
7
7
} ,
8
- white_point:: { self , WhitePoint , D65 } ,
8
+ white_point:: { self , WhitePoint } ,
9
9
Xyz ,
10
10
} ;
11
11
@@ -56,31 +56,36 @@ pub type ParametersDynamicWp<T> = Parameters<Xyz<white_point::Any, T>, T>;
56
56
#[ derive( Clone , Copy ) ]
57
57
#[ non_exhaustive]
58
58
pub struct Parameters < WpParam , T > {
59
- /// The reference white point. Defaults to `Wp` when it implements
60
- /// [`WhitePoint`], or [`D65`] when `Wp` is [`white_point::Any`]. It can
61
- /// also be set to a custom value if `Wp` results in the wrong white point.
59
+ /// White point of the test illuminant, *X<sub>w</sub>* *Y<sub>w</sub>*
60
+ /// *Z<sub>w</sub>*. *Y<sub>w</sub>* should be normalized to 1.0.
61
+ ///
62
+ /// Defaults to `Wp` when it implements [`WhitePoint`]. It can also be set
63
+ /// to a custom value if `Wp` results in the wrong white point.
62
64
pub white_point : WpParam ,
63
65
64
- /// The average luminance of the environment (*L<sub>A</sub>*) in
65
- /// *cd/m<sup>2</sup>* (nits). Under a “gray world” assumption this is 20%
66
- /// of the luminance of a white reference. Defaults to `T::default()` (0.0
67
- /// for `f32` and `f64`).
66
+ /// The average luminance of the environment (test adapting field)
67
+ /// (*L<sub>A</sub>*) in *cd/m<sup>2</sup>* (nits).
68
+ ///
69
+ /// Under a “gray world” assumption this is 20% of the luminance of a white
70
+ /// reference. Defaults to `T::default()` (0.0 for `f32` and `f64`).
68
71
pub adapting_luminance : T ,
69
72
70
- /// The relative luminance of the nearby background (*Y<sub>b</sub>*), out
71
- /// to 10°, on a scale of 0 to 100. Defaults to `T::default()` (0.0 for
72
- /// `f32` and `f64`).
73
+ /// The luminance factor of the background (*Y<sub>b</sub>*), on a scale
74
+ /// from `0.0` to `1.0` (relative to *Y<sub>w</sub>* = 1.0). Medium grey
75
+ /// would be `0.2`.
76
+ ///
77
+ /// Defaults to `T::default()` (0.0 for `f32` and `f64`).
73
78
pub background_luminance : T ,
74
79
75
- /// A description of the peripheral area, with a value from `0` to `2` . Any
76
- /// value outside that range will be clamped to `0` or `2` . It has presets
77
- /// for "dark", "dim" and "average". Defaults to "average" (`2` ).
80
+ /// A description of the peripheral area, with a value from 0% to 20% . Any
81
+ /// value outside that range will be clamped to 0% or 20% . It has presets
82
+ /// for "dark", "dim" and "average". Defaults to "average" (20% ).
78
83
pub surround : Surround < T > ,
79
84
80
- /// Set to `true` to assume that the observer's eyes have fully adapted to
81
- /// the illuminant. The degree of discounting will be set based on the other
82
- /// parameters. Defaults to `false` .
83
- pub discounting : bool ,
85
+ /// The degree of discounting of (or adaptation to) the reference
86
+ /// illuminant. Defaults to `Auto`, making the degree of discounting depend
87
+ /// on the other parameters, but can be customized if necessary .
88
+ pub discounting : Discounting < T > ,
84
89
}
85
90
86
91
impl < WpParam , T > Parameters < WpParam , T >
@@ -144,7 +149,7 @@ impl<Wp> Parameters<StaticWp<Wp>, f64> {
144
149
adapting_luminance : 40.0f64 ,
145
150
background_luminance : 20.0f64 ,
146
151
surround : Surround :: Average ,
147
- discounting : false ,
152
+ discounting : Discounting :: Auto ,
148
153
} ;
149
154
}
150
155
@@ -159,23 +164,7 @@ where
159
164
adapting_luminance : T :: default ( ) ,
160
165
background_luminance : T :: default ( ) ,
161
166
surround : Surround :: Average ,
162
- discounting : false ,
163
- }
164
- }
165
- }
166
-
167
- impl < T > Default for Parameters < Xyz < white_point:: Any , T > , T >
168
- where
169
- T : Real + Default ,
170
- {
171
- #[ inline]
172
- fn default ( ) -> Self {
173
- Self {
174
- white_point : D65 :: get_xyz ( ) ,
175
- adapting_luminance : T :: default ( ) ,
176
- background_luminance : T :: default ( ) ,
177
- surround : Surround :: Average ,
178
- discounting : false ,
167
+ discounting : Discounting :: Auto ,
179
168
}
180
169
}
181
170
}
@@ -235,35 +224,54 @@ where
235
224
#[ non_exhaustive]
236
225
pub enum Surround < T > {
237
226
/// Represents a dark room, such as a movie theatre. Corresponds to a
238
- /// surround value of `0` .
227
+ /// surround value of 0% .
239
228
Dark ,
240
229
241
230
/// Represents a dimly lit room with a bright TV or monitor. Corresponds to
242
- /// a surround value of `1` .
231
+ /// a surround value of 10% .
243
232
Dim ,
244
233
245
- /// Represents a surface color. Corresponds to a surround value of `2`.
234
+ /// Represents a surface color, such as a print on a 20% reflective,
235
+ /// uniformly lit background surface. Corresponds to a surround value of
236
+ /// 20%.
246
237
Average ,
247
238
248
- /// Any custom value from `0` to `2` . Any value outside that range will be
249
- /// clamped to either `0` or `2 `.
250
- Custom ( T ) ,
239
+ /// Any custom value from 0% to 20% . Any value outside that range will be
240
+ /// clamped to either `0.0 ` or `20.0 `.
241
+ Percent ( T ) ,
251
242
}
252
243
253
244
impl < T > Surround < T > {
254
- pub ( crate ) fn into_value ( self ) -> T
245
+ pub ( crate ) fn into_percent ( self ) -> T
255
246
where
256
247
T : Real + Clamp ,
257
248
{
258
249
match self {
259
250
Surround :: Dark => T :: from_f64 ( 0.0 ) ,
260
- Surround :: Dim => T :: from_f64 ( 1 .0) ,
261
- Surround :: Average => T :: from_f64 ( 2 .0) ,
262
- Surround :: Custom ( value) => value. clamp ( T :: from_f64 ( 0.0 ) , T :: from_f64 ( 2 .0) ) ,
251
+ Surround :: Dim => T :: from_f64 ( 10 .0) ,
252
+ Surround :: Average => T :: from_f64 ( 20 .0) ,
253
+ Surround :: Percent ( value) => value. clamp ( T :: from_f64 ( 0.0 ) , T :: from_f64 ( 20 .0) ) ,
263
254
}
264
255
}
265
256
}
266
257
258
+ /// The degree of discounting of (or adaptation to) the illuminant.
259
+ ///
260
+ /// See also: https://en.wikipedia.org/wiki/CIECAM02#CAT02.
261
+ #[ derive( Clone , Copy ) ]
262
+ #[ non_exhaustive]
263
+ pub enum Discounting < T > {
264
+ /// Uses luminance levels and surround conditions to calculate the
265
+ /// discounting, using the original CIECAM16 *D* function. Ranges from
266
+ /// `0.65` to `1.0`.
267
+ Auto ,
268
+
269
+ /// A value between `0.0` and `1.0`, where `0.0` represents no adaptation,
270
+ /// and `1.0` represents that the observer's vision is fully adapted to the
271
+ /// illuminant. Values outside that range will be clamped.
272
+ Custom ( T ) ,
273
+ }
274
+
267
275
/// A trait for types that can be used as white point parameters in
268
276
/// [`Parameters`].
269
277
pub trait WhitePointParameter < T > {
0 commit comments