5 |
|
* General matrix operations. |
6 |
|
*/ |
7 |
|
|
8 |
– |
#include <stdio.h> |
8 |
|
#include <stdlib.h> |
9 |
< |
#include <string.h> |
10 |
< |
#include <fcntl.h> |
9 |
> |
#include <errno.h> |
10 |
> |
#include "rtio.h" |
11 |
> |
#include "platform.h" |
12 |
|
#include "resolu.h" |
13 |
< |
#include "rtprocess.h" |
13 |
> |
#include "paths.h" |
14 |
|
#include "rmatrix.h" |
15 |
|
|
16 |
|
static char rmx_mismatch_warn[] = "WARNING: data type mismatch\n"; |
24 |
|
if ((nr <= 0) | (nc <= 0) | (n <= 0)) |
25 |
|
return(NULL); |
26 |
|
dnew = (RMATRIX *)malloc(sizeof(RMATRIX)-sizeof(dnew->mtx) + |
27 |
< |
sizeof(dnew->mtx[0])*(n*nr*nc)); |
28 |
< |
if (dnew == NULL) |
27 |
> |
sizeof(dnew->mtx[0])*n*nr*nc); |
28 |
> |
if (!dnew) |
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 |
|
} |
61 |
|
int |
62 |
|
rmx_addinfo(RMATRIX *rm, const char *info) |
63 |
|
{ |
64 |
< |
if (!info || !*info) |
64 |
> |
if (!rm || !info || !*info) |
65 |
|
return(0); |
66 |
|
if (!rm->info) { |
67 |
|
rm->info = (char *)malloc(strlen(info)+1); |
79 |
|
get_dminfo(char *s, void *p) |
80 |
|
{ |
81 |
|
RMATRIX *ip = (RMATRIX *)p; |
82 |
< |
char fmt[64]; |
82 |
> |
char fmt[MAXFMTLEN]; |
83 |
|
int i; |
84 |
|
|
85 |
|
if (headidval(fmt, s)) |
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); |
148 |
|
} |
149 |
|
for (i = 0; i < rm->nrows; i++) |
150 |
|
for (j = 0; j < rm->ncols; j++) { |
151 |
< |
if (fread(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
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, k; |
147 |
< |
double val[100]; |
164 |
> |
int i; |
165 |
|
|
166 |
< |
if (rm->ncomp > 100) { |
167 |
< |
fputs("Unsupported # components in rmx_load_double()\n", stderr); |
166 |
> |
if ((char *)&rmx_lval(rm,1,0,0) - (char *)&rmx_lval(rm,0,0,0) != |
167 |
> |
sizeof(double)*rm->ncols*rm->ncomp) { |
168 |
> |
fputs("Code error in rmx_load_double()\n", stderr); |
169 |
|
exit(1); |
170 |
|
} |
171 |
< |
for (i = 0; i < rm->nrows; i++) |
172 |
< |
for (j = 0; j < rm->ncols; j++) { |
173 |
< |
if (fread(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
174 |
< |
return(0); |
175 |
< |
for (k = rm->ncomp; k--; ) |
176 |
< |
rmx_lval(rm,i,j,k) = val[k]; |
177 |
< |
} |
171 |
> |
for (i = 0; i < rm->nrows; i++) { |
172 |
> |
if (getbinary(&rmx_lval(rm,i,0,0), sizeof(double)*rm->ncomp, |
173 |
> |
rm->ncols, fp) != rm->ncols) |
174 |
> |
return(0); |
175 |
> |
if (rm->swapin) |
176 |
> |
swap64((char *)&rmx_lval(rm,i,0,0), rm->ncols*rm->ncomp); |
177 |
> |
} |
178 |
|
return(1); |
179 |
|
} |
180 |
|
|
184 |
|
COLOR *scan = (COLOR *)malloc(sizeof(COLOR)*rm->ncols); |
185 |
|
int i, j; |
186 |
|
|
187 |
< |
if (scan == NULL) |
187 |
> |
if (!scan) |
188 |
|
return(0); |
189 |
|
for (i = 0; i < rm->nrows; i++) { |
190 |
|
if (freadscan(scan, rm->ncols, fp) < 0) { |
203 |
|
|
204 |
|
/* Load matrix from supported file type */ |
205 |
|
RMATRIX * |
206 |
< |
rmx_load(const char *inspec) |
206 |
> |
rmx_load(const char *inspec, RMPref rmp) |
207 |
|
{ |
208 |
< |
FILE *fp = stdin; |
208 |
> |
FILE *fp; |
209 |
|
RMATRIX dinfo; |
210 |
|
RMATRIX *dnew; |
211 |
|
|
212 |
< |
if (inspec == NULL) { /* reading from stdin? */ |
213 |
< |
inspec = "<stdin>"; |
214 |
< |
#ifdef _WIN32 |
215 |
< |
_setmode(fileno(stdin), _O_BINARY); |
198 |
< |
#endif |
212 |
> |
if (!inspec || !*inspec) |
213 |
> |
return(NULL); |
214 |
> |
if (inspec == stdin_name) { /* reading from stdin? */ |
215 |
> |
fp = stdin; |
216 |
|
} else if (inspec[0] == '!') { |
217 |
< |
if ((fp = popen(inspec+1, "r")) == NULL) |
217 |
> |
if (!(fp = popen(inspec+1, "r"))) |
218 |
|
return(NULL); |
202 |
– |
#ifdef _WIN32 |
203 |
– |
_setmode(fileno(fp), _O_BINARY); |
204 |
– |
#endif |
219 |
|
} else { |
220 |
|
const char *sp = inspec; /* check suffix */ |
221 |
|
while (*sp) |
223 |
|
while (sp > inspec && sp[-1] != '.') |
224 |
|
--sp; |
225 |
|
if (!strcasecmp(sp, "XML")) { /* assume it's a BSDF */ |
226 |
< |
CMATRIX *cm = cm_loadBTDF((char *)inspec); |
227 |
< |
if (cm == NULL) |
226 |
> |
CMATRIX *cm = rmp==RMPtrans ? cm_loadBTDF(inspec) : |
227 |
> |
cm_loadBRDF(inspec, rmp==RMPreflB) ; |
228 |
> |
if (!cm) |
229 |
|
return(NULL); |
230 |
|
dnew = rmx_from_cmatrix(cm); |
231 |
|
cm_free(cm); |
233 |
|
return(dnew); |
234 |
|
} |
235 |
|
/* else open it ourselves */ |
236 |
< |
if ((fp = fopen(inspec, "rb")) == NULL) |
236 |
> |
if (!(fp = fopen(inspec, "r"))) |
237 |
|
return(NULL); |
238 |
|
} |
239 |
+ |
SET_FILE_BINARY(fp); |
240 |
|
#ifdef getc_unlocked |
241 |
|
flockfile(fp); |
242 |
|
#endif |
243 |
|
dinfo.nrows = dinfo.ncols = dinfo.ncomp = 0; |
244 |
|
dinfo.dtype = DTascii; /* assumed w/o FORMAT */ |
245 |
+ |
dinfo.swapin = 0; |
246 |
|
dinfo.info = NULL; |
247 |
+ |
dinfo.mtx[0] = dinfo.mtx[1] = dinfo.mtx[2] = 1.; |
248 |
|
if (getheader(fp, get_dminfo, &dinfo) < 0) { |
249 |
|
fclose(fp); |
250 |
|
return(NULL); |
263 |
|
} |
264 |
|
} |
265 |
|
dnew = rmx_alloc(dinfo.nrows, dinfo.ncols, dinfo.ncomp); |
266 |
< |
if (dnew == NULL) { |
266 |
> |
if (!dnew) { |
267 |
|
fclose(fp); |
268 |
|
return(NULL); |
269 |
|
} |
270 |
|
dnew->info = dinfo.info; |
271 |
|
switch (dinfo.dtype) { |
272 |
|
case DTascii: |
273 |
< |
#ifdef _WIN32 |
256 |
< |
_setmode(fileno(fp), _O_TEXT); |
257 |
< |
#endif |
273 |
> |
SET_FILE_TEXT(fp); |
274 |
|
if (!rmx_load_ascii(dnew, fp)) |
275 |
|
goto loaderr; |
276 |
|
dnew->dtype = DTascii; /* should leave double? */ |
277 |
|
break; |
278 |
|
case DTfloat: |
279 |
+ |
dnew->swapin = dinfo.swapin; |
280 |
|
if (!rmx_load_float(dnew, fp)) |
281 |
|
goto loaderr; |
282 |
|
dnew->dtype = DTfloat; |
283 |
|
break; |
284 |
|
case DTdouble: |
285 |
+ |
dnew->swapin = dinfo.swapin; |
286 |
|
if (!rmx_load_double(dnew, fp)) |
287 |
|
goto loaderr; |
288 |
|
dnew->dtype = DTdouble; |
291 |
|
case DTxyze: |
292 |
|
if (!rmx_load_rgbe(dnew, fp)) |
293 |
|
goto loaderr; |
294 |
< |
dnew->dtype = dinfo.dtype; |
294 |
> |
dnew->dtype = dinfo.dtype; /* undo exposure? */ |
295 |
> |
if ((dinfo.mtx[0] != 1.) | (dinfo.mtx[1] != 1.) | |
296 |
> |
(dinfo.mtx[2] != 1.)) { |
297 |
> |
dinfo.mtx[0] = 1./dinfo.mtx[0]; |
298 |
> |
dinfo.mtx[1] = 1./dinfo.mtx[1]; |
299 |
> |
dinfo.mtx[2] = 1./dinfo.mtx[2]; |
300 |
> |
rmx_scale(dnew, dinfo.mtx); |
301 |
> |
} |
302 |
|
break; |
303 |
|
default: |
304 |
|
goto loaderr; |
326 |
|
static int |
327 |
|
rmx_write_ascii(const RMATRIX *rm, FILE *fp) |
328 |
|
{ |
329 |
+ |
const char *fmt = (rm->dtype == DTfloat) ? " %.7e" : |
330 |
+ |
(rm->dtype == DTrgbe) | (rm->dtype == DTxyze) ? " %.3e" : |
331 |
+ |
" %.15e" ; |
332 |
|
int i, j, k; |
333 |
|
|
334 |
|
for (i = 0; i < rm->nrows; i++) { |
335 |
|
for (j = 0; j < rm->ncols; j++) { |
336 |
|
for (k = 0; k < rm->ncomp; k++) |
337 |
< |
fprintf(fp, " %.15e", rmx_lval(rm,i,j,k)); |
337 |
> |
fprintf(fp, fmt, rmx_lval(rm,i,j,k)); |
338 |
|
fputc('\t', fp); |
339 |
|
} |
340 |
|
fputc('\n', fp); |
356 |
|
for (j = 0; j < rm->ncols; j++) { |
357 |
|
for (k = rm->ncomp; k--; ) |
358 |
|
val[k] = (float)rmx_lval(rm,i,j,k); |
359 |
< |
if (fwrite(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
359 |
> |
if (putbinary(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
360 |
|
return(0); |
361 |
|
} |
362 |
|
return(1); |
365 |
|
static int |
366 |
|
rmx_write_double(const RMATRIX *rm, FILE *fp) |
367 |
|
{ |
368 |
< |
int i, j, k; |
341 |
< |
double val[100]; |
368 |
> |
int i, j; |
369 |
|
|
343 |
– |
if (rm->ncomp > 100) { |
344 |
– |
fputs("Unsupported # components in rmx_write_double()\n", stderr); |
345 |
– |
exit(1); |
346 |
– |
} |
370 |
|
for (i = 0; i < rm->nrows; i++) |
371 |
< |
for (j = 0; j < rm->ncols; j++) { |
372 |
< |
for (k = rm->ncomp; k--; ) |
350 |
< |
val[k] = rmx_lval(rm,i,j,k); |
351 |
< |
if (fwrite(val, sizeof(val[0]), rm->ncomp, fp) != rm->ncomp) |
371 |
> |
for (j = 0; j < rm->ncols; j++) |
372 |
> |
if (putbinary(&rmx_lval(rm,i,j,0), sizeof(double), rm->ncomp, fp) != rm->ncomp) |
373 |
|
return(0); |
353 |
– |
} |
374 |
|
return(1); |
375 |
|
} |
376 |
|
|
377 |
|
static int |
378 |
|
rmx_write_rgbe(const RMATRIX *rm, FILE *fp) |
379 |
|
{ |
380 |
< |
COLOR *scan = (COLOR *)malloc(sizeof(COLOR)*rm->ncols); |
380 |
> |
COLR *scan = (COLR *)malloc(sizeof(COLR)*rm->ncols); |
381 |
|
int i, j; |
382 |
|
|
383 |
< |
if (scan == NULL) |
383 |
> |
if (!scan) |
384 |
|
return(0); |
385 |
|
for (i = 0; i < rm->nrows; i++) { |
386 |
|
for (j = rm->ncols; j--; ) |
387 |
< |
setcolor(scan[j], rmx_lval(rm,i,j,0), |
387 |
> |
setcolr(scan[j], rmx_lval(rm,i,j,0), |
388 |
|
rmx_lval(rm,i,j,1), |
389 |
|
rmx_lval(rm,i,j,2) ); |
390 |
< |
if (fwritescan(scan, rm->ncols, fp) < 0) { |
390 |
> |
if (fwritecolrs(scan, rm->ncols, fp) < 0) { |
391 |
|
free(scan); |
392 |
|
return(0); |
393 |
|
} |
403 |
|
RMATRIX *mydm = NULL; |
404 |
|
int ok = 1; |
405 |
|
|
406 |
< |
if ((rm == NULL) | (fp == NULL)) |
406 |
> |
if (!rm | !fp) |
407 |
|
return(0); |
408 |
|
#ifdef getc_unlocked |
409 |
|
flockfile(fp); |
427 |
|
return(0); |
428 |
|
cmtx[0] = cmtx[1] = cmtx[2] = 1; |
429 |
|
mydm = rmx_transform(rm, 3, cmtx); |
430 |
< |
if (mydm == NULL) |
430 |
> |
if (!mydm) |
431 |
|
return(0); |
432 |
|
rm = mydm; |
433 |
|
} |
434 |
+ |
if ((dtype == DTfloat) | (dtype == DTdouble)) |
435 |
+ |
fputendian(fp); /* important to record */ |
436 |
|
fputformat((char *)cm_fmt_id[dtype], fp); |
437 |
|
fputc('\n', fp); |
438 |
|
switch (dtype) { /* write data */ |
457 |
|
#ifdef getc_unlocked |
458 |
|
funlockfile(fp); |
459 |
|
#endif |
460 |
< |
rmx_free(mydm); |
460 |
> |
if (mydm) |
461 |
> |
rmx_free(mydm); |
462 |
|
return(ok); |
463 |
|
} |
464 |
|
|
469 |
|
RMATRIX *rid = rmx_alloc(dim, dim, n); |
470 |
|
int i, k; |
471 |
|
|
472 |
< |
if (rid == NULL) |
472 |
> |
if (!rid) |
473 |
|
return(NULL); |
474 |
|
memset(rid->mtx, 0, sizeof(rid->mtx[0])*n*dim*dim); |
475 |
|
for (i = dim; i--; ) |
484 |
|
{ |
485 |
|
RMATRIX *dnew; |
486 |
|
|
487 |
< |
if (rm == NULL) |
487 |
> |
if (!rm) |
488 |
|
return(NULL); |
489 |
|
dnew = rmx_alloc(rm->nrows, rm->ncols, rm->ncomp); |
490 |
< |
if (dnew == NULL) |
490 |
> |
if (!dnew) |
491 |
|
return(NULL); |
492 |
|
rmx_addinfo(dnew, rm->info); |
493 |
|
dnew->dtype = rm->dtype; |
503 |
|
RMATRIX *dnew; |
504 |
|
int i, j, k; |
505 |
|
|
506 |
< |
if (rm == NULL) |
506 |
> |
if (!rm) |
507 |
|
return(0); |
508 |
+ |
if ((rm->nrows == 1) | (rm->ncols == 1)) { |
509 |
+ |
dnew = rmx_copy(rm); |
510 |
+ |
if (!dnew) |
511 |
+ |
return(NULL); |
512 |
+ |
dnew->nrows = rm->ncols; |
513 |
+ |
dnew->ncols = rm->nrows; |
514 |
+ |
return(dnew); |
515 |
+ |
} |
516 |
|
dnew = rmx_alloc(rm->ncols, rm->nrows, rm->ncomp); |
517 |
< |
if (dnew == NULL) |
517 |
> |
if (!dnew) |
518 |
|
return(NULL); |
519 |
|
if (rm->info) { |
520 |
|
rmx_addinfo(dnew, rm->info); |
535 |
|
RMATRIX *mres; |
536 |
|
int i, j, k, h; |
537 |
|
|
538 |
< |
if ((m1 == NULL) | (m2 == NULL) || |
508 |
< |
(m1->ncomp != m2->ncomp) | (m1->ncols != m2->nrows)) |
538 |
> |
if (!m1 | !m2 || (m1->ncomp != m2->ncomp) | (m1->ncols != m2->nrows)) |
539 |
|
return(NULL); |
540 |
|
mres = rmx_alloc(m1->nrows, m2->ncols, m1->ncomp); |
541 |
< |
if (mres == NULL) |
541 |
> |
if (!mres) |
542 |
|
return(NULL); |
543 |
|
i = rmx_newtype(m1->dtype, m2->dtype); |
544 |
|
if (i) |
556 |
|
return(mres); |
557 |
|
} |
558 |
|
|
559 |
+ |
/* Element-wise multiplication (or division) of m2 into m1 */ |
560 |
+ |
int |
561 |
+ |
rmx_elemult(RMATRIX *m1, const RMATRIX *m2, int divide) |
562 |
+ |
{ |
563 |
+ |
int zeroDivides = 0; |
564 |
+ |
int i, j, k; |
565 |
+ |
|
566 |
+ |
if (!m1 | !m2 || (m1->ncols != m2->ncols) | (m1->nrows != m2->nrows)) |
567 |
+ |
return(0); |
568 |
+ |
if ((m2->ncomp > 1) & (m2->ncomp != m1->ncomp)) |
569 |
+ |
return(0); |
570 |
+ |
i = rmx_newtype(m1->dtype, m2->dtype); |
571 |
+ |
if (i) |
572 |
+ |
m1->dtype = i; |
573 |
+ |
else |
574 |
+ |
rmx_addinfo(m1, rmx_mismatch_warn); |
575 |
+ |
for (i = m1->nrows; i--; ) |
576 |
+ |
for (j = m1->ncols; j--; ) |
577 |
+ |
if (divide) { |
578 |
+ |
double d; |
579 |
+ |
if (m2->ncomp == 1) { |
580 |
+ |
d = rmx_lval(m2,i,j,0); |
581 |
+ |
if (d == 0) { |
582 |
+ |
++zeroDivides; |
583 |
+ |
for (k = m1->ncomp; k--; ) |
584 |
+ |
rmx_lval(m1,i,j,k) = 0; |
585 |
+ |
} else { |
586 |
+ |
d = 1./d; |
587 |
+ |
for (k = m1->ncomp; k--; ) |
588 |
+ |
rmx_lval(m1,i,j,k) *= d; |
589 |
+ |
} |
590 |
+ |
} else |
591 |
+ |
for (k = m1->ncomp; k--; ) { |
592 |
+ |
d = rmx_lval(m2,i,j,k); |
593 |
+ |
if (d == 0) { |
594 |
+ |
++zeroDivides; |
595 |
+ |
rmx_lval(m1,i,j,k) = 0; |
596 |
+ |
} else |
597 |
+ |
rmx_lval(m1,i,j,k) /= d; |
598 |
+ |
} |
599 |
+ |
} else { |
600 |
+ |
if (m2->ncomp == 1) { |
601 |
+ |
const double d = rmx_lval(m2,i,j,0); |
602 |
+ |
for (k = m1->ncomp; k--; ) |
603 |
+ |
rmx_lval(m1,i,j,k) *= d; |
604 |
+ |
} else |
605 |
+ |
for (k = m1->ncomp; k--; ) |
606 |
+ |
rmx_lval(m1,i,j,k) *= rmx_lval(m2,i,j,k); |
607 |
+ |
} |
608 |
+ |
if (zeroDivides) { |
609 |
+ |
rmx_addinfo(m1, "WARNING: zero divide(s) corrupted results\n"); |
610 |
+ |
errno = ERANGE; |
611 |
+ |
} |
612 |
+ |
return(1); |
613 |
+ |
} |
614 |
+ |
|
615 |
|
/* Sum second matrix into first, applying scale factor beforehand */ |
616 |
|
int |
617 |
|
rmx_sum(RMATRIX *msum, const RMATRIX *madd, const double sf[]) |
619 |
|
double *mysf = NULL; |
620 |
|
int i, j, k; |
621 |
|
|
622 |
< |
if ((msum == NULL) | (madd == NULL) || |
622 |
> |
if (!msum | !madd || |
623 |
|
(msum->nrows != madd->nrows) | |
624 |
|
(msum->ncols != madd->ncols) | |
625 |
|
(msum->ncomp != madd->ncomp)) |
626 |
|
return(0); |
627 |
< |
if (sf == NULL) { |
627 |
> |
if (!sf) { |
628 |
|
mysf = (double *)malloc(sizeof(double)*msum->ncomp); |
629 |
< |
if (mysf == NULL) |
629 |
> |
if (!mysf) |
630 |
|
return(0); |
631 |
|
for (k = msum->ncomp; k--; ) |
632 |
|
mysf[k] = 1; |
641 |
|
for (j = msum->ncols; j--; ) |
642 |
|
for (k = msum->ncomp; k--; ) |
643 |
|
rmx_lval(msum,i,j,k) += sf[k] * rmx_lval(madd,i,j,k); |
644 |
< |
|
645 |
< |
free(mysf); |
644 |
> |
if (mysf) |
645 |
> |
free(mysf); |
646 |
|
return(1); |
647 |
|
} |
648 |
|
|
652 |
|
{ |
653 |
|
int i, j, k; |
654 |
|
|
655 |
< |
if ((rm == NULL) | (sf == NULL)) |
655 |
> |
if (!rm | !sf) |
656 |
|
return(0); |
657 |
|
for (i = rm->nrows; i--; ) |
658 |
|
for (j = rm->ncols; j--; ) |
659 |
|
for (k = rm->ncomp; k--; ) |
660 |
|
rmx_lval(rm,i,j,k) *= sf[k]; |
661 |
|
|
662 |
+ |
if (rm->info) |
663 |
+ |
rmx_addinfo(rm, "Applied scalar\n"); |
664 |
|
return(1); |
665 |
|
} |
666 |
|
|
671 |
|
int i, j, ks, kd; |
672 |
|
RMATRIX *dnew; |
673 |
|
|
674 |
< |
if ((msrc == NULL) | (n <= 0) | (cmat == NULL)) |
674 |
> |
if (!msrc | (n <= 0) | !cmat) |
675 |
|
return(NULL); |
676 |
|
dnew = rmx_alloc(msrc->nrows, msrc->ncols, n); |
677 |
< |
if (dnew == NULL) |
677 |
> |
if (!dnew) |
678 |
|
return(NULL); |
679 |
+ |
if (msrc->info) { |
680 |
+ |
char buf[128]; |
681 |
+ |
sprintf(buf, "Applied %dx%d component transform\n", |
682 |
+ |
dnew->ncomp, msrc->ncomp); |
683 |
+ |
rmx_addinfo(dnew, msrc->info); |
684 |
+ |
rmx_addinfo(dnew, buf); |
685 |
+ |
} |
686 |
|
dnew->dtype = msrc->dtype; |
687 |
|
for (i = dnew->nrows; i--; ) |
688 |
|
for (j = dnew->ncols; j--; ) |
702 |
|
int i, j; |
703 |
|
RMATRIX *dnew; |
704 |
|
|
705 |
< |
if (cm == NULL) |
705 |
> |
if (!cm) |
706 |
|
return(NULL); |
707 |
|
dnew = rmx_alloc(cm->nrows, cm->ncols, 3); |
708 |
< |
if (dnew == NULL) |
708 |
> |
if (!dnew) |
709 |
|
return(NULL); |
710 |
|
dnew->dtype = DTfloat; |
711 |
|
for (i = dnew->nrows; i--; ) |
725 |
|
int i, j; |
726 |
|
CMATRIX *cnew; |
727 |
|
|
728 |
< |
if (rm == NULL || rm->ncomp != 3) |
728 |
> |
if (!rm || rm->ncomp != 3) |
729 |
|
return(NULL); |
730 |
|
cnew = cm_alloc(rm->nrows, rm->ncols); |
731 |
< |
if (cnew == NULL) |
731 |
> |
if (!cnew) |
732 |
|
return(NULL); |
733 |
|
for (i = cnew->nrows; i--; ) |
734 |
|
for (j = cnew->ncols; j--; ) { |