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.67 by greg, Fri Dec 1 02:05:00 2023 UTC vs.
Revision 2.70 by greg, Tue Dec 5 01:06:10 2023 UTC

# Line 31 | Line 31 | rmx_new(int nr, int nc, int n)
31                  return(NULL);
32  
33          dnew = (RMATRIX *)calloc(1, sizeof(RMATRIX));
34 <        if (dnew) {
35 <                dnew->dtype = DTdouble;
36 <                dnew->nrows = nr;
37 <                dnew->ncols = nc;
38 <                dnew->ncomp = n;
39 <                setcolor(dnew->cexp, 1.f, 1.f, 1.f);
40 <                memcpy(dnew->wlpart, WLPART, sizeof(dnew->wlpart));
41 <        }
34 >        if (!dnew)
35 >                return(NULL);
36 >
37 >        dnew->dtype = DTdouble;
38 >        dnew->nrows = nr;
39 >        dnew->ncols = nc;
40 >        dnew->ncomp = n;
41 >        setcolor(dnew->cexp, 1.f, 1.f, 1.f);
42 >        memcpy(dnew->wlpart, WLPART, sizeof(dnew->wlpart));
43 >
44          return(dnew);
45   }
46  
# Line 292 | Line 294 | rmx_load_header(RMATRIX *rm, FILE *fp)
294                  fputs("Unrecognized matrix format\n", stderr);
295                  return(0);
296          }
297 <                                                /* resolution string? */
298 <        if ((rm->nrows <= 0) | (rm->ncols <= 0)) {
299 <                if (!fscnresolu(&rm->ncols, &rm->nrows, fp))
300 <                        return(0);
301 <                if ((rm->dtype == DTrgbe) | (rm->dtype == DTxyze) &&
302 <                                rm->ncomp != 3)
303 <                        return(0);
302 <        }
303 <        if (rm->dtype == DTascii)               /* set input type (WINDOWS) */
297 >        if ((rm->dtype == DTrgbe) | (rm->dtype == DTxyze) &&
298 >                        rm->ncomp != 3)
299 >                return(0);
300 >        if (rm->ncols <= 0 &&                   /* resolution string? */
301 >                        !fscnresolu(&rm->ncols, &rm->nrows, fp))
302 >                return(0);
303 >        if (rm->dtype == DTascii)               /* set file type (WINDOWS) */
304                  SET_FILE_TEXT(fp);
305          else
306                  SET_FILE_BINARY(fp);
# Line 527 | Line 527 | findCIEprims(const char *info)
527   int
528   rmx_write_header(const RMATRIX *rm, int dtype, FILE *fp)
529   {
530 <        if (!rm | !fp || !rm->mtx)
530 >        if (!rm | !fp || rm->ncols <= 0)
531                  return(0);
532          if (rm->info)
533                  fputs(rm->info, fp);
# Line 538 | Line 538 | rmx_write_header(const RMATRIX *rm, int dtype, FILE *f
538                  dtype = DTxyze;
539          else if ((dtype == DTxyze) & (rm->dtype == DTrgbe))
540                  dtype = DTrgbe;
541 +        if ((dtype == DTspec) & (rm->ncomp < 3))
542 +                return(0);
543  
544 <        if (dtype == DTascii)                   /* set output type (WINDOWS) */
544 >        if (dtype == DTascii)                   /* set file type (WINDOWS) */
545                  SET_FILE_TEXT(fp);
546          else
547                  SET_FILE_BINARY(fp);
# Line 549 | Line 551 | rmx_write_header(const RMATRIX *rm, int dtype, FILE *f
551                  fputcolcor(rm->cexp, fp);
552          else if (rm->cexp[GRN] != 1.f)
553                  fputexpos(rm->cexp[GRN], fp);
554 <        if ((dtype != DTrgbe) & (dtype != DTxyze)) {
555 <                if (dtype != DTspec) {
554 >                                                /* matrix size? */
555 >        if ((dtype > DTspec) | (rm->nrows <= 0)) {
556 >                if (rm->nrows > 0)
557                          fprintf(fp, "NROWS=%d\n", rm->nrows);
558 <                        fprintf(fp, "NCOLS=%d\n", rm->ncols);
559 <                } else if (rm->ncomp < 3)
560 <                        return(0);              /* bad # components */
558 >                fprintf(fp, "NCOLS=%d\n", rm->ncols);
559 >        }
560 >        if (dtype >= DTspec) {                  /* # components & split? */
561                  fputncomp(rm->ncomp, fp);
562                  if (dtype == DTspec || (rm->ncomp > 3 &&
563                                  memcmp(rm->wlpart, WLPART, sizeof(WLPART))))
# Line 565 | Line 568 | rmx_write_header(const RMATRIX *rm, int dtype, FILE *f
568                  fputendian(fp);                 /* important to record */
569          fputformat(cm_fmt_id[dtype], fp);
570          fputc('\n', fp);                        /* end of header */
571 <        if (dtype <= DTspec)
571 >        if ((dtype <= DTspec) & (rm->nrows > 0))
572                  fprtresolu(rm->ncols, rm->nrows, fp);
573          return(dtype);
574   }
# Line 639 | Line 642 | rmx_identity(const int dim, const int n)
642          return(rid);
643   }
644  
645 < /* Duplicate the given matrix */
645 > /* Duplicate the given matrix (may be unallocated) */
646   RMATRIX *
647   rmx_copy(const RMATRIX *rm)
648   {
649          RMATRIX *dnew;
650  
651 <        if (!rm || !rm->mtx)
651 >        if (!rm)
652                  return(NULL);
653 <        dnew = rmx_alloc(rm->nrows, rm->ncols, rm->ncomp);
653 >        dnew = rmx_new(rm->nrows, rm->ncols, rm->ncomp);
654          if (!dnew)
655                  return(NULL);
656 +        if (rm->mtx) {
657 +                if (!rmx_prepare(dnew)) {
658 +                        rmx_free(dnew);
659 +                        return(NULL);
660 +                }
661 +                memcpy(dnew->mtx, rm->mtx, array_size(dnew));
662 +        }
663          rmx_addinfo(dnew, rm->info);
664          dnew->dtype = rm->dtype;
665          copycolor(dnew->cexp, rm->cexp);
666          memcpy(dnew->wlpart, rm->wlpart, sizeof(dnew->wlpart));
657        memcpy(dnew->mtx, rm->mtx, array_size(dnew));
667          return(dnew);
668   }
669  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines