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