--- ray/src/util/rmtxop.c 2023/11/28 16:36:50 2.23 +++ ray/src/util/rmtxop.c 2023/12/01 02:05:00 2.26 @@ -1,11 +1,10 @@ #ifndef lint -static const char RCSid[] = "$Id: rmtxop.c,v 2.23 2023/11/28 16:36:50 greg Exp $"; +static const char RCSid[] = "$Id: rmtxop.c,v 2.26 2023/12/01 02:05:00 greg Exp $"; #endif /* * General component matrix operations. */ -#include #include #include #include "rtio.h" @@ -92,7 +91,7 @@ sensrow(ROPMAT *rop, int r, double (*sf)(SCOLOR sc, in for (i = nc; i--; ) { SCOLOR sclr; scolorblack(sclr); - sclr[i] = 1; + sclr[i] = 1.f; rop->preop.cmat[r*nc+i] = (*sf)(sclr, nc, rop->mtx->wlpart); } } @@ -156,16 +155,20 @@ checksymbolic(ROPMAT *rop) for (i = nc*(dt != DTxyze); i--; ) rop->preop.cmat[j*nc+i] *= WHTEFFICACY; break; - case 'S': + case 'S': /* scotopic (il)luminance */ sensrow(rop, j, scolor2scotopic); for (i = nc; i--; ) rop->preop.cmat[j*nc+i] *= WHTSCOTOPIC; break; - case 'M': + case 'M': /* melanopic (il)luminance */ sensrow(rop, j, scolor2melanopic); for (i = nc; i--; ) rop->preop.cmat[j*nc+i] *= WHTMELANOPIC; break; + case 'A': /* average component */ + for (i = nc; i--; ) + rop->preop.cmat[j*nc+i] = 1./(double)nc; + break; default: fprintf(stderr, "%s: -c '%c' unsupported\n", rop->inspec, rop->preop.csym[j]); @@ -232,7 +235,7 @@ loadop(ROPMAT *rop) rop->inspec, mres->ncomp, rop->mtx->ncomp, rop->preop.nsf ? " (* scalar)" : ""); - rop->preop.nsf = 0; + rop->preop.nsf = 0; /* now folded in */ if ((mres->ncomp > 3) & (mres->dtype <= DTspec)) outtype = DTfloat; /* probably not actual spectrum */ rmx_free(rop->mtx); @@ -445,15 +448,18 @@ get_factors(double da[], int n, char *av[]) } static ROPMAT * -grow_moparray(ROPMAT *mop, int n2alloc) +resize_moparr(ROPMAT *mop, int n2alloc) { int nmats = 0; + int i; while (mop[nmats++].binop) ; + for (i = nmats; i > n2alloc; i--) + rmx_free(mop[i].mtx); mop = (ROPMAT *)realloc(mop, n2alloc*sizeof(ROPMAT)); if (mop == NULL) { - fputs("Out of memory in grow_moparray()\n", stderr); + fputs("Out of memory in resize_moparr()\n", stderr); exit(1); } if (n2alloc > nmats) @@ -569,7 +575,7 @@ main(int argc, char *argv[]) } } if (nmats >= nall) - mop = grow_moparray(mop, nall += 2); + mop = resize_moparr(mop, nall += 2); } if (mop[0].inspec == NULL) /* nothing to do? */ goto userr; @@ -597,15 +603,12 @@ main(int argc, char *argv[]) else if (mres->dtype == DTxyze) outfmt = DTxyze; } - if (outfmt != DTascii) /* write result to stdout */ - SET_FILE_BINARY(stdout); - newheader("RADIANCE", stdout); + newheader("RADIANCE", stdout); /* write result to stdout */ printargs(argc, argv, stdout); - return(rmx_write(mres, outfmt, stdout) ? 0 : 1); userr: fprintf(stderr, - "Usage: %s [-v][-f[adfc][-t][-s sf .. | -c ce ..][-rf|-rb] m1 [.+*/] .. > mres\n", + "Usage: %s [-v][-f{adfc}][-t][-s sf .. | -c ce ..][-rf|-rb] m1 [.+*/] .. > mres\n", argv[0]); return(1); }