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

Comparing ray/src/util/rmatrix.c (file contents):
Revision 2.84 by greg, Sat Mar 22 01:27:22 2025 UTC vs.
Revision 2.86 by greg, Fri Mar 28 00:06:36 2025 UTC

# Line 16 | Line 16 | static const char RCSid[] = "$Id$";
16   #include <sys/mman.h>
17   #endif
18  
19 + #ifndef MAXCOMP
20 + #define MAXCOMP         MAXCSAMP        /* #components we support */
21 + #endif
22 +
23   static const char       rmx_mismatch_warn[] = "WARNING: data type mismatch\n";
24  
25   /* Initialize a RMATRIX struct but don't allocate array space */
# Line 203 | Line 207 | static int
207   rmx_load_float(rmx_dtype *drp, const RMATRIX *rm, FILE *fp)
208   {
209          int     j, k;
210 <        float   val[100];
210 >        float   val[MAXCOMP];
211  
212 <        if (rm->ncomp > 100) {
212 >        if (rm->ncomp > MAXCOMP) {
213                  fputs("Unsupported # components in rmx_load_float()\n", stderr);
214                  exit(1);
215          }
# Line 256 | Line 260 | rmx_load_rgbe(rmx_dtype *drp, const RMATRIX *rm, FILE
260   static int
261   rmx_load_spec(rmx_dtype *drp, const RMATRIX *rm, FILE *fp)
262   {
263 <        uby8    *scan;
264 <        SCOLOR  scol;
263 >        COLRV   *scan;
264 >        COLORV  scol[MAXCOMP];
265          int     j, k;
266  
267 <        if ((rm->ncomp < 3) | (rm->ncomp > MAXCSAMP))
267 >        if ((rm->ncomp < 3) | (rm->ncomp > MAXCOMP))
268                  return(0);
269 <        scan = (uby8 *)tempbuffer((rm->ncomp+1)*rm->ncols);
269 >        scan = (COLRV *)tempbuffer((rm->ncomp+1)*rm->ncols);
270          if (!scan)
271                  return(0);
272          if (freadscolrs(scan, rm->ncomp, rm->ncols, fp) < 0)
# Line 428 | Line 432 | rmx_load(const char *inspec, RMPref rmp)
432                                                  /* undo exposure? */
433          if ((dnew->cexp[0] != 1.f) |
434                          (dnew->cexp[1] != 1.f) | (dnew->cexp[2] != 1.f)) {
435 <                double  cmlt[MAXCSAMP];
435 >                double  cmlt[MAXCOMP];
436                  int     i;
437 <                if (dnew->ncomp > MAXCSAMP) {
437 >                if (dnew->ncomp > MAXCOMP) {
438                          fprintf(stderr, "Excess spectral components in: %s\n",
439                                          inspec);
440                          rmx_free(dnew);
# Line 494 | Line 498 | rmx_write_rgbe(const rmx_dtype *dp, int nc, int len, F
498   static int
499   rmx_write_spec(const rmx_dtype *dp, int nc, int len, FILE *fp)
500   {
501 <        uby8    *scan;
502 <        SCOLOR  scol;
501 >        COLRV   *scan;
502 >        COLORV  scol[MAXCOMP];
503          int     j, k;
504  
505 <        if (nc < 3) return(0);
506 <        scan = (uby8 *)tempbuffer((nc+1)*len);
505 >        if ((nc < 3) | (nc > MAXCOMP)) return(0);
506 >        scan = (COLRV *)tempbuffer((nc+1)*len);
507          if (!scan) return(0);
508          for (j = 0; j < len; j++, dp += nc) {
509                  for (k = nc; k--; )
# Line 944 | Line 948 | cm_from_rmatrix(const RMATRIX *rm)
948          int     i, j;
949          CMATRIX *cnew;
950  
951 <        if (!rm || !rm->mtx | (rm->ncomp == 2))
951 >        if (!rm || !rm->mtx | (rm->ncomp == 2) | (rm->ncomp > MAXCOMP))
952                  return(NULL);
953          cnew = cm_alloc(rm->nrows, rm->ncols);
954          if (!cnew)
# Line 961 | Line 965 | cm_from_rmatrix(const RMATRIX *rm)
965                      setcolor(cv, dp[0], dp[0], dp[0]);
966                      break;
967                  default: {
968 <                        SCOLOR  scol;
968 >                        COLORV  scol[MAXCOMP];
969                          int     k;
970                          for (k = rm->ncomp; k--; )
971                                  scol[k] = dp[k];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines