7 |
|
* Greg Ward 09Dec89 |
8 |
|
*/ |
9 |
|
|
10 |
< |
#include "standard.h" |
10 |
> |
#include "copyright.h" |
11 |
|
|
12 |
|
#include <ctype.h> |
13 |
+ |
#include <string.h> |
14 |
|
|
15 |
+ |
#include "platform.h" |
16 |
+ |
#include "standard.h" |
17 |
+ |
#include "rtprocess.h" /* Windows: must come before color.h */ |
18 |
|
#include "view.h" |
15 |
– |
|
19 |
|
#include "color.h" |
20 |
|
|
21 |
|
#define LOG2 0.69314718055994530942 |
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 |
|
|
87 |
|
MAT4 theirs2ours; /* transformation matrix */ |
88 |
|
int hasmatrix = 0; /* has transformation matrix */ |
89 |
|
|
90 |
< |
int PDesc[3] = {-1,-1,-1}; /* rtrace process descriptor */ |
88 |
< |
#define childpid (PDesc[2]) |
90 |
> |
static SUBPROC PDesc = SP_INACTIVE; /* rtrace process descriptor */ |
91 |
|
unsigned short queue[PACKSIZ][2]; /* pending pixels */ |
92 |
|
int packsiz; /* actual packet size */ |
93 |
|
int queuesiz = 0; /* number of pixels pending */ |
233 |
|
fillo &= ~F_BACK; |
234 |
|
if (doavg < 0) |
235 |
|
doavg = (argc-an) > 2; |
236 |
< |
if (expcomp != NULL) |
237 |
< |
if (expcomp[0] == '+' | expcomp[0] == '-') { |
236 |
> |
if (expcomp != NULL) { |
237 |
> |
if ((expcomp[0] == '+') | (expcomp[0] == '-')) { |
238 |
|
expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5); |
239 |
|
if (doavg | doblur) |
240 |
|
rexpadj = pow(2.0, atof(expcomp)); |
248 |
|
if (!(doavg | doblur)) |
249 |
|
rexpadj = pow(2.0, (double)expadj); |
250 |
|
} |
251 |
+ |
} |
252 |
|
/* set view */ |
253 |
|
if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) { |
254 |
|
fprintf(stderr, "%s: no view on standard input!\n", |
260 |
|
if (doavg) { |
261 |
|
ourspict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); |
262 |
|
ourweigh = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
263 |
< |
if (ourspict == NULL | ourweigh == NULL) |
263 |
> |
if ((ourspict == NULL) | (ourweigh == NULL)) |
264 |
|
syserror(progname); |
265 |
|
} else { |
266 |
|
ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); |
280 |
|
fputnow(stdout); |
281 |
|
/* run pictures */ |
282 |
|
do { |
283 |
< |
bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); |
283 |
> |
memset((char *)ourzbuf, '\0', hresolu*vresolu*sizeof(float)); |
284 |
|
for (i = an; i < argc; i += 2) |
285 |
|
addpicture(argv[i], argv[i+1]); |
286 |
|
if (fillo&F_BACK) /* fill in spaces */ |
300 |
|
fprintview(&avgview, stdout); |
301 |
|
putc('\n', stdout); |
302 |
|
} |
303 |
< |
if (pixaspect < .99 | pixaspect > 1.01) |
303 |
> |
if ((pixaspect < .99) | (pixaspect > 1.01)) |
304 |
|
fputaspect(pixaspect, stdout); |
305 |
|
if (ourexp > 0) |
306 |
|
ourexp *= rexpadj; |
307 |
|
else |
308 |
|
ourexp = rexpadj; |
309 |
< |
if (ourexp < .995 | ourexp > 1.005) |
309 |
> |
if ((ourexp < .995) | (ourexp > 1.005)) |
310 |
|
fputexpos(ourexp, stdout); |
311 |
|
if (strcmp(ourfmt, PICFMT)) /* print format if known */ |
312 |
|
fputformat(ourfmt, stdout); |
376 |
|
exit(1); |
377 |
|
} |
378 |
|
if (!nvavg) { /* first view */ |
379 |
< |
copystruct(&avgview, &ourview); |
379 |
> |
avgview = ourview; |
380 |
|
return(nvavg++); |
381 |
|
} |
382 |
|
/* add to average view */ |
415 |
|
avgview.vfore *= f; |
416 |
|
avgview.vaft *= f; |
417 |
|
if (setview(&avgview) != NULL) /* in case of emergency... */ |
418 |
< |
copystruct(&avgview, &ourview); |
418 |
> |
avgview = ourview; |
419 |
|
pixaspect = viewaspect(&avgview) * hresolu / vresolu; |
420 |
|
} |
421 |
|
|
436 |
|
syserror(pfile); |
437 |
|
/* get header with exposure and view */ |
438 |
|
theirexp = 1.0; |
439 |
< |
copystruct(&theirview, &stdview); |
439 |
> |
theirview = stdview; |
440 |
|
gotview = 0; |
441 |
|
if (nvavg < 2) |
442 |
|
printf("%s:\n", pfile); |
449 |
|
ourexp = theirexp; |
450 |
|
else if (ABS(theirexp-ourexp) > .01*ourexp) |
451 |
|
fprintf(stderr, "%s: different exposure (warning)\n", pfile); |
452 |
< |
if (err = setview(&theirview)) { |
452 |
> |
if ( (err = setview(&theirview)) ) { |
453 |
|
fprintf(stderr, "%s: %s\n", pfile, err); |
454 |
|
exit(1); |
455 |
|
} |
483 |
|
scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); |
484 |
|
plast = (struct position *)calloc(scanlen(&tresolu), |
485 |
|
sizeof(struct position)); |
486 |
< |
if (scanin == NULL | plast == NULL) |
486 |
> |
if ((scanin == NULL) | (plast == NULL)) |
487 |
|
syserror(progname); |
488 |
|
/* skip to starting point */ |
489 |
|
for (y = 0; y < ylim.min; y++) |
492 |
|
exit(1); |
493 |
|
} |
494 |
|
if (zfd != -1 && lseek(zfd, |
495 |
< |
(off_t)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0) |
495 |
> |
(off_t)ylim.min*scanlen(&tresolu)*sizeof(float), |
496 |
> |
SEEK_SET) < 0) |
497 |
|
syserror(zspec); |
498 |
|
/* load image */ |
499 |
|
for (y = ylim.min; y <= ylim.max; y++) { |
524 |
|
{ |
525 |
|
double m4t[4][4]; |
526 |
|
|
527 |
< |
if (vw1->type != VT_PER & vw1->type != VT_PAR) |
527 |
> |
if ((vw1->type != VT_PER) & (vw1->type != VT_PAR)) |
528 |
|
return(0); |
529 |
< |
if (vw2->type != VT_PER & vw2->type != VT_PAR) |
529 |
> |
if ((vw2->type != VT_PER) & (vw2->type != VT_PAR)) |
530 |
|
return(0); |
531 |
|
setident4(xfmat); |
532 |
|
xfmat[0][0] = vw1->hvec[0]; |
610 |
|
s1x = p1->x - p0->x; |
611 |
|
s1y = p1->y - p0->y; |
612 |
|
l1 = ABS(s1x); |
613 |
< |
if (p1isy = (ABS(s1y) > l1)) |
613 |
> |
if ( (p1isy = (ABS(s1y) > l1)) ) |
614 |
|
l1 = ABS(s1y); |
615 |
|
else if (l1 < 1) |
616 |
|
l1 = 1; |
643 |
|
y1 = p0->y + c1*s1y/l1; |
644 |
|
for (c2 = l2; c2-- > 0; ) { |
645 |
|
x = x1 + c2*s2x/l2; |
646 |
< |
if (x < 0 | x >= hresolu) |
646 |
> |
if ((x < 0) | (x >= hresolu)) |
647 |
|
continue; |
648 |
|
y = y1 + c2*s2y/l2; |
649 |
< |
if (y < 0 | y >= vresolu) |
649 |
> |
if ((y < 0) | (y >= vresolu)) |
650 |
|
continue; |
651 |
|
if (averaging) { |
652 |
|
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
680 |
|
if (usematrix) { |
681 |
|
pos[0] += theirview.hoff - .5; |
682 |
|
pos[1] += theirview.voff - .5; |
683 |
< |
if (normdist & theirview.type == VT_PER) |
683 |
> |
if (normdist & (theirview.type == VT_PER)) |
684 |
|
d = sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
685 |
|
+ pos[1]*pos[1]*theirview.vn2); |
686 |
|
else |
704 |
|
} else { |
705 |
|
if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) |
706 |
|
return(0); |
707 |
< |
if (!normdist & theirview.type == VT_PER) /* adjust */ |
707 |
> |
if ((!normdist) & (theirview.type == VT_PER)) /* adjust */ |
708 |
|
pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
709 |
|
+ pos[1]*pos[1]*theirview.vn2); |
710 |
|
pt[0] += tdir[0]*pos[2]; |
714 |
|
if (pos[2] <= 0) |
715 |
|
return(0); |
716 |
|
} |
717 |
< |
if (pos[0] < 0 | pos[0] >= 1-FTINY | pos[1] < 0 | pos[1] >= 1-FTINY) |
717 |
> |
if ((pos[0] < 0) | (pos[0] >= 1-FTINY) | (pos[1] < 0) | (pos[1] >= 1-FTINY)) |
718 |
|
return(0); |
719 |
|
if (!averaging) |
720 |
|
return(1); |
761 |
|
for (y = step - 1; y < numscans(&tresolu); y += step) { |
762 |
|
if (zfd != -1) { |
763 |
|
if (lseek(zfd, (off_t)y*scanlen(&tresolu)*sizeof(float), |
764 |
< |
0) < 0) |
764 |
> |
SEEK_SET) < 0) |
765 |
|
syserror("lseek"); |
766 |
|
if (read(zfd, (char *)zline, |
767 |
|
scanlen(&tresolu)*sizeof(float)) |
806 |
|
xl[y-1].max = xl[y-step].max; |
807 |
|
} |
808 |
|
for (x = 2; x < step; x++) |
809 |
< |
copystruct(xl+y-x, xl+y-1); |
809 |
> |
*(xl+y-x) = *(xl+y-1); |
810 |
|
} |
811 |
|
if (yl->max >= numscans(&tresolu)) |
812 |
|
yl->max = numscans(&tresolu) - 1; |
813 |
|
y -= step; |
814 |
|
for (x = numscans(&tresolu) - 1; x > y; x--) /* fill bottom rows */ |
815 |
< |
copystruct(xl+x, xl+y); |
815 |
> |
*(xl+x) = *(xl+y); |
816 |
|
return(yl->max >= yl->min); |
817 |
|
} |
818 |
|
|
942 |
|
clipaft() /* perform aft clipping as indicated */ |
943 |
|
{ |
944 |
|
register int x, y; |
945 |
< |
int adjtest = ourview.type == VT_PER & zisnorm; |
945 |
> |
int adjtest = (ourview.type == VT_PER) & zisnorm; |
946 |
|
double tstdist; |
947 |
|
double yzn2, vx; |
948 |
|
|
965 |
|
continue; |
966 |
|
} |
967 |
|
if (averaging) |
968 |
< |
bzero(sscan(y)[x], sizeof(COLOR)); |
968 |
> |
memset(sscan(y)[x], '\0', sizeof(COLOR)); |
969 |
|
else |
970 |
< |
bzero(pscan(y)[x], sizeof(COLR)); |
970 |
> |
memset(pscan(y)[x], '\0', sizeof(COLR)); |
971 |
|
zscan(y)[x] = 0.0; |
972 |
|
} |
973 |
|
} |
1050 |
|
char *fname; |
1051 |
|
{ |
1052 |
|
int donorm = normdist & !zisnorm ? 1 : |
1053 |
< |
ourview.type == VT_PER & !normdist & zisnorm ? -1 : 0; |
1053 |
> |
(ourview.type == VT_PER) & !normdist & zisnorm ? -1 : 0; |
1054 |
|
int fd; |
1055 |
|
int y; |
1056 |
|
|
1099 |
|
int rval; |
1100 |
|
register char **wp, *cp; |
1101 |
|
|
1102 |
< |
if (childpid != -1) { |
1102 |
> |
if (PDesc.running) { |
1103 |
|
fprintf(stderr, "%s: too many calculations\n", progname); |
1104 |
|
exit(1); |
1105 |
|
} |
1118 |
|
} |
1119 |
|
*wp = NULL; |
1120 |
|
/* start process */ |
1121 |
< |
if ((rval = open_process(PDesc, argv)) < 0) |
1121 |
> |
if ((rval = open_process(&PDesc, argv)) < 0) |
1122 |
|
syserror(progname); |
1123 |
|
if (rval == 0) { |
1124 |
|
fprintf(stderr, "%s: command not found\n", argv[0]); |
1133 |
|
|
1134 |
|
caldone() /* done with calculation */ |
1135 |
|
{ |
1136 |
< |
if (childpid == -1) |
1136 |
> |
if (!PDesc.running) |
1137 |
|
return; |
1138 |
|
clearqueue(); |
1139 |
< |
close_process(PDesc); |
1136 |
< |
childpid = -1; |
1139 |
> |
close_process(&PDesc); |
1140 |
|
} |
1141 |
|
|
1142 |
|
|
1171 |
|
*fbp++ = dir[0]; *fbp++ = dir[1]; *fbp++ = dir[2]; |
1172 |
|
} |
1173 |
|
/* mark end and get results */ |
1174 |
< |
bzero((char *)fbp, 6*sizeof(float)); |
1175 |
< |
if (process(PDesc, (char *)fbuf, (char *)fbuf, |
1174 |
> |
memset((char *)fbp, '\0', 6*sizeof(float)); |
1175 |
> |
if (process(&PDesc, (char *)fbuf, (char *)fbuf, |
1176 |
|
4*sizeof(float)*(queuesiz+1), |
1177 |
|
6*sizeof(float)*(queuesiz+1)) != |
1178 |
|
4*sizeof(float)*(queuesiz+1)) { |