| 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 |
|
|
| 279 |
|
spec_dot( /* spectrum dot-product with cumulative observer */ |
| 280 |
|
SCOLOR scol, |
| 281 |
|
int ncs, |
| 282 |
< |
float wlpt[4], |
| 282 |
> |
const float wlpt[4], |
| 283 |
|
const unsigned short cumul[], |
| 284 |
|
int wlmin, |
| 285 |
|
int wlmax |
| 298 |
|
|
| 299 |
|
while (n < ncs) { |
| 300 |
|
int wl0 = wl1; |
| 301 |
< |
wl1 = (int)(ncs==3 ? wlpt[ncs-1-n] : wlpt[3] + (n+1)*wlstp); |
| 301 |
> |
wl1 = (int)(ncs==3 ? wlpt[2-n] : wlpt[3] + (n+1)*wlstp); |
| 302 |
|
if (wl1 >= wlmax) { |
| 303 |
< |
sum += (65535 - cumul[wl0-wlmin]) * scol[n]; |
| 303 |
> |
sum += (65535 - cumul[wl0-wlmin]) * scol[ncs-1-n]; |
| 304 |
|
break; |
| 305 |
|
} |
| 306 |
< |
sum += (cumul[wl1-wlmin] - cumul[wl0-wlmin]) * scol[n++]; |
| 306 |
> |
sum += (cumul[wl1-wlmin] - cumul[wl0-wlmin]) * scol[ncs-1-n++]; |
| 307 |
|
} |
| 308 |
|
return(sum * (1./65535.)); |
| 309 |
|
} |
| 314 |
|
COLOR col, |
| 315 |
|
SCOLOR scol, |
| 316 |
|
int ncs, |
| 317 |
< |
float wlpt[4] |
| 317 |
> |
const float wlpt[4] |
| 318 |
|
) |
| 319 |
|
{ |
| 320 |
|
if (ncs == 3) { /* not a spectrum! */ |
| 332 |
|
COLOR col, |
| 333 |
|
SCOLOR scol, |
| 334 |
|
int ncs, |
| 335 |
< |
float wlpt[4] |
| 335 |
> |
const float wlpt[4] |
| 336 |
|
) |
| 337 |
|
{ |
| 338 |
|
COLOR ciecolor; |
| 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 |
|
|