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

Comparing ray/src/util/rmatrix.c (file contents):
Revision 2.69 by greg, Mon Dec 4 22:02:40 2023 UTC vs.
Revision 2.76 by greg, Tue Dec 12 18:45:53 2023 UTC

# Line 374 | Line 374 | rmx_load(const char *inspec, RMPref rmp)
374                  fp = stdin;
375          else if (inspec[0] == '!')
376                  fp = popen(inspec+1, "r");
377 <        else if (rmp != RMPnone) {
377 >        else {
378                  const char      *sp = inspec;   /* check suffix */
379                  while (*sp)
380                          ++sp;
381                  while (sp > inspec && sp[-1] != '.')
382                          --sp;
383                  if (!strcasecmp(sp, "XML")) {   /* assume it's a BSDF */
384 <                        CMATRIX *cm = rmp==RMPtrans ? cm_loadBTDF(inspec) :
384 >                        CMATRIX *cm = rmp==RMPnone ? (CMATRIX *)NULL :
385 >                                        rmp==RMPtrans ? cm_loadBTDF(inspec) :
386                                          cm_loadBRDF(inspec, rmp==RMPreflB) ;
387                          if (!cm)
388                                  return(NULL);
# Line 449 | Line 450 | rmx_write_ascii(const double *dp, int nc, int len, FIL
450   {
451          while (len-- > 0) {
452                  int     k = nc;
453 <                while (nc-- > 0)
453 >                while (k-- > 0)
454                          fprintf(fp, " %.7e", *dp++);
455                  fputc('\t', fp);
456          }
# Line 527 | Line 528 | findCIEprims(const char *info)
528   int
529   rmx_write_header(const RMATRIX *rm, int dtype, FILE *fp)
530   {
531 <        if (!rm | !fp || !rm->mtx | (rm->ncols <= 0))
531 >        if (!rm | !fp || rm->ncols <= 0)
532                  return(0);
533          if (rm->info)
534                  fputs(rm->info, fp);
# Line 538 | Line 539 | rmx_write_header(const RMATRIX *rm, int dtype, FILE *f
539                  dtype = DTxyze;
540          else if ((dtype == DTxyze) & (rm->dtype == DTrgbe))
541                  dtype = DTrgbe;
542 <        if ((dtype == DTspec) & (rm->ncomp < 3))
542 >        if ((dtype < DTspec) & (rm->ncomp > 3))
543 >                dtype = DTspec;
544 >        else if ((dtype == DTspec) & (rm->ncomp <= 3))
545                  return(0);
546  
547          if (dtype == DTascii)                   /* set file type (WINDOWS) */
# Line 559 | Line 562 | rmx_write_header(const RMATRIX *rm, int dtype, FILE *f
562          }
563          if (dtype >= DTspec) {                  /* # components & split? */
564                  fputncomp(rm->ncomp, fp);
565 <                if (dtype == DTspec || (rm->ncomp > 3 &&
566 <                                memcmp(rm->wlpart, WLPART, sizeof(WLPART))))
565 >                if (rm->ncomp > 3 &&
566 >                                memcmp(rm->wlpart, WLPART, sizeof(WLPART)))
567                          fputwlsplit(rm->wlpart, fp);
568          } else if ((rm->ncomp != 3) & (rm->ncomp != 1))
569                  return(0);                      /* wrong # components */
# Line 665 | Line 668 | rmx_copy(const RMATRIX *rm)
668          copycolor(dnew->cexp, rm->cexp);
669          memcpy(dnew->wlpart, rm->wlpart, sizeof(dnew->wlpart));
670          return(dnew);
671 + }
672 +
673 + /* Replace data in first matrix with data from second */
674 + int
675 + rmx_transfer_data(RMATRIX *rdst, RMATRIX *rsrc, int dometa)
676 + {
677 +        if (!rdst | !rsrc || (rdst->nrows != rsrc->nrows) |
678 +                        (rdst->ncols != rsrc->ncols) |
679 +                        (rdst->ncomp != rsrc->ncomp))
680 +                return(0);
681 +
682 +        if (dometa) {           /* transfer everything? */
683 +                rmx_reset(rdst);
684 +                *rdst = *rsrc;
685 +                rsrc->info = NULL; rsrc->mapped = NULL; rsrc->mtx = NULL;
686 +                return(1);
687 +        }
688 + #ifdef MAP_FILE                 /* just matrix data -- leave metadata */
689 +        if (rdst->mapped)
690 +                munmap(rdst->mapped, mapped_size(rdst));
691 +        else
692 + #endif
693 +        if (rdst->mtx)
694 +                free(rdst->mtx);
695 +        rdst->mapped = rsrc->mapped;
696 +        rdst->mtx = rsrc->mtx;
697 +        rsrc->mapped = NULL; rsrc->mtx = NULL;
698 +        return(1);
699   }
700  
701   /* Allocate and assign transposed matrix */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines