1 |
– |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Interpolate and extrapolate pictures with different view parameters. |
6 |
|
* |
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 "standard.h" |
16 |
+ |
#include "rtprocess.h" /* Windows: must come before color.h */ |
17 |
|
#include "view.h" |
18 |
– |
|
18 |
|
#include "color.h" |
19 |
|
|
21 |
– |
#include "resolu.h" |
22 |
– |
|
20 |
|
#define LOG2 0.69314718055994530942 |
21 |
|
|
22 |
|
#define pscan(y) (ourpict+(y)*hresolu) |
36 |
|
|
37 |
|
#define PACKSIZ 256 /* max. calculation packet size */ |
38 |
|
|
39 |
< |
#define RTCOM "rtrace -h- -ovl -fff " |
39 |
> |
#define RTCOM "rtrace -h- -ovl -fff -ld- -i- -I- " |
40 |
|
|
41 |
|
#define ABS(x) ((x)>0?(x):-(x)) |
42 |
|
|
73 |
|
COLOR backcolor = BLKCOLOR; /* background color (float) */ |
74 |
|
double backz = 0.0; /* background z value */ |
75 |
|
int normdist = 1; /* i/o normalized distance? */ |
76 |
+ |
char ourfmt[LPICFMT+1] = PICFMT; /* original picture format */ |
77 |
|
double ourexp = -1; /* original picture exposure */ |
78 |
|
int expadj = 0; /* exposure adjustment (f-stops) */ |
79 |
|
double rexpadj = 1; /* real exposure adjustment */ |
86 |
|
MAT4 theirs2ours; /* transformation matrix */ |
87 |
|
int hasmatrix = 0; /* has transformation matrix */ |
88 |
|
|
89 |
< |
int PDesc[3] = {-1,-1,-1}; /* rtrace process descriptor */ |
92 |
< |
#define childpid (PDesc[2]) |
89 |
> |
static SUBPROC PDesc = SP_INACTIVE; /* rtrace process descriptor */ |
90 |
|
unsigned short queue[PACKSIZ][2]; /* pending pixels */ |
91 |
|
int packsiz; /* actual packet size */ |
92 |
< |
int queuesiz; /* number of pixels pending */ |
92 |
> |
int queuesiz = 0; /* number of pixels pending */ |
93 |
|
|
94 |
|
extern double movepixel(); |
95 |
|
|
209 |
|
if (argv[an][2] != 'f') |
210 |
|
goto badopt; |
211 |
|
check(3,"s"); |
212 |
< |
gotvfile = viewfile(argv[++an], &ourview, 0, 0); |
212 |
> |
gotvfile = viewfile(argv[++an], &ourview, NULL); |
213 |
|
if (gotvfile < 0) |
214 |
|
syserror(argv[an]); |
215 |
|
else if (gotvfile == 0) { |
232 |
|
fillo &= ~F_BACK; |
233 |
|
if (doavg < 0) |
234 |
|
doavg = (argc-an) > 2; |
235 |
< |
if (expcomp != NULL) |
235 |
> |
if (expcomp != NULL) { |
236 |
|
if (expcomp[0] == '+' | expcomp[0] == '-') { |
237 |
|
expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5); |
238 |
|
if (doavg | doblur) |
247 |
|
if (!(doavg | doblur)) |
248 |
|
rexpadj = pow(2.0, (double)expadj); |
249 |
|
} |
250 |
+ |
} |
251 |
|
/* set view */ |
252 |
< |
if (nextview(doblur ? stdin : NULL) == EOF) { |
252 |
> |
if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) { |
253 |
|
fprintf(stderr, "%s: no view on standard input!\n", |
254 |
|
progname); |
255 |
|
exit(1); |
276 |
|
syserror(progname); |
277 |
|
/* new header */ |
278 |
|
newheader("RADIANCE", stdout); |
279 |
+ |
fputnow(stdout); |
280 |
|
/* run pictures */ |
281 |
|
do { |
282 |
< |
bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); |
282 |
> |
memset((char *)ourzbuf, '\0', hresolu*vresolu*sizeof(float)); |
283 |
|
for (i = an; i < argc; i += 2) |
284 |
|
addpicture(argv[i], argv[i+1]); |
285 |
|
if (fillo&F_BACK) /* fill in spaces */ |
307 |
|
ourexp = rexpadj; |
308 |
|
if (ourexp < .995 | ourexp > 1.005) |
309 |
|
fputexpos(ourexp, stdout); |
310 |
< |
fputformat(COLRFMT, stdout); |
310 |
> |
if (strcmp(ourfmt, PICFMT)) /* print format if known */ |
311 |
> |
fputformat(ourfmt, stdout); |
312 |
|
putc('\n', stdout); |
313 |
|
/* write picture */ |
314 |
|
writepicture(); |
326 |
|
} |
327 |
|
|
328 |
|
|
329 |
+ |
int |
330 |
|
headline(s) /* process header string */ |
331 |
|
char *s; |
332 |
|
{ |
333 |
|
char fmt[32]; |
334 |
|
|
335 |
|
if (isheadid(s)) |
336 |
< |
return; |
336 |
> |
return(0); |
337 |
|
if (formatval(fmt, s)) { |
338 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
339 |
< |
return; |
338 |
> |
if (globmatch(ourfmt, fmt)) { |
339 |
> |
wrongformat = 0; |
340 |
> |
strcpy(ourfmt, fmt); |
341 |
> |
} else |
342 |
> |
wrongformat = 1; |
343 |
> |
return(0); |
344 |
|
} |
345 |
|
if (nvavg < 2) { |
346 |
|
putc('\t', stdout); |
348 |
|
} |
349 |
|
if (isexpos(s)) { |
350 |
|
theirexp *= exposval(s); |
351 |
< |
return; |
351 |
> |
return(0); |
352 |
|
} |
353 |
|
if (isview(s) && sscanview(&theirview, s) > 0) |
354 |
|
gotview++; |
355 |
+ |
return(0); |
356 |
|
} |
357 |
|
|
358 |
|
|
375 |
|
exit(1); |
376 |
|
} |
377 |
|
if (!nvavg) { /* first view */ |
378 |
< |
copystruct(&avgview, &ourview); |
378 |
> |
avgview = ourview; |
379 |
|
return(nvavg++); |
380 |
|
} |
381 |
|
/* add to average view */ |
414 |
|
avgview.vfore *= f; |
415 |
|
avgview.vaft *= f; |
416 |
|
if (setview(&avgview) != NULL) /* in case of emergency... */ |
417 |
< |
copystruct(&avgview, &ourview); |
417 |
> |
avgview = ourview; |
418 |
|
pixaspect = viewaspect(&avgview) * hresolu / vresolu; |
419 |
|
} |
420 |
|
|
435 |
|
syserror(pfile); |
436 |
|
/* get header with exposure and view */ |
437 |
|
theirexp = 1.0; |
438 |
< |
copystruct(&theirview, &stdview); |
438 |
> |
theirview = stdview; |
439 |
|
gotview = 0; |
440 |
|
if (nvavg < 2) |
441 |
|
printf("%s:\n", pfile); |
471 |
|
if (xlim == NULL) |
472 |
|
syserror(progname); |
473 |
|
if (!getperim(xlim, &ylim, zin, zfd)) { /* overlapping area? */ |
474 |
< |
free((char *)zin); |
475 |
< |
free((char *)xlim); |
474 |
> |
free((void *)zin); |
475 |
> |
free((void *)xlim); |
476 |
|
if (zfd != -1) |
477 |
|
close(zfd); |
478 |
|
fclose(pfp); |
491 |
|
exit(1); |
492 |
|
} |
493 |
|
if (zfd != -1 && lseek(zfd, |
494 |
< |
(long)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0) |
494 |
> |
(off_t)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0) |
495 |
|
syserror(zspec); |
496 |
|
/* load image */ |
497 |
|
for (y = ylim.min; y <= ylim.max; y++) { |
506 |
|
addscanline(xlim+y, y, scanin, zin, plast); |
507 |
|
} |
508 |
|
/* clean up */ |
509 |
< |
free((char *)xlim); |
510 |
< |
free((char *)scanin); |
511 |
< |
free((char *)zin); |
512 |
< |
free((char *)plast); |
509 |
> |
free((void *)xlim); |
510 |
> |
free((void *)scanin); |
511 |
> |
free((void *)zin); |
512 |
> |
free((void *)plast); |
513 |
|
fclose(pfp); |
514 |
|
if (zfd != -1) |
515 |
|
close(zfd); |
672 |
|
{ |
673 |
|
FVECT pt, tdir, odir; |
674 |
|
double d; |
669 |
– |
register int i; |
675 |
|
|
676 |
|
if (pos[2] <= 0) /* empty pixel */ |
677 |
|
return(0); |
716 |
|
return(0); |
717 |
|
if (!averaging) |
718 |
|
return(1); |
719 |
< |
if (ourview.type == VT_PAR) /* compute our direction */ |
720 |
< |
VCOPY(odir, ourview.vdir); |
721 |
< |
else |
722 |
< |
for (i = 0; i < 3; i++) |
723 |
< |
odir[i] = (pt[i] - ourview.vp[i])/pos[2]; |
724 |
< |
d = DOT(odir,tdir); /* compute pixel weight */ |
725 |
< |
if (d >= 1.-1./MAXWT/MAXWT) |
719 |
> |
/* compute pixel weight */ |
720 |
> |
if (ourview.type == VT_PAR) { |
721 |
> |
d = DOT(ourview.vdir,tdir); |
722 |
> |
d = 1. - d*d; |
723 |
> |
} else { |
724 |
> |
VSUB(odir, pt, ourview.vp); |
725 |
> |
d = DOT(odir,tdir); |
726 |
> |
d = 1. - d*d/DOT(odir,odir); |
727 |
> |
} |
728 |
> |
if (d <= 1./MAXWT/MAXWT) |
729 |
|
return(MAXWT); /* clip to maximum weight */ |
730 |
< |
return(1./sqrt(1.-d)); |
730 |
> |
return(1./sqrt(d)); |
731 |
|
} |
732 |
|
|
733 |
|
|
758 |
|
yl->min = 32000; yl->max = 0; /* search for points on image */ |
759 |
|
for (y = step - 1; y < numscans(&tresolu); y += step) { |
760 |
|
if (zfd != -1) { |
761 |
< |
if (lseek(zfd, (long)y*scanlen(&tresolu)*sizeof(float), |
761 |
> |
if (lseek(zfd, (off_t)y*scanlen(&tresolu)*sizeof(float), |
762 |
|
0) < 0) |
763 |
|
syserror("lseek"); |
764 |
|
if (read(zfd, (char *)zline, |
804 |
|
xl[y-1].max = xl[y-step].max; |
805 |
|
} |
806 |
|
for (x = 2; x < step; x++) |
807 |
< |
copystruct(xl+y-x, xl+y-1); |
807 |
> |
*(xl+y-x) = *(xl+y-1); |
808 |
|
} |
809 |
|
if (yl->max >= numscans(&tresolu)) |
810 |
|
yl->max = numscans(&tresolu) - 1; |
811 |
|
y -= step; |
812 |
|
for (x = numscans(&tresolu) - 1; x > y; x--) /* fill bottom rows */ |
813 |
< |
copystruct(xl+x, xl+y); |
813 |
> |
*(xl+x) = *(xl+y); |
814 |
|
return(yl->max >= yl->min); |
815 |
|
} |
816 |
|
|
919 |
|
xback = -2; |
920 |
|
} |
921 |
|
} |
922 |
< |
free((char *)yback); |
922 |
> |
free((void *)yback); |
923 |
|
} |
924 |
|
|
925 |
|
|
932 |
|
for (x = 0; x < hresolu; x++) |
933 |
|
if (zscan(y)[x] <= 0) |
934 |
|
(*fill)(x,y); |
935 |
+ |
if (fill == rcalfill) |
936 |
+ |
clearqueue(); |
937 |
|
} |
938 |
|
|
939 |
|
|
963 |
|
continue; |
964 |
|
} |
965 |
|
if (averaging) |
966 |
< |
bzero(sscan(y)[x], sizeof(COLOR)); |
966 |
> |
memset(sscan(y)[x], '\0', sizeof(COLOR)); |
967 |
|
else |
968 |
< |
bzero(pscan(y)[x], sizeof(COLR)); |
968 |
> |
memset(pscan(y)[x], '\0', sizeof(COLR)); |
969 |
|
zscan(y)[x] = 0.0; |
970 |
|
} |
971 |
|
} |
1097 |
|
int rval; |
1098 |
|
register char **wp, *cp; |
1099 |
|
|
1100 |
< |
if (childpid != -1) { |
1100 |
> |
if (PDesc.running) { |
1101 |
|
fprintf(stderr, "%s: too many calculations\n", progname); |
1102 |
|
exit(1); |
1103 |
|
} |
1116 |
|
} |
1117 |
|
*wp = NULL; |
1118 |
|
/* start process */ |
1119 |
< |
if ((rval = open_process(PDesc, argv)) < 0) |
1119 |
> |
if ((rval = open_process(&PDesc, argv)) < 0) |
1120 |
|
syserror(progname); |
1121 |
|
if (rval == 0) { |
1122 |
|
fprintf(stderr, "%s: command not found\n", argv[0]); |
1131 |
|
|
1132 |
|
caldone() /* done with calculation */ |
1133 |
|
{ |
1134 |
< |
if (childpid == -1) |
1134 |
> |
if (!PDesc.running) |
1135 |
|
return; |
1136 |
|
clearqueue(); |
1137 |
< |
close_process(PDesc); |
1128 |
< |
childpid = -1; |
1137 |
> |
close_process(&PDesc); |
1138 |
|
} |
1139 |
|
|
1140 |
|
|
1169 |
|
*fbp++ = dir[0]; *fbp++ = dir[1]; *fbp++ = dir[2]; |
1170 |
|
} |
1171 |
|
/* mark end and get results */ |
1172 |
< |
bzero((char *)fbp, 6*sizeof(float)); |
1173 |
< |
if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*queuesiz, |
1172 |
> |
memset((char *)fbp, '\0', 6*sizeof(float)); |
1173 |
> |
if (process(&PDesc, (char *)fbuf, (char *)fbuf, |
1174 |
> |
4*sizeof(float)*(queuesiz+1), |
1175 |
|
6*sizeof(float)*(queuesiz+1)) != |
1176 |
< |
4*sizeof(float)*queuesiz) { |
1176 |
> |
4*sizeof(float)*(queuesiz+1)) { |
1177 |
|
fprintf(stderr, "%s: error reading from rtrace process\n", |
1178 |
|
progname); |
1179 |
|
exit(1); |
1188 |
|
if (averaging) { |
1189 |
|
setcolor(sscan(queue[i][1])[queue[i][0]], |
1190 |
|
fbp[0], fbp[1], fbp[2]); |
1191 |
< |
wscan(queue[i][1])[queue[i][0]] = MAXWT; |
1191 |
> |
wscan(queue[i][1])[queue[i][0]] = 1; |
1192 |
|
} else |
1193 |
|
setcolr(pscan(queue[i][1])[queue[i][0]], |
1194 |
|
fbp[0], fbp[1], fbp[2]); |