1 |
+ |
/* Copyright (c) 1990 Regents of the University of California */ |
2 |
+ |
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
5 |
|
#endif |
39 |
|
} |
40 |
|
}; |
41 |
|
|
42 |
+ |
static float xyz2rgbmat[3][3] = { /* XYZ to RGB */ |
43 |
+ |
{(CIE_y_g - CIE_y_b - CIE_x_b*CIE_y_g + CIE_y_b*CIE_x_g)/CIE_C_rD, |
44 |
+ |
(CIE_x_b - CIE_x_g - CIE_x_b*CIE_y_g + CIE_x_g*CIE_y_b)/CIE_C_rD, |
45 |
+ |
(CIE_x_g*CIE_y_b - CIE_x_b*CIE_y_g)/CIE_C_rD}, |
46 |
+ |
{(CIE_y_b - CIE_y_r - CIE_y_b*CIE_x_r + CIE_y_r*CIE_x_b)/CIE_C_gD, |
47 |
+ |
(CIE_x_r - CIE_x_b - CIE_x_r*CIE_y_b + CIE_x_b*CIE_y_r)/CIE_C_gD, |
48 |
+ |
(CIE_x_b*CIE_y_r - CIE_x_r*CIE_y_b)/CIE_C_gD}, |
49 |
+ |
{(CIE_y_r - CIE_y_g - CIE_y_r*CIE_x_g + CIE_y_g*CIE_x_r)/CIE_C_bD, |
50 |
+ |
(CIE_x_g - CIE_x_r - CIE_x_g*CIE_y_r + CIE_x_r*CIE_y_g)/CIE_C_bD, |
51 |
+ |
(CIE_x_r*CIE_y_g - CIE_x_g*CIE_y_r)/CIE_C_bD} |
52 |
+ |
}; |
53 |
|
|
54 |
+ |
static float rgb2xyzmat[3][3] = { /* RGB to XYZ */ |
55 |
+ |
{CIE_x_r*CIE_C_rD/CIE_D,CIE_x_g*CIE_C_gD/CIE_D,CIE_x_b*CIE_C_bD/CIE_D}, |
56 |
+ |
{CIE_y_r*CIE_C_rD/CIE_D,CIE_y_g*CIE_C_gD/CIE_D,CIE_y_b*CIE_C_bD/CIE_D}, |
57 |
+ |
{(1.-CIE_x_r-CIE_y_r)*CIE_C_rD/CIE_D, |
58 |
+ |
(1.-CIE_x_g-CIE_y_g)*CIE_C_gD/CIE_D, |
59 |
+ |
(1.-CIE_x_b-CIE_y_b)*CIE_C_bD/CIE_D} |
60 |
+ |
}; |
61 |
+ |
|
62 |
+ |
|
63 |
+ |
|
64 |
|
spec_rgb(col, s, e) /* compute RGB color from spectral range */ |
65 |
|
COLOR col; |
66 |
|
int s, e; |
83 |
|
s = 0; |
84 |
|
|
85 |
|
e -= STARTWL; |
86 |
+ |
if (e <= s) { |
87 |
+ |
col[RED] = col[GRN] = col[BLU] = 0.0; |
88 |
+ |
return; |
89 |
+ |
} |
90 |
|
if (e >= INCWL*(NINC - 1)) |
91 |
|
e = INCWL*(NINC - 1) - 1; |
92 |
|
|
106 |
|
} |
107 |
|
|
108 |
|
|
109 |
< |
cie_rgb(rgbcolor, ciecolor) /* convert CIE to RGB (NTSC) */ |
109 |
> |
cie_rgb(rgbcolor, ciecolor) /* convert CIE to RGB */ |
110 |
|
register COLOR rgbcolor, ciecolor; |
111 |
|
{ |
85 |
– |
static float cmat[3][3] = { |
86 |
– |
1.73, -.48, -.26, |
87 |
– |
-.81, 1.65, -.02, |
88 |
– |
.08, -.17, 1.28, |
89 |
– |
}; |
112 |
|
register int i; |
113 |
|
|
114 |
|
for (i = 0; i < 3; i++) { |
115 |
< |
rgbcolor[i] = cmat[i][0]*ciecolor[0] + |
116 |
< |
cmat[i][1]*ciecolor[1] + |
117 |
< |
cmat[i][2]*ciecolor[2] ; |
115 |
> |
rgbcolor[i] = xyz2rgbmat[i][0]*ciecolor[0] + |
116 |
> |
xyz2rgbmat[i][1]*ciecolor[1] + |
117 |
> |
xyz2rgbmat[i][2]*ciecolor[2] ; |
118 |
|
if (rgbcolor[i] < 0.0) |
119 |
|
rgbcolor[i] = 0.0; |
120 |
|
} |
121 |
+ |
} |
122 |
+ |
|
123 |
+ |
|
124 |
+ |
rgb_cie(ciecolor, rgbcolor) /* convert RGB to CIE */ |
125 |
+ |
register COLOR ciecolor, rgbcolor; |
126 |
+ |
{ |
127 |
+ |
register int i; |
128 |
+ |
|
129 |
+ |
for (i = 0; i < 3; i++) |
130 |
+ |
ciecolor[i] = rgb2xyzmat[i][0]*rgbcolor[0] + |
131 |
+ |
rgb2xyzmat[i][1]*rgbcolor[1] + |
132 |
+ |
rgb2xyzmat[i][2]*rgbcolor[2] ; |
133 |
|
} |