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.5 by greg, Fri Dec 8 00:12:31 2023 UTC

# Line 89 | Line 89 | checkreffile(ROPMAT *rop)
89                  fclose(fp);
90                  curRF = rop->preop.csym;
91          }
92 <        if ((refm.ncomp == 3) & (refm.dtype != DTspec)) {
92 >        if (refm.ncomp == 3) {
93                  rop->preop.csym = (refm.dtype == DTxyze) ? "XYZ" : "RGB";
94                  return(checksymbolic(rop));
95          }
# 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 +                        memcpy(rop->rmp->wlpart, WLPART, sizeof(rop->rmp->wlpart));
349 +                }
350          } else if (rop->preop.nsf > 0) {        /* else use scalar(s)? */
351                  if (rop->preop.nsf == 1) {
352                          for (i = rop->rmp->ncomp; --i; )
# Line 357 | Line 364 | get_component_xfm(ROPMAT *rop)
364   static int
365   apply_op(RMATRIX *dst, const RMATRIX *src, const RUNARYOP *ro)
366   {
360 /*
361        if (!dst | !src | !ro || (dst->nrows != src->nrows) |
362                        (dst->ncols != src->ncols))
363                return(0);
364 */
367          if (ro->clen > 0) {
368                  RMATRIX *res = rmx_transform(src, dst->ncomp, ro->cmat);
369                  if (!res) {
370                          fputs("Error in call to rmx_transform()\n", stderr);
371                          return(0);
372                  }
373 <                if (dst->mtx) free(dst->mtx);
374 <                dst->mtx = res->mtx; res->mtx = NULL;
373 >                if (!rmx_transfer_data(dst, res, 0))
374 >                        return(0);
375                  rmx_free(res);
376          } else if (dst != src)
377                  memcpy(dst->mtx, src->mtx,
# Line 435 | Line 437 | l_chanin(char *nam)
437                  errno = EDOM;
438                  return(.0);
439          }
440 <        if (!mi)                                /* asking for #inputs? */
440 >        if (inp < .5)                   /* asking for #inputs? */
441                  return(nmats);
442  
443          if (nargum() >= 2) {
# Line 521 | Line 523 | output_headinfo(FILE *fp)
523   static int
524   combine_input(ROPMAT *res, FILE *fout)
525   {
526 <        int     user_set_r, user_set_c;
526 >        int     set_r, set_c;
527          RMATRIX *tmp = NULL;
528          int     co_set;
529          int     i;
# Line 547 | Line 549 | combine_input(ROPMAT *res, FILE *fout)
549                          goto memerror;
550          }
551          if (mcat && mcat_last &&
552 <                        !(tmp = rmx_new(1, res->imx.ncols, res->rmp->ncomp)))
552 >                        !(tmp = rmx_alloc(1, res->imx.ncols, res->rmp->ncomp)))
553                  goto memerror;
554          res->imx.nrows = 1;
555          if (!rmx_prepare(&res->imx))
# Line 561 | Line 563 | combine_input(ROPMAT *res, FILE *fout)
563                  scompile("co(p)=select(p,ro,go,bo)", NULL, 0);
564                  co_set = 1;
565          }
566 <        user_set_r = vardefined("r");
567 <        user_set_c = vardefined("c");
566 >        if (co_set) {                   /* don't override user */
567 >                set_r = !vardefined("r");
568 >                set_c = !vardefined("c");
569 >        } else                          /* save a little time */
570 >                set_r = set_c = 0;
571                                          /* read/process row-by-row */
572          for (cur_row = 0; cur_row < in_nrows; cur_row++) {
573              RMATRIX     *mres = NULL;
574              for (i = 0; i < nmats; i++) {
575 <                if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp))
575 >                if (!rmx_load_row(mop[i].imx.mtx, &mop[i].imx, mop[i].infp)) {
576 >                        fprintf(stderr, "%s: read error at row %d\n",
577 >                                        mop[i].inspec, cur_row);
578                          return(0);
579 +                }
580                  if (!apply_op(mop[i].rmp, &mop[i].imx, &mop[i].preop))
581                          return(0);
582              }
583 <            if (!user_set_r) varset("r", '=', cur_row);
583 >            if (set_r) varset("r", '=', cur_row);
584              for (cur_col = 0; cur_col < in_ncols; cur_col++) {
585 <                if (!user_set_c) varset("c", '=', cur_col);
585 >                if (set_c) varset("c", '=', cur_col);
586                  for (cur_chan = 0; cur_chan < in_ncomp; cur_chan++) {
587                      const int   ndx = cur_col*in_ncomp + cur_chan;
588                      eclock++;
# Line 583 | Line 591 | combine_input(ROPMAT *res, FILE *fout)
591                          for (i = nmats; i--; )
592                                  res->imx.mtx[ndx] += mop[i].rmp->mtx[ndx];
593                      } else if (co_set > 0) {
594 <                        double  dchan = cur_chan;
594 >                        double  dchan = cur_chan+1;
595                          res->imx.mtx[ndx] = funvalue("co", 1, &dchan);
596                      } else
597                          res->imx.mtx[ndx] = varvalue("co");
# Line 598 | Line 606 | combine_input(ROPMAT *res, FILE *fout)
606                  mres = rmx_multiply(tmp, mcat);
607                  if (!mres)
608                          goto multerror;
609 <                if (res->rmp->mtx) free(res->rmp->mtx);
610 <                res->rmp->mtx = mres->mtx; mres->mtx = NULL;
609 >                if (!rmx_transfer_data(res->rmp, mres, 0))
610 >                        return(0);
611              } else /* mcat && !mcat_last */ {
612                  mres = rmx_multiply(&res->imx, mcat);
613                  if (!mres)
# Line 612 | Line 620 | combine_input(ROPMAT *res, FILE *fout)
620                                  res->rmp->ncols, res->rmp->dtype, fout))
621                  return(0);
622          }
623 + #if 0           /* we're about to exit, so who cares? */
624          rmx_free(tmp);                  /* clean up */
625 <        if (res->rmp != &res->imx) {
617 <                rmx_free(res->rmp);
618 <                res->rmp = NULL;
619 <        }
625 >        rmx_reset(res->rmp);
626          rmx_reset(&res->imx);
627 <        return(1);
627 >        for (i = 0; i < nmats; i++) {
628 >                rmx_reset(mop[i].rmp);
629 >                rmx_reset(&mop[i].imx);
630 >                if (mop[i].inspec[0] == '!')
631 >                        pclose(mop[i].infp);
632 >                else if (mop[i].inspec != stdin_name)
633 >                        fclose(mop[i].infp);
634 >                mop[i].infp = NULL;
635 >        }
636 > #endif
637 >        return(fflush(fout) != EOF);
638   memerror:
639          fputs("Out of buffer space in combine_input()\n", stderr);
640          return(0);
# Line 778 | Line 794 | main(int argc, char *argv[])
794          mop[nmats].inspec = "trailing_ops";
795                                          /* load final concatenation matrix */
796          if (mcat_spec && !(mcat = rmx_load(mcat_spec, RMPnone))) {
797 <                fprintf(stderr, "%s: error loading concatenation matrix: %s",
797 >                fprintf(stderr, "%s: error loading concatenation matrix: %s\n",
798                                  argv[0], mcat_spec);
799                  return(1);
800          }
# Line 816 | Line 832 | main(int argc, char *argv[])
832                                          argv[0], mcat_spec);
833                          return(1);
834                  }
835 +                if (!split_input(&mop[nmats]))
836 +                        return(1);
837                  mop[nmats].rmp->ncols = mcat->ncols;
838          }
839 <        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);
839 >        newheader("RADIANCE", stdout);  /* write output header */
840          if (echoheader)
841                  output_headinfo(stdout);
842          printargs(argc, argv, stdout);
843          fputnow(stdout);
844 <        mop[nmats].rmp->dtype = rmx_write_header(mop[nmats].rmp, mop[nmats].rmp->dtype, stdout);
845 <        if (mop[nmats].rmp->dtype <= 0) {
846 <                fprintf(stderr, "%s: unexpected error writing header!\n", argv[0]);
844 >        mop[nmats].rmp->dtype = rmx_write_header(mop[nmats].rmp, outfmt, stdout);
845 >        if (!mop[nmats].rmp->dtype) {
846 >                fprintf(stderr, "%s: unsupported output format\n", argv[0]);
847                  return(1);
848          }
849                                          /* process & write rows */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines