15 |
|
#ifdef BSD |
16 |
|
#include <sys/time.h> |
17 |
|
#include <sys/resource.h> |
18 |
– |
#else |
19 |
– |
#include <signal.h> |
18 |
|
#endif |
19 |
+ |
|
20 |
+ |
#include <signal.h> |
21 |
|
#include <fcntl.h> |
22 |
|
|
23 |
|
#include "view.h" |
24 |
|
|
25 |
+ |
#include "resolu.h" |
26 |
+ |
|
27 |
|
#include "random.h" |
28 |
|
|
29 |
|
int dimlist[MAXDIM]; /* sampling dimensions */ |
42 |
|
double dstrsrc = 0.0; /* square source distribution */ |
43 |
|
double shadthresh = .05; /* shadow threshold */ |
44 |
|
double shadcert = .5; /* shadow certainty */ |
45 |
< |
int directrelay = 0; /* number of source relays */ |
45 |
> |
int directrelay = 1; /* number of source relays */ |
46 |
|
int vspretest = 512; /* virtual source pretest density */ |
47 |
+ |
int directinvis = 0; /* sources invisible? */ |
48 |
+ |
double srcsizerat = .25; /* maximum ratio source size/dist. */ |
49 |
|
|
50 |
|
int maxdepth = 6; /* maximum recursion depth */ |
51 |
|
double minweight = 5e-3; /* minimum ray weight */ |
125 |
|
float *zbar[MAXDIV+1]; /* z values */ |
126 |
|
int ypos; /* current scanline */ |
127 |
|
int ystep; /* current y step size */ |
128 |
+ |
int hstep; /* h step size */ |
129 |
|
int zfd; |
130 |
|
COLOR *colptr; |
131 |
|
float *zptr; |
162 |
|
zbar[i] = NULL; |
163 |
|
} |
164 |
|
/* write out boundaries */ |
165 |
< |
fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout); |
165 |
> |
fprtresolu(hresolu, vresolu, stdout); |
166 |
|
/* recover file and compute first */ |
167 |
|
i = salvage(oldfile); |
168 |
|
if (zfd != -1 && i > 0 && |
171 |
|
pctdone = 100.0*i/vresolu; |
172 |
|
if (ralrm > 0) /* report init stats */ |
173 |
|
report(); |
174 |
+ |
#ifndef BSD |
175 |
+ |
else |
176 |
+ |
#endif |
177 |
+ |
signal(SIGALRM, report); |
178 |
|
ypos = vresolu-1 - i; |
179 |
< |
fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample); |
180 |
< |
ystep = psample; |
179 |
> |
hstep = (psample*140+49)/99; /* quincunx sampling */ |
180 |
> |
ystep = (psample*99+70)/140; |
181 |
> |
fillscanline(scanbar[0], zbar[0], hresolu, ypos, hstep); |
182 |
|
/* compute scanlines */ |
183 |
|
for (ypos -= ystep; ypos > -ystep; ypos -= ystep) { |
184 |
|
/* bottom adjust? */ |
193 |
|
zbar[ystep] = zbar[0]; |
194 |
|
zbar[0] = zptr; |
195 |
|
/* fill base line */ |
196 |
< |
fillscanline(scanbar[0], zbar[0], hresolu, ypos, psample); |
196 |
> |
fillscanline(scanbar[0], zbar[0], hresolu, ypos, hstep); |
197 |
|
/* fill bar */ |
198 |
|
fillscanbar(scanbar, zbar, hresolu, ypos, ystep); |
199 |
|
/* write it out */ |
200 |
+ |
#ifndef BSD |
201 |
+ |
signal(SIGALRM, SIG_IGN); /* don't interrupt writes */ |
202 |
+ |
#endif |
203 |
|
for (i = ystep; i > 0; i--) { |
204 |
|
if (zfd != -1 && write(zfd, (char *)zbar[i], |
205 |
|
hresolu*sizeof(float)) |
214 |
|
pctdone = 100.0*(vresolu-1-ypos)/vresolu; |
215 |
|
if (ralrm > 0 && time((long *)0) >= tlastrept+ralrm) |
216 |
|
report(); |
217 |
+ |
#ifndef BSD |
218 |
+ |
else |
219 |
+ |
signal(SIGALRM, report); |
220 |
+ |
#endif |
221 |
|
} |
222 |
|
/* clean up */ |
223 |
|
if (zfd != -1) { |
248 |
|
register float *zline; |
249 |
|
int xres, y, xstep; |
250 |
|
{ |
251 |
+ |
static int nc = 0; /* number of calls */ |
252 |
|
int b = xstep; |
253 |
|
double z; |
254 |
|
register int i; |
255 |
|
|
256 |
|
z = pixvalue(scanline[0], 0, y); |
257 |
|
if (zline) zline[0] = z; |
258 |
< |
|
259 |
< |
for (i = xstep; i < xres-1+xstep; i += xstep) { |
258 |
> |
/* zig-zag start for quincunx pattern */ |
259 |
> |
for (i = nc++ & 1 ? xstep/2 : xstep; i < xres-1+xstep; i += xstep) { |
260 |
|
if (i >= xres) { |
261 |
|
xstep += xres-1-i; |
262 |
|
i = xres-1; |
371 |
|
|
372 |
|
rayorigin(&thisray, NULL, PRIMARY, 1.0); |
373 |
|
|
374 |
< |
samplendx = 3*y + x; /* set pixel index */ |
374 |
> |
samplendx = pixnumber(x,y,hresolu,vresolu); /* set pixel index */ |
375 |
|
|
376 |
|
rayvalue(&thisray); /* trace ray */ |
377 |
|
|
400 |
|
/* discard header */ |
401 |
|
getheader(fp, NULL); |
402 |
|
/* get picture size */ |
403 |
< |
if (fgetresolu(&x, &y, fp) != (YMAJOR|YDECR)) { |
403 |
> |
if (!fscnresolu(&x, &y, fp)) { |
404 |
|
sprintf(errmsg, "bad recover file \"%s\"", oldfile); |
405 |
|
error(WARNING, errmsg); |
406 |
|
fclose(fp); |
430 |
|
return(y); |
431 |
|
writerr: |
432 |
|
error(SYSTEM, "write error in salvage"); |
433 |
+ |
} |
434 |
+ |
|
435 |
+ |
|
436 |
+ |
int |
437 |
+ |
pixnumber(x, y, xres, yres) /* compute pixel index (brushed) */ |
438 |
+ |
register int x, y; |
439 |
+ |
int xres, yres; |
440 |
+ |
{ |
441 |
+ |
x -= y; |
442 |
+ |
while (x < 0) |
443 |
+ |
x += xres; |
444 |
+ |
return((((x>>2)*yres + y) << 2) + (x & 3)); |
445 |
|
} |