| 9 |
|
#include <stdlib.h> |
| 10 |
|
#include <string.h> |
| 11 |
|
#include <fcntl.h> |
| 12 |
+ |
#include <errno.h> |
| 13 |
+ |
#include "rtio.h" |
| 14 |
+ |
#include "platform.h" |
| 15 |
|
#include "resolu.h" |
| 16 |
+ |
#include "paths.h" |
| 17 |
|
#include "rmatrix.h" |
| 18 |
|
|
| 19 |
< |
typedef struct { |
| 16 |
< |
int nrows, ncols, ncomp; |
| 17 |
< |
int dtype; |
| 18 |
< |
} DMINFO; |
| 19 |
> |
static char rmx_mismatch_warn[] = "WARNING: data type mismatch\n"; |
| 20 |
|
|
| 21 |
|
/* Allocate a nr x nc matrix with n components */ |
| 22 |
|
RMATRIX * |
| 31 |
|
if (dnew == NULL) |
| 32 |
|
return(NULL); |
| 33 |
|
dnew->nrows = nr; dnew->ncols = nc; dnew->ncomp = n; |
| 34 |
+ |
dnew->dtype = DTdouble; |
| 35 |
+ |
dnew->info = NULL; |
| 36 |
|
return(dnew); |
| 37 |
|
} |
| 38 |
|
|
| 39 |
+ |
/* Free a RMATRIX array */ |
| 40 |
+ |
void |
| 41 |
+ |
rmx_free(RMATRIX *rm) |
| 42 |
+ |
{ |
| 43 |
+ |
if (!rm) return; |
| 44 |
+ |
if (rm->info) |
| 45 |
+ |
free(rm->info); |
| 46 |
+ |
free(rm); |
| 47 |
+ |
} |
| 48 |
+ |
|
| 49 |
+ |
/* Resolve data type based on two input types (returns 0 for mismatch) */ |
| 50 |
+ |
int |
| 51 |
+ |
rmx_newtype(int dtyp1, int dtyp2) |
| 52 |
+ |
{ |
| 53 |
+ |
if ((dtyp1==DTxyze) | (dtyp1==DTrgbe) | |
| 54 |
+ |
(dtyp2==DTxyze) | (dtyp2==DTrgbe) |
| 55 |
+ |
&& dtyp1 != dtyp2) |
| 56 |
+ |
return(0); |
| 57 |
+ |
if (dtyp1 < dtyp2) |
| 58 |
+ |
return(dtyp1); |
| 59 |
+ |
return(dtyp2); |
| 60 |
+ |
} |
| 61 |
+ |
|
| 62 |
+ |
/* Append header information associated with matrix data */ |
| 63 |
+ |
int |
| 64 |
+ |
rmx_addinfo(RMATRIX *rm, const char *info) |
| 65 |
+ |
{ |
| 66 |
+ |
if (!info || !*info) |
| 67 |
+ |
return(0); |
| 68 |
+ |
if (!rm->info) { |
| 69 |
+ |
rm->info = (char *)malloc(strlen(info)+1); |
| 70 |
+ |
if (rm->info) rm->info[0] = '\0'; |
| 71 |
+ |
} else |
| 72 |
+ |
rm->info = (char *)realloc(rm->info, |
| 73 |
+ |
strlen(rm->info)+strlen(info)+1); |
| 74 |
+ |
if (!rm->info) |
| 75 |
+ |
return(0); |
| 76 |
+ |
strcat(rm->info, info); |
| 77 |
+ |
return(1); |
| 78 |
+ |
} |
| 79 |
+ |
|
| 80 |
|
static int |
| 81 |
|
get_dminfo(char *s, void *p) |
| 82 |
|
{ |
| 83 |
< |
DMINFO *ip = (DMINFO *)p; |
| 84 |
< |
char fmt[32]; |
| 83 |
> |
RMATRIX *ip = (RMATRIX *)p; |
| 84 |
> |
char fmt[64]; |
| 85 |
|
int i; |
| 86 |
|
|
| 87 |
+ |
if (headidval(fmt, s)) |
| 88 |
+ |
return(0); |
| 89 |
|
if (!strncmp(s, "NCOMP=", 6)) { |
| 90 |
|
ip->ncomp = atoi(s+6); |
| 91 |
|
return(0); |
| 98 |
|
ip->ncols = atoi(s+6); |
| 99 |
|
return(0); |
| 100 |
|
} |
| 101 |
< |
if (!formatval(fmt, s)) |
| 101 |
> |
if (!formatval(fmt, s)) { |
| 102 |
> |
rmx_addinfo(ip, s); |
| 103 |
|
return(0); |
| 104 |
+ |
} |
| 105 |
|
for (i = 1; i < DTend; i++) |
| 106 |
|
if (!strcmp(fmt, cm_fmt_id[i])) { |
| 107 |
|
ip->dtype = i; |
| 114 |
|
rmx_load_ascii(RMATRIX *rm, FILE *fp) |
| 115 |
|
{ |
| 116 |
|
int i, j, k; |
| 117 |
< |
#ifdef _WIN32 |
| 70 |
< |
_setmode(fileno(fp), _O_TEXT); |
| 71 |
< |
#endif |
| 117 |
> |
|
| 118 |
|
for (i = 0; i < rm->nrows; i++) |
| 119 |
|
for (j = 0; j < rm->ncols; j++) |
| 120 |
|
for (k = 0; k < rm->ncomp; k++) |
| 135 |
|
} |
| 136 |
|
for (i = 0; i < rm->nrows; i++) |
| 137 |
|
for (j = 0; j < rm->ncols; j++) { |
| 138 |
< |
if (fread(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
| 138 |
> |
if (getbinary(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
| 139 |
|
return(0); |
| 140 |
|
for (k = rm->ncomp; k--; ) |
| 141 |
|
rmx_lval(rm,i,j,k) = val[k]; |
| 146 |
|
static int |
| 147 |
|
rmx_load_double(RMATRIX *rm, FILE *fp) |
| 148 |
|
{ |
| 149 |
< |
int i, j, k; |
| 104 |
< |
double val[100]; |
| 149 |
> |
int i, j; |
| 150 |
|
|
| 106 |
– |
if (rm->ncomp > 100) { |
| 107 |
– |
fputs("Unsupported # components in rmx_load_double()\n", stderr); |
| 108 |
– |
exit(1); |
| 109 |
– |
} |
| 151 |
|
for (i = 0; i < rm->nrows; i++) |
| 152 |
< |
for (j = 0; j < rm->ncols; j++) { |
| 153 |
< |
if (fread(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
| 152 |
> |
for (j = 0; j < rm->ncols; j++) |
| 153 |
> |
if (getbinary(&rmx_lval(rm,i,j,0), sizeof(double), rm->ncomp, fp) != rm->ncomp) |
| 154 |
|
return(0); |
| 114 |
– |
for (k = rm->ncomp; k--; ) |
| 115 |
– |
rmx_lval(rm,i,j,k) = val[k]; |
| 116 |
– |
} |
| 155 |
|
return(1); |
| 156 |
|
} |
| 157 |
|
|
| 180 |
|
|
| 181 |
|
/* Load matrix from supported file type */ |
| 182 |
|
RMATRIX * |
| 183 |
< |
rmx_load(const char *fname) |
| 183 |
> |
rmx_load(const char *inspec) |
| 184 |
|
{ |
| 185 |
|
FILE *fp = stdin; |
| 186 |
< |
DMINFO dinfo; |
| 186 |
> |
RMATRIX dinfo; |
| 187 |
|
RMATRIX *dnew; |
| 188 |
|
|
| 189 |
< |
if (fname == NULL) { /* reading from stdin? */ |
| 190 |
< |
fname = "<stdin>"; |
| 189 |
> |
if (inspec == NULL) { /* reading from stdin? */ |
| 190 |
> |
inspec = "<stdin>"; |
| 191 |
> |
SET_FILE_BINARY(stdin); |
| 192 |
> |
} else if (inspec[0] == '!') { |
| 193 |
> |
if ((fp = popen(inspec+1, "r")) == NULL) |
| 194 |
> |
return(NULL); |
| 195 |
> |
SET_FILE_BINARY(stdin); |
| 196 |
|
} else { |
| 197 |
< |
const char *sp = fname; /* check suffix */ |
| 197 |
> |
const char *sp = inspec; /* check suffix */ |
| 198 |
|
while (*sp) |
| 199 |
|
++sp; |
| 200 |
< |
while (sp > fname && sp[-1] != '.') |
| 200 |
> |
while (sp > inspec && sp[-1] != '.') |
| 201 |
|
--sp; |
| 202 |
|
if (!strcasecmp(sp, "XML")) { /* assume it's a BSDF */ |
| 203 |
< |
CMATRIX *cm = cm_loadBTDF((char *)fname); |
| 203 |
> |
CMATRIX *cm = cm_loadBTDF((char *)inspec); |
| 204 |
|
if (cm == NULL) |
| 205 |
|
return(NULL); |
| 206 |
|
dnew = rmx_from_cmatrix(cm); |
| 207 |
|
cm_free(cm); |
| 208 |
+ |
dnew->dtype = DTascii; |
| 209 |
|
return(dnew); |
| 210 |
|
} |
| 211 |
|
/* else open it ourselves */ |
| 212 |
< |
if ((fp = fopen(fname, "rb")) == NULL) |
| 212 |
> |
if ((fp = fopen(inspec, "rb")) == NULL) |
| 213 |
|
return(NULL); |
| 214 |
|
} |
| 215 |
|
#ifdef getc_unlocked |
| 216 |
|
flockfile(fp); |
| 217 |
|
#endif |
| 218 |
|
dinfo.nrows = dinfo.ncols = dinfo.ncomp = 0; |
| 219 |
< |
dinfo.dtype = DTascii; |
| 219 |
> |
dinfo.dtype = DTascii; /* assumed w/o FORMAT */ |
| 220 |
> |
dinfo.info = NULL; |
| 221 |
|
if (getheader(fp, get_dminfo, &dinfo) < 0) { |
| 222 |
|
fclose(fp); |
| 223 |
|
return(NULL); |
| 224 |
|
} |
| 225 |
< |
if ((dinfo.dtype == DTrgbe) | (dinfo.dtype == DTxyze)) { |
| 225 |
> |
if ((dinfo.nrows <= 0) | (dinfo.ncols <= 0)) { |
| 226 |
|
if (!fscnresolu(&dinfo.ncols, &dinfo.nrows, fp)) { |
| 227 |
|
fclose(fp); |
| 228 |
|
return(NULL); |
| 229 |
|
} |
| 230 |
< |
dinfo.ncomp = 3; |
| 230 |
> |
if (dinfo.ncomp <= 0) |
| 231 |
> |
dinfo.ncomp = 3; |
| 232 |
> |
else if ((dinfo.dtype == DTrgbe) | (dinfo.dtype == DTxyze) && |
| 233 |
> |
dinfo.ncomp != 3) { |
| 234 |
> |
fclose(fp); |
| 235 |
> |
return(NULL); |
| 236 |
> |
} |
| 237 |
|
} |
| 238 |
|
dnew = rmx_alloc(dinfo.nrows, dinfo.ncols, dinfo.ncomp); |
| 239 |
|
if (dnew == NULL) { |
| 240 |
|
fclose(fp); |
| 241 |
|
return(NULL); |
| 242 |
|
} |
| 243 |
+ |
dnew->info = dinfo.info; |
| 244 |
|
switch (dinfo.dtype) { |
| 245 |
|
case DTascii: |
| 246 |
+ |
SET_FILE_TEXT(stdin); |
| 247 |
|
if (!rmx_load_ascii(dnew, fp)) |
| 248 |
|
goto loaderr; |
| 249 |
+ |
dnew->dtype = DTascii; /* should leave double? */ |
| 250 |
|
break; |
| 251 |
|
case DTfloat: |
| 252 |
|
if (!rmx_load_float(dnew, fp)) |
| 253 |
|
goto loaderr; |
| 254 |
+ |
dnew->dtype = DTfloat; |
| 255 |
|
break; |
| 256 |
|
case DTdouble: |
| 257 |
|
if (!rmx_load_double(dnew, fp)) |
| 258 |
|
goto loaderr; |
| 259 |
+ |
dnew->dtype = DTdouble; |
| 260 |
|
break; |
| 261 |
|
case DTrgbe: |
| 262 |
|
case DTxyze: |
| 263 |
|
if (!rmx_load_rgbe(dnew, fp)) |
| 264 |
|
goto loaderr; |
| 265 |
+ |
dnew->dtype = dinfo.dtype; |
| 266 |
|
break; |
| 267 |
|
default: |
| 268 |
|
goto loaderr; |
| 269 |
|
} |
| 270 |
< |
if (fp != stdin) |
| 271 |
< |
fclose(fp); |
| 270 |
> |
if (fp != stdin) { |
| 271 |
> |
if (inspec[0] == '!') |
| 272 |
> |
pclose(fp); |
| 273 |
> |
else |
| 274 |
> |
fclose(fp); |
| 275 |
> |
} |
| 276 |
> |
#ifdef getc_unlocked |
| 277 |
> |
else |
| 278 |
> |
funlockfile(fp); |
| 279 |
> |
#endif |
| 280 |
|
return(dnew); |
| 281 |
|
loaderr: /* should report error? */ |
| 282 |
< |
fclose(fp); |
| 282 |
> |
if (inspec[0] == '!') |
| 283 |
> |
pclose(fp); |
| 284 |
> |
else |
| 285 |
> |
fclose(fp); |
| 286 |
|
rmx_free(dnew); |
| 287 |
|
return(NULL); |
| 288 |
|
} |
| 291 |
|
rmx_write_ascii(const RMATRIX *rm, FILE *fp) |
| 292 |
|
{ |
| 293 |
|
int i, j, k; |
| 294 |
< |
#ifdef _WIN32 |
| 227 |
< |
_setmode(fileno(fp), _O_TEXT); |
| 228 |
< |
#endif |
| 294 |
> |
|
| 295 |
|
for (i = 0; i < rm->nrows; i++) { |
| 296 |
|
for (j = 0; j < rm->ncols; j++) { |
| 297 |
|
for (k = 0; k < rm->ncomp; k++) |
| 317 |
|
for (j = 0; j < rm->ncols; j++) { |
| 318 |
|
for (k = rm->ncomp; k--; ) |
| 319 |
|
val[k] = (float)rmx_lval(rm,i,j,k); |
| 320 |
< |
if (fwrite(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
| 320 |
> |
if (putbinary(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
| 321 |
|
return(0); |
| 322 |
|
} |
| 323 |
|
return(1); |
| 326 |
|
static int |
| 327 |
|
rmx_write_double(const RMATRIX *rm, FILE *fp) |
| 328 |
|
{ |
| 329 |
< |
int i, j, k; |
| 264 |
< |
double val[100]; |
| 329 |
> |
int i, j; |
| 330 |
|
|
| 266 |
– |
if (rm->ncomp > 100) { |
| 267 |
– |
fputs("Unsupported # components in rmx_write_double()\n", stderr); |
| 268 |
– |
exit(1); |
| 269 |
– |
} |
| 331 |
|
for (i = 0; i < rm->nrows; i++) |
| 332 |
< |
for (j = 0; j < rm->ncols; j++) { |
| 333 |
< |
for (k = rm->ncomp; k--; ) |
| 273 |
< |
val[k] = rmx_lval(rm,i,j,k); |
| 274 |
< |
if (fwrite(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
| 332 |
> |
for (j = 0; j < rm->ncols; j++) |
| 333 |
> |
if (putbinary(&rmx_lval(rm,i,j,0), sizeof(double), rm->ncomp, fp) != rm->ncomp) |
| 334 |
|
return(0); |
| 276 |
– |
} |
| 335 |
|
return(1); |
| 336 |
|
} |
| 337 |
|
|
| 357 |
|
return(1); |
| 358 |
|
} |
| 359 |
|
|
| 360 |
< |
/* Write matrix to file type indicated by dt */ |
| 361 |
< |
long |
| 360 |
> |
/* Write matrix to file type indicated by dtype */ |
| 361 |
> |
int |
| 362 |
|
rmx_write(const RMATRIX *rm, int dtype, FILE *fp) |
| 363 |
|
{ |
| 364 |
|
RMATRIX *mydm = NULL; |
| 366 |
|
|
| 367 |
|
if ((rm == NULL) | (fp == NULL)) |
| 368 |
|
return(0); |
| 369 |
+ |
#ifdef getc_unlocked |
| 370 |
+ |
flockfile(fp); |
| 371 |
+ |
#endif |
| 372 |
|
/* complete header */ |
| 373 |
+ |
if (rm->info) |
| 374 |
+ |
fputs(rm->info, fp); |
| 375 |
+ |
if (dtype == DTfromHeader) |
| 376 |
+ |
dtype = rm->dtype; |
| 377 |
+ |
else if ((dtype == DTrgbe) & (rm->dtype == DTxyze)) |
| 378 |
+ |
dtype = DTxyze; |
| 379 |
+ |
else if ((dtype == DTxyze) & (rm->dtype == DTrgbe)) |
| 380 |
+ |
dtype = DTrgbe; |
| 381 |
|
if ((dtype != DTrgbe) & (dtype != DTxyze)) { |
| 382 |
|
fprintf(fp, "NROWS=%d\n", rm->nrows); |
| 383 |
|
fprintf(fp, "NCOLS=%d\n", rm->ncols); |
| 413 |
|
return(0); |
| 414 |
|
} |
| 415 |
|
ok &= (fflush(fp) == 0); |
| 416 |
+ |
#ifdef getc_unlocked |
| 417 |
+ |
funlockfile(fp); |
| 418 |
+ |
#endif |
| 419 |
|
rmx_free(mydm); |
| 420 |
< |
return(ftell(fp) * ok); /* return # bytes written */ |
| 420 |
> |
return(ok); |
| 421 |
|
} |
| 422 |
|
|
| 423 |
|
/* Allocate and assign square identity matrix with n components */ |
| 425 |
|
rmx_identity(const int dim, const int n) |
| 426 |
|
{ |
| 427 |
|
RMATRIX *rid = rmx_alloc(dim, dim, n); |
| 428 |
< |
int i; |
| 428 |
> |
int i, k; |
| 429 |
|
|
| 430 |
|
if (rid == NULL) |
| 431 |
|
return(NULL); |
| 432 |
< |
memset(rid->mtx, 0, sizeof(rid->mtx[0])*dim*dim); |
| 432 |
> |
memset(rid->mtx, 0, sizeof(rid->mtx[0])*n*dim*dim); |
| 433 |
|
for (i = dim; i--; ) |
| 434 |
< |
rmx_lval(rid,i,i,0) = 1; |
| 435 |
< |
for (i = n; --i; ) |
| 364 |
< |
memcpy(rid->mtx+i*(dim*dim), rid->mtx, |
| 365 |
< |
sizeof(rid->mtx[0])*dim*dim); |
| 434 |
> |
for (k = n; k--; ) |
| 435 |
> |
rmx_lval(rid,i,i,k) = 1; |
| 436 |
|
return(rid); |
| 437 |
|
} |
| 438 |
|
|
| 447 |
|
dnew = rmx_alloc(rm->nrows, rm->ncols, rm->ncomp); |
| 448 |
|
if (dnew == NULL) |
| 449 |
|
return(NULL); |
| 450 |
+ |
rmx_addinfo(dnew, rm->info); |
| 451 |
+ |
dnew->dtype = rm->dtype; |
| 452 |
|
memcpy(dnew->mtx, rm->mtx, |
| 453 |
|
sizeof(rm->mtx[0])*rm->ncomp*rm->nrows*rm->ncols); |
| 454 |
|
return(dnew); |
| 466 |
|
dnew = rmx_alloc(rm->ncols, rm->nrows, rm->ncomp); |
| 467 |
|
if (dnew == NULL) |
| 468 |
|
return(NULL); |
| 469 |
+ |
if (rm->info) { |
| 470 |
+ |
rmx_addinfo(dnew, rm->info); |
| 471 |
+ |
rmx_addinfo(dnew, "Transposed rows and columns\n"); |
| 472 |
+ |
} |
| 473 |
+ |
dnew->dtype = rm->dtype; |
| 474 |
|
for (i = dnew->nrows; i--; ) |
| 475 |
|
for (j = dnew->ncols; j--; ) |
| 476 |
|
for (k = dnew->ncomp; k--; ) |
| 491 |
|
mres = rmx_alloc(m1->nrows, m2->ncols, m1->ncomp); |
| 492 |
|
if (mres == NULL) |
| 493 |
|
return(NULL); |
| 494 |
+ |
i = rmx_newtype(m1->dtype, m2->dtype); |
| 495 |
+ |
if (i) |
| 496 |
+ |
mres->dtype = i; |
| 497 |
+ |
else |
| 498 |
+ |
rmx_addinfo(mres, rmx_mismatch_warn); |
| 499 |
|
for (i = mres->nrows; i--; ) |
| 500 |
|
for (j = mres->ncols; j--; ) |
| 501 |
< |
for (h = m1->ncols; h--; ) { |
| 501 |
> |
for (k = mres->ncomp; k--; ) { |
| 502 |
|
long double d = 0; |
| 503 |
< |
for (k = mres->ncomp; k--; ) |
| 504 |
< |
d += (long double)rmx_lval(m1,i,h,k) * |
| 423 |
< |
(long double)rmx_lval(m2,h,j,k); |
| 503 |
> |
for (h = m1->ncols; h--; ) |
| 504 |
> |
d += rmx_lval(m1,i,h,k) * rmx_lval(m2,h,j,k); |
| 505 |
|
rmx_lval(mres,i,j,k) = (double)d; |
| 506 |
|
} |
| 507 |
|
return(mres); |
| 508 |
|
} |
| 509 |
|
|
| 510 |
+ |
/* Element-wise multiplication (or division) of m2 into m1 */ |
| 511 |
+ |
int |
| 512 |
+ |
rmx_elemult(RMATRIX *m1, const RMATRIX *m2, int divide) |
| 513 |
+ |
{ |
| 514 |
+ |
int zeroDivides = 0; |
| 515 |
+ |
int i, j, k; |
| 516 |
+ |
|
| 517 |
+ |
if ((m1 == NULL) | (m2 == NULL) || |
| 518 |
+ |
(m1->ncols != m2->ncols) | (m1->nrows != m2->nrows)) |
| 519 |
+ |
return(0); |
| 520 |
+ |
if ((m2->ncomp > 1) & (m2->ncomp != m1->ncomp)) |
| 521 |
+ |
return(0); |
| 522 |
+ |
i = rmx_newtype(m1->dtype, m2->dtype); |
| 523 |
+ |
if (i) |
| 524 |
+ |
m1->dtype = i; |
| 525 |
+ |
else |
| 526 |
+ |
rmx_addinfo(m1, rmx_mismatch_warn); |
| 527 |
+ |
for (i = m1->nrows; i--; ) |
| 528 |
+ |
for (j = m1->ncols; j--; ) |
| 529 |
+ |
if (divide) { |
| 530 |
+ |
double d; |
| 531 |
+ |
if (m2->ncomp == 1) { |
| 532 |
+ |
d = rmx_lval(m2,i,j,0); |
| 533 |
+ |
if (d == 0) { |
| 534 |
+ |
++zeroDivides; |
| 535 |
+ |
for (k = m1->ncomp; k--; ) |
| 536 |
+ |
rmx_lval(m1,i,j,k) = 0; |
| 537 |
+ |
} else { |
| 538 |
+ |
d = 1./d; |
| 539 |
+ |
for (k = m1->ncomp; k--; ) |
| 540 |
+ |
rmx_lval(m1,i,j,k) *= d; |
| 541 |
+ |
} |
| 542 |
+ |
} else |
| 543 |
+ |
for (k = m1->ncomp; k--; ) { |
| 544 |
+ |
d = rmx_lval(m2,i,j,k); |
| 545 |
+ |
if (d == 0) { |
| 546 |
+ |
++zeroDivides; |
| 547 |
+ |
rmx_lval(m1,i,j,k) = 0; |
| 548 |
+ |
} else |
| 549 |
+ |
rmx_lval(m1,i,j,k) /= d; |
| 550 |
+ |
} |
| 551 |
+ |
} else { |
| 552 |
+ |
if (m2->ncomp == 1) { |
| 553 |
+ |
const double d = rmx_lval(m2,i,j,0); |
| 554 |
+ |
for (k = m1->ncomp; k--; ) |
| 555 |
+ |
rmx_lval(m1,i,j,k) *= d; |
| 556 |
+ |
} else |
| 557 |
+ |
for (k = m1->ncomp; k--; ) |
| 558 |
+ |
rmx_lval(m1,i,j,k) *= rmx_lval(m2,i,j,k); |
| 559 |
+ |
} |
| 560 |
+ |
if (zeroDivides) { |
| 561 |
+ |
fputs("Divide by zero in rmx_elemult()\n", stderr); |
| 562 |
+ |
errno = ERANGE; |
| 563 |
+ |
} |
| 564 |
+ |
return(1); |
| 565 |
+ |
} |
| 566 |
+ |
|
| 567 |
|
/* Sum second matrix into first, applying scale factor beforehand */ |
| 568 |
|
int |
| 569 |
|
rmx_sum(RMATRIX *msum, const RMATRIX *madd, const double sf[]) |
| 584 |
|
mysf[k] = 1; |
| 585 |
|
sf = mysf; |
| 586 |
|
} |
| 587 |
+ |
i = rmx_newtype(msum->dtype, madd->dtype); |
| 588 |
+ |
if (i) |
| 589 |
+ |
msum->dtype = i; |
| 590 |
+ |
else |
| 591 |
+ |
rmx_addinfo(msum, rmx_mismatch_warn); |
| 592 |
|
for (i = msum->nrows; i--; ) |
| 593 |
|
for (j = msum->ncols; j--; ) |
| 594 |
|
for (k = msum->ncomp; k--; ) |
| 626 |
|
dnew = rmx_alloc(msrc->nrows, msrc->ncols, n); |
| 627 |
|
if (dnew == NULL) |
| 628 |
|
return(NULL); |
| 629 |
+ |
dnew->dtype = msrc->dtype; |
| 630 |
|
for (i = dnew->nrows; i--; ) |
| 631 |
|
for (j = dnew->ncols; j--; ) |
| 632 |
|
for (kd = dnew->ncomp; kd--; ) { |
| 650 |
|
dnew = rmx_alloc(cm->nrows, cm->ncols, 3); |
| 651 |
|
if (dnew == NULL) |
| 652 |
|
return(NULL); |
| 653 |
+ |
dnew->dtype = DTfloat; |
| 654 |
|
for (i = dnew->nrows; i--; ) |
| 655 |
|
for (j = dnew->ncols; j--; ) { |
| 656 |
|
const COLORV *cv = cm_lval(cm,i,j); |