| 2 |
|
static const char RCSid[] = "$Id$"; |
| 3 |
|
#endif |
| 4 |
|
/* |
| 5 |
< |
* Convert MGF color to RGB representation |
| 5 |
> |
* Convert MGF color to Radiance RGB and spectral representations |
| 6 |
|
*/ |
| 7 |
|
|
| 8 |
|
#include <stdio.h> |
| 43 |
|
cout->cx = xyz[CIEX]*df; |
| 44 |
|
cout->cy = xyz[CIEZ]*df; |
| 45 |
|
cout->flags = (C_CSXY|C_CDXY); |
| 46 |
– |
cout->clock++; |
| 46 |
|
|
| 47 |
|
return(xyz[CIEY]); |
| 48 |
+ |
} |
| 49 |
+ |
|
| 50 |
+ |
void |
| 51 |
+ |
ccy2scolor( /* convert MGF color, Y to spectral color */ |
| 52 |
+ |
C_COLOR *cin, /* input MGF color or spectrum */ |
| 53 |
+ |
double cieY, /* input luminance or reflectance */ |
| 54 |
+ |
SCOLOR sco /* output spectral color */ |
| 55 |
+ |
) |
| 56 |
+ |
{ |
| 57 |
+ |
COLORV nf, sorig[C_CNSS]; |
| 58 |
+ |
int i; |
| 59 |
+ |
|
| 60 |
+ |
if (cin->flags & C_CDXY || NCSAMP <= 3) { |
| 61 |
+ |
COLOR col; /* tristimulus in or out, so... */ |
| 62 |
+ |
ccy2rgb(cin, cieY, col); |
| 63 |
+ |
setscolor(sco, colval(col,RED), colval(col,GRN), colval(col,BLU)); |
| 64 |
+ |
return; |
| 65 |
+ |
} |
| 66 |
+ |
c_ccvt(cin, C_CSXY); |
| 67 |
+ |
nf = cieY*C_CNSS/(cin->ssum*3*cin->cy); |
| 68 |
+ |
for (i = C_CNSS; i--; ) /* may as well reverse order */ |
| 69 |
+ |
sorig[C_CNSS-1-i] = nf*(COLORV)cin->ssamp[i]; |
| 70 |
+ |
|
| 71 |
+ |
convertscolor(sco, NCSAMP, WLPART[0], WLPART[3], |
| 72 |
+ |
sorig, C_CNSS, C_CMAXWL+.5*C_CWLI, C_CMINWL-.5*C_CWLI); |
| 73 |
+ |
} |
| 74 |
+ |
|
| 75 |
+ |
/* Convert spectral color to MGF color and Y value */ |
| 76 |
+ |
double |
| 77 |
+ |
scolor2ccy(SCOLOR sci, C_COLOR *cout) |
| 78 |
+ |
{ |
| 79 |
+ |
float hinc, cspec[MAXCSAMP]; |
| 80 |
+ |
int i = NCSAMP; |
| 81 |
+ |
|
| 82 |
+ |
if (i <= 3) /* defined as RGB, so... */ |
| 83 |
+ |
return(rgb2ccy(sci, cout)); |
| 84 |
+ |
|
| 85 |
+ |
while (i-- > 0) /* need to reverse array */ |
| 86 |
+ |
cspec[i] = sci[NCSAMP-1-i]; |
| 87 |
+ |
|
| 88 |
+ |
hinc = (WLPART[0]-WLPART[3])/(float)(2*NCSAMP); |
| 89 |
+ |
|
| 90 |
+ |
return(c_sset(cout, WLPART[3]+hinc, WLPART[0]-hinc, cspec, NCSAMP)); |
| 91 |
|
} |