| 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 100. /* maximum pixel weight (averaging) */ |
| 33 |
> |
#define MAXWT 1000. /* maximum pixel weight (averaging) */ |
| 34 |
|
|
| 35 |
|
#define F_FORE 1 /* fill foreground */ |
| 36 |
|
#define F_BACK 2 /* fill background */ |
| 56 |
|
double zeps = .02; /* allowed z epsilon */ |
| 57 |
|
|
| 58 |
|
COLR *ourpict; /* output picture (COLR's) */ |
| 59 |
< |
COLOR *ourspict; /* output pixel sums (-a option) */ |
| 60 |
< |
float *ourweigh = NULL; /* output pixel weights (-a option) */ |
| 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; |
| 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? */ |
| 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]); |
| 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 */ |
| 222 |
– |
if (doavg < 0) |
| 223 |
– |
doavg = (argc-i) > 2; |
| 250 |
|
if (doavg) { |
| 251 |
|
ourspict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); |
| 252 |
|
ourweigh = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
| 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 |
| 520 |
|
l1 = ABS(s1x); |
| 521 |
|
if (p1isy = (ABS(s1y) > l1)) |
| 522 |
|
l1 = ABS(s1y); |
| 523 |
< |
if (l1 < 1) |
| 523 |
> |
else if (l1 < 1) |
| 524 |
|
l1 = 1; |
| 525 |
|
} else { |
| 526 |
|
l1 = s1x = s1y = 1; |
| 578 |
|
|
| 579 |
|
double |
| 580 |
|
movepixel(pos) /* reposition image point */ |
| 581 |
< |
FVECT pos; |
| 581 |
> |
register FVECT pos; |
| 582 |
|
{ |
| 553 |
– |
double d0, d1; |
| 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 (normdist && theirview.type == VT_PER) { /* adjust distance */ |
| 560 |
< |
d0 = pos[0] + theirview.hoff - .5; |
| 561 |
< |
d1 = pos[1] + theirview.voff - .5; |
| 562 |
< |
pos[2] /= sqrt(1. + d0*d0*theirview.hn2 + d1*d1*theirview.vn2); |
| 563 |
< |
} |
| 564 |
< |
if (!averaging && hasmatrix) { |
| 589 |
> |
if (usematrix) { |
| 590 |
|
pos[0] += theirview.hoff - .5; |
| 591 |
|
pos[1] += theirview.voff - .5; |
| 592 |
+ |
if (normdist && theirview.type == VT_PER) |
| 593 |
+ |
d = sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
| 594 |
+ |
+ pos[1]*pos[1]*theirview.vn2); |
| 595 |
+ |
else |
| 596 |
+ |
d = 1.; |
| 597 |
+ |
pos[2] += d*theirview.vfore; |
| 598 |
|
if (theirview.type == VT_PER) { |
| 599 |
+ |
pos[2] /= d; |
| 600 |
|
pos[0] *= pos[2]; |
| 601 |
|
pos[1] *= pos[2]; |
| 602 |
|
} |
| 603 |
|
multp3(pos, pos, theirs2ours); |
| 604 |
< |
if (pos[2] <= 0) |
| 604 |
> |
if (pos[2] <= ourview.vfore) |
| 605 |
|
return(0); |
| 606 |
|
if (ourview.type == VT_PER) { |
| 607 |
|
pos[0] /= pos[2]; |
| 609 |
|
} |
| 610 |
|
pos[0] += .5 - ourview.hoff; |
| 611 |
|
pos[1] += .5 - ourview.voff; |
| 612 |
+ |
pos[2] -= ourview.vfore; |
| 613 |
|
} else { |
| 614 |
|
if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) |
| 615 |
|
return(0); |
| 616 |
+ |
if (!normdist & theirview.type == VT_PER) /* adjust */ |
| 617 |
+ |
pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
| 618 |
+ |
+ pos[1]*pos[1]*theirview.vn2); |
| 619 |
|
pt[0] += tdir[0]*pos[2]; |
| 620 |
|
pt[1] += tdir[1]*pos[2]; |
| 621 |
|
pt[2] += tdir[2]*pos[2]; |
| 632 |
|
else |
| 633 |
|
for (i = 0; i < 3; i++) |
| 634 |
|
odir[i] = (pt[i] - ourview.vp[i])/pos[2]; |
| 635 |
< |
d0 = DOT(odir,tdir); /* compute pixel weight */ |
| 636 |
< |
if (d0 <= FTINY) |
| 601 |
< |
return(0); /* relative angle >= 90 degrees */ |
| 602 |
< |
if (d0 >= 1.-1./MAXWT/MAXWT) |
| 635 |
> |
d = DOT(odir,tdir); /* compute pixel weight */ |
| 636 |
> |
if (d >= 1.-1./MAXWT/MAXWT) |
| 637 |
|
return(MAXWT); /* clip to maximum weight */ |
| 638 |
< |
return(1./sqrt(1.-d0)); |
| 638 |
> |
return(1./sqrt(1.-d)); |
| 639 |
|
} |
| 640 |
|
|
| 641 |
|
|
| 716 |
|
} |
| 717 |
|
if (yl->max >= numscans(&tresolu)) |
| 718 |
|
yl->max = numscans(&tresolu) - 1; |
| 719 |
+ |
y -= step; |
| 720 |
|
for (x = numscans(&tresolu) - 1; x > y; x--) /* fill bottom rows */ |
| 721 |
|
copystruct(xl+x, xl+y); |
| 722 |
|
return(yl->max >= yl->min); |
| 846 |
|
clipaft() /* perform aft clipping as indicated */ |
| 847 |
|
{ |
| 848 |
|
register int x, y; |
| 849 |
+ |
int adjtest = ourview.type == VT_PER & zisnorm; |
| 850 |
|
double tstdist; |
| 851 |
|
double yzn2, vx; |
| 852 |
|
|
| 854 |
|
return; |
| 855 |
|
tstdist = ourview.vaft - ourview.vfore; |
| 856 |
|
for (y = 0; y < vresolu; y++) { |
| 857 |
< |
if (ourview.type == VT_PER) { /* adjust distance */ |
| 857 |
> |
if (adjtest) { /* adjust test */ |
| 858 |
|
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
| 859 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
| 860 |
|
tstdist = (ourview.vaft - ourview.vfore)*sqrt(yzn2); |
| 861 |
|
} |
| 862 |
|
for (x = 0; x < hresolu; x++) |
| 863 |
|
if (zscan(y)[x] > tstdist) { |
| 864 |
< |
if (ourview.type == VT_PER) { |
| 864 |
> |
if (adjtest) { |
| 865 |
|
vx = (x+.5)/hresolu + ourview.hoff - .5; |
| 866 |
|
if (zscan(y)[x] <= (ourview.vaft - |
| 867 |
|
ourview.vfore) * |
| 878 |
|
} |
| 879 |
|
|
| 880 |
|
|
| 881 |
< |
writepicture() /* write out picture */ |
| 881 |
> |
writepicture() /* write out picture (alters buffer) */ |
| 882 |
|
{ |
| 883 |
|
int y; |
| 884 |
|
register int x; |
| 888 |
|
for (y = vresolu-1; y >= 0; y--) |
| 889 |
|
if (averaging) { |
| 890 |
|
for (x = 0; x < hresolu; x++) { /* average pixels */ |
| 891 |
< |
d = 1./wscan(y)[x]; |
| 891 |
> |
d = rexpadj/wscan(y)[x]; |
| 892 |
|
scalecolor(sscan(y)[x], d); |
| 893 |
|
} |
| 894 |
|
if (fwritescan(sscan(y), hresolu, stdout) < 0) |
| 895 |
|
syserror(progname); |
| 896 |
< |
} else if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
| 897 |
< |
syserror(progname); |
| 896 |
> |
} else { |
| 897 |
> |
if (expadj) |
| 898 |
> |
shiftcolrs(pscan(y), hresolu, expadj); |
| 899 |
> |
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
| 900 |
> |
syserror(progname); |
| 901 |
> |
} |
| 902 |
|
} |
| 903 |
|
|
| 904 |
|
|
| 905 |
< |
writedistance(fname) /* write out z file */ |
| 905 |
> |
writedistance(fname) /* write out z file (alters buffer) */ |
| 906 |
|
char *fname; |
| 907 |
|
{ |
| 908 |
< |
int donorm = normdist && ourview.type == VT_PER; |
| 908 |
> |
int donorm = normdist & !zisnorm ? 1 : |
| 909 |
> |
ourview.type == VT_PER & !normdist & zisnorm ? -1 : 0; |
| 910 |
|
int fd; |
| 911 |
|
int y; |
| 871 |
– |
float *zout; |
| 912 |
|
|
| 913 |
|
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) |
| 914 |
|
syserror(fname); |
| 875 |
– |
if (donorm |
| 876 |
– |
&& (zout = (float *)malloc(hresolu*sizeof(float))) == NULL) |
| 877 |
– |
syserror(progname); |
| 915 |
|
for (y = vresolu-1; y >= 0; y--) { |
| 916 |
|
if (donorm) { |
| 917 |
< |
double vx, yzn2; |
| 917 |
> |
double vx, yzn2, d; |
| 918 |
|
register int x; |
| 919 |
|
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
| 920 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
| 921 |
|
for (x = 0; x < hresolu; x++) { |
| 922 |
|
vx = (x+.5)/hresolu + ourview.hoff - .5; |
| 923 |
< |
zout[x] = zscan(y)[x] |
| 924 |
< |
* sqrt(vx*vx*ourview.hn2 + yzn2); |
| 923 |
> |
d = sqrt(vx*vx*ourview.hn2 + yzn2); |
| 924 |
> |
if (donorm > 0) |
| 925 |
> |
zscan(y)[x] *= d; |
| 926 |
> |
else |
| 927 |
> |
zscan(y)[x] /= d; |
| 928 |
|
} |
| 929 |
< |
} else |
| 930 |
< |
zout = zscan(y); |
| 891 |
< |
if (write(fd, (char *)zout, hresolu*sizeof(float)) |
| 929 |
> |
} |
| 930 |
> |
if (write(fd, (char *)zscan(y), hresolu*sizeof(float)) |
| 931 |
|
< hresolu*sizeof(float)) |
| 932 |
|
syserror(fname); |
| 933 |
|
} |
| 895 |
– |
if (donorm) |
| 896 |
– |
free((char *)zout); |
| 934 |
|
close(fd); |
| 935 |
|
} |
| 936 |
|
|
| 1015 |
|
float fbuf[6*(PACKSIZ+1)]; |
| 1016 |
|
register float *fbp; |
| 1017 |
|
register int i; |
| 1018 |
+ |
double vx, vy; |
| 1019 |
|
|
| 1020 |
|
if (queuesiz == 0) |
| 1021 |
|
return; |
| 1050 |
|
} else |
| 1051 |
|
setcolr(pscan(queue[i][1])[queue[i][0]], |
| 1052 |
|
fbp[0], fbp[1], fbp[2]); |
| 1053 |
< |
zscan(queue[i][1])[queue[i][0]] = fbp[3]; |
| 1053 |
> |
if (zisnorm) |
| 1054 |
> |
zscan(queue[i][1])[queue[i][0]] = fbp[3]; |
| 1055 |
> |
else { |
| 1056 |
> |
vx = (queue[i][0]+.5)/hresolu + ourview.hoff - .5; |
| 1057 |
> |
vy = (queue[i][1]+.5)/vresolu + ourview.voff - .5; |
| 1058 |
> |
zscan(queue[i][1])[queue[i][0]] = fbp[3] / sqrt(1. + |
| 1059 |
> |
vx*vx*ourview.hn2 + vy*vy*ourview.vn2); |
| 1060 |
> |
} |
| 1061 |
|
fbp += 4; |
| 1062 |
|
} |
| 1063 |
|
queuesiz = 0; |