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> |
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 |
|
|
33 |
|
double dstrsrc = 0.0; /* square source distribution */ |
34 |
|
double shadthresh = .1; /* shadow threshold */ |
35 |
|
double shadcert = .25; /* shadow certainty */ |
36 |
+ |
int directrelay = 0; /* number of source relays */ |
37 |
+ |
int vspretest = 128; /* virtual source pretest density */ |
38 |
+ |
int directinvis = 0; /* sources invisible? */ |
39 |
+ |
double srcsizerat = 0.; /* maximum ratio source size/dist. */ |
40 |
|
|
41 |
|
int maxdepth = 4; /* maximum recursion depth */ |
42 |
|
double minweight = 1e-2; /* minimum ray weight */ |
51 |
|
int ambincl = -1; /* include == 1, exclude == 0 */ |
52 |
|
|
53 |
|
int greyscale = 0; /* map colors to brightness? */ |
54 |
< |
char *devname = "X"; /* output device name */ |
54 |
> |
char *devname = dev_default; /* output device name */ |
55 |
|
|
56 |
|
struct driver *dev = NULL; /* driver functions */ |
57 |
|
|
61 |
|
RECT pframe; /* current frame boundaries */ |
62 |
|
int pdepth; /* image depth in current frame */ |
63 |
|
|
64 |
+ |
static char *reserve_mem = NULL; /* pre-allocated reserve memory */ |
65 |
+ |
|
66 |
+ |
#define RESERVE_AMT 32768 /* amount of memory to reserve */ |
67 |
+ |
|
68 |
|
#define CTRL(c) ('c'-'@') |
69 |
|
|
70 |
|
|
122 |
|
char buf[32]; |
123 |
|
|
124 |
|
devopen(devname); /* open device */ |
125 |
< |
newimage(); /* set up image */ |
125 |
> |
newimage(); /* start image (calls fillreserves) */ |
126 |
|
|
127 |
|
for ( ; ; ) { /* quit in command() */ |
128 |
< |
while (hresolu <= 1<<pdepth && |
119 |
< |
vresolu <= 1<<pdepth) |
128 |
> |
while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth) |
129 |
|
command("done: "); |
130 |
< |
|
131 |
< |
if (hresolu <= psample<<pdepth && |
132 |
< |
vresolu <= psample<<pdepth) { |
130 |
> |
while (reserve_mem == NULL) |
131 |
> |
command("out of memory: "); |
132 |
> |
errno = 0; |
133 |
> |
if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) { |
134 |
|
sprintf(buf, "%d sampling...\n", 1<<pdepth); |
135 |
|
(*dev->comout)(buf); |
136 |
|
rsample(); |
139 |
|
(*dev->comout)(buf); |
140 |
|
refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1); |
141 |
|
} |
142 |
< |
if (dev->inpready) |
142 |
> |
if (errno == ENOMEM) /* ran out of memory */ |
143 |
> |
freereserves(); |
144 |
> |
else if (dev->inpready) /* noticed some input */ |
145 |
|
command(": "); |
146 |
< |
else |
146 |
> |
else /* finished this depth */ |
147 |
|
pdepth++; |
148 |
|
} |
149 |
|
} |
150 |
|
|
151 |
|
|
152 |
+ |
fillreserves() /* fill memory reserves */ |
153 |
+ |
{ |
154 |
+ |
if (reserve_mem != NULL) |
155 |
+ |
return; |
156 |
+ |
reserve_mem = malloc(RESERVE_AMT); |
157 |
+ |
} |
158 |
+ |
|
159 |
+ |
|
160 |
+ |
freereserves() /* free memory reserves */ |
161 |
+ |
{ |
162 |
+ |
if (reserve_mem == NULL) |
163 |
+ |
return; |
164 |
+ |
free(reserve_mem); |
165 |
+ |
reserve_mem = NULL; |
166 |
+ |
} |
167 |
+ |
|
168 |
+ |
|
169 |
|
command(prompt) /* get/execute command */ |
170 |
|
char *prompt; |
171 |
|
{ |
297 |
|
xsiz = (((pframe.r-pframe.l)<<pdepth)+hresolu-1) / hresolu; |
298 |
|
ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu; |
299 |
|
rl = (RECT *)malloc(xsiz*sizeof(RECT)); |
300 |
+ |
if (rl == NULL) |
301 |
+ |
return; |
302 |
|
pl = (PNODE **)malloc(xsiz*sizeof(PNODE *)); |
303 |
< |
if (rl == NULL || pl == NULL) |
304 |
< |
error(SYSTEM, "out of memory in rsample"); |
303 |
> |
if (pl == NULL) |
304 |
> |
return; |
305 |
|
/* |
306 |
|
* Initialize the bottom row. |
307 |
|
*/ |
317 |
|
/* sample the image */ |
318 |
|
for (y = 0; /* y < ysiz */ ; y++) { |
319 |
|
for (x = 0; x < xsiz-1; x++) { |
320 |
< |
if (dev->inpready) |
320 |
> |
if (dev->inpready || errno == ENOMEM) |
321 |
|
goto escape; |
322 |
|
/* |
323 |
|
* Test super-pixel to the right. |
333 |
|
if (y >= ysiz-1) |
334 |
|
break; |
335 |
|
for (x = 0; x < xsiz; x++) { |
336 |
< |
if (dev->inpready) |
336 |
> |
if (dev->inpready || errno == ENOMEM) |
337 |
|
goto escape; |
338 |
|
/* |
339 |
|
* Find super-pixel at this position in next row. |
388 |
|
if (p->kid == NULL) { /* subdivide */ |
389 |
|
|
390 |
|
if ((p->kid = newptree()) == NULL) |
391 |
< |
error(SYSTEM, "out of memory in refine"); |
391 |
> |
return(0); |
392 |
|
/* |
393 |
|
* The following paint order can leave a black pixel |
394 |
|
* when redraw() is called in (*dev->paintr)(). |