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.37 by greg, Fri Apr 4 01:48:25 2025 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  
13 + #ifndef MAXCOMP
14   #define MAXCOMP         MAXCSAMP        /* #components we support */
15 + #endif
16  
17   /* Unary matrix operation(s) */
18   typedef struct {
# Line 35 | Line 36 | typedef struct {
36   int     verbose = 0;                    /* verbose reporting? */
37  
38   /* Load matrix */
39 < static int
39 > int
40   loadmatrix(ROPMAT *rop)
41   {
42          if (rop->mtx != NULL)           /* already loaded? */
# Line 46 | Line 47 | loadmatrix(ROPMAT *rop)
47          return(!rop->mtx ? -1 : 1);
48   }
49  
50 < static int      checksymbolic(ROPMAT *rop);
50 > extern int      checksymbolic(ROPMAT *rop);
51  
52   /* Check/set transform based on a reference input file */
53 < static int
53 > int
54   checkreffile(ROPMAT *rop)
55   {
56          static const char       *curRF = NULL;
# Line 108 | Line 109 | checkreffile(ROPMAT *rop)
109   }
110  
111   /* Compute conversion row from spectrum to one channel of RGB */
112 < static void
112 > void
113   rgbrow(ROPMAT *rop, int r, int p)
114   {
115          const int       nc = rop->mtx->ncomp;
# Line 125 | Line 126 | rgbrow(ROPMAT *rop, int r, int p)
126   }
127  
128   /* Compute conversion row from spectrum to one channel of XYZ */
129 < static void
129 > void
130   xyzrow(ROPMAT *rop, int r, int p)
131   {
132          const int       nc = rop->mtx->ncomp;
# Line 142 | Line 143 | xyzrow(ROPMAT *rop, int r, int p)
143   }
144  
145   /* Use the spectral sensitivity function to compute matrix coefficients */
146 < static void
147 < sensrow(ROPMAT *rop, int r, double (*sf)(SCOLOR sc, int ncs, const float wlpt[4]))
146 > void
147 > sensrow(ROPMAT *rop, int r, double (*sf)(const SCOLOR sc, int ncs, const float wlpt[4]))
148   {
149          const int       nc = rop->mtx->ncomp;
150          int             i;
# Line 157 | Line 158 | sensrow(ROPMAT *rop, int r, double (*sf)(SCOLOR sc, in
158   }
159  
160   /* Check/set symbolic transform */
161 < static int
161 > int
162   checksymbolic(ROPMAT *rop)
163   {
164          const int       nc = rop->mtx->ncomp;
165          const int       dt = rop->mtx->dtype;
166 +        double          cf = 1;
167          int             i, j;
168                                          /* check suffix => reference file */
169          if (strchr(rop->preop.csym, '.') > rop->preop.csym)
# Line 182 | Line 184 | checksymbolic(ROPMAT *rop)
184                  int     comp = 0;
185                  switch (rop->preop.csym[j]) {
186                  case 'B':
187 +                case 'b':
188                          ++comp;
189                          /* fall through */
190                  case 'G':
191 +                case 'g':
192                          ++comp;
193                          /* fall through */
194                  case 'R':
195 +                case 'r':
196 +                        if (rop->preop.csym[j] <= 'Z')
197 +                                cf = 1./WHTEFFICACY;
198                          if (dt == DTxyze) {
199                                  for (i = 3; i--; )
200 <                                        rop->preop.cmat[j*nc+i] = 1./WHTEFFICACY *
194 <                                                        xyz2rgbmat[comp][i];
200 >                                        rop->preop.cmat[j*nc+i] = cf*xyz2rgbmat[comp][i];
201                          } else if (nc == 3)
202                                  rop->preop.cmat[j*nc+comp] = 1.;
203                          else
204                                  rgbrow(rop, j, comp);
205                          break;
206                  case 'Z':
207 +                case 'z':
208                          ++comp;
209                          /* fall through */
210                  case 'Y':
211 +                case 'y':
212                          ++comp;
213                          /* fall through */
214                  case 'X':
215 +                case 'x':
216 +                        if ((rop->preop.csym[j] <= 'Z') & (dt != DTxyze))
217 +                                cf = WHTEFFICACY;
218                          if (dt == DTxyze) {
219                                  rop->preop.cmat[j*nc+comp] = 1.;
220                          } else if (nc == 3) {
# Line 215 | Line 226 | checksymbolic(ROPMAT *rop)
226                          else
227                                  xyzrow(rop, j, comp);
228  
229 <                        for (i = nc*(dt != DTxyze); i--; )
230 <                                rop->preop.cmat[j*nc+i] *= WHTEFFICACY;
229 >                        for (i = nc*(cf != 1); i--; )
230 >                                rop->preop.cmat[j*nc+i] *= cf;
231                          break;
232                  case 'S':               /* scotopic (il)luminance */
233 +                        cf = WHTSCOTOPIC;
234 +                        /* fall through */
235 +                case 's':
236                          sensrow(rop, j, scolor2scotopic);
237 <                        for (i = nc; i--; )
238 <                                rop->preop.cmat[j*nc+i] *= WHTSCOTOPIC;
237 >                        for (i = nc*(cf != 1); i--; )
238 >                                rop->preop.cmat[j*nc+i] *= cf;
239                          break;
240                  case 'M':               /* melanopic (il)luminance */
241 +                        cf = WHTMELANOPIC;
242 +                        /* fall through */
243 +                case 'm':
244                          sensrow(rop, j, scolor2melanopic);
245 <                        for (i = nc; i--; )
246 <                                rop->preop.cmat[j*nc+i] *= WHTMELANOPIC;
245 >                        for (i = nc*(cf != 1); i--; )
246 >                                rop->preop.cmat[j*nc+i] *= cf;
247                          break;
248                  case 'A':               /* average component */
249 +                case 'a':
250                          for (i = nc; i--; )
251                                  rop->preop.cmat[j*nc+i] = 1./(double)nc;
252                          break;
# Line 239 | Line 257 | checksymbolic(ROPMAT *rop)
257                  }
258          }
259                                          /* return recommended output type */
260 <        if (!strcmp(rop->preop.csym, "XYZ")) {
260 >        if (!strcasecmp(rop->preop.csym, "XYZ")) {
261                  if (dt <= DTspec)
262                          return(DTxyze);
263 <        } else if (!strcmp(rop->preop.csym, "RGB")) {
263 >        } else if (!strcasecmp(rop->preop.csym, "RGB")) {
264                  if (dt <= DTspec)
265                          return(DTrgbe);
266          } else if (dt == DTspec)
# Line 251 | Line 269 | checksymbolic(ROPMAT *rop)
269   }
270  
271   /* Get matrix and perform unary operations */
272 < static RMATRIX *
272 > RMATRIX *
273   loadop(ROPMAT *rop)
274   {
275          int     outtype = 0;
# Line 327 | Line 345 | loadop(ROPMAT *rop)
345                  }
346          }
347          if (rop->preop.transpose) {             /* transpose matrix? */
348 <                mres = rmx_transpose(rop->mtx);
331 <                if (mres == NULL) {
348 >                if (!rmx_transpose(rop->mtx)) {
349                          fputs(rop->inspec, stderr);
350                          fputs(": transpose failed\n", stderr);
351                          goto failure;
# Line 337 | Line 354 | loadop(ROPMAT *rop)
354                          fputs(rop->inspec, stderr);
355                          fputs(": transposed rows and columns\n", stderr);
356                  }
340                rmx_free(rop->mtx);
341                rop->mtx = mres;
357          }
358          mres = rop->mtx;
359          rop->mtx = NULL;
# Line 351 | Line 366 | failure:
366   }
367  
368   /* Execute binary operation, free matrix arguments and return new result */
369 < static RMATRIX *
369 > RMATRIX *
370   binaryop(const char *inspec, RMATRIX *mleft, int op, RMATRIX *mright)
371   {
372          RMATRIX *mres = NULL;
# Line 428 | Line 443 | binaryop(const char *inspec, RMATRIX *mleft, int op, R
443   }
444  
445   /* Perform matrix operations from left to right */
446 < static RMATRIX *
446 > RMATRIX *
447   op_left2right(ROPMAT *mop)
448   {
449          RMATRIX *mleft = loadop(mop);
# Line 444 | Line 459 | op_left2right(ROPMAT *mop)
459   }
460  
461   /* Perform matrix operations from right to left */
462 < static RMATRIX *
462 > RMATRIX *
463   op_right2left(ROPMAT *mop)
464   {
465          RMATRIX *mright;
# Line 473 | Line 488 | op_right2left(ROPMAT *mop)
488                                                  : (mop)->mtx->ncols)
489  
490   /* Should we prefer concatenating from rightmost matrix towards left? */
491 < static int
491 > int
492   prefer_right2left(ROPMAT *mop)
493   {
494          int     mri = 0;
# Line 500 | Line 515 | prefer_right2left(ROPMAT *mop)
515          return(t_ncols(mop+mri) < t_nrows(mop));
516   }
517  
518 < static int
518 > int
519   get_factors(double da[], int n, char *av[])
520   {
521          int     ac;
# Line 510 | Line 525 | get_factors(double da[], int n, char *av[])
525          return(ac);
526   }
527  
528 < static ROPMAT *
528 > ROPMAT *
529   resize_moparr(ROPMAT *mop, int n2alloc)
530   {
531          int     nmats = 0;
# Line 518 | Line 533 | resize_moparr(ROPMAT *mop, int n2alloc)
533  
534          while (mop[nmats++].binop)
535                  ;
536 <        for (i = nmats; i > n2alloc; i--)
536 >        for (i = nmats; i >= n2alloc; i--)
537                  rmx_free(mop[i].mtx);
538          mop = (ROPMAT *)realloc(mop, n2alloc*sizeof(ROPMAT));
539          if (mop == NULL) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines