@@ -79,6 +79,10 @@ public sealed class CIEUCS : AConvertibleColor
79
79
80
80
static List < CIEUCS > TemperatureChromaticities = null ;
81
81
82
+ double CCT = double . NaN ;
83
+
84
+ double Duv = double . NaN ;
85
+
82
86
#endregion
83
87
84
88
@@ -188,6 +192,11 @@ public override double GetCCT ()
188
192
return ( DataSource as BlackBodySpectrum ) . CCT ;
189
193
}
190
194
195
+ if ( ! double . IsNaN ( CCT ) ) {
196
+ return CCT ;
197
+ }
198
+
199
+ // Precomputing interpolation tables...
191
200
if ( TemperatureChromaticities == null ) {
192
201
// Oversized to improve alignment (needs 302).
193
202
TemperatureChromaticities = new List < CIEUCS > ( 512 ) ;
@@ -201,7 +210,7 @@ public override double GetCCT ()
201
210
}
202
211
203
212
int bestI = 0 ;
204
- double minDuv = double . PositiveInfinity ;
213
+ Duv = double . PositiveInfinity ;
205
214
206
215
// First gross grained search
207
216
// TODO: This is a naive search, must be improved!
@@ -211,12 +220,12 @@ public override double GetCCT ()
211
220
Math . Pow ( v - TemperatureChromaticities [ i ] . v , 2 )
212
221
) ;
213
222
214
- if ( minDuv > tmpDuv ) {
215
- minDuv = tmpDuv ;
223
+ if ( Duv > tmpDuv ) {
224
+ Duv = tmpDuv ;
216
225
bestI = i ;
217
226
}
218
227
}
219
- double bestTmp = TemperatureChromaticities [ bestI ] . GetCCT ( ) ;
228
+ CCT = TemperatureChromaticities [ bestI ] . GetCCT ( ) ;
220
229
221
230
// Preparing the following fine grained search
222
231
double tMin = TemperatureChromaticities [
@@ -233,13 +242,26 @@ public override double GetCCT ()
233
242
234
243
double tmpDuv = Math . Sqrt ( Math . Pow ( u - tmpUV . u , 2 ) + Math . Pow ( v - tmpUV . v , 2 ) ) ;
235
244
236
- if ( minDuv > tmpDuv ) {
237
- minDuv = tmpDuv ;
238
- bestTmp = t ;
245
+ if ( Duv > tmpDuv ) {
246
+ Duv = tmpDuv ;
247
+ CCT = t ;
239
248
}
240
249
}
241
250
242
- return bestTmp ;
251
+ return CCT ;
252
+ }
253
+
254
+ public override double GetDuv ( )
255
+ {
256
+ if ( DataSource is BlackBodySpectrum ) {
257
+ return 0 ;
258
+ }
259
+
260
+ if ( double . IsNaN ( Duv ) ) {
261
+ GetCCT ( ) ;
262
+ }
263
+
264
+ return Duv ;
243
265
}
244
266
245
267
/**
0 commit comments