5 |
|
* General matrix operations. |
6 |
|
*/ |
7 |
|
|
8 |
– |
#include <stdio.h> |
8 |
|
#include <stdlib.h> |
10 |
– |
#include <string.h> |
11 |
– |
#include <fcntl.h> |
9 |
|
#include <errno.h> |
10 |
|
#include "rtio.h" |
11 |
|
#include "platform.h" |
29 |
|
return(NULL); |
30 |
|
dnew->nrows = nr; dnew->ncols = nc; dnew->ncomp = n; |
31 |
|
dnew->dtype = DTdouble; |
32 |
+ |
dnew->swapin = 0; |
33 |
|
dnew->info = NULL; |
34 |
|
return(dnew); |
35 |
|
} |
96 |
|
ip->ncols = atoi(s+6); |
97 |
|
return(0); |
98 |
|
} |
99 |
+ |
if ((i = isbigendian(s)) >= 0) { |
100 |
+ |
ip->swapin = (nativebigendian() != i); |
101 |
+ |
return(0); |
102 |
+ |
} |
103 |
+ |
if (isexpos(s)) { |
104 |
+ |
double d = exposval(s); |
105 |
+ |
scalecolor(ip->mtx, d); |
106 |
+ |
return(0); |
107 |
+ |
} |
108 |
+ |
if (iscolcor(s)) { |
109 |
+ |
COLOR ctmp; |
110 |
+ |
colcorval(ctmp, s); |
111 |
+ |
multcolor(ip->mtx, ctmp); |
112 |
+ |
return(0); |
113 |
+ |
} |
114 |
|
if (!formatval(fmt, s)) { |
115 |
|
rmx_addinfo(ip, s); |
116 |
|
return(0); |
150 |
|
for (j = 0; j < rm->ncols; j++) { |
151 |
|
if (getbinary(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
152 |
|
return(0); |
153 |
+ |
if (rm->swapin) |
154 |
+ |
swap32((char *)val, rm->ncomp); |
155 |
|
for (k = rm->ncomp; k--; ) |
156 |
|
rmx_lval(rm,i,j,k) = val[k]; |
157 |
|
} |
161 |
|
static int |
162 |
|
rmx_load_double(RMATRIX *rm, FILE *fp) |
163 |
|
{ |
164 |
< |
int i, j; |
164 |
> |
int i; |
165 |
|
|
166 |
< |
for (i = 0; i < rm->nrows; i++) |
167 |
< |
for (j = 0; j < rm->ncols; j++) |
168 |
< |
if (getbinary(&rmx_lval(rm,i,j,0), sizeof(double), rm->ncomp, fp) != rm->ncomp) |
169 |
< |
return(0); |
166 |
> |
if (&rmx_lval(rm,0,0,0) - &rmx_lval(rm,1,0,0) != rm->ncols*rm->ncomp) { |
167 |
> |
fputs("Code error in rmx_load_double()\n", stderr); |
168 |
> |
exit(1); |
169 |
> |
} |
170 |
> |
for (i = 0; i < rm->nrows; i++) { |
171 |
> |
if (getbinary(&rmx_lval(rm,i,0,0), sizeof(double)*rm->ncomp, |
172 |
> |
rm->ncols, fp) != rm->ncols) |
173 |
> |
return(0); |
174 |
> |
if (rm->swapin) |
175 |
> |
swap64((char *)&rmx_lval(rm,i,0,0), rm->ncols*rm->ncomp); |
176 |
> |
} |
177 |
|
return(1); |
178 |
|
} |
179 |
|
|
214 |
|
} else if (inspec[0] == '!') { |
215 |
|
if (!(fp = popen(inspec+1, "r"))) |
216 |
|
return(NULL); |
217 |
< |
SET_FILE_BINARY(stdin); |
217 |
> |
SET_FILE_BINARY(fp); |
218 |
|
} else { |
219 |
|
const char *sp = inspec; /* check suffix */ |
220 |
|
while (*sp) |
239 |
|
#endif |
240 |
|
dinfo.nrows = dinfo.ncols = dinfo.ncomp = 0; |
241 |
|
dinfo.dtype = DTascii; /* assumed w/o FORMAT */ |
242 |
+ |
dinfo.swapin = 0; |
243 |
|
dinfo.info = NULL; |
244 |
+ |
dinfo.mtx[0] = dinfo.mtx[1] = dinfo.mtx[2] = 1.; |
245 |
|
if (getheader(fp, get_dminfo, &dinfo) < 0) { |
246 |
|
fclose(fp); |
247 |
|
return(NULL); |
267 |
|
dnew->info = dinfo.info; |
268 |
|
switch (dinfo.dtype) { |
269 |
|
case DTascii: |
270 |
< |
SET_FILE_TEXT(stdin); |
270 |
> |
SET_FILE_TEXT(fp); |
271 |
|
if (!rmx_load_ascii(dnew, fp)) |
272 |
|
goto loaderr; |
273 |
|
dnew->dtype = DTascii; /* should leave double? */ |
274 |
|
break; |
275 |
|
case DTfloat: |
276 |
+ |
dnew->swapin = dinfo.swapin; |
277 |
|
if (!rmx_load_float(dnew, fp)) |
278 |
|
goto loaderr; |
279 |
|
dnew->dtype = DTfloat; |
280 |
|
break; |
281 |
|
case DTdouble: |
282 |
+ |
dnew->swapin = dinfo.swapin; |
283 |
|
if (!rmx_load_double(dnew, fp)) |
284 |
|
goto loaderr; |
285 |
|
dnew->dtype = DTdouble; |
288 |
|
case DTxyze: |
289 |
|
if (!rmx_load_rgbe(dnew, fp)) |
290 |
|
goto loaderr; |
291 |
< |
dnew->dtype = dinfo.dtype; |
291 |
> |
dnew->dtype = dinfo.dtype; /* undo exposure? */ |
292 |
> |
if ((dinfo.mtx[0] != 1.) | (dinfo.mtx[1] != 1.) | |
293 |
> |
(dinfo.mtx[2] != 1.)) { |
294 |
> |
dinfo.mtx[0] = 1./dinfo.mtx[0]; |
295 |
> |
dinfo.mtx[1] = 1./dinfo.mtx[1]; |
296 |
> |
dinfo.mtx[2] = 1./dinfo.mtx[2]; |
297 |
> |
rmx_scale(dnew, dinfo.mtx); |
298 |
> |
} |
299 |
|
break; |
300 |
|
default: |
301 |
|
goto loaderr; |
428 |
|
return(0); |
429 |
|
rm = mydm; |
430 |
|
} |
431 |
+ |
if ((dtype == DTfloat) | (dtype == DTdouble)) |
432 |
+ |
fputendian(fp); /* important to record */ |
433 |
|
fputformat((char *)cm_fmt_id[dtype], fp); |
434 |
|
fputc('\n', fp); |
435 |
|
switch (dtype) { /* write data */ |
603 |
|
rmx_lval(m1,i,j,k) *= rmx_lval(m2,i,j,k); |
604 |
|
} |
605 |
|
if (zeroDivides) { |
606 |
< |
fputs("Divide by zero in rmx_elemult()\n", stderr); |
606 |
> |
rmx_addinfo(m1, "WARNING: zero divide(s) corrupted results\n"); |
607 |
|
errno = ERANGE; |
608 |
|
} |
609 |
|
return(1); |
675 |
|
return(NULL); |
676 |
|
if (msrc->info) { |
677 |
|
char buf[128]; |
678 |
< |
sprintf(buf, "Applied %dx%d matrix transform\n", |
678 |
> |
sprintf(buf, "Applied %dx%d component transform\n", |
679 |
|
dnew->ncomp, msrc->ncomp); |
680 |
|
rmx_addinfo(dnew, msrc->info); |
681 |
|
rmx_addinfo(dnew, buf); |