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.82 by greg, Thu Jun 6 17:01:05 2024 UTC vs.
Revision 2.83 by greg, Tue Oct 8 00:43:57 2024 UTC

# Line 46 | Line 46 | int
46   rmx_prepare(RMATRIX *rm)
47   {
48          if (!rm) return(0);
49 <        if (rm->mtx)
49 >        if (rm->mtx)                    /* assume it's right size */
50                  return(1);
51          if ((rm->nrows <= 0) | (rm->ncols <= 0) | (rm->ncomp <= 0))
52                  return(0);
# Line 61 | Line 61 | rmx_alloc(int nr, int nc, int n)
61   {
62          RMATRIX *dnew = rmx_new(nr, nc, n);
63  
64 <        if (dnew && !rmx_prepare(dnew)) {
64 >        if (!rmx_prepare(dnew)) {
65                  rmx_free(dnew);
66 <                dnew = NULL;
66 >                return(NULL);
67          }
68          return(dnew);
69   }
# Line 116 | Line 116 | rmx_newtype(int dtyp1, int dtyp2)
116   int
117   rmx_addinfo(RMATRIX *rm, const char *info)
118   {
119 <        int     oldlen = 0;
119 >        size_t  oldlen = 0;
120  
121          if (!rm || !info || !*info)
122                  return(0);
123          if (!rm->info) {
124                  rm->info = (char *)malloc(strlen(info)+1);
125                if (rm->info) rm->info[0] = '\0';
125          } else {
126                  oldlen = strlen(rm->info);
127                  rm->info = (char *)realloc(rm->info,
# Line 141 | Line 140 | get_dminfo(char *s, void *p)
140          char    fmt[MAXFMTLEN];
141          int     i;
142  
143 <        if (headidval(NULL, s))
143 >        if (isheadid(s))
144                  return(0);
145          if (isncomp(s)) {
146                  ip->ncomp = ncompval(s);
147 <                return(0);
147 >                return(ip->ncomp - 1);
148          }
149          if (!strncmp(s, "NROWS=", 6)) {
150                  ip->nrows = atoi(s+6);
151 <                return(0);
151 >                return(ip->nrows - 1);
152          }
153          if (!strncmp(s, "NCOLS=", 6)) {
154                  ip->ncols = atoi(s+6);
155 <                return(0);
155 >                return(ip->ncols - 1);
156          }
157          if ((i = isbigendian(s)) >= 0) {
158                  if (nativebigendian() != i)
# Line 165 | Line 164 | get_dminfo(char *s, void *p)
164          if (isexpos(s)) {
165                  float   f = exposval(s);
166                  scalecolor(ip->cexp, f);
167 <                return(0);
167 >                return(f > .0 ? 0 : -1);
168          }
169          if (iscolcor(s)) {
170                  COLOR   ctmp;
171 <                colcorval(ctmp, s);
171 >                if (!colcorval(ctmp, s)) return(-1);
172                  multcolor(ip->cexp, ctmp);
173                  return(0);
174          }
175 <        if (iswlsplit(s)) {
176 <                wlsplitval(ip->wlpart, s);
177 <                return(0);
179 <        }
175 >        if (iswlsplit(s))
176 >                return(wlsplitval(ip->wlpart, s) - 1);
177 >
178          if (!formatval(fmt, s)) {
179                  rmx_addinfo(ip, s);
180                  return(0);
# Line 186 | Line 184 | get_dminfo(char *s, void *p)
184                          ip->dtype = i;
185                          return(0);
186                  }
187 <        return(-1);
187 >        return(-1);             /* bad format */
188   }
189  
190   static int
# Line 293 | Line 291 | rmx_load_header(RMATRIX *rm, FILE *fp)
291          }
292          rm->dtype = DTascii;                    /* assumed w/o FORMAT */
293          if (getheader(fp, get_dminfo, rm) < 0) {
294 <                fputs("Unrecognized matrix format\n", stderr);
294 >                fputs("Bad matrix header\n", stderr);
295                  return(0);
296          }
297          if ((rm->dtype == DTrgbe) | (rm->dtype == DTxyze) &&
# Line 698 | Line 696 | rmx_transfer_data(RMATRIX *rdst, RMATRIX *rsrc, int do
696                  munmap(rdst->mapped, rmx_mapped_size(rdst));
697          else
698   #endif
699 <        if (rdst->pflags & RMF_FREEMEM)
699 >        if (rdst->pflags & RMF_FREEMEM) {
700                  free(rdst->mtx);
701 +                rdst->pflags &= ~RMF_FREEMEM;
702 +        }
703          rdst->mapped = rsrc->mapped;
704          rdst->mtx = rsrc->mtx;
705 <        if (rsrc->pflags & RMF_FREEMEM)
706 <                rdst->pflags |= RMF_FREEMEM;
707 <        else
708 <                rdst->pflags &= ~RMF_FREEMEM;
705 >        rdst->pflags |= rsrc->pflags & RMF_FREEMEM;
706          rsrc->mapped = NULL; rsrc->mtx = NULL;
707          return(1);
708   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines