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.5 by greg, Fri May 30 00:00:54 2014 UTC vs.
Revision 2.7 by greg, Tue Jul 8 16:39:41 2014 UTC

# Line 39 | Line 39 | cm_alloc(int nrows, int ncols)
39          return(cm);
40   }
41  
42 + static void
43 + adjacent_ra_sizes(size_t bounds[2], size_t target)
44 + {
45 +        bounds[0] = 0; bounds[1] = 2048;
46 +        while (bounds[1] < target) {
47 +                bounds[0] = bounds[1];
48 +                bounds[1] += bounds[1]>>1;
49 +        }
50 + }
51 +
52   /* Resize color coefficient matrix */
53   CMATRIX *
54   cm_resize(CMATRIX *cm, int nrows)
55   {
56 +        size_t  old_size, new_size, ra_bounds[2];
57 +
58          if (nrows == cm->nrows)
59                  return(cm);
60          if (nrows <= 0) {
61                  cm_free(cm);
62                  return(NULL);
63          }
64 <        cm = (CMATRIX *)realloc(cm, sizeof(CMATRIX) +
65 <                        sizeof(COLOR)*(nrows*cm->ncols - 1));
66 <        if (cm == NULL)
67 <                error(SYSTEM, "out of memory in cm_resize()");
64 >        old_size = sizeof(CMATRIX) + sizeof(COLOR)*(cm->nrows*cm->ncols - 1);
65 >        adjacent_ra_sizes(ra_bounds, old_size);
66 >        new_size = sizeof(CMATRIX) + sizeof(COLOR)*(nrows*cm->ncols - 1);
67 >        if (nrows < cm->nrows ? new_size <= ra_bounds[0] :
68 >                                new_size > ra_bounds[1]) {
69 >                adjacent_ra_sizes(ra_bounds, new_size);
70 >                cm = (CMATRIX *)realloc(cm, ra_bounds[1]);
71 >                if (cm == NULL)
72 >                        error(SYSTEM, "out of memory in cm_resize()");
73 >        }
74          cm->nrows = nrows;
75          return(cm);
76   }
# Line 99 | Line 117 | cm_getheader(int *dt, int *nr, int *nc, FILE *fp)
117          cmi.dtype = DTfromHeader;
118          cmi.nrows = cmi.ncols = 0;
119          cmi.err = "unexpected EOF in header";
120 <        if (getheader(fp, &get_cminfo, &cmi) < 0)
120 >        if (getheader(fp, get_cminfo, &cmi) < 0)
121                  return(cmi.err);
122          if (dt != NULL) {                       /* get/check data type? */
123                  if (cmi.dtype == DTfromHeader) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines