| 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 */ |
| 346 |
|
} |
| 347 |
|
|
| 348 |
|
|
| 349 |
+ |
void |
| 350 |
+ |
scolor_out( /* prepare (spectral) color for output */ |
| 351 |
+ |
COLORV *cout, |
| 352 |
+ |
RGBPRIMP primp, |
| 353 |
+ |
SCOLOR cres |
| 354 |
+ |
) |
| 355 |
+ |
{ |
| 356 |
+ |
static COLORMAT xyz2myp; |
| 357 |
+ |
static RGBPRIMP lastp = NULL; |
| 358 |
+ |
|
| 359 |
+ |
if (!primp) { /* output is spectral */ |
| 360 |
+ |
copyscolor(cout, cres); |
| 361 |
+ |
} else if (primp == stdprims) { /* output is standard RGB */ |
| 362 |
+ |
scolor_rgb(cout, cres); |
| 363 |
+ |
} else if (primp == xyzprims) { /* output is XYZ */ |
| 364 |
+ |
scolor_cie(cout, cres); |
| 365 |
+ |
scalecolor(cout, WHTEFFICACY); |
| 366 |
+ |
} else if (NCSAMP > 3) { /* spectral -> custom RGB */ |
| 367 |
+ |
COLOR xyz; |
| 368 |
+ |
if (lastp != primp) |
| 369 |
+ |
compxyz2rgbWBmat(xyz2myp, lastp=primp); |
| 370 |
+ |
scolor_cie(xyz, cres); |
| 371 |
+ |
colortrans(cout, xyz2myp, xyz); |
| 372 |
+ |
clipgamut(cout, xyz[CIEY], CGAMUT_LOWER, cblack, cwhite); |
| 373 |
+ |
} else { /* else copy unknown RGB */ |
| 374 |
+ |
copycolor(cout, cres); |
| 375 |
+ |
} |
| 376 |
+ |
} |
| 377 |
+ |
|
| 378 |
+ |
|
| 379 |
|
double |
| 380 |
|
scolor2photopic( /* compute scotopic integral for spectral color */ |
| 381 |
|
SCOLOR scol, |
| 436 |
|
) |
| 437 |
|
{ |
| 438 |
|
return(scolor2melanopic(scol, NCSAMP, WLPART)); |
| 439 |
+ |
} |
| 440 |
+ |
|
| 441 |
+ |
|
| 442 |
+ |
void |
| 443 |
+ |
convertscolorcol( /* any uniform spectrum to working */ |
| 444 |
+ |
SCOLOR rcol, |
| 445 |
+ |
const COLORV src[], |
| 446 |
+ |
int snc, |
| 447 |
+ |
double swl0, |
| 448 |
+ |
double swl1 |
| 449 |
+ |
) |
| 450 |
+ |
{ |
| 451 |
+ |
if (NCSAMP > 3) { /* spectrum -> spectrum */ |
| 452 |
+ |
convertscolor(rcol, NCSAMP, WLPART[0], WLPART[3], |
| 453 |
+ |
src, snc, swl0, swl1); |
| 454 |
+ |
} else if ((snc <= MAXCSAMP) & (swl0 > swl1)) { |
| 455 |
+ |
float wlpt[4]; /* no intermediate conversion needed */ |
| 456 |
+ |
wlpt[0] = swl0; wlpt[3] = swl1; |
| 457 |
+ |
wlpt[1] = WLPART[1]; wlpt[2] = WLPART[2]; |
| 458 |
+ |
scolor2rgb(rcol, (COLORV *)src, snc, wlpt); |
| 459 |
+ |
} else { |
| 460 |
+ |
SCOLOR dcol; /* else convert spectrum first */ |
| 461 |
+ |
int dnc = snc*(WLPART[0] - WLPART[3])/fabs(swl0 - swl1) + .99; |
| 462 |
+ |
if (dnc > MAXCSAMP) dnc = MAXCSAMP; |
| 463 |
+ |
convertscolor(dcol, dnc, WLPART[0], WLPART[3], src, snc, swl0, swl1); |
| 464 |
+ |
scolor2rgb(rcol, dcol, dnc, WLPART); |
| 465 |
+ |
} |
| 466 |
|
} |
| 467 |
|
|
| 468 |
|
|