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.13 by greg, Fri May 3 15:43:32 1991 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>
18  
21 #include  <setjmp.h>
22
19   #include  <ctype.h>
20  
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 57 | 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 jmp_buf  mainloop;               /* longjmp back to main loop */
60   static char  *reserve_mem = NULL;       /* pre-allocated reserve memory */
61  
62   #define RESERVE_AMT     8192            /* amount of memory to reserve */
# Line 119 | Line 118 | rview()                                /* do a view */
118          char  buf[32];
119  
120          devopen(devname);               /* open device */
121 <        newimage();                     /* set up image */
122 <        setjmp(mainloop);
121 >        newimage();                     /* start image (calls fillreserves) */
122 >
123          for ( ; ; ) {                   /* quit in command() */
124 <                while (hresolu <= 1<<pdepth &&
126 <                                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 136 | 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 < memreserve()                    /* fill memory reserves */
148 > fillreserves()                  /* fill memory reserves */
149   {
150          if (reserve_mem != NULL)
151 <                return;                 /* got some already */
151 >                return;
152          reserve_mem = malloc(RESERVE_AMT);
153   }
154  
155  
156 < memerror(detail)                /* try and rescue a memory error */
156 < char    *detail;
156 > freereserves()                  /* free memory reserves */
157   {
158 <        if (reserve_mem == NULL) {
159 <                sprintf(errmsg, "out of memory %s", detail);
160 <                error(SYSTEM, errmsg);
161 <        }
158 >        if (reserve_mem == NULL)
159 >                return;
160          free(reserve_mem);
161          reserve_mem = NULL;
164        do
165                command("out of memory: ");
166        while (reserve_mem == NULL);
167        longjmp(mainloop, 1);
162   }
163  
164  
# Line 300 | Line 294 | rsample()                      /* sample the image */
294          ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu;
295          rl = (RECT *)malloc(xsiz*sizeof(RECT));
296          if (rl == NULL)
297 <                memerror("in rsample");
297 >                return;
298          pl = (PNODE **)malloc(xsiz*sizeof(PNODE *));
299          if (pl == NULL)
300 <                memerror("in rsample");
300 >                return;
301          /*
302           * Initialize the bottom row.
303           */
# Line 390 | Line 384 | int  pd;
384          if (p->kid == NULL) {                   /* subdivide */
385  
386                  if ((p->kid = newptree()) == NULL)
387 <                        memerror("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