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

Comparing ray/src/rt/rview.c (file contents):
Revision 1.11 by greg, Fri Mar 9 14:00:06 1990 UTC vs.
Revision 1.15 by greg, Tue May 21 17:41:32 1991 UTC

# Line 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10   *     3/24/87
11   */
12  
13 < #include  "standard.h"
13 > #include  "ray.h"
14  
15 #include  "color.h"
16
15   #include  "rpaint.h"
16  
17   #include  <signal.h>
# Line 23 | Line 21 | static char SCCSid[] = "$SunId$ LBL";
21   VIEW  ourview = STDVIEW;                /* viewing parameters */
22   int  hresolu, vresolu;                  /* image resolution */
23  
24 + int  dimlist[MAXDIM];                   /* sampling dimensions */
25 + int  ndims = 0;                         /* number of sampling dimensions */
26 + int  samplendx = 0;                     /* index for this sample */
27 +
28   int  psample = 8;                       /* pixel sample size */
29   double  maxdiff = .15;                  /* max. sample difference */
30  
# Line 55 | Line 57 | PNODE  ptrunk;                         /* the base of our image */
57   RECT  pframe;                           /* current frame boundaries */
58   int  pdepth;                            /* image depth in current frame */
59  
60 + static char  *reserve_mem = NULL;       /* pre-allocated reserve memory */
61 +
62 + #define RESERVE_AMT     8192            /* amount of memory to reserve */
63 +
64   #define  CTRL(c)        ('c'-'@')
65  
66  
# Line 112 | Line 118 | rview()                                /* do a view */
118          char  buf[32];
119  
120          devopen(devname);               /* open device */
121 <        newimage();                     /* set up image */
121 >        newimage();                     /* start image (calls fillreserves) */
122  
123          for ( ; ; ) {                   /* quit in command() */
124 <                while (hresolu <= 1<<pdepth &&
119 <                                vresolu <= 1<<pdepth)
124 >                while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth)
125                          command("done: ");
126 <
127 <                if (hresolu <= psample<<pdepth &&
128 <                                vresolu <= psample<<pdepth) {
126 >                while (reserve_mem == NULL)
127 >                        command("out of memory: ");
128 >                errno = 0;
129 >                if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) {
130                          sprintf(buf, "%d sampling...\n", 1<<pdepth);
131                          (*dev->comout)(buf);
132                          rsample();
# Line 129 | Line 135 | rview()                                /* do a view */
135                          (*dev->comout)(buf);
136                          refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1);
137                  }
138 <                if (dev->inpready)
138 >                if (errno == ENOMEM)            /* ran out of memory */
139 >                        freereserves();
140 >                else if (dev->inpready)         /* noticed some input */
141                          command(": ");
142 <                else
142 >                else                            /* finished this depth */
143                          pdepth++;
144          }
145   }
146  
147  
148 + fillreserves()                  /* fill memory reserves */
149 + {
150 +        if (reserve_mem != NULL)
151 +                return;
152 +        reserve_mem = malloc(RESERVE_AMT);
153 + }
154 +
155 +
156 + freereserves()                  /* free memory reserves */
157 + {
158 +        if (reserve_mem == NULL)
159 +                return;
160 +        free(reserve_mem);
161 +        reserve_mem = NULL;
162 + }
163 +
164 +
165   command(prompt)                 /* get/execute command */
166   char  *prompt;
167   {
# Line 268 | Line 293 | rsample()                      /* sample the image */
293          xsiz = (((pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu;
294          ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu;
295          rl = (RECT *)malloc(xsiz*sizeof(RECT));
296 +        if (rl == NULL)
297 +                return;
298          pl = (PNODE **)malloc(xsiz*sizeof(PNODE *));
299 <        if (rl == NULL || pl == NULL)
300 <                error(SYSTEM, "out of memory in rsample");
299 >        if (pl == NULL)
300 >                return;
301          /*
302           * Initialize the bottom row.
303           */
# Line 357 | Line 384 | int  pd;
384          if (p->kid == NULL) {                   /* subdivide */
385  
386                  if ((p->kid = newptree()) == NULL)
387 <                        error(SYSTEM, "out of memory in refine");
387 >                        return(growth);
388                  /*
389                   *  The following paint order can leave a black pixel
390                   *  when redraw() is called in (*dev->paintr)().

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines