--- ray/src/util/rmtxop.c 2024/08/21 01:09:25 2.34 +++ ray/src/util/rmtxop.c 2025/04/04 18:06:48 2.38 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: rmtxop.c,v 2.34 2024/08/21 01:09:25 greg Exp $"; +static const char RCSid[] = "$Id: rmtxop.c,v 2.38 2025/04/04 18:06:48 greg Exp $"; #endif /* * General component matrix operations. @@ -10,8 +10,6 @@ static const char RCSid[] = "$Id: rmtxop.c,v 2.34 2024 #include "rmatrix.h" #include "platform.h" -#define MAXCOMP MAXCSAMP /* #components we support */ - /* Unary matrix operation(s) */ typedef struct { double cmat[MAXCOMP*MAXCOMP]; /* component transformation */ @@ -34,7 +32,7 @@ typedef struct { int verbose = 0; /* verbose reporting? */ /* Load matrix */ -static int +int loadmatrix(ROPMAT *rop) { if (rop->mtx != NULL) /* already loaded? */ @@ -45,10 +43,10 @@ loadmatrix(ROPMAT *rop) return(!rop->mtx ? -1 : 1); } -static int checksymbolic(ROPMAT *rop); +extern int checksymbolic(ROPMAT *rop); /* Check/set transform based on a reference input file */ -static int +int checkreffile(ROPMAT *rop) { static const char *curRF = NULL; @@ -107,7 +105,7 @@ checkreffile(ROPMAT *rop) } /* Compute conversion row from spectrum to one channel of RGB */ -static void +void rgbrow(ROPMAT *rop, int r, int p) { const int nc = rop->mtx->ncomp; @@ -124,7 +122,7 @@ rgbrow(ROPMAT *rop, int r, int p) } /* Compute conversion row from spectrum to one channel of XYZ */ -static void +void xyzrow(ROPMAT *rop, int r, int p) { const int nc = rop->mtx->ncomp; @@ -141,7 +139,7 @@ xyzrow(ROPMAT *rop, int r, int p) } /* Use the spectral sensitivity function to compute matrix coefficients */ -static void +void sensrow(ROPMAT *rop, int r, double (*sf)(const SCOLOR sc, int ncs, const float wlpt[4])) { const int nc = rop->mtx->ncomp; @@ -156,7 +154,7 @@ sensrow(ROPMAT *rop, int r, double (*sf)(const SCOLOR } /* Check/set symbolic transform */ -static int +int checksymbolic(ROPMAT *rop) { const int nc = rop->mtx->ncomp; @@ -267,7 +265,7 @@ checksymbolic(ROPMAT *rop) } /* Get matrix and perform unary operations */ -static RMATRIX * +RMATRIX * loadop(ROPMAT *rop) { int outtype = 0; @@ -343,8 +341,7 @@ loadop(ROPMAT *rop) } } if (rop->preop.transpose) { /* transpose matrix? */ - mres = rmx_transpose(rop->mtx); - if (mres == NULL) { + if (!rmx_transpose(rop->mtx)) { fputs(rop->inspec, stderr); fputs(": transpose failed\n", stderr); goto failure; @@ -353,8 +350,6 @@ loadop(ROPMAT *rop) fputs(rop->inspec, stderr); fputs(": transposed rows and columns\n", stderr); } - rmx_free(rop->mtx); - rop->mtx = mres; } mres = rop->mtx; rop->mtx = NULL; @@ -367,7 +362,7 @@ failure: } /* Execute binary operation, free matrix arguments and return new result */ -static RMATRIX * +RMATRIX * binaryop(const char *inspec, RMATRIX *mleft, int op, RMATRIX *mright) { RMATRIX *mres = NULL; @@ -444,7 +439,7 @@ binaryop(const char *inspec, RMATRIX *mleft, int op, R } /* Perform matrix operations from left to right */ -static RMATRIX * +RMATRIX * op_left2right(ROPMAT *mop) { RMATRIX *mleft = loadop(mop); @@ -460,7 +455,7 @@ op_left2right(ROPMAT *mop) } /* Perform matrix operations from right to left */ -static RMATRIX * +RMATRIX * op_right2left(ROPMAT *mop) { RMATRIX *mright; @@ -489,7 +484,7 @@ op_right2left(ROPMAT *mop) : (mop)->mtx->ncols) /* Should we prefer concatenating from rightmost matrix towards left? */ -static int +int prefer_right2left(ROPMAT *mop) { int mri = 0; @@ -516,7 +511,7 @@ prefer_right2left(ROPMAT *mop) return(t_ncols(mop+mri) < t_nrows(mop)); } -static int +int get_factors(double da[], int n, char *av[]) { int ac; @@ -526,7 +521,7 @@ get_factors(double da[], int n, char *av[]) return(ac); } -static ROPMAT * +ROPMAT * resize_moparr(ROPMAT *mop, int n2alloc) { int nmats = 0; @@ -534,7 +529,7 @@ resize_moparr(ROPMAT *mop, int n2alloc) while (mop[nmats++].binop) ; - for (i = nmats; i > n2alloc; i--) + for (i = nmats; i >= n2alloc; i--) rmx_free(mop[i].mtx); mop = (ROPMAT *)realloc(mop, n2alloc*sizeof(ROPMAT)); if (mop == NULL) {