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

Comparing ray/src/util/rmtxcomb.c (file contents):
Revision 2.1 by greg, Tue Dec 5 01:06:10 2023 UTC vs.
Revision 2.2 by greg, Tue Dec 5 20:05:36 2023 UTC

# Line 273 | Line 273 | checksymbolic(ROPMAT *rop)
273          } else if (!strcmp(rop->preop.csym, "RGB")) {
274                  if (dt <= DTspec)
275                          rop->rmp->dtype = DTrgbe;
276 <        }
277 <        if (rop->rmp->dtype == DTspec)
276 >        } else if (rop->rmp->dtype == DTspec)
277                  rop->rmp->dtype = DTfloat;
278          return(1);
279   }
# Line 301 | Line 300 | get_component_xfm(ROPMAT *rop)
300                          while (i--)
301                                  rop->preop.sca[i] = 1.;
302                  }
303 <                if (rop->preop.nsf == 1)
304 <                        rop->preop.sca[0] /= rop->rmp->cexp[GRN];
305 <                else if (rop->preop.nsf == 3)
303 >                if (rop->preop.nsf == 1) {
304 >                        if (rop->rmp->ncomp == 3) {
305 >                                rop->preop.sca[2] = rop->preop.sca[1] =
306 >                                                rop->preop.sca[0];
307 >                                rop->preop.nsf = 3;
308 >                        } else
309 >                                rop->preop.sca[0] /= bright(rop->rmp->cexp);
310 >                }
311 >                if (rop->preop.nsf == 3) {
312                          opcolor(rop->preop.sca, /=, rop->rmp->cexp);
313 <                else if (rop->preop.nsf > 3) {  /* punt */
313 >                } else if (rop->preop.nsf > 3) {        /* punt */
314                          double  mult = 1./bright(rop->rmp->cexp);
315                          for (i = rop->preop.nsf; i--; )
316                                  rop->preop.sca[i] *= mult;
# Line 338 | Line 343 | get_component_xfm(ROPMAT *rop)
343                  if (!split_input(rop))          /* get our own struct */
344                          return(0);
345                  rop->rmp->ncomp = rop->preop.clen / rop->imx.ncomp;
346 <                if (rop->rmp->dtype <= DTspec)
346 >                if ((rop->rmp->ncomp > 3) & (rop->rmp->dtype <= DTspec))
347                          rop->rmp->dtype = DTfloat;      /* probably not actual spectrum */
348          } else if (rop->preop.nsf > 0) {        /* else use scalar(s)? */
349                  if (rop->preop.nsf == 1) {
# Line 435 | Line 440 | l_chanin(char *nam)
440                  errno = EDOM;
441                  return(.0);
442          }
443 <        if (!mi)                                /* asking for #inputs? */
443 >        if (inp < .5)                   /* asking for #inputs? */
444                  return(nmats);
445  
446          if (nargum() >= 2) {
# Line 521 | Line 526 | output_headinfo(FILE *fp)
526   static int
527   combine_input(ROPMAT *res, FILE *fout)
528   {
529 <        int     user_set_r, user_set_c;
529 >        int     set_r, set_c;
530          RMATRIX *tmp = NULL;
531          int     co_set;
532          int     i;
# Line 561 | Line 566 | combine_input(ROPMAT *res, FILE *fout)
566                  scompile("co(p)=select(p,ro,go,bo)", NULL, 0);
567                  co_set = 1;
568          }
569 <        user_set_r = vardefined("r");
570 <        user_set_c = vardefined("c");
569 >        if (co_set) {                   /* don't override user */
570 >                set_r = !vardefined("r");
571 >                set_c = !vardefined("c");
572 >        } else                          /* save a little time */
573 >                set_r = set_c = 0;
574                                          /* read/process row-by-row */
575          for (cur_row = 0; cur_row < in_nrows; cur_row++) {
576              RMATRIX     *mres = NULL;
577              for (i = 0; i < nmats; i++) {
578 <                if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp))
578 >                if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp)) {
579 >                        fprintf(stderr, "%s: read error at row %d\n",
580 >                                        mop[i].inspec, cur_row);
581                          return(0);
582 +                }
583                  if (!apply_op(mop[i].rmp, &mop[i].imx, &mop[i].preop))
584                          return(0);
585              }
586 <            if (!user_set_r) varset("r", '=', cur_row);
586 >            if (set_r) varset("r", '=', cur_row);
587              for (cur_col = 0; cur_col < in_ncols; cur_col++) {
588 <                if (!user_set_c) varset("c", '=', cur_col);
588 >                if (set_c) varset("c", '=', cur_col);
589                  for (cur_chan = 0; cur_chan < in_ncomp; cur_chan++) {
590                      const int   ndx = cur_col*in_ncomp + cur_chan;
591                      eclock++;
# Line 583 | Line 594 | combine_input(ROPMAT *res, FILE *fout)
594                          for (i = nmats; i--; )
595                                  res->imx.mtx[ndx] += mop[i].rmp->mtx[ndx];
596                      } else if (co_set > 0) {
597 <                        double  dchan = cur_chan;
597 >                        double  dchan = cur_chan+1;
598                          res->imx.mtx[ndx] = funvalue("co", 1, &dchan);
599                      } else
600                          res->imx.mtx[ndx] = varvalue("co");
# Line 612 | Line 623 | combine_input(ROPMAT *res, FILE *fout)
623                                  res->rmp->ncols, res->rmp->dtype, fout))
624                  return(0);
625          }
626 + #if 0           /* we're about to exit, so who cares? */
627          rmx_free(tmp);                  /* clean up */
628 <        if (res->rmp != &res->imx) {
617 <                rmx_free(res->rmp);
618 <                res->rmp = NULL;
619 <        }
628 >        rmx_reset(res->rmp);
629          rmx_reset(&res->imx);
630 <        return(1);
630 >        for (i = 0; i < nmats; i++) {
631 >                rmx_reset(mop[i].rmp);
632 >                rmx_reset(&mop[i].imx);
633 >                if (mop[i].inspec[0] == '!')
634 >                        pclose(mop[i].infp);
635 >                else if (mop[i].inspec != stdin_name)
636 >                        fclose(mop[i].infp);
637 >                mop[i].infp = NULL;
638 >        }
639 > #endif
640 >        return(fflush(fout) != EOF);
641   memerror:
642          fputs("Out of buffer space in combine_input()\n", stderr);
643          return(0);
# Line 818 | Line 837 | main(int argc, char *argv[])
837                  }
838                  mop[nmats].rmp->ncols = mcat->ncols;
839          }
840 <        if (outfmt == DTfromHeader)     /* set final output format */
822 <                outfmt = mop[nmats].rmp->dtype;
823 <        if (outfmt == DTrgbe) {
824 <                if (mop[nmats].rmp->ncomp > 3)
825 <                        outfmt = DTspec;
826 <                else if (mop[nmats].rmp->dtype == DTxyze)
827 <                        outfmt = DTxyze;
828 <        }
829 <        mop[nmats].rmp->dtype = outfmt;
830 <        if (outfmt != DTascii)
831 <                SET_FILE_BINARY(stdout);
832 <                                        /* write output header */
833 <        newheader("RADIANCE", stdout);
840 >        newheader("RADIANCE", stdout);  /* write output header */
841          if (echoheader)
842                  output_headinfo(stdout);
843          printargs(argc, argv, stdout);
844          fputnow(stdout);
845 <        mop[nmats].rmp->dtype = rmx_write_header(mop[nmats].rmp, mop[nmats].rmp->dtype, stdout);
846 <        if (mop[nmats].rmp->dtype <= 0) {
847 <                fprintf(stderr, "%s: unexpected error writing header!\n", argv[0]);
845 >        mop[nmats].rmp->dtype = rmx_write_header(mop[nmats].rmp, outfmt, stdout);
846 >        if (!mop[nmats].rmp->dtype) {
847 >                fprintf(stderr, "%s: unsupported output format\n", argv[0]);
848                  return(1);
849          }
850                                          /* process & write rows */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines