12 |
|
|
13 |
|
#include <stdio.h> |
14 |
|
#include <string.h> |
15 |
+ |
#include <math.h> |
16 |
|
#include "color.h" |
17 |
|
|
18 |
|
#define CEPS 1e-4 /* color epsilon */ |
271 |
|
COLOR ciecolor; |
272 |
|
|
273 |
|
spec_cie(ciecolor, s, e); |
274 |
< |
cie_rgb(col, ciecolor); |
274 |
> |
colortrans(col, xyz2rgbmat, ciecolor); |
275 |
|
} |
276 |
|
|
277 |
|
|
347 |
|
|
348 |
|
|
349 |
|
double |
350 |
< |
scolor_photopic( /* compute scotopic integral for spectral color */ |
351 |
< |
SCOLOR scol |
350 |
> |
scolor2photopic( /* compute scotopic integral for spectral color */ |
351 |
> |
SCOLOR scol, |
352 |
> |
int ncs, |
353 |
> |
const float wlpt[4] |
354 |
|
) |
355 |
|
{ |
356 |
< |
if (NCSAMP == 3) |
356 |
> |
if (ncs == 3) |
357 |
|
return bright(scol); |
358 |
|
|
359 |
< |
return(spec_dot(scol, NCSAMP, WLPART, cie_y_cumul, CIE_Y_WLMIN, CIE_Y_WLMAX)); |
359 |
> |
return(spec_dot(scol, ncs, wlpt, cie_y_cumul, CIE_Y_WLMIN, CIE_Y_WLMAX)); |
360 |
|
} |
361 |
|
|
362 |
|
|
363 |
|
double |
364 |
+ |
scolor2scotopic( /* compute Y channel for spectral color */ |
365 |
+ |
SCOLOR scol, |
366 |
+ |
int ncs, |
367 |
+ |
const float wlpt[4] |
368 |
+ |
) |
369 |
+ |
{ |
370 |
+ |
return(spec_dot(scol, ncs, wlpt, scotopic_cumul, SCOTOPIC_WLMIN, SCOTOPIC_WLMAX)); |
371 |
+ |
} |
372 |
+ |
|
373 |
+ |
|
374 |
+ |
double |
375 |
+ |
scolor2melanopic( /* compute melanopic integral for spectral color */ |
376 |
+ |
SCOLOR scol, |
377 |
+ |
int ncs, |
378 |
+ |
const float wlpt[4] |
379 |
+ |
) |
380 |
+ |
{ |
381 |
+ |
return(spec_dot(scol, ncs, wlpt, melanopic_cumul, MELANOPIC_WLMIN, MELANOPIC_WLMAX)); |
382 |
+ |
} |
383 |
+ |
|
384 |
+ |
|
385 |
+ |
double |
386 |
+ |
scolor_photopic( /* compute scotopic integral for spectral color */ |
387 |
+ |
SCOLOR scol |
388 |
+ |
) |
389 |
+ |
{ |
390 |
+ |
return(scolor2photopic(scol, NCSAMP, WLPART)); |
391 |
+ |
} |
392 |
+ |
|
393 |
+ |
|
394 |
+ |
double |
395 |
|
scolor_scotopic( /* compute Y channel for spectral color */ |
396 |
|
SCOLOR scol |
397 |
|
) |
398 |
|
{ |
399 |
< |
return(spec_dot(scol, NCSAMP, WLPART, scotopic_cumul, SCOTOPIC_WLMIN, SCOTOPIC_WLMAX)); |
399 |
> |
return(scolor2scotopic(scol, NCSAMP, WLPART)); |
400 |
|
} |
401 |
|
|
402 |
|
|
405 |
|
SCOLOR scol |
406 |
|
) |
407 |
|
{ |
408 |
< |
return(spec_dot(scol, NCSAMP, WLPART, melanopic_cumul, MELANOPIC_WLMIN, MELANOPIC_WLMAX)); |
408 |
> |
return(scolor2melanopic(scol, NCSAMP, WLPART)); |
409 |
> |
} |
410 |
> |
|
411 |
> |
|
412 |
> |
void |
413 |
> |
convertscolorcol( /* any uniform spectrum to working */ |
414 |
> |
SCOLOR rcol, |
415 |
> |
const COLORV src[], |
416 |
> |
int snc, |
417 |
> |
double swl0, |
418 |
> |
double swl1 |
419 |
> |
) |
420 |
> |
{ |
421 |
> |
if (NCSAMP > 3) { /* spectrum -> spectrum */ |
422 |
> |
convertscolor(rcol, NCSAMP, WLPART[0], WLPART[3], |
423 |
> |
src, snc, swl0, swl1); |
424 |
> |
} else if ((snc <= MAXCSAMP) & (swl0 > swl1)) { |
425 |
> |
float wlpt[4]; /* no intermediate conversion needed */ |
426 |
> |
wlpt[0] = swl0; wlpt[3] = swl1; |
427 |
> |
wlpt[1] = WLPART[1]; wlpt[2] = WLPART[2]; |
428 |
> |
scolor2rgb(rcol, (COLORV *)src, snc, wlpt); |
429 |
> |
} else { |
430 |
> |
SCOLOR dcol; /* else convert spectrum first */ |
431 |
> |
int dnc = snc*(WLPART[0] - WLPART[3])/fabs(swl0 - swl1) + .99; |
432 |
> |
if (dnc > MAXCSAMP) dnc = MAXCSAMP; |
433 |
> |
convertscolor(dcol, dnc, WLPART[0], WLPART[3], src, snc, swl0, swl1); |
434 |
> |
scolor2rgb(rcol, dcol, dnc, WLPART); |
435 |
> |
} |
436 |
|
} |
437 |
|
|
438 |
|
|