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

Comparing ray/src/util/rmtxop.c (file contents):
Revision 2.30 by greg, Fri Dec 8 00:12:31 2023 UTC vs.
Revision 2.35 by greg, Fri Nov 8 17:52:26 2024 UTC

# Line 7 | Line 7 | static const char RCSid[] = "$Id$";
7  
8   #include <errno.h>
9   #include "rtio.h"
10 #include "resolu.h"
10   #include "rmatrix.h"
11   #include "platform.h"
12  
# Line 35 | Line 34 | typedef struct {
34   int     verbose = 0;                    /* verbose reporting? */
35  
36   /* Load matrix */
37 < static int
37 > int
38   loadmatrix(ROPMAT *rop)
39   {
40          if (rop->mtx != NULL)           /* already loaded? */
# Line 46 | Line 45 | loadmatrix(ROPMAT *rop)
45          return(!rop->mtx ? -1 : 1);
46   }
47  
48 < static int      checksymbolic(ROPMAT *rop);
48 > extern int      checksymbolic(ROPMAT *rop);
49  
50   /* Check/set transform based on a reference input file */
51 < static int
51 > int
52   checkreffile(ROPMAT *rop)
53   {
54          static const char       *curRF = NULL;
# Line 108 | Line 107 | checkreffile(ROPMAT *rop)
107   }
108  
109   /* Compute conversion row from spectrum to one channel of RGB */
110 < static void
110 > void
111   rgbrow(ROPMAT *rop, int r, int p)
112   {
113          const int       nc = rop->mtx->ncomp;
# Line 125 | Line 124 | rgbrow(ROPMAT *rop, int r, int p)
124   }
125  
126   /* Compute conversion row from spectrum to one channel of XYZ */
127 < static void
127 > void
128   xyzrow(ROPMAT *rop, int r, int p)
129   {
130          const int       nc = rop->mtx->ncomp;
# Line 142 | Line 141 | xyzrow(ROPMAT *rop, int r, int p)
141   }
142  
143   /* Use the spectral sensitivity function to compute matrix coefficients */
144 < static void
145 < sensrow(ROPMAT *rop, int r, double (*sf)(SCOLOR sc, int ncs, const float wlpt[4]))
144 > void
145 > sensrow(ROPMAT *rop, int r, double (*sf)(const SCOLOR sc, int ncs, const float wlpt[4]))
146   {
147          const int       nc = rop->mtx->ncomp;
148          int             i;
# Line 157 | Line 156 | sensrow(ROPMAT *rop, int r, double (*sf)(SCOLOR sc, in
156   }
157  
158   /* Check/set symbolic transform */
159 < static int
159 > int
160   checksymbolic(ROPMAT *rop)
161   {
162          const int       nc = rop->mtx->ncomp;
163          const int       dt = rop->mtx->dtype;
164 +        double          cf = 1;
165          int             i, j;
166                                          /* check suffix => reference file */
167          if (strchr(rop->preop.csym, '.') > rop->preop.csym)
# Line 182 | Line 182 | checksymbolic(ROPMAT *rop)
182                  int     comp = 0;
183                  switch (rop->preop.csym[j]) {
184                  case 'B':
185 +                case 'b':
186                          ++comp;
187                          /* fall through */
188                  case 'G':
189 +                case 'g':
190                          ++comp;
191                          /* fall through */
192                  case 'R':
193 +                case 'r':
194 +                        if (rop->preop.csym[j] <= 'Z')
195 +                                cf = 1./WHTEFFICACY;
196                          if (dt == DTxyze) {
197                                  for (i = 3; i--; )
198 <                                        rop->preop.cmat[j*nc+i] = 1./WHTEFFICACY *
194 <                                                        xyz2rgbmat[comp][i];
198 >                                        rop->preop.cmat[j*nc+i] = cf*xyz2rgbmat[comp][i];
199                          } else if (nc == 3)
200                                  rop->preop.cmat[j*nc+comp] = 1.;
201                          else
202                                  rgbrow(rop, j, comp);
203                          break;
204                  case 'Z':
205 +                case 'z':
206                          ++comp;
207                          /* fall through */
208                  case 'Y':
209 +                case 'y':
210                          ++comp;
211                          /* fall through */
212                  case 'X':
213 +                case 'x':
214 +                        if ((rop->preop.csym[j] <= 'Z') & (dt != DTxyze))
215 +                                cf = WHTEFFICACY;
216                          if (dt == DTxyze) {
217                                  rop->preop.cmat[j*nc+comp] = 1.;
218                          } else if (nc == 3) {
# Line 215 | Line 224 | checksymbolic(ROPMAT *rop)
224                          else
225                                  xyzrow(rop, j, comp);
226  
227 <                        for (i = nc*(dt != DTxyze); i--; )
228 <                                rop->preop.cmat[j*nc+i] *= WHTEFFICACY;
227 >                        for (i = nc*(cf != 1); i--; )
228 >                                rop->preop.cmat[j*nc+i] *= cf;
229                          break;
230                  case 'S':               /* scotopic (il)luminance */
231 +                        cf = WHTSCOTOPIC;
232 +                        /* fall through */
233 +                case 's':
234                          sensrow(rop, j, scolor2scotopic);
235 <                        for (i = nc; i--; )
236 <                                rop->preop.cmat[j*nc+i] *= WHTSCOTOPIC;
235 >                        for (i = nc*(cf != 1); i--; )
236 >                                rop->preop.cmat[j*nc+i] *= cf;
237                          break;
238                  case 'M':               /* melanopic (il)luminance */
239 +                        cf = WHTMELANOPIC;
240 +                        /* fall through */
241 +                case 'm':
242                          sensrow(rop, j, scolor2melanopic);
243 <                        for (i = nc; i--; )
244 <                                rop->preop.cmat[j*nc+i] *= WHTMELANOPIC;
243 >                        for (i = nc*(cf != 1); i--; )
244 >                                rop->preop.cmat[j*nc+i] *= cf;
245                          break;
246                  case 'A':               /* average component */
247 +                case 'a':
248                          for (i = nc; i--; )
249                                  rop->preop.cmat[j*nc+i] = 1./(double)nc;
250                          break;
# Line 239 | Line 255 | checksymbolic(ROPMAT *rop)
255                  }
256          }
257                                          /* return recommended output type */
258 <        if (!strcmp(rop->preop.csym, "XYZ")) {
258 >        if (!strcasecmp(rop->preop.csym, "XYZ")) {
259                  if (dt <= DTspec)
260                          return(DTxyze);
261 <        } else if (!strcmp(rop->preop.csym, "RGB")) {
261 >        } else if (!strcasecmp(rop->preop.csym, "RGB")) {
262                  if (dt <= DTspec)
263                          return(DTrgbe);
264          } else if (dt == DTspec)
# Line 251 | Line 267 | checksymbolic(ROPMAT *rop)
267   }
268  
269   /* Get matrix and perform unary operations */
270 < static RMATRIX *
270 > RMATRIX *
271   loadop(ROPMAT *rop)
272   {
273          int     outtype = 0;
# Line 351 | Line 367 | failure:
367   }
368  
369   /* Execute binary operation, free matrix arguments and return new result */
370 < static RMATRIX *
370 > RMATRIX *
371   binaryop(const char *inspec, RMATRIX *mleft, int op, RMATRIX *mright)
372   {
373          RMATRIX *mres = NULL;
# Line 428 | Line 444 | binaryop(const char *inspec, RMATRIX *mleft, int op, R
444   }
445  
446   /* Perform matrix operations from left to right */
447 < static RMATRIX *
447 > RMATRIX *
448   op_left2right(ROPMAT *mop)
449   {
450          RMATRIX *mleft = loadop(mop);
# Line 444 | Line 460 | op_left2right(ROPMAT *mop)
460   }
461  
462   /* Perform matrix operations from right to left */
463 < static RMATRIX *
463 > RMATRIX *
464   op_right2left(ROPMAT *mop)
465   {
466          RMATRIX *mright;
# Line 473 | Line 489 | op_right2left(ROPMAT *mop)
489                                                  : (mop)->mtx->ncols)
490  
491   /* Should we prefer concatenating from rightmost matrix towards left? */
492 < static int
492 > int
493   prefer_right2left(ROPMAT *mop)
494   {
495          int     mri = 0;
# Line 500 | Line 516 | prefer_right2left(ROPMAT *mop)
516          return(t_ncols(mop+mri) < t_nrows(mop));
517   }
518  
519 < static int
519 > int
520   get_factors(double da[], int n, char *av[])
521   {
522          int     ac;
# Line 510 | Line 526 | get_factors(double da[], int n, char *av[])
526          return(ac);
527   }
528  
529 < static ROPMAT *
529 > ROPMAT *
530   resize_moparr(ROPMAT *mop, int n2alloc)
531   {
532          int     nmats = 0;
# Line 518 | Line 534 | resize_moparr(ROPMAT *mop, int n2alloc)
534  
535          while (mop[nmats++].binop)
536                  ;
537 <        for (i = nmats; i > n2alloc; i--)
537 >        for (i = nmats; i >= n2alloc; i--)
538                  rmx_free(mop[i].mtx);
539          mop = (ROPMAT *)realloc(mop, n2alloc*sizeof(ROPMAT));
540          if (mop == NULL) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines