18 |
|
|
19 |
|
#include <signal.h> |
20 |
|
|
21 |
– |
#include <setjmp.h> |
22 |
– |
|
21 |
|
#include <ctype.h> |
22 |
|
|
23 |
|
VIEW ourview = STDVIEW; /* viewing parameters */ |
55 |
|
RECT pframe; /* current frame boundaries */ |
56 |
|
int pdepth; /* image depth in current frame */ |
57 |
|
|
60 |
– |
static jmp_buf mainloop; /* longjmp back to main loop */ |
58 |
|
static char *reserve_mem = NULL; /* pre-allocated reserve memory */ |
59 |
|
|
60 |
|
#define RESERVE_AMT 8192 /* amount of memory to reserve */ |
116 |
|
char buf[32]; |
117 |
|
|
118 |
|
devopen(devname); /* open device */ |
119 |
< |
newimage(); /* set up image */ |
120 |
< |
setjmp(mainloop); |
119 |
> |
newimage(); /* start image (calls fillreserves) */ |
120 |
> |
|
121 |
|
for ( ; ; ) { /* quit in command() */ |
122 |
< |
while (hresolu <= 1<<pdepth && |
126 |
< |
vresolu <= 1<<pdepth) |
122 |
> |
while (hresolu <= 1<<pdepth && vresolu <= 1<<pdepth) |
123 |
|
command("done: "); |
124 |
< |
|
125 |
< |
if (hresolu <= psample<<pdepth && |
126 |
< |
vresolu <= psample<<pdepth) { |
124 |
> |
while (reserve_mem == NULL) |
125 |
> |
command("out of memory: "); |
126 |
> |
errno = 0; |
127 |
> |
if (hresolu <= psample<<pdepth && vresolu <= psample<<pdepth) { |
128 |
|
sprintf(buf, "%d sampling...\n", 1<<pdepth); |
129 |
|
(*dev->comout)(buf); |
130 |
|
rsample(); |
133 |
|
(*dev->comout)(buf); |
134 |
|
refine(&ptrunk, 0, 0, hresolu, vresolu, pdepth+1); |
135 |
|
} |
136 |
< |
if (dev->inpready) |
136 |
> |
if (errno == ENOMEM) /* ran out of memory */ |
137 |
> |
freereserves(); |
138 |
> |
else if (dev->inpready) /* noticed some input */ |
139 |
|
command(": "); |
140 |
< |
else |
140 |
> |
else /* finished this depth */ |
141 |
|
pdepth++; |
142 |
|
} |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
< |
memreserve() /* fill memory reserves */ |
146 |
> |
fillreserves() /* fill memory reserves */ |
147 |
|
{ |
148 |
|
if (reserve_mem != NULL) |
149 |
< |
return; /* got some already */ |
149 |
> |
return; |
150 |
|
reserve_mem = malloc(RESERVE_AMT); |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
< |
memerror(detail) /* try and rescue a memory error */ |
156 |
< |
char *detail; |
154 |
> |
freereserves() /* free memory reserves */ |
155 |
|
{ |
156 |
< |
if (reserve_mem == NULL) { |
157 |
< |
sprintf(errmsg, "out of memory %s", detail); |
160 |
< |
error(SYSTEM, errmsg); |
161 |
< |
} |
156 |
> |
if (reserve_mem == NULL) |
157 |
> |
return; |
158 |
|
free(reserve_mem); |
159 |
|
reserve_mem = NULL; |
164 |
– |
do |
165 |
– |
command("out of memory: "); |
166 |
– |
while (reserve_mem == NULL); |
167 |
– |
longjmp(mainloop, 1); |
160 |
|
} |
161 |
|
|
162 |
|
|
292 |
|
ysiz = (((pframe.u-pframe.d)<<pdepth)+vresolu-1) / vresolu; |
293 |
|
rl = (RECT *)malloc(xsiz*sizeof(RECT)); |
294 |
|
if (rl == NULL) |
295 |
< |
memerror("in rsample"); |
295 |
> |
return; |
296 |
|
pl = (PNODE **)malloc(xsiz*sizeof(PNODE *)); |
297 |
|
if (pl == NULL) |
298 |
< |
memerror("in rsample"); |
298 |
> |
return; |
299 |
|
/* |
300 |
|
* Initialize the bottom row. |
301 |
|
*/ |
382 |
|
if (p->kid == NULL) { /* subdivide */ |
383 |
|
|
384 |
|
if ((p->kid = newptree()) == NULL) |
385 |
< |
memerror("in refine"); |
385 |
> |
return(growth); |
386 |
|
/* |
387 |
|
* The following paint order can leave a black pixel |
388 |
|
* when redraw() is called in (*dev->paintr)(). |