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

Comparing ray/src/util/cmatrix.c (file contents):
Revision 2.22 by greg, Wed Aug 14 18:20:02 2019 UTC vs.
Revision 2.23 by greg, Wed Oct 23 17:00:14 2019 UTC

# Line 155 | Line 155 | cm_getheader(int *dt, int *nr, int *nc, int *swp, FILE
155          return(NULL);
156   }
157  
158 + /* Allocate and load image data into matrix */
159 + static CMATRIX *
160 + cm_load_rgbe(FILE *fp, int nrows, int ncols)
161 + {
162 +        CMATRIX *cm;
163 +        COLORV  *mp;
164 +                                                /* header already loaded */
165 +        if ((nrows <= 0) | (ncols <= 0) && !fscnresolu(&ncols, &nrows, fp)) {
166 +                error(USER, "bad picture resolution string");
167 +                return(NULL);
168 +        }
169 +        cm = cm_alloc(nrows, ncols);
170 +        if (!cm)
171 +                return(NULL);
172 +        mp = cm->cmem;
173 +        while (nrows--) {
174 +                if (freadscan((COLOR *)mp, ncols, fp) < 0) {
175 +                        error(USER, "error reading color picture as matrix");
176 +                        cm_free(cm);
177 +                        return(NULL);
178 +                }
179 +                mp += 3*ncols;
180 +        }                                       /* caller closes stream */
181 +        return(cm);
182 + }
183 +
184   /* Allocate and load a matrix from the given input (or stdin if NULL) */
185   CMATRIX *
186   cm_load(const char *inspec, int nrows, int ncols, int dtype)
# Line 193 | Line 219 | cm_load(const char *inspec, int nrows, int ncols, int
219          case DTfloat:
220          case DTdouble:
221                  break;
222 +        case DTrgbe:
223 +        case DTxyze:
224 +                cm = cm_load_rgbe(fp, nrows, ncols);
225 +                goto cleanup;
226          default:
227                  error(USER, "unexpected data type in cm_load()");
228          }
# Line 312 | Line 342 | cm_load(const char *inspec, int nrows, int ncols, int
342                  else if (dtype == DTdouble)
343                          swap64((char *)cm->cmem, 3*cm->nrows*cm->ncols);
344          }
345 + cleanup:
346          if (fp != stdin) {
347                  if (inspec[0] != '!')
348                          fclose(fp);
# Line 328 | Line 359 | cm_load(const char *inspec, int nrows, int ncols, int
359   EOFerror:
360          sprintf(errmsg, "unexpected EOF reading %s", inspec);
361          error(USER, errmsg);
362 +        return(NULL);
363   not_handled:
364          error(INTERNAL, "unhandled data size or length in cm_load()");
365          return(NULL);   /* gratis return */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines