10 |
|
#include <string.h> |
11 |
|
#include <fcntl.h> |
12 |
|
#include "resolu.h" |
13 |
+ |
#include "rtprocess.h" |
14 |
|
#include "rmatrix.h" |
15 |
|
|
16 |
|
static char rmx_mismatch_warn[] = "WARNING: data type mismatch\n"; |
47 |
|
int |
48 |
|
rmx_newtype(int dtyp1, int dtyp2) |
49 |
|
{ |
50 |
< |
if ((dtyp1==DTxyze) | (dtyp1==DTrgbe) && dtyp1 != dtyp2) |
50 |
> |
if ((dtyp1==DTxyze) | (dtyp1==DTrgbe) | |
51 |
> |
(dtyp2==DTxyze) | (dtyp2==DTrgbe) |
52 |
> |
&& dtyp1 != dtyp2) |
53 |
|
return(0); |
54 |
|
if (dtyp1 < dtyp2) |
55 |
|
return(dtyp1); |
187 |
|
|
188 |
|
/* Load matrix from supported file type */ |
189 |
|
RMATRIX * |
190 |
< |
rmx_load(const char *fname) |
190 |
> |
rmx_load(const char *inspec) |
191 |
|
{ |
192 |
|
FILE *fp = stdin; |
193 |
|
RMATRIX dinfo; |
194 |
|
RMATRIX *dnew; |
195 |
|
|
196 |
< |
if (fname == NULL) { /* reading from stdin? */ |
197 |
< |
fname = "<stdin>"; |
196 |
> |
if (inspec == NULL) { /* reading from stdin? */ |
197 |
> |
inspec = "<stdin>"; |
198 |
|
#ifdef _WIN32 |
199 |
|
_setmode(fileno(stdin), _O_BINARY); |
200 |
|
#endif |
201 |
+ |
} else if (inspec[0] == '!') { |
202 |
+ |
if ((fp = popen(inspec+1, "r")) == NULL) |
203 |
+ |
return(NULL); |
204 |
+ |
#ifdef _WIN32 |
205 |
+ |
_setmode(fileno(fp), _O_BINARY); |
206 |
+ |
#endif |
207 |
|
} else { |
208 |
< |
const char *sp = fname; /* check suffix */ |
208 |
> |
const char *sp = inspec; /* check suffix */ |
209 |
|
while (*sp) |
210 |
|
++sp; |
211 |
< |
while (sp > fname && sp[-1] != '.') |
211 |
> |
while (sp > inspec && sp[-1] != '.') |
212 |
|
--sp; |
213 |
|
if (!strcasecmp(sp, "XML")) { /* assume it's a BSDF */ |
214 |
< |
CMATRIX *cm = cm_loadBTDF((char *)fname); |
214 |
> |
CMATRIX *cm = cm_loadBTDF((char *)inspec); |
215 |
|
if (cm == NULL) |
216 |
|
return(NULL); |
217 |
|
dnew = rmx_from_cmatrix(cm); |
219 |
|
return(dnew); |
220 |
|
} |
221 |
|
/* else open it ourselves */ |
222 |
< |
if ((fp = fopen(fname, "rb")) == NULL) |
222 |
> |
if ((fp = fopen(inspec, "rb")) == NULL) |
223 |
|
return(NULL); |
224 |
|
} |
225 |
|
#ifdef getc_unlocked |
276 |
|
default: |
277 |
|
goto loaderr; |
278 |
|
} |
279 |
< |
if (fp != stdin) |
280 |
< |
fclose(fp); |
279 |
> |
if (fp != stdin) { |
280 |
> |
if (inspec[0] == '!') |
281 |
> |
pclose(fp); |
282 |
> |
else |
283 |
> |
fclose(fp); |
284 |
> |
} |
285 |
> |
#ifdef getc_unlocked |
286 |
> |
else |
287 |
> |
funlockfile(fp); |
288 |
> |
#endif |
289 |
|
return(dnew); |
290 |
|
loaderr: /* should report error? */ |
291 |
< |
fclose(fp); |
291 |
> |
if (inspec[0] == '!') |
292 |
> |
pclose(fp); |
293 |
> |
else |
294 |
> |
fclose(fp); |
295 |
|
rmx_free(dnew); |
296 |
|
return(NULL); |
297 |
|
} |
514 |
|
for (k = mres->ncomp; k--; ) { |
515 |
|
long double d = 0; |
516 |
|
for (h = m1->ncols; h--; ) |
517 |
< |
d += (long double)rmx_lval(m1,i,h,k) * |
498 |
< |
(long double)rmx_lval(m2,h,j,k); |
517 |
> |
d += rmx_lval(m1,i,h,k) * rmx_lval(m2,h,j,k); |
518 |
|
rmx_lval(mres,i,j,k) = (double)d; |
519 |
|
} |
520 |
|
return(mres); |