1 |
< |
/* Copyright (c) 1994 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
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) |
138 |
|
mg_ehand[MG_E_CMIX] != NULL) |
139 |
|
uneed |= 1<<MG_E_COLOR; |
140 |
|
if (mg_ehand[MG_E_RD] != NULL || mg_ehand[MG_E_TD] != NULL || |
141 |
+ |
mg_ehand[MG_E_IR] != NULL || |
142 |
|
mg_ehand[MG_E_ED] != NULL || |
143 |
|
mg_ehand[MG_E_RS] != NULL || |
144 |
|
mg_ehand[MG_E_TS] != NULL || |
165 |
|
e_supp[MG_E_CSPEC] = c_hcolor; |
166 |
|
if (ineed & 1<<MG_E_CMIX && mg_ehand[MG_E_CMIX] != c_hcolor) |
167 |
|
e_supp[MG_E_CMIX] = c_hcolor; |
168 |
+ |
if (ineed & 1<<MG_E_CCT && mg_ehand[MG_E_CCT] != c_hcolor) |
169 |
+ |
e_supp[MG_E_CCT] = c_hcolor; |
170 |
|
/* discard remaining entities */ |
171 |
|
for (i = 0; i < MG_NENTITIES; i++) |
172 |
|
if (mg_ehand[i] == NULL) |
174 |
|
} |
175 |
|
|
176 |
|
|
169 |
– |
|
177 |
|
int |
178 |
|
mg_entity(name) /* get entity number from its name */ |
179 |
|
char *name; |
219 |
|
char *fn; |
220 |
|
{ |
221 |
|
static int nfids; |
215 |
– |
int olen; |
222 |
|
register char *cp; |
223 |
|
|
224 |
|
ctx->fid = ++nfids; |
231 |
|
return(MG_OK); |
232 |
|
} |
233 |
|
/* get name relative to this context */ |
234 |
< |
if (mg_file != NULL && |
229 |
< |
(cp = strrchr(mg_file->fname, '/')) != NULL) |
230 |
< |
olen = cp - mg_file->fname + 1; |
231 |
< |
else |
232 |
< |
olen = 0; |
233 |
< |
if (olen) |
234 |
> |
if (mg_file != NULL && (cp = strrchr(mg_file->fname, '/')) != NULL) { |
235 |
|
strcpy(ctx->fname, mg_file->fname); |
236 |
< |
strcpy(ctx->fname+olen, fn); |
236 |
> |
strcpy(ctx->fname+(cp-mg_file->fname+1), fn); |
237 |
> |
} else |
238 |
> |
strcpy(ctx->fname, fn); |
239 |
|
ctx->fp = fopen(ctx->fname, "r"); |
240 |
|
if (ctx->fp == NULL) |
241 |
|
return(MG_ENOFILE); |
386 |
|
{ |
387 |
|
char *xfarg[MG_MAXARGC]; |
388 |
|
MG_FCTXT ictx; |
389 |
+ |
XF_SPEC *xf_orig = xf_context; |
390 |
|
int rv; |
391 |
|
|
392 |
|
if (ac < 2) |
403 |
|
if ((rv = mg_handle(MG_E_XF, ac-1, xfarg)) != MG_OK) |
404 |
|
return(rv); |
405 |
|
} |
406 |
< |
while (!feof(mg_file->fp)) { |
406 |
> |
do { |
407 |
|
while (mg_read()) |
408 |
|
if ((rv = mg_parse()) != MG_OK) { |
409 |
|
fprintf(stderr, "%s: %d: %s:\n%s", ictx.fname, |
415 |
|
if (ac > 2) |
416 |
|
if ((rv = mg_handle(MG_E_XF, 1, xfarg)) != MG_OK) |
417 |
|
return(rv); |
418 |
< |
} |
418 |
> |
} while (xf_context != xf_orig); |
419 |
|
mg_close(); |
420 |
|
return(MG_OK); |
421 |
|
} |
972 |
|
|
973 |
|
|
974 |
|
static int |
975 |
< |
e_cspec(ac, av) /* handle spectral color */ |
972 |
< |
int ac; |
973 |
< |
char **av; |
975 |
> |
put_cxy() /* put out current xy chromaticities */ |
976 |
|
{ |
977 |
|
static char xbuf[24], ybuf[24]; |
978 |
|
static char *ccom[4] = {mg_ename[MG_E_CXY], xbuf, ybuf}; |
979 |
|
int rv; |
980 |
|
|
981 |
+ |
sprintf(xbuf, "%.4f", c_ccolor->cx); |
982 |
+ |
sprintf(ybuf, "%.4f", c_ccolor->cy); |
983 |
+ |
if ((rv = mg_handle(MG_E_CXY, 3, ccom)) != MG_OK) |
984 |
+ |
return(rv); |
985 |
+ |
return(MG_OK); |
986 |
+ |
} |
987 |
+ |
|
988 |
+ |
|
989 |
+ |
static int |
990 |
+ |
put_cspec() /* put out current color spectrum */ |
991 |
+ |
{ |
992 |
+ |
char wl[2][6], vbuf[C_CNSS][24]; |
993 |
+ |
char *newav[C_CNSS+4]; |
994 |
+ |
double sf; |
995 |
+ |
register int i; |
996 |
+ |
|
997 |
+ |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
998 |
+ |
sprintf(wl[0], "%d", C_CMINWL); |
999 |
+ |
sprintf(wl[1], "%d", C_CMAXWL); |
1000 |
+ |
newav[0] = mg_ename[MG_E_CSPEC]; |
1001 |
+ |
newav[1] = wl[0]; |
1002 |
+ |
newav[2] = wl[1]; |
1003 |
+ |
sf = (double)C_CNSS / c_ccolor->ssum; |
1004 |
+ |
for (i = 0; i < C_CNSS; i++) { |
1005 |
+ |
sprintf(vbuf[i], "%.4f", sf*c_ccolor->ssamp[i]); |
1006 |
+ |
newav[i+3] = vbuf[i]; |
1007 |
+ |
} |
1008 |
+ |
newav[C_CNSS+3] = NULL; |
1009 |
+ |
if ((i = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1010 |
+ |
return(i); |
1011 |
+ |
} |
1012 |
+ |
return(MG_OK); |
1013 |
+ |
} |
1014 |
+ |
|
1015 |
+ |
|
1016 |
+ |
static int |
1017 |
+ |
e_cspec(ac, av) /* handle spectral color */ |
1018 |
+ |
int ac; |
1019 |
+ |
char **av; |
1020 |
+ |
{ |
1021 |
+ |
/* convert to xy chromaticity */ |
1022 |
|
c_ccvt(c_ccolor, C_CSXY); |
1023 |
|
/* if it's really their handler, use it */ |
1024 |
< |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
1025 |
< |
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 |
< |
} |
1024 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1025 |
> |
return(put_cxy()); |
1026 |
|
return(MG_OK); |
1027 |
|
} |
1028 |
|
|
1032 |
|
int ac; |
1033 |
|
char **av; |
1034 |
|
{ |
996 |
– |
char wl[2][6], vbuf[C_CNSS][24]; |
997 |
– |
char *newav[C_CNSS+4]; |
998 |
– |
int rv; |
999 |
– |
register int i; |
1035 |
|
/* |
1036 |
|
* Contorted logic works as follows: |
1037 |
|
* 1. the colors are already mixed in c_hcolor() support function |
1042 |
|
*/ |
1043 |
|
if (mg_ehand[MG_E_CSPEC] == e_cspec) |
1044 |
|
c_ccvt(c_ccolor, C_CSXY); |
1045 |
< |
else if (c_ccolor->flags & C_CDSPEC) { |
1046 |
< |
if (mg_ehand[MG_E_CSPEC] != c_hcolor) { |
1047 |
< |
sprintf(wl[0], "%d", C_CMINWL); |
1048 |
< |
sprintf(wl[1], "%d", C_CMAXWL); |
1049 |
< |
newav[0] = mg_ename[MG_E_CSPEC]; |
1050 |
< |
newav[1] = wl[0]; |
1051 |
< |
newav[2] = wl[1]; |
1052 |
< |
for (i = 0; i < C_CNSS; i++) { |
1053 |
< |
sprintf(vbuf[i], "%.6f", |
1054 |
< |
(double)c_ccolor->ssamp[i] / |
1055 |
< |
c_ccolor->ssum); |
1056 |
< |
newav[i+3] = vbuf[i]; |
1057 |
< |
} |
1058 |
< |
newav[C_CNSS+3] = NULL; |
1059 |
< |
if ((rv = mg_handle(MG_E_CSPEC, C_CNSS+3, newav)) != MG_OK) |
1060 |
< |
return(rv); |
1061 |
< |
} |
1062 |
< |
return(MG_OK); |
1063 |
< |
} |
1064 |
< |
if (mg_ehand[MG_E_CXY] != c_hcolor) { |
1065 |
< |
sprintf(vbuf[0], "%.4f", c_ccolor->cx); |
1066 |
< |
sprintf(vbuf[1], "%.4f", c_ccolor->cy); |
1067 |
< |
newav[0] = mg_ename[MG_E_CXY]; |
1068 |
< |
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 |
< |
} |
1045 |
> |
else if (c_ccolor->flags & C_CDSPEC) |
1046 |
> |
return(put_cspec()); |
1047 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1048 |
> |
return(put_cxy()); |
1049 |
> |
return(MG_OK); |
1050 |
> |
} |
1051 |
> |
|
1052 |
> |
|
1053 |
> |
static int |
1054 |
> |
e_cct(ac, av) /* handle color temperature */ |
1055 |
> |
int ac; |
1056 |
> |
char **av; |
1057 |
> |
{ |
1058 |
> |
/* |
1059 |
> |
* Logic is similar to e_cmix here. Support handler has already |
1060 |
> |
* converted temperature to spectral color. Put it out as such |
1061 |
> |
* if they support it, otherwise convert to xy chromaticity and |
1062 |
> |
* put it out if they handle it. |
1063 |
> |
*/ |
1064 |
> |
if (mg_ehand[MG_E_CSPEC] != e_cspec) |
1065 |
> |
return(put_cspec()); |
1066 |
> |
c_ccvt(c_ccolor, C_CSXY); |
1067 |
> |
if (mg_ehand[MG_E_CXY] != c_hcolor) |
1068 |
> |
return(put_cxy()); |
1069 |
|
return(MG_OK); |
1070 |
|
} |