70 |
|
|
71 |
|
extern long nrays; /* number of rays traced */ |
72 |
|
|
73 |
< |
#define MAXDIV 15 /* maximum sample size */ |
73 |
> |
#define MAXDIV 16 /* maximum sample size */ |
74 |
|
|
75 |
|
#define pixjitter() (.5+dstrpix*(.5-frandom())) |
76 |
|
|
108 |
|
#else |
109 |
|
report() /* report progress */ |
110 |
|
{ |
111 |
– |
signal(SIGALRM, report); |
111 |
|
tlastrept = time((long *)0); |
112 |
|
sprintf(errmsg, "%ld rays, %4.2f%% done after %5.4f hours\n", |
113 |
|
nrays, pctdone, (tlastrept-tstart)/3600.0); |
114 |
|
eputs(errmsg); |
115 |
+ |
signal(SIGALRM, report); |
116 |
|
} |
117 |
|
#endif |
118 |
|
|
123 |
|
extern long lseek(); |
124 |
|
COLOR *scanbar[MAXDIV+1]; /* scanline arrays of pixel values */ |
125 |
|
float *zbar[MAXDIV+1]; /* z values */ |
126 |
+ |
char *sampdens; /* previous sample density */ |
127 |
|
int ypos; /* current scanline */ |
128 |
|
int ystep; /* current y step size */ |
129 |
|
int hstep; /* h step size */ |
146 |
|
if (scanbar[i] == NULL) |
147 |
|
goto memerr; |
148 |
|
} |
149 |
+ |
hstep = (psample*140+49)/99; /* quincunx sampling */ |
150 |
+ |
ystep = (psample*99+70)/140; |
151 |
+ |
if (hstep > 2) { |
152 |
+ |
i = hresolu/hstep + 2; |
153 |
+ |
if ((sampdens = malloc(i)) == NULL) |
154 |
+ |
goto memerr; |
155 |
+ |
while (i--) |
156 |
+ |
sampdens[i] = hstep; |
157 |
+ |
} else |
158 |
+ |
sampdens = NULL; |
159 |
|
/* open z file */ |
160 |
|
if (zfile != NULL) { |
161 |
|
if ((zfd = open(zfile, O_WRONLY|O_CREAT, 0666)) == -1) { |
187 |
|
#endif |
188 |
|
signal(SIGALRM, report); |
189 |
|
ypos = vresolu-1 - i; |
190 |
< |
hstep = (psample*140+49)/99; /* quincunx sampling */ |
180 |
< |
ystep = (psample*99+70)/140; |
181 |
< |
fillscanline(scanbar[0], zbar[0], hresolu, ypos, hstep); |
190 |
> |
fillscanline(scanbar[0], zbar[0], sampdens, hresolu, ypos, hstep); |
191 |
|
/* compute scanlines */ |
192 |
|
for (ypos -= ystep; ypos > -ystep; ypos -= ystep) { |
193 |
|
/* bottom adjust? */ |
202 |
|
zbar[ystep] = zbar[0]; |
203 |
|
zbar[0] = zptr; |
204 |
|
/* fill base line */ |
205 |
< |
fillscanline(scanbar[0], zbar[0], hresolu, ypos, hstep); |
205 |
> |
fillscanline(scanbar[0], zbar[0], sampdens, |
206 |
> |
hresolu, ypos, hstep); |
207 |
|
/* fill bar */ |
208 |
|
fillscanbar(scanbar, zbar, hresolu, ypos, ystep); |
209 |
|
/* write it out */ |
244 |
|
goto writerr; |
245 |
|
for (i = 0; i <= psample; i++) |
246 |
|
free((char *)scanbar[i]); |
247 |
+ |
if (sampdens != NULL) |
248 |
+ |
free(sampdens); |
249 |
|
pctdone = 100.0; |
250 |
|
return; |
251 |
|
writerr: |
255 |
|
} |
256 |
|
|
257 |
|
|
258 |
< |
fillscanline(scanline, zline, xres, y, xstep) /* fill scan line at y */ |
258 |
> |
fillscanline(scanline, zline, sd, xres, y, xstep) /* fill scan at y */ |
259 |
|
register COLOR *scanline; |
260 |
|
register float *zline; |
261 |
+ |
register char *sd; |
262 |
|
int xres, y, xstep; |
263 |
|
{ |
264 |
|
static int nc = 0; /* number of calls */ |
265 |
< |
int b = xstep; |
265 |
> |
int bl = xstep, b = xstep; |
266 |
|
double z; |
267 |
|
register int i; |
268 |
|
|
269 |
|
z = pixvalue(scanline[0], 0, y); |
270 |
|
if (zline) zline[0] = z; |
271 |
|
/* zig-zag start for quincunx pattern */ |
272 |
< |
for (i = nc++ & 1 ? xstep/2 : xstep; i < xres-1+xstep; i += xstep) { |
272 |
> |
for (i = ++nc & 1 ? xstep : xstep/2; i < xres-1+xstep; i += xstep) { |
273 |
|
if (i >= xres) { |
274 |
|
xstep += xres-1-i; |
275 |
|
i = xres-1; |
276 |
|
} |
277 |
|
z = pixvalue(scanline[i], i, y); |
278 |
|
if (zline) zline[i] = z; |
279 |
< |
|
280 |
< |
b = fillsample(scanline+i-xstep, zline ? zline+i-xstep : NULL, |
281 |
< |
i-xstep, y, xstep, 0, b/2); |
279 |
> |
if (sd) b = sd[0] > sd[1] ? sd[0] : sd[1]; |
280 |
> |
if (i <= xstep) |
281 |
> |
b = fillsample(scanline, zline, 0, y, i, 0, b/2); |
282 |
> |
else |
283 |
> |
b = fillsample(scanline+i-xstep, |
284 |
> |
zline ? zline+i-xstep : NULL, |
285 |
> |
i-xstep, y, xstep, 0, b/2); |
286 |
> |
if (sd) *sd++ = nc & 1 ? bl : b; |
287 |
> |
bl = b; |
288 |
|
} |
289 |
+ |
if (sd && nc & 1) *sd = bl; |
290 |
|
} |
291 |
|
|
292 |
|
|