5 |
|
* General component matrix operations. |
6 |
|
*/ |
7 |
|
|
8 |
– |
#include <stdlib.h> |
8 |
|
#include <errno.h> |
9 |
|
#include <ctype.h> |
10 |
|
#include "rtio.h" |
43 |
|
return(0); |
44 |
|
|
45 |
|
rop->mtx = rmx_load(rop->inspec, rop->rmp); |
46 |
< |
if (rop->mtx == NULL) { |
47 |
< |
fputs(rop->inspec, stderr); |
49 |
< |
fputs(": cannot load matrix\n", stderr); |
50 |
< |
return(-1); |
51 |
< |
} |
52 |
< |
return(1); |
46 |
> |
|
47 |
> |
return(!rop->mtx ? -1 : 1); |
48 |
|
} |
49 |
|
|
50 |
|
/* Compute conversion row from spectrum to one channel of RGB */ |
91 |
|
for (i = nc; i--; ) { |
92 |
|
SCOLOR sclr; |
93 |
|
scolorblack(sclr); |
94 |
< |
sclr[i] = 1; |
94 |
> |
sclr[i] = 1.f; |
95 |
|
rop->preop.cmat[r*nc+i] = (*sf)(sclr, nc, rop->mtx->wlpart); |
96 |
|
} |
97 |
|
} |
155 |
|
for (i = nc*(dt != DTxyze); i--; ) |
156 |
|
rop->preop.cmat[j*nc+i] *= WHTEFFICACY; |
157 |
|
break; |
158 |
< |
case 'S': |
158 |
> |
case 'S': /* scotopic (il)luminance */ |
159 |
|
sensrow(rop, j, scolor2scotopic); |
160 |
|
for (i = nc; i--; ) |
161 |
|
rop->preop.cmat[j*nc+i] *= WHTSCOTOPIC; |
162 |
|
break; |
163 |
< |
case 'M': |
163 |
> |
case 'M': /* melanopic (il)luminance */ |
164 |
|
sensrow(rop, j, scolor2melanopic); |
165 |
|
for (i = nc; i--; ) |
166 |
|
rop->preop.cmat[j*nc+i] *= WHTMELANOPIC; |
167 |
|
break; |
168 |
+ |
case 'A': /* average component */ |
169 |
+ |
for (i = nc; i--; ) |
170 |
+ |
rop->preop.cmat[j*nc+i] = 1./(double)nc; |
171 |
+ |
break; |
172 |
|
default: |
173 |
|
fprintf(stderr, "%s: -c '%c' unsupported\n", |
174 |
|
rop->inspec, rop->preop.csym[j]); |
235 |
|
rop->inspec, mres->ncomp, |
236 |
|
rop->mtx->ncomp, |
237 |
|
rop->preop.nsf ? " (* scalar)" : ""); |
238 |
< |
rop->preop.nsf = 0; |
238 |
> |
rop->preop.nsf = 0; /* now folded in */ |
239 |
|
if ((mres->ncomp > 3) & (mres->dtype <= DTspec)) |
240 |
|
outtype = DTfloat; /* probably not actual spectrum */ |
241 |
|
rmx_free(rop->mtx); |
448 |
|
} |
449 |
|
|
450 |
|
static ROPMAT * |
451 |
< |
grow_moparray(ROPMAT *mop, int n2alloc) |
451 |
> |
resize_moparr(ROPMAT *mop, int n2alloc) |
452 |
|
{ |
453 |
|
int nmats = 0; |
454 |
+ |
int i; |
455 |
|
|
456 |
|
while (mop[nmats++].binop) |
457 |
|
; |
458 |
+ |
for (i = nmats; i > n2alloc; i--) |
459 |
+ |
rmx_free(mop[i].mtx); |
460 |
|
mop = (ROPMAT *)realloc(mop, n2alloc*sizeof(ROPMAT)); |
461 |
|
if (mop == NULL) { |
462 |
< |
fputs("Out of memory in grow_moparray()\n", stderr); |
462 |
> |
fputs("Out of memory in resize_moparr()\n", stderr); |
463 |
|
exit(1); |
464 |
|
} |
465 |
|
if (n2alloc > nmats) |
575 |
|
} |
576 |
|
} |
577 |
|
if (nmats >= nall) |
578 |
< |
mop = grow_moparray(mop, nall += 2); |
578 |
> |
mop = resize_moparr(mop, nall += 2); |
579 |
|
} |
580 |
|
if (mop[0].inspec == NULL) /* nothing to do? */ |
581 |
|
goto userr; |
603 |
|
else if (mres->dtype == DTxyze) |
604 |
|
outfmt = DTxyze; |
605 |
|
} |
606 |
< |
if (outfmt != DTascii) /* write result to stdout */ |
605 |
< |
SET_FILE_BINARY(stdout); |
606 |
< |
newheader("RADIANCE", stdout); |
606 |
> |
newheader("RADIANCE", stdout); /* write result to stdout */ |
607 |
|
printargs(argc, argv, stdout); |
608 |
< |
if (!rmx_write(mres, outfmt, stdout)) { |
609 |
< |
fprintf(stderr, "%s: error writing result matrix\n", argv[0]); |
610 |
< |
return(1); |
611 |
< |
} |
612 |
< |
/* rmx_free(mres); free(mop); */ |
613 |
< |
return(0); |
608 |
> |
return(rmx_write(mres, outfmt, stdout) ? 0 : 1); |
609 |
|
userr: |
610 |
|
fprintf(stderr, |
611 |
< |
"Usage: %s [-v][-f[adfc][-t][-s sf .. | -c ce ..][-rf|-rb] m1 [.+*/] .. > mres\n", |
611 |
> |
"Usage: %s [-v][-f{adfc}][-t][-s sf .. | -c ce ..][-rf|-rb] m1 [.+*/] .. > mres\n", |
612 |
|
argv[0]); |
613 |
|
return(1); |
614 |
|
} |