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 |
255 |
|
case DTascii: |
256 |
|
if (!rmx_load_ascii(dnew, fp)) |
257 |
|
goto loaderr; |
258 |
+ |
dnew->dtype = DTascii; /* should leave double? */ |
259 |
|
break; |
260 |
|
case DTfloat: |
261 |
|
if (!rmx_load_float(dnew, fp)) |
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 |
|
} |
438 |
|
rmx_identity(const int dim, const int n) |
439 |
|
{ |
440 |
|
RMATRIX *rid = rmx_alloc(dim, dim, n); |
441 |
< |
int i; |
441 |
> |
int i, k; |
442 |
|
|
443 |
|
if (rid == NULL) |
444 |
|
return(NULL); |
445 |
< |
memset(rid->mtx, 0, sizeof(rid->mtx[0])*dim*dim); |
445 |
> |
memset(rid->mtx, 0, sizeof(rid->mtx[0])*n*dim*dim); |
446 |
|
for (i = dim; i--; ) |
447 |
< |
rmx_lval(rid,i,i,0) = 1; |
448 |
< |
for (i = n; --i; ) |
428 |
< |
memcpy(rid->mtx+i*(dim*dim), rid->mtx, |
429 |
< |
sizeof(rid->mtx[0])*dim*dim); |
447 |
> |
for (k = n; k--; ) |
448 |
> |
rmx_lval(rid,i,i,k) = 1; |
449 |
|
return(rid); |
450 |
|
} |
451 |
|
|