20 |
|
|
21 |
|
#include "resolu.h" |
22 |
|
|
23 |
+ |
#define LOG2 0.69314718055994530942 |
24 |
+ |
|
25 |
|
#define pscan(y) (ourpict+(y)*hresolu) |
26 |
+ |
#define sscan(y) (ourspict+(y)*hresolu) |
27 |
+ |
#define wscan(y) (ourweigh+(y)*hresolu) |
28 |
|
#define zscan(y) (ourzbuf+(y)*hresolu) |
29 |
+ |
#define averaging (ourweigh != NULL) |
30 |
+ |
#define usematrix (hasmatrix & !averaging) |
31 |
+ |
#define zisnorm (!usematrix | ourview.type != VT_PER) |
32 |
|
|
33 |
+ |
#define MAXWT 1000. /* maximum pixel weight (averaging) */ |
34 |
+ |
|
35 |
|
#define F_FORE 1 /* fill foreground */ |
36 |
|
#define F_BACK 2 /* fill background */ |
37 |
|
|
55 |
|
|
56 |
|
double zeps = .02; /* allowed z epsilon */ |
57 |
|
|
58 |
< |
COLR *ourpict; /* output picture */ |
58 |
> |
COLR *ourpict; /* output picture (COLR's) */ |
59 |
> |
COLOR *ourspict; /* output pixel sums (averaging) */ |
60 |
> |
float *ourweigh = NULL; /* output pixel weights (averaging) */ |
61 |
|
float *ourzbuf; /* corresponding z-buffer */ |
62 |
|
|
63 |
|
char *progname; |
67 |
|
extern int backfill(), rcalfill(); /* fill functions */ |
68 |
|
int (*fillfunc)() = backfill; /* selected fill function */ |
69 |
|
COLR backcolr = BLKCOLR; /* background color */ |
70 |
+ |
COLOR backcolor = BLKCOLOR; /* background color (float) */ |
71 |
|
double backz = 0.0; /* background z value */ |
72 |
< |
int normdist = 1; /* normalized distance? */ |
73 |
< |
double ourexp = -1; /* output picture exposure */ |
72 |
> |
int normdist = 1; /* i/o normalized distance? */ |
73 |
> |
double ourexp = -1; /* original picture exposure */ |
74 |
> |
int expadj = 0; /* exposure adjustment (f-stops) */ |
75 |
> |
double rexpadj = 1; /* real exposure adjustment */ |
76 |
|
|
77 |
|
VIEW theirview = STDVIEW; /* input view */ |
78 |
|
int gotview; /* got input view? */ |
79 |
|
int wrongformat = 0; /* input in another format? */ |
80 |
|
RESOLU tresolu; /* input resolution */ |
81 |
|
double theirexp; /* input picture exposure */ |
82 |
< |
double theirs2ours[4][4]; /* transformation matrix */ |
82 |
> |
MAT4 theirs2ours; /* transformation matrix */ |
83 |
|
int hasmatrix = 0; /* has transformation matrix */ |
84 |
|
|
85 |
|
int PDesc[3] = {-1,-1,-1}; /* rtrace process descriptor */ |
88 |
|
int packsiz; /* actual packet size */ |
89 |
|
int queuesiz; /* number of pixels pending */ |
90 |
|
|
91 |
+ |
extern double movepixel(); |
92 |
|
|
93 |
+ |
|
94 |
|
main(argc, argv) /* interpolate pictures */ |
95 |
|
int argc; |
96 |
|
char *argv[]; |
99 |
|
badarg(argc-i-1,argv+i+1,al)) \ |
100 |
|
goto badopt |
101 |
|
int gotvfile = 0; |
102 |
+ |
int doavg = -1; |
103 |
|
char *zfile = NULL; |
104 |
+ |
char *expcomp = NULL; |
105 |
|
char *err; |
106 |
|
int i, rval; |
107 |
|
|
114 |
|
continue; |
115 |
|
} |
116 |
|
switch (argv[i][1]) { |
117 |
+ |
case 'e': /* exposure */ |
118 |
+ |
check(2,"f"); |
119 |
+ |
expcomp = argv[++i]; |
120 |
+ |
break; |
121 |
|
case 't': /* threshold */ |
122 |
|
check(2,"f"); |
123 |
|
zeps = atof(argv[++i]); |
124 |
|
break; |
125 |
+ |
case 'a': /* average */ |
126 |
+ |
check(2,NULL); |
127 |
+ |
doavg = 1; |
128 |
+ |
break; |
129 |
+ |
case 'q': /* quick (no avg.) */ |
130 |
+ |
check(2,NULL); |
131 |
+ |
doavg = 0; |
132 |
+ |
break; |
133 |
|
case 'n': /* dist. normalized? */ |
134 |
|
check(2,NULL); |
135 |
|
normdist = !normdist; |
159 |
|
case 'c': /* color */ |
160 |
|
check(3,"fff"); |
161 |
|
fillfunc = backfill; |
162 |
< |
setcolr(backcolr, atof(argv[i+1]), |
162 |
> |
setcolor(backcolor, atof(argv[i+1]), |
163 |
|
atof(argv[i+2]), atof(argv[i+3])); |
164 |
+ |
setcolr(backcolr, colval(backcolor,RED), |
165 |
+ |
colval(backcolor,GRN), |
166 |
+ |
colval(backcolor,BLU)); |
167 |
|
i += 3; |
168 |
|
break; |
169 |
|
case 'z': /* z value */ |
223 |
|
goto userr; |
224 |
|
if (fillsamp == 1) |
225 |
|
fillo &= ~F_BACK; |
226 |
+ |
if (doavg < 0) |
227 |
+ |
doavg = (argc-i) > 2; |
228 |
+ |
if (expcomp != NULL) |
229 |
+ |
if (expcomp[0] == '+' | expcomp[0] == '-') { |
230 |
+ |
expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5); |
231 |
+ |
if (doavg) |
232 |
+ |
rexpadj = pow(2.0, atof(expcomp)); |
233 |
+ |
else |
234 |
+ |
rexpadj = pow(2.0, (double)expadj); |
235 |
+ |
} else { |
236 |
+ |
if (!isflt(expcomp)) |
237 |
+ |
goto userr; |
238 |
+ |
rexpadj = atof(expcomp); |
239 |
+ |
expadj = log(rexpadj)/LOG2 + (rexpadj>1 ? .5 : -.5); |
240 |
+ |
if (!doavg) |
241 |
+ |
rexpadj = pow(2.0, (double)expadj); |
242 |
+ |
} |
243 |
|
/* set view */ |
244 |
|
if ((err = setview(&ourview)) != NULL) { |
245 |
|
fprintf(stderr, "%s: %s\n", progname, err); |
247 |
|
} |
248 |
|
normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); |
249 |
|
/* allocate frame */ |
250 |
< |
ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); |
250 |
> |
if (doavg) { |
251 |
> |
ourspict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); |
252 |
> |
ourweigh = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
253 |
> |
if (ourspict == NULL | ourweigh == NULL) |
254 |
> |
syserror(progname); |
255 |
> |
} else { |
256 |
> |
ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); |
257 |
> |
if (ourpict == NULL) |
258 |
> |
syserror(progname); |
259 |
> |
} |
260 |
|
ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
261 |
< |
if (ourpict == NULL || ourzbuf == NULL) |
261 |
> |
if (ourzbuf == NULL) |
262 |
|
syserror(progname); |
263 |
|
bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); |
264 |
|
/* new header */ |
282 |
|
fprintview(&ourview, stdout); |
283 |
|
putc('\n', stdout); |
284 |
|
} |
285 |
< |
if (pixaspect < .99 || pixaspect > 1.01) |
285 |
> |
if (pixaspect < .99 | pixaspect > 1.01) |
286 |
|
fputaspect(pixaspect, stdout); |
287 |
< |
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
287 |
> |
if (ourexp > 0) |
288 |
> |
ourexp *= rexpadj; |
289 |
> |
else |
290 |
> |
ourexp = rexpadj; |
291 |
> |
if (ourexp < .995 | ourexp > 1.005) |
292 |
|
fputexpos(ourexp, stdout); |
293 |
|
fputformat(COLRFMT, stdout); |
294 |
|
putc('\n', stdout); |
301 |
|
exit(0); |
302 |
|
userr: |
303 |
|
fprintf(stderr, |
304 |
< |
"Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n", |
304 |
> |
"Usage: %s [view opts][-t eps][-z zout][-e spec][-a|-q][-fT][-n] pfile zspec ..\n", |
305 |
|
progname); |
306 |
|
exit(1); |
307 |
|
#undef check |
371 |
|
if ((zfd = open(zspec, O_RDONLY)) == -1) { |
372 |
|
double zvalue; |
373 |
|
register int x; |
374 |
< |
if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) |
374 |
> |
if (!isflt(zspec) || (zvalue = atof(zspec)) <= 0.0) |
375 |
|
syserror(zspec); |
376 |
|
for (x = scanlen(&tresolu); x-- > 0; ) |
377 |
|
zin[x] = zvalue; |
427 |
|
|
428 |
|
|
429 |
|
pixform(xfmat, vw1, vw2) /* compute view1 to view2 matrix */ |
430 |
< |
register double xfmat[4][4]; |
430 |
> |
register MAT4 xfmat; |
431 |
|
register VIEW *vw1, *vw2; |
432 |
|
{ |
433 |
|
double m4t[4][4]; |
476 |
|
{ |
477 |
|
FVECT pos; |
478 |
|
struct position lastx, newpos; |
479 |
+ |
double wt; |
480 |
|
register int x; |
481 |
|
|
482 |
|
lastx.z = 0; |
483 |
|
for (x = xl->max; x >= xl->min; x--) { |
484 |
|
pix2loc(pos, &tresolu, x, y); |
485 |
|
pos[2] = zline[x]; |
486 |
< |
if (movepixel(pos) < 0) { |
486 |
> |
if ((wt = movepixel(pos)) <= FTINY) { |
487 |
|
lasty[x].z = lastx.z = 0; /* mark invalid */ |
488 |
|
continue; |
489 |
|
} |
490 |
+ |
/* add pixel to our image */ |
491 |
|
newpos.x = pos[0] * hresolu; |
492 |
|
newpos.y = pos[1] * vresolu; |
493 |
|
newpos.z = zline[x]; |
494 |
< |
/* add pixel to our image */ |
495 |
< |
if (pos[0] >= 0 && newpos.x < hresolu |
496 |
< |
&& pos[1] >= 0 && newpos.y < vresolu) { |
497 |
< |
addpixel(&newpos, &lastx, &lasty[x], pline[x], pos[2]); |
433 |
< |
lasty[x].x = lastx.x = newpos.x; |
434 |
< |
lasty[x].y = lastx.y = newpos.y; |
435 |
< |
lasty[x].z = lastx.z = newpos.z; |
436 |
< |
} else |
437 |
< |
lasty[x].z = lastx.z = 0; /* mark invalid */ |
494 |
> |
addpixel(&newpos, &lastx, &lasty[x], pline[x], wt, pos[2]); |
495 |
> |
lasty[x].x = lastx.x = newpos.x; |
496 |
> |
lasty[x].y = lastx.y = newpos.y; |
497 |
> |
lasty[x].z = lastx.z = newpos.z; |
498 |
|
} |
499 |
|
} |
500 |
|
|
501 |
|
|
502 |
< |
addpixel(p0, p1, p2, pix, z) /* fill in pixel parallelogram */ |
502 |
> |
addpixel(p0, p1, p2, pix, w, z) /* fill in pixel parallelogram */ |
503 |
|
struct position *p0, *p1, *p2; |
504 |
|
COLR pix; |
505 |
+ |
double w; |
506 |
|
double z; |
507 |
|
{ |
508 |
|
double zt = 2.*zeps*p0->z; /* threshold */ |
509 |
+ |
COLOR pval; /* converted+weighted pixel */ |
510 |
|
int s1x, s1y, s2x, s2y; /* step sizes */ |
511 |
|
int l1, l2, c1, c2; /* side lengths and counters */ |
512 |
|
int p1isy; /* p0p1 along y? */ |
520 |
|
l1 = ABS(s1x); |
521 |
|
if (p1isy = (ABS(s1y) > l1)) |
522 |
|
l1 = ABS(s1y); |
523 |
+ |
else if (l1 < 1) |
524 |
+ |
l1 = 1; |
525 |
|
} else { |
526 |
|
l1 = s1x = s1y = 1; |
527 |
|
p1isy = -1; |
537 |
|
if (p1isy != 0 && ABS(s2x) > l2) |
538 |
|
l2 = ABS(s2x); |
539 |
|
} |
540 |
+ |
if (l2 < 1) |
541 |
+ |
l2 = 1; |
542 |
|
} else |
543 |
|
l2 = s2x = s2y = 1; |
544 |
|
/* fill the parallelogram */ |
545 |
+ |
if (averaging) { |
546 |
+ |
colr_color(pval, pix); |
547 |
+ |
scalecolor(pval, w); |
548 |
+ |
} |
549 |
|
for (c1 = l1; c1-- > 0; ) { |
550 |
|
x1 = p0->x + c1*s1x/l1; |
551 |
|
y1 = p0->y + c1*s1y/l1; |
556 |
|
y = y1 + c2*s2y/l2; |
557 |
|
if (y < 0 || y >= vresolu) |
558 |
|
continue; |
559 |
< |
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
559 |
> |
if (averaging) { |
560 |
> |
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
561 |
|
> zeps*zscan(y)[x]) { |
562 |
< |
zscan(y)[x] = z; |
562 |
> |
copycolor(sscan(y)[x], pval); |
563 |
> |
wscan(y)[x] = w; |
564 |
> |
zscan(y)[x] = z; |
565 |
> |
} else if (z-zscan(y)[x] <= zeps*zscan(y)[x]) { |
566 |
> |
addcolor(sscan(y)[x], pval); |
567 |
> |
wscan(y)[x] += w; |
568 |
> |
} |
569 |
> |
} else if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
570 |
> |
> zeps*zscan(y)[x]) { |
571 |
|
copycolr(pscan(y)[x], pix); |
572 |
+ |
zscan(y)[x] = z; |
573 |
|
} |
574 |
|
} |
575 |
|
} |
576 |
|
} |
577 |
|
|
578 |
|
|
579 |
+ |
double |
580 |
+ |
movepixel(pos) /* reposition image point */ |
581 |
+ |
register FVECT pos; |
582 |
+ |
{ |
583 |
+ |
FVECT pt, tdir, odir; |
584 |
+ |
double d; |
585 |
+ |
register int i; |
586 |
+ |
|
587 |
+ |
if (pos[2] <= 0) /* empty pixel */ |
588 |
+ |
return(0); |
589 |
+ |
if (usematrix) { |
590 |
+ |
pos[0] += theirview.hoff - .5; |
591 |
+ |
pos[1] += theirview.voff - .5; |
592 |
+ |
if (theirview.type == VT_PER) { |
593 |
+ |
if (normdist) /* adjust distance */ |
594 |
+ |
pos[2] /= sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
595 |
+ |
+ pos[1]*pos[1]*theirview.vn2); |
596 |
+ |
pos[0] *= pos[2]; |
597 |
+ |
pos[1] *= pos[2]; |
598 |
+ |
} |
599 |
+ |
multp3(pos, pos, theirs2ours); |
600 |
+ |
if (pos[2] <= 0) |
601 |
+ |
return(0); |
602 |
+ |
if (ourview.type == VT_PER) { |
603 |
+ |
pos[0] /= pos[2]; |
604 |
+ |
pos[1] /= pos[2]; |
605 |
+ |
} |
606 |
+ |
pos[0] += .5 - ourview.hoff; |
607 |
+ |
pos[1] += .5 - ourview.voff; |
608 |
+ |
} else { |
609 |
+ |
if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) |
610 |
+ |
return(0); |
611 |
+ |
if (!normdist & theirview.type == VT_PER) /* adjust */ |
612 |
+ |
pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
613 |
+ |
+ pos[1]*pos[1]*theirview.vn2); |
614 |
+ |
pt[0] += tdir[0]*pos[2]; |
615 |
+ |
pt[1] += tdir[1]*pos[2]; |
616 |
+ |
pt[2] += tdir[2]*pos[2]; |
617 |
+ |
viewloc(pos, &ourview, pt); |
618 |
+ |
if (pos[2] <= 0) |
619 |
+ |
return(0); |
620 |
+ |
} |
621 |
+ |
if (pos[0] < 0 || pos[0] >= 1-FTINY || pos[1] < 0 || pos[1] >= 1-FTINY) |
622 |
+ |
return(0); |
623 |
+ |
if (!averaging) |
624 |
+ |
return(1); |
625 |
+ |
if (ourview.type == VT_PAR) /* compute our direction */ |
626 |
+ |
VCOPY(odir, ourview.vdir); |
627 |
+ |
else |
628 |
+ |
for (i = 0; i < 3; i++) |
629 |
+ |
odir[i] = (pt[i] - ourview.vp[i])/pos[2]; |
630 |
+ |
d = DOT(odir,tdir); /* compute pixel weight */ |
631 |
+ |
if (d >= 1.-1./MAXWT/MAXWT) |
632 |
+ |
return(MAXWT); /* clip to maximum weight */ |
633 |
+ |
return(1./sqrt(1.-d)); |
634 |
+ |
} |
635 |
+ |
|
636 |
+ |
|
637 |
|
getperim(xl, yl, zline, zfd) /* compute overlapping image area */ |
638 |
|
register struct bound *xl; |
639 |
|
struct bound *yl; |
673 |
|
for (x = scanlen(&tresolu); (x -= step) > 0; ) { |
674 |
|
pix2loc(pos, &tresolu, x, y); |
675 |
|
pos[2] = zline[x]; |
676 |
< |
if (movepixel(pos) == 0 && pos[0] >= 0 && |
539 |
< |
pos[0] < 1 && pos[1] >= 0 && |
540 |
< |
pos[1] < 1) { |
676 |
> |
if (movepixel(pos) > FTINY) { |
677 |
|
xl[y].max = x + step - 1; |
678 |
|
xl[y].min = x - step + 1; /* x min */ |
679 |
|
if (xl[y].min < 0) |
681 |
|
for (x = step - 1; x < xl[y].max; x += step) { |
682 |
|
pix2loc(pos, &tresolu, x, y); |
683 |
|
pos[2] = zline[x]; |
684 |
< |
if (movepixel(pos) == 0 && |
549 |
< |
pos[0] >= 0 && |
550 |
< |
pos[0] < 1 && |
551 |
< |
pos[1] >= 0 && |
552 |
< |
pos[1] < 1) { |
684 |
> |
if (movepixel(pos) > FTINY) { |
685 |
|
xl[y].min = x - step + 1; |
686 |
|
break; |
687 |
|
} |
693 |
|
} |
694 |
|
} |
695 |
|
/* fill in between */ |
696 |
< |
if (xl[y].min < xl[y-step].min) |
696 |
> |
if (y < step) { |
697 |
|
xl[y-1].min = xl[y].min; |
566 |
– |
else |
567 |
– |
xl[y-1].min = xl[y-step].min; |
568 |
– |
if (xl[y].max > xl[y-step].max) |
698 |
|
xl[y-1].max = xl[y].max; |
699 |
< |
else |
700 |
< |
xl[y-1].max = xl[y-step].max; |
699 |
> |
} else { |
700 |
> |
if (xl[y].min < xl[y-step].min) |
701 |
> |
xl[y-1].min = xl[y].min; |
702 |
> |
else |
703 |
> |
xl[y-1].min = xl[y-step].min; |
704 |
> |
if (xl[y].max > xl[y-step].max) |
705 |
> |
xl[y-1].max = xl[y].max; |
706 |
> |
else |
707 |
> |
xl[y-1].max = xl[y-step].max; |
708 |
> |
} |
709 |
|
for (x = 2; x < step; x++) |
710 |
|
copystruct(xl+y-x, xl+y-1); |
711 |
|
} |
712 |
|
if (yl->max >= numscans(&tresolu)) |
713 |
|
yl->max = numscans(&tresolu) - 1; |
714 |
+ |
y -= step; |
715 |
|
for (x = numscans(&tresolu) - 1; x > y; x--) /* fill bottom rows */ |
716 |
|
copystruct(xl+x, xl+y); |
717 |
|
return(yl->max >= yl->min); |
718 |
|
} |
719 |
|
|
720 |
|
|
583 |
– |
movepixel(pos) /* reposition image point */ |
584 |
– |
FVECT pos; |
585 |
– |
{ |
586 |
– |
double d0, d1; |
587 |
– |
FVECT pt, direc; |
588 |
– |
|
589 |
– |
if (pos[2] <= 0) /* empty pixel */ |
590 |
– |
return(-1); |
591 |
– |
if (normdist && theirview.type == VT_PER) { /* adjust distance */ |
592 |
– |
d0 = pos[0] + theirview.hoff - .5; |
593 |
– |
d1 = pos[1] + theirview.voff - .5; |
594 |
– |
pos[2] /= sqrt(1. + d0*d0*theirview.hn2 + d1*d1*theirview.vn2); |
595 |
– |
} |
596 |
– |
if (hasmatrix) { |
597 |
– |
pos[0] += theirview.hoff - .5; |
598 |
– |
pos[1] += theirview.voff - .5; |
599 |
– |
if (theirview.type == VT_PER) { |
600 |
– |
pos[0] *= pos[2]; |
601 |
– |
pos[1] *= pos[2]; |
602 |
– |
} |
603 |
– |
multp3(pos, pos, theirs2ours); |
604 |
– |
if (pos[2] <= 0) |
605 |
– |
return(-1); |
606 |
– |
if (ourview.type == VT_PER) { |
607 |
– |
pos[0] /= pos[2]; |
608 |
– |
pos[1] /= pos[2]; |
609 |
– |
} |
610 |
– |
pos[0] += .5 - ourview.hoff; |
611 |
– |
pos[1] += .5 - ourview.voff; |
612 |
– |
return(0); |
613 |
– |
} |
614 |
– |
if (viewray(pt, direc, &theirview, pos[0], pos[1]) < -FTINY) |
615 |
– |
return(-1); |
616 |
– |
pt[0] += direc[0]*pos[2]; |
617 |
– |
pt[1] += direc[1]*pos[2]; |
618 |
– |
pt[2] += direc[2]*pos[2]; |
619 |
– |
viewloc(pos, &ourview, pt); |
620 |
– |
if (pos[2] <= 0) |
621 |
– |
return(-1); |
622 |
– |
return(0); |
623 |
– |
} |
624 |
– |
|
625 |
– |
|
721 |
|
backpicture(fill, samp) /* background fill algorithm */ |
722 |
|
int (*fill)(); |
723 |
|
int samp; |
788 |
|
< zscan(y)[xback] ) ) { |
789 |
|
if (samp > 0 && ABS(x-xback) >= samp) |
790 |
|
goto fillit; |
791 |
< |
copycolr(pscan(y)[x],pscan(y)[xback]); |
791 |
> |
if (averaging) { |
792 |
> |
copycolor(sscan(y)[x], |
793 |
> |
sscan(y)[xback]); |
794 |
> |
wscan(y)[x] = wscan(y)[xback]; |
795 |
> |
} else |
796 |
> |
copycolr(pscan(y)[x], |
797 |
> |
pscan(y)[xback]); |
798 |
|
zscan(y)[x] = zscan(y)[xback]; |
799 |
|
} else { |
800 |
|
if (samp > 0 && ABS(y-yback[x]) > samp) |
801 |
|
goto fillit; |
802 |
< |
copycolr(pscan(y)[x],pscan(yback[x])[x]); |
802 |
> |
if (averaging) { |
803 |
> |
copycolor(sscan(y)[x], |
804 |
> |
sscan(yback[x])[x]); |
805 |
> |
wscan(y)[x] = |
806 |
> |
wscan(yback[x])[x]; |
807 |
> |
} else |
808 |
> |
copycolr(pscan(y)[x], |
809 |
> |
pscan(yback[x])[x]); |
810 |
|
zscan(y)[x] = zscan(yback[x])[x]; |
811 |
|
} |
812 |
|
continue; |
841 |
|
clipaft() /* perform aft clipping as indicated */ |
842 |
|
{ |
843 |
|
register int x, y; |
844 |
+ |
int adjtest = ourview.type == VT_PER & zisnorm; |
845 |
|
double tstdist; |
846 |
|
double yzn2, vx; |
847 |
|
|
848 |
|
if (ourview.vaft <= FTINY) |
849 |
|
return; |
850 |
< |
tstdist = ourview.vaft; |
850 |
> |
tstdist = ourview.vaft - ourview.vfore; |
851 |
|
for (y = 0; y < vresolu; y++) { |
852 |
< |
if (ourview.type == VT_PER) { /* adjust distance */ |
852 |
> |
if (adjtest) { /* adjust test */ |
853 |
|
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
854 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
855 |
< |
tstdist = ourview.vaft * sqrt(yzn2); |
855 |
> |
tstdist = (ourview.vaft - ourview.vfore)*sqrt(yzn2); |
856 |
|
} |
857 |
|
for (x = 0; x < hresolu; x++) |
858 |
|
if (zscan(y)[x] > tstdist) { |
859 |
< |
if (ourview.type == VT_PER) { |
859 |
> |
if (adjtest) { |
860 |
|
vx = (x+.5)/hresolu + ourview.hoff - .5; |
861 |
< |
if (zscan(y)[x] <= ourview.vaft * |
861 |
> |
if (zscan(y)[x] <= (ourview.vaft - |
862 |
> |
ourview.vfore) * |
863 |
|
sqrt(vx*vx*ourview.hn2 + yzn2)) |
864 |
|
continue; |
865 |
|
} |
866 |
< |
bzero(pscan(y)[x], sizeof(COLR)); |
866 |
> |
if (averaging) |
867 |
> |
bzero(sscan(y)[x], sizeof(COLOR)); |
868 |
> |
else |
869 |
> |
bzero(pscan(y)[x], sizeof(COLR)); |
870 |
|
zscan(y)[x] = 0.0; |
871 |
|
} |
872 |
|
} |
873 |
|
} |
874 |
|
|
875 |
|
|
876 |
< |
writepicture() /* write out picture */ |
876 |
> |
writepicture() /* write out picture (alters buffer) */ |
877 |
|
{ |
878 |
|
int y; |
879 |
+ |
register int x; |
880 |
+ |
double d; |
881 |
|
|
882 |
|
fprtresolu(hresolu, vresolu, stdout); |
883 |
|
for (y = vresolu-1; y >= 0; y--) |
884 |
< |
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
885 |
< |
syserror(progname); |
884 |
> |
if (averaging) { |
885 |
> |
for (x = 0; x < hresolu; x++) { /* average pixels */ |
886 |
> |
d = rexpadj/wscan(y)[x]; |
887 |
> |
scalecolor(sscan(y)[x], d); |
888 |
> |
} |
889 |
> |
if (fwritescan(sscan(y), hresolu, stdout) < 0) |
890 |
> |
syserror(progname); |
891 |
> |
} else { |
892 |
> |
if (expadj) |
893 |
> |
shiftcolrs(pscan(y), hresolu, expadj); |
894 |
> |
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
895 |
> |
syserror(progname); |
896 |
> |
} |
897 |
|
} |
898 |
|
|
899 |
|
|
900 |
< |
writedistance(fname) /* write out z file */ |
900 |
> |
writedistance(fname) /* write out z file (alters buffer) */ |
901 |
|
char *fname; |
902 |
|
{ |
903 |
< |
int donorm = normdist && ourview.type == VT_PER; |
903 |
> |
int donorm = normdist & !zisnorm ? 1 : |
904 |
> |
ourview.type == VT_PER & !normdist & zisnorm ? -1 : 0; |
905 |
|
int fd; |
906 |
|
int y; |
780 |
– |
float *zout; |
907 |
|
|
908 |
|
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) |
909 |
|
syserror(fname); |
784 |
– |
if (donorm |
785 |
– |
&& (zout = (float *)malloc(hresolu*sizeof(float))) == NULL) |
786 |
– |
syserror(progname); |
910 |
|
for (y = vresolu-1; y >= 0; y--) { |
911 |
|
if (donorm) { |
912 |
< |
double vx, yzn2; |
912 |
> |
double vx, yzn2, d; |
913 |
|
register int x; |
914 |
|
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
915 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
916 |
|
for (x = 0; x < hresolu; x++) { |
917 |
|
vx = (x+.5)/hresolu + ourview.hoff - .5; |
918 |
< |
zout[x] = zscan(y)[x] |
919 |
< |
* sqrt(vx*vx*ourview.hn2 + yzn2); |
918 |
> |
d = sqrt(vx*vx*ourview.hn2 + yzn2); |
919 |
> |
if (donorm > 0) |
920 |
> |
zscan(y)[x] *= d; |
921 |
> |
else |
922 |
> |
zscan(y)[x] /= d; |
923 |
|
} |
924 |
< |
} else |
925 |
< |
zout = zscan(y); |
800 |
< |
if (write(fd, (char *)zout, hresolu*sizeof(float)) |
924 |
> |
} |
925 |
> |
if (write(fd, (char *)zscan(y), hresolu*sizeof(float)) |
926 |
|
< hresolu*sizeof(float)) |
927 |
|
syserror(fname); |
928 |
|
} |
804 |
– |
if (donorm) |
805 |
– |
free((char *)zout); |
929 |
|
close(fd); |
930 |
|
} |
931 |
|
|
932 |
|
|
810 |
– |
isfloat(s) /* see if string is floating number */ |
811 |
– |
register char *s; |
812 |
– |
{ |
813 |
– |
for ( ; *s; s++) |
814 |
– |
if ((*s < '0' || *s > '9') && *s != '.' && *s != '-' |
815 |
– |
&& *s != 'e' && *s != 'E' && *s != '+') |
816 |
– |
return(0); |
817 |
– |
return(1); |
818 |
– |
} |
819 |
– |
|
820 |
– |
|
933 |
|
backfill(x, y) /* fill pixel with background */ |
934 |
|
int x, y; |
935 |
|
{ |
936 |
< |
register BYTE *dest = pscan(y)[x]; |
937 |
< |
|
938 |
< |
copycolr(dest, backcolr); |
936 |
> |
if (averaging) { |
937 |
> |
copycolor(sscan(y)[x], backcolor); |
938 |
> |
wscan(y)[x] = 1; |
939 |
> |
} else |
940 |
> |
copycolr(pscan(y)[x], backcolr); |
941 |
|
zscan(y)[x] = backz; |
942 |
|
} |
943 |
|
|
1010 |
|
float fbuf[6*(PACKSIZ+1)]; |
1011 |
|
register float *fbp; |
1012 |
|
register int i; |
1013 |
+ |
double vx, vy; |
1014 |
|
|
1015 |
|
if (queuesiz == 0) |
1016 |
|
return; |
1038 |
|
fbp[1] *= ourexp; |
1039 |
|
fbp[2] *= ourexp; |
1040 |
|
} |
1041 |
< |
setcolr(pscan(queue[i][1])[queue[i][0]], |
1042 |
< |
fbp[0], fbp[1], fbp[2]); |
1043 |
< |
zscan(queue[i][1])[queue[i][0]] = fbp[3]; |
1041 |
> |
if (averaging) { |
1042 |
> |
setcolor(sscan(queue[i][1])[queue[i][0]], |
1043 |
> |
fbp[0], fbp[1], fbp[2]); |
1044 |
> |
wscan(queue[i][1])[queue[i][0]] = 1; |
1045 |
> |
} else |
1046 |
> |
setcolr(pscan(queue[i][1])[queue[i][0]], |
1047 |
> |
fbp[0], fbp[1], fbp[2]); |
1048 |
> |
if (zisnorm) |
1049 |
> |
zscan(queue[i][1])[queue[i][0]] = fbp[3]; |
1050 |
> |
else { |
1051 |
> |
vx = (queue[i][0]+.5)/hresolu + ourview.hoff - .5; |
1052 |
> |
vy = (queue[i][1]+.5)/vresolu + ourview.voff - .5; |
1053 |
> |
zscan(queue[i][1])[queue[i][0]] = fbp[3] / sqrt(1. + |
1054 |
> |
vx*vx*ourview.hn2 + vy*vy*ourview.vn2); |
1055 |
> |
} |
1056 |
|
fbp += 4; |
1057 |
|
} |
1058 |
|
queuesiz = 0; |