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.36 by greg, Sun Dec 4 16:58:08 2022 UTC vs.
Revision 2.41 by greg, Sat Apr 19 17:12:59 2025 UTC

# Line 15 | Line 15 | static const char RCSid[] = "$Id$";
15   #include "paths.h"
16   #include "resolu.h"
17  
18 const char      stdin_name[] = "<stdin>";
19
20 const char      *cm_fmt_id[] = {
21                        "unknown", COLRFMT, CIEFMT,
22                        "float", "ascii", "double"
23                };
24
25 const int       cm_elem_size[] = {
26                        0, 4, 4, 3*sizeof(float), 0, 3*sizeof(double)
27                };
28
18   /* Allocate a color coefficient matrix */
19   CMATRIX *
20   cm_alloc(int nrows, int ncols)
# Line 96 | Line 85 | get_cminfo(char *s, void *p)
85          char    fmt[MAXFMTLEN];
86          int     i;
87  
88 <        if (!strncmp(s, "NCOMP=", 6) && atoi(s+6) != 3) {
88 >        if (isncomp(s) && ncompval(s) != 3) {
89                  ip->err = "unexpected # components (must be 3)";
90                  return(-1);
91          }
# Line 177 | Line 166 | cm_getheader(int *dt, int *nr, int *nc, int *swp, COLO
166  
167   /* Allocate and load image data into matrix */
168   static CMATRIX *
169 < cm_load_rgbe(FILE *fp, int nrows, int ncols, COLOR scale)
169 > cm_load_rgbe(FILE *fp, int nrows, int ncols)
170   {
182        int     doscale;
171          CMATRIX *cm;
172          COLORV  *mp;
173                                                  /* header already loaded */
174          cm = cm_alloc(nrows, ncols);
175          if (!cm)
176                  return(NULL);
189        doscale = (scale[0] < .99) | (scale[0] > 1.01) |
190                        (scale[1] < .99) | (scale[1] > 1.01) |
191                        (scale[2] < .99) | (scale[2] > 1.01) ;
177          mp = cm->cmem;
178          while (nrows--) {
179                  if (freadscan((COLOR *)mp, ncols, fp) < 0) {
# Line 196 | Line 181 | cm_load_rgbe(FILE *fp, int nrows, int ncols, COLOR sca
181                          cm_free(cm);
182                          return(NULL);
183                  }
184 <                if (doscale) {
200 <                        int     i = ncols;
201 <                        while (i--) {
202 <                                *mp++ *= scale[0];
203 <                                *mp++ *= scale[1];
204 <                                *mp++ *= scale[2];
205 <                        }
206 <                } else
207 <                        mp += 3*ncols;
184 >                mp += 3*ncols;
185          }                                       /* caller closes stream */
186          return(cm);
187   }
# Line 257 | Line 234 | cm_load(const char *inspec, int nrows, int ncols, int
234                  break;
235          case DTrgbe:
236          case DTxyze:
237 <                cm = cm_load_rgbe(fp, nrows, ncols, scale);
237 >                cm = cm_load_rgbe(fp, nrows, ncols);
238                  goto cleanup;
239          default:
240                  error(USER, "unexpected data type in cm_load()");
# Line 394 | Line 371 | cleanup:
371          else
372                  funlockfile(fp);
373   #endif
374 +        if ((scale[0] < .99) | (scale[0] > 1.01) |
375 +                        (scale[1] < .99) | (scale[1] > 1.01) |
376 +                        (scale[2] < .99) | (scale[2] > 1.01)) {
377 +                size_t  n = (size_t)ncols*nrows;
378 +                COLORV  *mp = cm->cmem;
379 +                while (n--) {           /* apply exposure scaling */
380 +                        *mp++ *= scale[0];
381 +                        *mp++ *= scale[1];
382 +                        *mp++ *= scale[2];
383 +                }
384 +        }
385          return(cm);
386   EOFerror:
387          sprintf(errmsg, "unexpected EOF reading %s", inspec);
# Line 496 | Line 484 | cm_write(const CMATRIX *cm, int dtype, FILE *fp)
484  
485          if (!cm)
486                  return(0);
487 + #ifdef getc_unlocked
488 +        flockfile(fp);
489 + #endif
490          mp = cm->cmem;
491          switch (dtype) {
492          case DTascii:
# Line 547 | Line 538 | cm_write(const CMATRIX *cm, int dtype, FILE *fp)
538                  fputs("Unsupported data type in cm_write()!\n", stderr);
539                  return(0);
540          }
541 + #ifdef getc_unlocked
542 +        funlockfile(fp);
543 + #endif
544          return(fflush(fp) == 0);
545   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines