59 |
|
e_ies(), /* IES luminaire file */ |
60 |
|
e_include(), /* include file */ |
61 |
|
e_sph(), /* sphere */ |
62 |
+ |
e_cct(), /* color temperature */ |
63 |
|
e_cmix(), /* color mixtures */ |
64 |
|
e_cspec(), /* color spectra */ |
65 |
|
e_cyl(), /* cylinder */ |
120 |
|
if (mg_ehand[MG_E_COLOR] != NULL) { |
121 |
|
if (mg_ehand[MG_E_CMIX] == NULL) { |
122 |
|
mg_ehand[MG_E_CMIX] = e_cmix; |
123 |
< |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX; |
123 |
> |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX|1<<MG_E_CCT; |
124 |
|
} |
125 |
|
if (mg_ehand[MG_E_CSPEC] == NULL) { |
126 |
|
mg_ehand[MG_E_CSPEC] = e_cspec; |
127 |
< |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX; |
127 |
> |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX|1<<MG_E_CCT; |
128 |
|
} |
129 |
+ |
if (mg_ehand[MG_E_CCT] == NULL) { |
130 |
+ |
mg_ehand[MG_E_CCT] = e_cct; |
131 |
+ |
ineed |= 1<<MG_E_COLOR|1<<MG_E_CXY|1<<MG_E_CSPEC|1<<MG_E_CMIX|1<<MG_E_CCT; |
132 |
+ |
} |
133 |
|
} |
134 |
|
/* check for consistency */ |
135 |
|
if (mg_ehand[MG_E_FACE] != NULL) |
164 |
|
e_supp[MG_E_CSPEC] = c_hcolor; |
165 |
|
if (ineed & 1<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor) |
166 |
|
e_supp[MG_E_CMIX] = c_hcolor; |
167 |
+ |
if (ineed & 1<<MG_E_CCT && mg_ehand[MG_E_CCT] != c_hcolor) |
168 |
+ |
e_supp[MG_E_CCT] = c_hcolor; |
169 |
|
/* discard remaining entities */ |
170 |
|
for (i = 0; i < MG_NENTITIES; i++) |
171 |
|
if (mg_ehand[i] == NULL) |
173 |
|
} |
174 |
|
|
175 |
|
|
169 |
– |
|
176 |
|
int |
177 |
|
mg_entity(name) /* get entity number from its name */ |
178 |
|
char *name; |
974 |
|
|
975 |
|
|
976 |
|
static int |
977 |
< |
e_cspec(ac, av) /* handle spectral color */ |
972 |
< |
int ac; |
973 |
< |
char **av; |
977 |
> |
put_cxy() /* put out current xy chromaticities */ |
978 |
|
{ |
979 |
|
static char xbuf[24], ybuf[24]; |
980 |
|
static char *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf}; |
981 |
|
int rv; |
982 |
|
|
983 |
+ |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
984 |
+ |
sprintf(ybuf, "%.4f", c_ccolor->cy); |
985 |
+ |
if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK) |
986 |
+ |
return(rv); |
987 |
+ |
return(MG_OK); |
988 |
+ |
} |
989 |
+ |
|
990 |
+ |
|
991 |
+ |
static int |
992 |
+ |
put_cspec() /* put out current color spectrum */ |
993 |
+ |
{ |
994 |
+ |
char wl[2][6], vbuf[C_CNSS][24]; |
995 |
+ |
char *newav[C_CNSS+4]; |
996 |
+ |
double sf; |
997 |
+ |
register int i; |
998 |
+ |
|
999 |
+ |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
1000 |
+ |
sprintf(wl[0], "%d", C_CMINWL); |
1001 |
+ |
sprintf(wl[1], "%d", C_CMAXWL); |
1002 |
+ |
newav[0] = mg_ename[MG_E_CSPEC]; |
1003 |
+ |
newav[1] = wl[0]; |
1004 |
+ |
newav[2] = wl[1]; |
1005 |
+ |
sf = (double)C_CNSS / c_ccolor->ssum; |
1006 |
+ |
for (i = 0; i < C_CNSS; i++) { |
1007 |
+ |
sprintf(vbuf[i], "%.6f", sf*c_ccolor->ssamp[i]); |
1008 |
+ |
newav[i+3] = vbuf[i]; |
1009 |
+ |
} |
1010 |
+ |
newav[C_CNSS+3] = NULL; |
1011 |
+ |
if ((i = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1012 |
+ |
return(i); |
1013 |
+ |
} |
1014 |
+ |
return(MG_OK); |
1015 |
+ |
} |
1016 |
+ |
|
1017 |
+ |
|
1018 |
+ |
static int |
1019 |
+ |
e_cspec(ac, av) /* handle spectral color */ |
1020 |
+ |
int ac; |
1021 |
+ |
char **av; |
1022 |
+ |
{ |
1023 |
+ |
/* convert to xy chromaticity */ |
1024 |
|
c_ccvt(c_ccolor, C_CSXY); |
1025 |
|
/* if it's really their handler, use it */ |
1026 |
< |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
1027 |
< |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
983 |
< |
sprintf(ybuf, "%.4f", c_ccolor->cy); |
984 |
< |
if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK) |
985 |
< |
return(rv); |
986 |
< |
} |
1026 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1027 |
> |
return(put_cxy()); |
1028 |
|
return(MG_OK); |
1029 |
|
} |
1030 |
|
|
1034 |
|
int ac; |
1035 |
|
char **av; |
1036 |
|
{ |
996 |
– |
char wl[2][6], vbuf[C_CNSS][24]; |
997 |
– |
char *newav[C_CNSS+4]; |
998 |
– |
int rv; |
999 |
– |
register int i; |
1037 |
|
/* |
1038 |
|
* Contorted logic works as follows: |
1039 |
|
* 1. the colors are already mixed in c_hcolor() support function |
1044 |
|
*/ |
1045 |
|
if (mg_ehand[MG_E_CSPEC] == e_cspec) |
1046 |
|
c_ccvt(c_ccolor, C_CSXY); |
1047 |
< |
else if (c_ccolor->flags & C_CDSPEC) { |
1048 |
< |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
1049 |
< |
sprintf(wl[0], "%d", C_CMINWL); |
1050 |
< |
sprintf(wl[1], "%d", C_CMAXWL); |
1051 |
< |
newav[0] = mg_ename[MG_E_CSPEC]; |
1052 |
< |
newav[1] = wl[0]; |
1053 |
< |
newav[2] = wl[1]; |
1054 |
< |
for (i = 0; i < C_CNSS; i++) { |
1055 |
< |
sprintf(vbuf[i], "%.6f", |
1056 |
< |
(double)c_ccolor->ssamp[i] / |
1057 |
< |
c_ccolor->ssum); |
1058 |
< |
newav[i+3] = vbuf[i]; |
1059 |
< |
} |
1060 |
< |
newav[C_CNSS+3] = NULL; |
1061 |
< |
if ((rv = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1062 |
< |
return(rv); |
1063 |
< |
} |
1064 |
< |
return(MG_OK); |
1065 |
< |
} |
1066 |
< |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
1067 |
< |
sprintf(vbuf[0], "%.4f", c_ccolor->cx); |
1068 |
< |
sprintf(vbuf[1], "%.4f", c_ccolor->cy); |
1069 |
< |
newav[0] = mg_ename[MG_E_CXY]; |
1070 |
< |
newav[1] = vbuf[0]; |
1034 |
< |
newav[2] = vbuf[1]; |
1035 |
< |
newav[3] = NULL; |
1036 |
< |
if ((rv = mg_handle(MG_E_CXY, 3, newav)) != MG_OK) |
1037 |
< |
return(rv); |
1038 |
< |
} |
1047 |
> |
else if (c_ccolor->flags & C_CDSPEC) |
1048 |
> |
return(put_cspec()); |
1049 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1050 |
> |
return(put_cxy()); |
1051 |
> |
return(MG_OK); |
1052 |
> |
} |
1053 |
> |
|
1054 |
> |
|
1055 |
> |
static int |
1056 |
> |
e_cct(ac, av) /* handle color temperature */ |
1057 |
> |
int ac; |
1058 |
> |
char **av; |
1059 |
> |
{ |
1060 |
> |
/* |
1061 |
> |
* Logic is similar to e_cmix here. Support handler has already |
1062 |
> |
* converted temperature to spectral color. Put it out as such |
1063 |
> |
* if they support it, otherwise convert to xy chromaticity and |
1064 |
> |
* put it out if they handle it. |
1065 |
> |
*/ |
1066 |
> |
if (mg_ehand[MG_E_CSPEC] != e_cspec) |
1067 |
> |
return(put_cspec()); |
1068 |
> |
c_ccvt(c_ccolor, C_CSXY); |
1069 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1070 |
> |
return(put_cxy()); |
1071 |
|
return(MG_OK); |
1072 |
|
} |