ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/rcomb.c
(Generate patch)

Comparing ray/src/util/rcomb.c (file contents):
Revision 2.1 by greg, Tue Dec 12 16:31:45 2023 UTC vs.
Revision 2.8 by greg, Thu May 16 18:59:19 2024 UTC

# Line 9 | Line 9 | static const char RCSid[] = "$Id$";
9   #include <math.h>
10   #include "platform.h"
11   #include "rtio.h"
12 #include "resolu.h"
12   #include "rmatrix.h"
13   #include "calcomp.h"
14   #include "paths.h"
# Line 45 | Line 44 | int            nmats = 0;                      /* number of actual inputs */
44   RMATRIX         *mcat = NULL;                   /* final concatenation */
45   int             mcat_last = 0;                  /* goes after trailing ops? */
46  
47 < int             in_nrows;                       /* input row count */
48 < #define in_ncols        (mop[0].rmp->ncols)     /* input column count */
47 > int             in_nrows;                       /* number of input rows (or 0) */
48 > #define in_ncols        (mop[0].rmp->ncols)     /* number of input columns */
49   #define in_ncomp        (mop[0].rmp->ncomp)     /* input #components */
50  
51   extern int      nowarn;                         /* turn off warnings? */
# Line 186 | Line 185 | checksymbolic(ROPMAT *rop)
185   {
186          const int       nc = rop->imx.ncomp;
187          const int       dt = rop->imx.dtype;
188 +        double          cf = 1;
189          int             i, j;
190                                          /* check suffix => reference file */
191          if (strchr(rop->preop.csym, '.') > rop->preop.csym)
# Line 206 | Line 206 | checksymbolic(ROPMAT *rop)
206                  int     comp = 0;
207                  switch (rop->preop.csym[j]) {
208                  case 'B':
209 +                case 'b':
210                          ++comp;
211                          /* fall through */
212                  case 'G':
213 +                case 'g':
214                          ++comp;
215                          /* fall through */
216                  case 'R':
217 +                case 'r':
218 +                        if (rop->preop.csym[j] <= 'Z')
219 +                                cf = 1./WHTEFFICACY;
220                          if (dt == DTxyze) {
221                                  for (i = 3; i--; )
222 <                                        rop->preop.cmat[j*nc+i] = 1./WHTEFFICACY *
218 <                                                        xyz2rgbmat[comp][i];
222 >                                        rop->preop.cmat[j*nc+i] = cf*xyz2rgbmat[comp][i];
223                          } else if (nc == 3)
224                                  rop->preop.cmat[j*nc+comp] = 1.;
225                          else
226                                  rgbrow(rop, j, comp);
227                          break;
228                  case 'Z':
229 +                case 'z':
230                          ++comp;
231                          /* fall through */
232                  case 'Y':
233 +                case 'y':
234                          ++comp;
235                          /* fall through */
236                  case 'X':
237 +                case 'x':
238 +                        if ((rop->preop.csym[j] <= 'Z') & (dt != DTxyze))
239 +                                cf = WHTEFFICACY;
240                          if (dt == DTxyze) {
241                                  rop->preop.cmat[j*nc+comp] = 1.;
242                          } else if (nc == 3) {
# Line 239 | Line 248 | checksymbolic(ROPMAT *rop)
248                          else
249                                  xyzrow(rop, j, comp);
250  
251 <                        for (i = nc*(dt != DTxyze); i--; )
252 <                                rop->preop.cmat[j*nc+i] *= WHTEFFICACY;
251 >                        for (i = nc*(cf != 1); i--; )
252 >                                rop->preop.cmat[j*nc+i] *= cf;
253                          break;
254                  case 'S':               /* scotopic (il)luminance */
255 +                        cf = WHTSCOTOPIC;
256 +                        /* fall through */
257 +                case 's':
258                          sensrow(rop, j, scolor2scotopic);
259 <                        for (i = nc; i--; )
260 <                                rop->preop.cmat[j*nc+i] *= WHTSCOTOPIC;
259 >                        for (i = nc*(cf != 1); i--; )
260 >                                rop->preop.cmat[j*nc+i] *= cf;
261                          break;
262                  case 'M':               /* melanopic (il)luminance */
263 +                        cf = WHTMELANOPIC;
264 +                        /* fall through */
265 +                case 'm':
266                          sensrow(rop, j, scolor2melanopic);
267 <                        for (i = nc; i--; )
268 <                                rop->preop.cmat[j*nc+i] *= WHTMELANOPIC;
267 >                        for (i = nc*(cf != 1); i--; )
268 >                                rop->preop.cmat[j*nc+i] *= cf;
269                          break;
270                  case 'A':               /* average component */
271 +                case 'a':
272                          for (i = nc; i--; )
273                                  rop->preop.cmat[j*nc+i] = 1./(double)nc;
274                          break;
# Line 267 | Line 283 | checksymbolic(ROPMAT *rop)
283          memcpy(rop->rmp->wlpart, WLPART, sizeof(rop->rmp->wlpart));
284          rop->rmp->ncomp = rop->preop.clen / nc;
285                                          /* decide on output type */
286 <        if (!strcmp(rop->preop.csym, "XYZ")) {
286 >        if (!strcasecmp(rop->preop.csym, "XYZ")) {
287                  if (dt <= DTspec)
288                          rop->rmp->dtype = DTxyze;
289 <        } else if (!strcmp(rop->preop.csym, "RGB")) {
289 >        } else if (!strcasecmp(rop->preop.csym, "RGB")) {
290                  if (dt <= DTspec)
291                          rop->rmp->dtype = DTrgbe;
292          } else if (rop->rmp->dtype == DTspec)
# Line 469 | Line 485 | initialize(RMATRIX *imp)
485                          fprintf(stderr, "%s: warning - data type mismatch\n",
486                                          mop[i].inspec);
487                  if (!i) {
472                        imp->nrows = in_nrows = mop[0].rmp->nrows;
488                          imp->ncols = mop[0].rmp->ncols;
489                          imp->ncomp = mop[0].rmp->ncomp;
490                          memcpy(imp->wlpart, mop[0].rmp->wlpart, sizeof(imp->wlpart));
491 <                } else if ((mop[i].rmp->nrows != imp->nrows) |
492 <                                (mop[i].rmp->ncols != imp->ncols) |
493 <                                (mop[i].rmp->ncomp != imp->ncomp)) {
491 >                } else if ((mop[i].rmp->ncols != imp->ncols) |
492 >                                (mop[i].rmp->ncomp != imp->ncomp) |
493 >                                ((in_nrows > 0) & (mop[i].rmp->nrows > 0) &
494 >                                        (mop[i].rmp->nrows != in_nrows))) {
495                          fprintf(stderr, "%s: mismatch in size or #components\n",
496                                          mop[i].inspec);
497                          return(0);
498                  }                       /* XXX should check wlpart? */
499 +                if (in_nrows <= 0)
500 +                        in_nrows = imp->nrows = mop[i].rmp->nrows;
501          }                               /* set up .cal environment */
502          esupport |= E_VARIABLE|E_FUNCTION|E_RCONST;
503          esupport &= ~(E_OUTCHAN|E_INCHAN);
# Line 569 | Line 587 | combine_input(ROPMAT *res, FILE *fout)
587          } else                          /* save a little time */
588                  set_r = set_c = 0;
589                                          /* read/process row-by-row */
590 <        for (cur_row = 0; cur_row < in_nrows; cur_row++) {
590 >        for (cur_row = 0; (in_nrows <= 0) | (cur_row < in_nrows); cur_row++) {
591              RMATRIX     *mres = NULL;
592              for (i = 0; i < nmats; i++) {
593                  if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp)) {
594 +                        if (cur_row > in_nrows) /* unknown #input rows? */
595 +                                goto loop_exit;
596                          fprintf(stderr, "%s: read error at row %d\n",
597                                          mop[i].inspec, cur_row);
598                          return(0);
# Line 620 | Line 640 | combine_input(ROPMAT *res, FILE *fout)
640                                  res->rmp->ncols, res->rmp->dtype, fout))
641                  return(0);
642          }
643 + loop_exit:
644   #if 0           /* we're about to exit, so who cares? */
645          rmx_free(tmp);                  /* clean up */
646          rmx_reset(res->rmp);
# Line 658 | Line 679 | resize_inparr(int n2alloc)
679   {
680          int     i;
681  
682 <        for (i = nmats; i > n2alloc; i--) {
682 >        if (n2alloc == nall)
683 >                return;
684 >        for (i = nall; i > n2alloc; i--) {
685                  rmx_reset(&mop[i].imx);
686                  if (mop[i].rmp != &mop[i].imx)
687                          rmx_free(mop[i].rmp);
# Line 668 | Line 691 | resize_inparr(int n2alloc)
691                  fputs("Out of memory in resize_inparr()\n", stderr);
692                  exit(1);
693          }
694 <        if (n2alloc > nmats)
695 <                memset(mop+nmats, 0, (n2alloc-nmats)*sizeof(ROPMAT));
694 >        if (n2alloc > nall)
695 >                memset(mop+nall, 0, (n2alloc-nall)*sizeof(ROPMAT));
696          nall = n2alloc;
697   }
698  
# Line 846 | Line 869 | main(int argc, char *argv[])
869                  fprintf(stderr, "%s: unsupported output format\n", argv[0]);
870                  return(1);
871          }
872 +        doptimize(1);                   /* optimize definitions */
873                                          /* process & write rows */
874          return(combine_input(&mop[nmats], stdout) ? 0 : 1);
875   stdin_error:

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines