28 |
|
#define averaging (ourweigh != NULL) |
29 |
|
#define blurring (ourbpict != NULL) |
30 |
|
#define usematrix (hasmatrix & !averaging) |
31 |
< |
#define zisnorm ((!usematrix) | (ourview.type != VT_PER)) |
31 |
> |
#define zisnorm (!usematrix | (ourview.type != VT_PER)) |
32 |
|
|
33 |
|
#define MAXWT 1000. /* maximum pixel weight (averaging) */ |
34 |
|
|
68 |
|
|
69 |
|
int fillo = F_FORE|F_BACK; /* selected fill options */ |
70 |
|
int fillsamp = 0; /* sample separation (0 == inf) */ |
71 |
– |
extern int backfill(), rcalfill(); /* fill functions */ |
72 |
– |
int (*fillfunc)() = backfill; /* selected fill function */ |
71 |
|
COLR backcolr = BLKCOLR; /* background color */ |
72 |
|
COLOR backcolor = BLKCOLOR; /* background color (float) */ |
73 |
|
double backz = 0.0; /* background z value */ |
74 |
|
int normdist = 1; /* i/o normalized distance? */ |
75 |
< |
char ourfmt[LPICFMT+1] = PICFMT; /* original picture format */ |
75 |
> |
char ourfmt[MAXFMTLEN] = PICFMT; /* original picture format */ |
76 |
|
double ourexp = -1; /* original picture exposure */ |
77 |
|
int expadj = 0; /* exposure adjustment (f-stops) */ |
78 |
|
double rexpadj = 1; /* real exposure adjustment */ |
90 |
|
int packsiz; /* actual packet size */ |
91 |
|
int queuesiz = 0; /* number of pixels pending */ |
92 |
|
|
93 |
< |
extern double movepixel(); |
93 |
> |
typedef void fillfunc_t(int x, int y); |
94 |
|
|
95 |
|
static gethfunc headline; |
96 |
+ |
static int nextview(FILE *fp); |
97 |
+ |
static void compavgview(void); |
98 |
+ |
static void addpicture(char *pfile, char *zspec); |
99 |
+ |
static int pixform(MAT4 xfmat, VIEW *vw1, VIEW *vw2); |
100 |
+ |
static void addscanline(struct bound *xl, int y, |
101 |
+ |
COLR *pline, float *zline, struct position *lasty); |
102 |
+ |
static void addpixel(struct position *p0, struct position *p1, |
103 |
+ |
struct position *p2, COLR pix, double w, double z); |
104 |
+ |
static double movepixel(FVECT pos); |
105 |
+ |
static int getperim(struct bound *xl, struct bound *yl, float *zline, int zfd); |
106 |
+ |
static void backpicture(fillfunc_t *fill, int samp); |
107 |
+ |
static void fillpicture(fillfunc_t *fill); |
108 |
+ |
static int clipaft(void); |
109 |
+ |
static int addblur(void); |
110 |
+ |
static void writepicture(void); |
111 |
+ |
static void writedistance(char *fname); |
112 |
+ |
static fillfunc_t backfill; |
113 |
+ |
static fillfunc_t rcalfill; |
114 |
+ |
static void calstart(char *prog, char *args); |
115 |
+ |
static void caldone(void); |
116 |
+ |
static void clearqueue(void); |
117 |
+ |
static void syserror(char *s); |
118 |
|
|
119 |
+ |
fillfunc_t *fillfunc = backfill; /* selected fill function */ |
120 |
|
|
121 |
< |
main(argc, argv) /* interpolate pictures */ |
122 |
< |
int argc; |
123 |
< |
char *argv[]; |
121 |
> |
int |
122 |
> |
main( /* interpolate pictures */ |
123 |
> |
int argc, |
124 |
> |
char *argv[] |
125 |
> |
) |
126 |
|
{ |
127 |
|
#define check(ol,al) if (argv[an][ol] || \ |
128 |
|
badarg(argc-an-1,argv+an+1,al)) \ |
134 |
|
char *expcomp = NULL; |
135 |
|
int i, an, rval; |
136 |
|
|
137 |
+ |
SET_DEFAULT_BINARY(); |
138 |
+ |
SET_FILE_BINARY(stdout); |
139 |
+ |
|
140 |
|
progname = argv[0]; |
141 |
|
|
142 |
|
for (an = 1; an < argc && argv[an][0] == '-'; an++) { |
361 |
|
void *p |
362 |
|
) |
363 |
|
{ |
364 |
< |
char fmt[32]; |
364 |
> |
char fmt[MAXFMTLEN]; |
365 |
|
|
366 |
|
if (isheadid(s)) |
367 |
|
return(0); |
387 |
|
} |
388 |
|
|
389 |
|
|
390 |
< |
nextview(fp) /* get and set next view */ |
391 |
< |
FILE *fp; |
390 |
> |
static int |
391 |
> |
nextview( /* get and set next view */ |
392 |
> |
FILE *fp |
393 |
> |
) |
394 |
|
{ |
395 |
|
char linebuf[256]; |
396 |
|
char *err; |
397 |
< |
register int i; |
397 |
> |
int i; |
398 |
|
|
399 |
|
if (fp != NULL) { |
400 |
|
do /* get new view */ |
417 |
|
avgview.vdir[i] += ourview.vdir[i]; |
418 |
|
avgview.vup[i] += ourview.vup[i]; |
419 |
|
} |
420 |
+ |
avgview.vdist += ourview.vdist; |
421 |
|
avgview.horiz += ourview.horiz; |
422 |
|
avgview.vert += ourview.vert; |
423 |
|
avgview.hoff += ourview.hoff; |
428 |
|
} |
429 |
|
|
430 |
|
|
431 |
< |
compavgview() /* compute average view */ |
431 |
> |
static void |
432 |
> |
compavgview(void) /* compute average view */ |
433 |
|
{ |
434 |
< |
register int i; |
434 |
> |
int i; |
435 |
|
double f; |
436 |
|
|
437 |
|
if (nvavg < 2) |
442 |
|
avgview.vdir[i] *= f; |
443 |
|
avgview.vup[i] *= f; |
444 |
|
} |
445 |
+ |
avgview.vdist *= f; |
446 |
|
avgview.horiz *= f; |
447 |
|
avgview.vert *= f; |
448 |
|
avgview.hoff *= f; |
455 |
|
} |
456 |
|
|
457 |
|
|
458 |
< |
addpicture(pfile, zspec) /* add picture to output */ |
459 |
< |
char *pfile, *zspec; |
458 |
> |
static void |
459 |
> |
addpicture( /* add picture to output */ |
460 |
> |
char *pfile, |
461 |
> |
char *zspec |
462 |
> |
) |
463 |
|
{ |
464 |
|
FILE *pfp; |
465 |
|
int zfd; |
497 |
|
zin = (float *)malloc(scanlen(&tresolu)*sizeof(float)); |
498 |
|
if (zin == NULL) |
499 |
|
syserror(progname); |
500 |
< |
if ((zfd = open(zspec, O_RDONLY)) == -1) { |
501 |
< |
double zvalue; |
502 |
< |
register int x; |
503 |
< |
if (!isflt(zspec) || (zvalue = atof(zspec)) <= 0.0) |
504 |
< |
syserror(zspec); |
500 |
> |
if (isflt(zspec)) { /* depth is a constant? */ |
501 |
> |
double zvalue = atof(zspec); |
502 |
> |
int x; |
503 |
> |
if (zvalue <= 0.0) { |
504 |
> |
fprintf(stderr, "%s: illegal Z-value %s\n", |
505 |
> |
progname, zspec); |
506 |
> |
exit(1); |
507 |
> |
} |
508 |
|
for (x = scanlen(&tresolu); x-- > 0; ) |
509 |
|
zin[x] = zvalue; |
510 |
< |
} |
510 |
> |
zfd = -1; |
511 |
> |
} else if ((zfd = open_float_depth(zspec, (long)tresolu.xr*tresolu.yr)) < 0) |
512 |
> |
exit(1); |
513 |
|
/* compute transferrable perimeter */ |
514 |
|
xlim = (struct bound *)malloc(numscans(&tresolu)*sizeof(struct bound)); |
515 |
|
if (xlim == NULL) |
561 |
|
} |
562 |
|
|
563 |
|
|
564 |
< |
pixform(xfmat, vw1, vw2) /* compute view1 to view2 matrix */ |
565 |
< |
register MAT4 xfmat; |
566 |
< |
register VIEW *vw1, *vw2; |
564 |
> |
static int |
565 |
> |
pixform( /* compute view1 to view2 matrix */ |
566 |
> |
MAT4 xfmat, |
567 |
> |
VIEW *vw1, |
568 |
> |
VIEW *vw2 |
569 |
> |
) |
570 |
|
{ |
571 |
< |
double m4t[4][4]; |
571 |
> |
MAT4 m4t; |
572 |
|
|
573 |
|
if ((vw1->type != VT_PER) & (vw1->type != VT_PAR)) |
574 |
|
return(0); |
605 |
|
} |
606 |
|
|
607 |
|
|
608 |
< |
addscanline(xl, y, pline, zline, lasty) /* add scanline to output */ |
609 |
< |
struct bound *xl; |
610 |
< |
int y; |
611 |
< |
COLR *pline; |
612 |
< |
float *zline; |
613 |
< |
struct position *lasty; /* input/output */ |
608 |
> |
static void |
609 |
> |
addscanline( /* add scanline to output */ |
610 |
> |
struct bound *xl, |
611 |
> |
int y, |
612 |
> |
COLR *pline, |
613 |
> |
float *zline, |
614 |
> |
struct position *lasty /* input/output */ |
615 |
> |
) |
616 |
|
{ |
617 |
|
FVECT pos; |
618 |
|
struct position lastx, newpos; |
619 |
|
double wt; |
620 |
< |
register int x; |
620 |
> |
int x; |
621 |
|
|
622 |
|
lastx.z = 0; |
623 |
|
for (x = xl->max; x >= xl->min; x--) { |
639 |
|
} |
640 |
|
|
641 |
|
|
642 |
< |
addpixel(p0, p1, p2, pix, w, z) /* fill in pixel parallelogram */ |
643 |
< |
struct position *p0, *p1, *p2; |
644 |
< |
COLR pix; |
645 |
< |
double w; |
646 |
< |
double z; |
642 |
> |
static void |
643 |
> |
addpixel( /* fill in pixel parallelogram */ |
644 |
> |
struct position *p0, |
645 |
> |
struct position *p1, |
646 |
> |
struct position *p2, |
647 |
> |
COLR pix, |
648 |
> |
double w, |
649 |
> |
double z |
650 |
> |
) |
651 |
|
{ |
652 |
|
double zt = 2.*zeps*p0->z; /* threshold */ |
653 |
|
COLOR pval; /* converted+weighted pixel */ |
655 |
|
int l1, l2, c1, c2; /* side lengths and counters */ |
656 |
|
int p1isy; /* p0p1 along y? */ |
657 |
|
int x1, y1; /* p1 position */ |
658 |
< |
register int x, y; /* final position */ |
658 |
> |
int x, y; /* final position */ |
659 |
|
|
660 |
|
/* compute vector p0p1 */ |
661 |
|
if (fillo&F_FORE && ABS(p1->z-p0->z) <= zt) { |
720 |
|
} |
721 |
|
|
722 |
|
|
723 |
< |
double |
724 |
< |
movepixel(pos) /* reposition image point */ |
725 |
< |
register FVECT pos; |
723 |
> |
static double |
724 |
> |
movepixel( /* reposition image point */ |
725 |
> |
FVECT pos |
726 |
> |
) |
727 |
|
{ |
728 |
|
FVECT pt, tdir, odir; |
729 |
|
double d; |
753 |
|
} |
754 |
|
pos[0] += .5 - ourview.hoff; |
755 |
|
pos[1] += .5 - ourview.voff; |
756 |
+ |
if ((pos[0] < 0) | (pos[0] >= 1-FTINY) | |
757 |
+ |
(pos[1] < 0) | (pos[1] >= 1-FTINY)) |
758 |
+ |
return(0); |
759 |
|
pos[2] -= ourview.vfore; |
760 |
|
} else { |
761 |
|
if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) |
762 |
|
return(0); |
763 |
< |
if ((!normdist) & (theirview.type == VT_PER)) /* adjust */ |
764 |
< |
pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
713 |
< |
+ pos[1]*pos[1]*theirview.vn2); |
763 |
> |
if (!normdist & (theirview.type == VT_PER)) /* adjust */ |
764 |
> |
pos[2] /= DOT(theirview.vdir, tdir); |
765 |
|
pt[0] += tdir[0]*pos[2]; |
766 |
|
pt[1] += tdir[1]*pos[2]; |
767 |
|
pt[2] += tdir[2]*pos[2]; |
768 |
< |
viewloc(pos, &ourview, pt); |
718 |
< |
if (pos[2] <= 0) |
768 |
> |
if (viewloc(pos, &ourview, pt) != VL_GOOD) |
769 |
|
return(0); |
770 |
|
} |
721 |
– |
if ((pos[0] < 0) | (pos[0] >= 1-FTINY) | (pos[1] < 0) | (pos[1] >= 1-FTINY)) |
722 |
– |
return(0); |
771 |
|
if (!averaging) |
772 |
|
return(1); |
773 |
|
/* compute pixel weight */ |
785 |
|
} |
786 |
|
|
787 |
|
|
788 |
< |
getperim(xl, yl, zline, zfd) /* compute overlapping image area */ |
789 |
< |
register struct bound *xl; |
790 |
< |
struct bound *yl; |
791 |
< |
float *zline; |
792 |
< |
int zfd; |
788 |
> |
static int |
789 |
> |
getperim( /* compute overlapping image area */ |
790 |
> |
struct bound *xl, |
791 |
> |
struct bound *yl, |
792 |
> |
float *zline, |
793 |
> |
int zfd |
794 |
> |
) |
795 |
|
{ |
796 |
|
int step; |
797 |
|
FVECT pos; |
798 |
< |
register int x, y; |
798 |
> |
int x, y; |
799 |
|
/* set up step size */ |
800 |
|
if (scanlen(&tresolu) < numscans(&tresolu)) |
801 |
|
step = scanlen(&tresolu)/NSTEPS; |
871 |
|
} |
872 |
|
|
873 |
|
|
874 |
< |
backpicture(fill, samp) /* background fill algorithm */ |
875 |
< |
int (*fill)(); |
876 |
< |
int samp; |
874 |
> |
static void |
875 |
> |
backpicture( /* background fill algorithm */ |
876 |
> |
fillfunc_t *fill, |
877 |
> |
int samp |
878 |
> |
) |
879 |
|
{ |
880 |
|
int *yback, xback; |
881 |
|
int y; |
882 |
< |
register int x, i; |
882 |
> |
int x, i; |
883 |
|
/* get back buffer */ |
884 |
|
yback = (int *)malloc(hresolu*sizeof(int)); |
885 |
|
if (yback == NULL) |
981 |
|
} |
982 |
|
|
983 |
|
|
984 |
< |
fillpicture(fill) /* paint in empty pixels using fill */ |
985 |
< |
int (*fill)(); |
984 |
> |
static void |
985 |
> |
fillpicture( /* paint in empty pixels using fill */ |
986 |
> |
fillfunc_t *fill |
987 |
> |
) |
988 |
|
{ |
989 |
< |
register int x, y; |
989 |
> |
int x, y; |
990 |
|
|
991 |
|
for (y = 0; y < vresolu; y++) |
992 |
|
for (x = 0; x < hresolu; x++) |
997 |
|
} |
998 |
|
|
999 |
|
|
1000 |
< |
clipaft() /* perform aft clipping as indicated */ |
1000 |
> |
static int |
1001 |
> |
clipaft(void) /* perform aft clipping as indicated */ |
1002 |
|
{ |
1003 |
< |
register int x, y; |
1003 |
> |
int x, y; |
1004 |
|
int adjtest = (ourview.type == VT_PER) & zisnorm; |
1005 |
|
double tstdist; |
1006 |
|
double yzn2, vx; |
1034 |
|
} |
1035 |
|
|
1036 |
|
|
1037 |
< |
addblur() /* add to blurred picture */ |
1037 |
> |
static int |
1038 |
> |
addblur(void) /* add to blurred picture */ |
1039 |
|
{ |
1040 |
|
COLOR cval; |
1041 |
|
double d; |
1042 |
< |
register int i; |
1042 |
> |
int i; |
1043 |
|
|
1044 |
|
if (!blurring) |
1045 |
|
return(0); |
1075 |
|
} |
1076 |
|
|
1077 |
|
|
1078 |
< |
writepicture() /* write out picture (alters buffer) */ |
1078 |
> |
static void |
1079 |
> |
writepicture(void) /* write out picture (alters buffer) */ |
1080 |
|
{ |
1081 |
|
int y; |
1082 |
< |
register int x; |
1082 |
> |
int x; |
1083 |
|
double d; |
1084 |
|
|
1085 |
|
fprtresolu(hresolu, vresolu, stdout); |
1107 |
|
} |
1108 |
|
|
1109 |
|
|
1110 |
< |
writedistance(fname) /* write out z file (alters buffer) */ |
1111 |
< |
char *fname; |
1110 |
> |
static void |
1111 |
> |
writedistance( /* write out z file (alters buffer) */ |
1112 |
> |
char *fname |
1113 |
> |
) |
1114 |
|
{ |
1115 |
|
int donorm = normdist & !zisnorm ? 1 : |
1116 |
|
(ourview.type == VT_PER) & !normdist & zisnorm ? -1 : 0; |
1122 |
|
for (y = vresolu-1; y >= 0; y--) { |
1123 |
|
if (donorm) { |
1124 |
|
double vx, yzn2, d; |
1125 |
< |
register int x; |
1125 |
> |
int x; |
1126 |
|
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
1127 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
1128 |
|
for (x = 0; x < hresolu; x++) { |
1142 |
|
} |
1143 |
|
|
1144 |
|
|
1145 |
< |
backfill(x, y) /* fill pixel with background */ |
1146 |
< |
int x, y; |
1145 |
> |
static void |
1146 |
> |
backfill( /* fill pixel with background */ |
1147 |
> |
int x, |
1148 |
> |
int y |
1149 |
> |
) |
1150 |
|
{ |
1151 |
|
if (averaging) { |
1152 |
|
copycolor(sscan(y)[x], backcolor); |
1157 |
|
} |
1158 |
|
|
1159 |
|
|
1160 |
< |
calstart(prog, args) /* start fill calculation */ |
1161 |
< |
char *prog, *args; |
1160 |
> |
static void |
1161 |
> |
calstart( /* start fill calculation */ |
1162 |
> |
char *prog, |
1163 |
> |
char *args |
1164 |
> |
) |
1165 |
|
{ |
1166 |
|
char combuf[512]; |
1167 |
|
char *argv[64]; |
1168 |
|
int rval; |
1169 |
< |
register char **wp, *cp; |
1169 |
> |
char **wp, *cp; |
1170 |
|
|
1171 |
< |
if (PDesc.running) { |
1171 |
> |
if (PDesc.flags & PF_RUNNING) { |
1172 |
|
fprintf(stderr, "%s: too many calculations\n", progname); |
1173 |
|
exit(1); |
1174 |
|
} |
1200 |
|
} |
1201 |
|
|
1202 |
|
|
1203 |
< |
caldone() /* done with calculation */ |
1203 |
> |
static void |
1204 |
> |
caldone(void) /* done with calculation */ |
1205 |
|
{ |
1206 |
< |
if (!PDesc.running) |
1206 |
> |
if (!(PDesc.flags & PF_RUNNING)) |
1207 |
|
return; |
1208 |
|
clearqueue(); |
1209 |
|
close_process(&PDesc); |
1210 |
|
} |
1211 |
|
|
1212 |
|
|
1213 |
< |
rcalfill(x, y) /* fill with ray-calculated pixel */ |
1214 |
< |
int x, y; |
1213 |
> |
static void |
1214 |
> |
rcalfill( /* fill with ray-calculated pixel */ |
1215 |
> |
int x, |
1216 |
> |
int y |
1217 |
> |
) |
1218 |
|
{ |
1219 |
|
if (queuesiz >= packsiz) /* flush queue if needed */ |
1220 |
|
clearqueue(); |
1225 |
|
} |
1226 |
|
|
1227 |
|
|
1228 |
< |
clearqueue() /* process queue */ |
1228 |
> |
static void |
1229 |
> |
clearqueue(void) /* process queue */ |
1230 |
|
{ |
1231 |
|
FVECT orig, dir; |
1232 |
|
float fbuf[6*(PACKSIZ+1)]; |
1233 |
< |
register float *fbp; |
1234 |
< |
register int i; |
1233 |
> |
float *fbp; |
1234 |
> |
int i; |
1235 |
|
double vx, vy; |
1236 |
|
|
1237 |
|
if (queuesiz == 0) |
1246 |
|
} |
1247 |
|
/* mark end and get results */ |
1248 |
|
memset((char *)fbp, '\0', 6*sizeof(float)); |
1249 |
< |
if (process(&PDesc, (char *)fbuf, (char *)fbuf, |
1249 |
> |
if (process(&PDesc, fbuf, fbuf, |
1250 |
|
4*sizeof(float)*(queuesiz+1), |
1251 |
|
6*sizeof(float)*(queuesiz+1)) != |
1252 |
|
4*sizeof(float)*(queuesiz+1)) { |
1282 |
|
} |
1283 |
|
|
1284 |
|
|
1285 |
< |
syserror(s) /* report error and exit */ |
1286 |
< |
char *s; |
1285 |
> |
static void |
1286 |
> |
syserror( /* report error and exit */ |
1287 |
> |
char *s |
1288 |
> |
) |
1289 |
|
{ |
1290 |
|
perror(s); |
1291 |
|
exit(1); |