1 |
< |
/* Copyright (c) 1994 Regents of the University of California */ |
1 |
> |
/* Copyright (c) 1995 Regents of the University of California */ |
2 |
|
|
3 |
|
#ifndef lint |
4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
26 |
|
#define sscan(y) (ourspict+(y)*hresolu) |
27 |
|
#define wscan(y) (ourweigh+(y)*hresolu) |
28 |
|
#define zscan(y) (ourzbuf+(y)*hresolu) |
29 |
+ |
#define bscan(y) (ourbpict+(y)*hresolu) |
30 |
|
#define averaging (ourweigh != NULL) |
31 |
+ |
#define blurring (ourbpict != NULL) |
32 |
|
#define usematrix (hasmatrix & !averaging) |
33 |
|
#define zisnorm (!usematrix | ourview.type != VT_PER) |
34 |
|
|
61 |
|
COLOR *ourspict; /* output pixel sums (averaging) */ |
62 |
|
float *ourweigh = NULL; /* output pixel weights (averaging) */ |
63 |
|
float *ourzbuf; /* corresponding z-buffer */ |
64 |
+ |
COLOR *ourbpict = NULL; /* blurred picture (view averaging) */ |
65 |
|
|
66 |
+ |
VIEW avgview; /* average view for -B option */ |
67 |
+ |
int nvavg; /* number of views averaged */ |
68 |
+ |
|
69 |
|
char *progname; |
70 |
|
|
71 |
|
int fillo = F_FORE|F_BACK; /* selected fill options */ |
80 |
|
int expadj = 0; /* exposure adjustment (f-stops) */ |
81 |
|
double rexpadj = 1; /* real exposure adjustment */ |
82 |
|
|
83 |
< |
VIEW theirview = STDVIEW; /* input view */ |
83 |
> |
VIEW theirview; /* input view */ |
84 |
|
int gotview; /* got input view? */ |
85 |
|
int wrongformat = 0; /* input in another format? */ |
86 |
|
RESOLU tresolu; /* input resolution */ |
92 |
|
#define childpid (PDesc[2]) |
93 |
|
unsigned short queue[PACKSIZ][2]; /* pending pixels */ |
94 |
|
int packsiz; /* actual packet size */ |
95 |
< |
int queuesiz; /* number of pixels pending */ |
95 |
> |
int queuesiz = 0; /* number of pixels pending */ |
96 |
|
|
97 |
|
extern double movepixel(); |
98 |
|
|
101 |
|
int argc; |
102 |
|
char *argv[]; |
103 |
|
{ |
104 |
< |
#define check(ol,al) if (argv[i][ol] || \ |
105 |
< |
badarg(argc-i-1,argv+i+1,al)) \ |
104 |
> |
#define check(ol,al) if (argv[an][ol] || \ |
105 |
> |
badarg(argc-an-1,argv+an+1,al)) \ |
106 |
|
goto badopt |
107 |
|
int gotvfile = 0; |
108 |
|
int doavg = -1; |
109 |
+ |
int doblur = 0; |
110 |
|
char *zfile = NULL; |
111 |
|
char *expcomp = NULL; |
112 |
< |
char *err; |
106 |
< |
int i, rval; |
112 |
> |
int i, an, rval; |
113 |
|
|
114 |
|
progname = argv[0]; |
115 |
|
|
116 |
< |
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
117 |
< |
rval = getviewopt(&ourview, argc-i, argv+i); |
116 |
> |
for (an = 1; an < argc && argv[an][0] == '-'; an++) { |
117 |
> |
rval = getviewopt(&ourview, argc-an, argv+an); |
118 |
|
if (rval >= 0) { |
119 |
< |
i += rval; |
119 |
> |
an += rval; |
120 |
|
continue; |
121 |
|
} |
122 |
< |
switch (argv[i][1]) { |
122 |
> |
switch (argv[an][1]) { |
123 |
|
case 'e': /* exposure */ |
124 |
|
check(2,"f"); |
125 |
< |
expcomp = argv[++i]; |
125 |
> |
expcomp = argv[++an]; |
126 |
|
break; |
127 |
|
case 't': /* threshold */ |
128 |
|
check(2,"f"); |
129 |
< |
zeps = atof(argv[++i]); |
129 |
> |
zeps = atof(argv[++an]); |
130 |
|
break; |
131 |
|
case 'a': /* average */ |
132 |
|
check(2,NULL); |
133 |
|
doavg = 1; |
134 |
|
break; |
135 |
+ |
case 'B': /* blur views */ |
136 |
+ |
check(2,NULL); |
137 |
+ |
doblur = 1; |
138 |
+ |
break; |
139 |
|
case 'q': /* quick (no avg.) */ |
140 |
|
check(2,NULL); |
141 |
|
doavg = 0; |
145 |
|
normdist = !normdist; |
146 |
|
break; |
147 |
|
case 'f': /* fill type */ |
148 |
< |
switch (argv[i][2]) { |
148 |
> |
switch (argv[an][2]) { |
149 |
|
case '0': /* none */ |
150 |
|
check(3,NULL); |
151 |
|
fillo = 0; |
164 |
|
break; |
165 |
|
case 's': /* sample */ |
166 |
|
check(3,"i"); |
167 |
< |
fillsamp = atoi(argv[++i]); |
167 |
> |
fillsamp = atoi(argv[++an]); |
168 |
|
break; |
169 |
|
case 'c': /* color */ |
170 |
|
check(3,"fff"); |
171 |
|
fillfunc = backfill; |
172 |
< |
setcolor(backcolor, atof(argv[i+1]), |
173 |
< |
atof(argv[i+2]), atof(argv[i+3])); |
172 |
> |
setcolor(backcolor, atof(argv[an+1]), |
173 |
> |
atof(argv[an+2]), atof(argv[an+3])); |
174 |
|
setcolr(backcolr, colval(backcolor,RED), |
175 |
|
colval(backcolor,GRN), |
176 |
|
colval(backcolor,BLU)); |
177 |
< |
i += 3; |
177 |
> |
an += 3; |
178 |
|
break; |
179 |
|
case 'z': /* z value */ |
180 |
|
check(3,"f"); |
181 |
|
fillfunc = backfill; |
182 |
< |
backz = atof(argv[++i]); |
182 |
> |
backz = atof(argv[++an]); |
183 |
|
break; |
184 |
|
case 'r': /* rtrace */ |
185 |
|
check(3,"s"); |
186 |
|
fillfunc = rcalfill; |
187 |
< |
calstart(RTCOM, argv[++i]); |
187 |
> |
calstart(RTCOM, argv[++an]); |
188 |
|
break; |
189 |
|
default: |
190 |
|
goto badopt; |
192 |
|
break; |
193 |
|
case 'z': /* z file */ |
194 |
|
check(2,"s"); |
195 |
< |
zfile = argv[++i]; |
195 |
> |
zfile = argv[++an]; |
196 |
|
break; |
197 |
|
case 'x': /* x resolution */ |
198 |
|
check(2,"i"); |
199 |
< |
hresolu = atoi(argv[++i]); |
199 |
> |
hresolu = atoi(argv[++an]); |
200 |
|
break; |
201 |
|
case 'y': /* y resolution */ |
202 |
|
check(2,"i"); |
203 |
< |
vresolu = atoi(argv[++i]); |
203 |
> |
vresolu = atoi(argv[++an]); |
204 |
|
break; |
205 |
|
case 'p': /* pixel aspect */ |
206 |
< |
if (argv[i][2] != 'a') |
206 |
> |
if (argv[an][2] != 'a') |
207 |
|
goto badopt; |
208 |
|
check(3,"f"); |
209 |
< |
pixaspect = atof(argv[++i]); |
209 |
> |
pixaspect = atof(argv[++an]); |
210 |
|
break; |
211 |
|
case 'v': /* view file */ |
212 |
< |
if (argv[i][2] != 'f') |
212 |
> |
if (argv[an][2] != 'f') |
213 |
|
goto badopt; |
214 |
|
check(3,"s"); |
215 |
< |
gotvfile = viewfile(argv[++i], &ourview, 0, 0); |
215 |
> |
gotvfile = viewfile(argv[++an], &ourview, 0, 0); |
216 |
|
if (gotvfile < 0) |
217 |
< |
syserror(argv[i]); |
217 |
> |
syserror(argv[an]); |
218 |
|
else if (gotvfile == 0) { |
219 |
|
fprintf(stderr, "%s: bad view file\n", |
220 |
< |
argv[i]); |
220 |
> |
argv[an]); |
221 |
|
exit(1); |
222 |
|
} |
223 |
|
break; |
224 |
|
default: |
225 |
|
badopt: |
226 |
|
fprintf(stderr, "%s: command line error at '%s'\n", |
227 |
< |
progname, argv[i]); |
227 |
> |
progname, argv[an]); |
228 |
|
goto userr; |
229 |
|
} |
230 |
|
} |
231 |
|
/* check arguments */ |
232 |
< |
if ((argc-i)%2) |
232 |
> |
if ((argc-an)%2) |
233 |
|
goto userr; |
234 |
|
if (fillsamp == 1) |
235 |
|
fillo &= ~F_BACK; |
236 |
|
if (doavg < 0) |
237 |
< |
doavg = (argc-i) > 2; |
237 |
> |
doavg = (argc-an) > 2; |
238 |
|
if (expcomp != NULL) |
239 |
|
if (expcomp[0] == '+' | expcomp[0] == '-') { |
240 |
|
expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5); |
241 |
< |
if (doavg) |
241 |
> |
if (doavg | doblur) |
242 |
|
rexpadj = pow(2.0, atof(expcomp)); |
243 |
|
else |
244 |
|
rexpadj = pow(2.0, (double)expadj); |
247 |
|
goto userr; |
248 |
|
rexpadj = atof(expcomp); |
249 |
|
expadj = log(rexpadj)/LOG2 + (rexpadj>1 ? .5 : -.5); |
250 |
< |
if (!doavg) |
250 |
> |
if (!(doavg | doblur)) |
251 |
|
rexpadj = pow(2.0, (double)expadj); |
252 |
|
} |
253 |
|
/* set view */ |
254 |
< |
if ((err = setview(&ourview)) != NULL) { |
255 |
< |
fprintf(stderr, "%s: %s\n", progname, err); |
254 |
> |
if (nextview(doblur ? stdin : NULL) == EOF) { |
255 |
> |
fprintf(stderr, "%s: no view on standard input!\n", |
256 |
> |
progname); |
257 |
|
exit(1); |
258 |
|
} |
259 |
|
normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); |
268 |
|
if (ourpict == NULL) |
269 |
|
syserror(progname); |
270 |
|
} |
271 |
+ |
if (doblur) { |
272 |
+ |
ourbpict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); |
273 |
+ |
if (ourbpict == NULL) |
274 |
+ |
syserror(progname); |
275 |
+ |
} |
276 |
|
ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
277 |
|
if (ourzbuf == NULL) |
278 |
|
syserror(progname); |
263 |
– |
bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); |
279 |
|
/* new header */ |
280 |
|
newheader("RADIANCE", stdout); |
281 |
< |
/* get input */ |
282 |
< |
for ( ; i < argc; i += 2) |
283 |
< |
addpicture(argv[i], argv[i+1]); |
284 |
< |
/* fill in spaces */ |
285 |
< |
if (fillo&F_BACK) |
286 |
< |
backpicture(fillfunc, fillsamp); |
287 |
< |
else |
288 |
< |
fillpicture(fillfunc); |
281 |
> |
/* run pictures */ |
282 |
> |
do { |
283 |
> |
bzero((char *)ourzbuf, 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 */ |
287 |
> |
backpicture(fillfunc, fillsamp); |
288 |
> |
else |
289 |
> |
fillpicture(fillfunc); |
290 |
> |
/* aft clipping */ |
291 |
> |
clipaft(); |
292 |
> |
} while (addblur() && nextview(stdin) != EOF); |
293 |
|
/* close calculation */ |
294 |
|
caldone(); |
276 |
– |
/* aft clipping */ |
277 |
– |
clipaft(); |
295 |
|
/* add to header */ |
296 |
|
printargs(argc, argv, stdout); |
297 |
< |
if (gotvfile) { |
297 |
> |
compavgview(); |
298 |
> |
if (doblur | gotvfile) { |
299 |
|
fputs(VIEWSTR, stdout); |
300 |
< |
fprintview(&ourview, stdout); |
300 |
> |
fprintview(&avgview, stdout); |
301 |
|
putc('\n', stdout); |
302 |
|
} |
303 |
|
if (pixaspect < .99 | pixaspect > 1.01) |
319 |
|
exit(0); |
320 |
|
userr: |
321 |
|
fprintf(stderr, |
322 |
< |
"Usage: %s [view opts][-t eps][-z zout][-e spec][-a|-q][-fT][-n] pfile zspec ..\n", |
322 |
> |
"Usage: %s [view opts][-t eps][-z zout][-e spec][-B][-a|-q][-fT][-n] pfile zspec ..\n", |
323 |
|
progname); |
324 |
|
exit(1); |
325 |
|
#undef check |
337 |
|
wrongformat = strcmp(fmt, COLRFMT); |
338 |
|
return; |
339 |
|
} |
340 |
< |
putc('\t', stdout); |
341 |
< |
fputs(s, stdout); |
342 |
< |
|
340 |
> |
if (nvavg < 2) { |
341 |
> |
putc('\t', stdout); |
342 |
> |
fputs(s, stdout); |
343 |
> |
} |
344 |
|
if (isexpos(s)) { |
345 |
|
theirexp *= exposval(s); |
346 |
|
return; |
350 |
|
} |
351 |
|
|
352 |
|
|
353 |
+ |
nextview(fp) /* get and set next view */ |
354 |
+ |
FILE *fp; |
355 |
+ |
{ |
356 |
+ |
char linebuf[256]; |
357 |
+ |
char *err; |
358 |
+ |
register int i; |
359 |
+ |
|
360 |
+ |
if (fp != NULL) { |
361 |
+ |
do /* get new view */ |
362 |
+ |
if (fgets(linebuf, sizeof(linebuf), fp) == NULL) |
363 |
+ |
return(EOF); |
364 |
+ |
while (!isview(linebuf) || !sscanview(&ourview, linebuf)); |
365 |
+ |
} |
366 |
+ |
/* set new view */ |
367 |
+ |
if ((err = setview(&ourview)) != NULL) { |
368 |
+ |
fprintf(stderr, "%s: %s\n", progname, err); |
369 |
+ |
exit(1); |
370 |
+ |
} |
371 |
+ |
if (!nvavg) { /* first view */ |
372 |
+ |
copystruct(&avgview, &ourview); |
373 |
+ |
return(nvavg++); |
374 |
+ |
} |
375 |
+ |
/* add to average view */ |
376 |
+ |
for (i = 0; i < 3; i++) { |
377 |
+ |
avgview.vp[i] += ourview.vp[i]; |
378 |
+ |
avgview.vdir[i] += ourview.vdir[i]; |
379 |
+ |
avgview.vup[i] += ourview.vup[i]; |
380 |
+ |
} |
381 |
+ |
avgview.horiz += ourview.horiz; |
382 |
+ |
avgview.vert += ourview.vert; |
383 |
+ |
avgview.hoff += ourview.hoff; |
384 |
+ |
avgview.voff += ourview.voff; |
385 |
+ |
avgview.vfore += ourview.vfore; |
386 |
+ |
avgview.vaft += ourview.vaft; |
387 |
+ |
return(nvavg++); |
388 |
+ |
} |
389 |
+ |
|
390 |
+ |
|
391 |
+ |
compavgview() /* compute average view */ |
392 |
+ |
{ |
393 |
+ |
register int i; |
394 |
+ |
double f; |
395 |
+ |
|
396 |
+ |
if (nvavg < 2) |
397 |
+ |
return; |
398 |
+ |
f = 1.0/nvavg; |
399 |
+ |
for (i = 0; i < 3; i++) { |
400 |
+ |
avgview.vp[i] *= f; |
401 |
+ |
avgview.vdir[i] *= f; |
402 |
+ |
avgview.vup[i] *= f; |
403 |
+ |
} |
404 |
+ |
avgview.horiz *= f; |
405 |
+ |
avgview.vert *= f; |
406 |
+ |
avgview.hoff *= f; |
407 |
+ |
avgview.voff *= f; |
408 |
+ |
avgview.vfore *= f; |
409 |
+ |
avgview.vaft *= f; |
410 |
+ |
if (setview(&avgview) != NULL) /* in case of emergency... */ |
411 |
+ |
copystruct(&avgview, &ourview); |
412 |
+ |
pixaspect = viewaspect(&avgview) * hresolu / vresolu; |
413 |
+ |
} |
414 |
+ |
|
415 |
+ |
|
416 |
|
addpicture(pfile, zspec) /* add picture to output */ |
417 |
|
char *pfile, *zspec; |
418 |
|
{ |
429 |
|
syserror(pfile); |
430 |
|
/* get header with exposure and view */ |
431 |
|
theirexp = 1.0; |
432 |
+ |
copystruct(&theirview, &stdview); |
433 |
|
gotview = 0; |
434 |
< |
printf("%s:\n", pfile); |
434 |
> |
if (nvavg < 2) |
435 |
> |
printf("%s:\n", pfile); |
436 |
|
getheader(pfp, headline, NULL); |
437 |
|
if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { |
438 |
|
fprintf(stderr, "%s: picture format error\n", pfile); |
516 |
|
{ |
517 |
|
double m4t[4][4]; |
518 |
|
|
519 |
< |
if (vw1->type != VT_PER && vw1->type != VT_PAR) |
519 |
> |
if (vw1->type != VT_PER & vw1->type != VT_PAR) |
520 |
|
return(0); |
521 |
< |
if (vw2->type != VT_PER && vw2->type != VT_PAR) |
521 |
> |
if (vw2->type != VT_PER & vw2->type != VT_PAR) |
522 |
|
return(0); |
523 |
|
setident4(xfmat); |
524 |
|
xfmat[0][0] = vw1->hvec[0]; |
635 |
|
y1 = p0->y + c1*s1y/l1; |
636 |
|
for (c2 = l2; c2-- > 0; ) { |
637 |
|
x = x1 + c2*s2x/l2; |
638 |
< |
if (x < 0 || x >= hresolu) |
638 |
> |
if (x < 0 | x >= hresolu) |
639 |
|
continue; |
640 |
|
y = y1 + c2*s2y/l2; |
641 |
< |
if (y < 0 || y >= vresolu) |
641 |
> |
if (y < 0 | y >= vresolu) |
642 |
|
continue; |
643 |
|
if (averaging) { |
644 |
|
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
673 |
|
if (usematrix) { |
674 |
|
pos[0] += theirview.hoff - .5; |
675 |
|
pos[1] += theirview.voff - .5; |
676 |
< |
if (normdist && theirview.type == VT_PER) |
676 |
> |
if (normdist & theirview.type == VT_PER) |
677 |
|
d = sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
678 |
|
+ pos[1]*pos[1]*theirview.vn2); |
679 |
|
else |
707 |
|
if (pos[2] <= 0) |
708 |
|
return(0); |
709 |
|
} |
710 |
< |
if (pos[0] < 0 || pos[0] >= 1-FTINY || pos[1] < 0 || pos[1] >= 1-FTINY) |
710 |
> |
if (pos[0] < 0 | pos[0] >= 1-FTINY | pos[1] < 0 | pos[1] >= 1-FTINY) |
711 |
|
return(0); |
712 |
|
if (!averaging) |
713 |
|
return(1); |
924 |
|
for (x = 0; x < hresolu; x++) |
925 |
|
if (zscan(y)[x] <= 0) |
926 |
|
(*fill)(x,y); |
927 |
+ |
if (fill == rcalfill) |
928 |
+ |
clearqueue(); |
929 |
|
} |
930 |
|
|
931 |
|
|
937 |
|
double yzn2, vx; |
938 |
|
|
939 |
|
if (ourview.vaft <= FTINY) |
940 |
< |
return; |
940 |
> |
return(0); |
941 |
|
tstdist = ourview.vaft - ourview.vfore; |
942 |
|
for (y = 0; y < vresolu; y++) { |
943 |
|
if (adjtest) { /* adjust test */ |
961 |
|
zscan(y)[x] = 0.0; |
962 |
|
} |
963 |
|
} |
964 |
+ |
return(1); |
965 |
|
} |
966 |
|
|
967 |
|
|
968 |
+ |
addblur() /* add to blurred picture */ |
969 |
+ |
{ |
970 |
+ |
COLOR cval; |
971 |
+ |
double d; |
972 |
+ |
register int i; |
973 |
+ |
|
974 |
+ |
if (!blurring) |
975 |
+ |
return(0); |
976 |
+ |
i = hresolu*vresolu; |
977 |
+ |
if (nvavg < 2) |
978 |
+ |
if (averaging) |
979 |
+ |
while (i--) { |
980 |
+ |
copycolor(ourbpict[i], ourspict[i]); |
981 |
+ |
d = 1.0/ourweigh[i]; |
982 |
+ |
scalecolor(ourbpict[i], d); |
983 |
+ |
} |
984 |
+ |
else |
985 |
+ |
while (i--) |
986 |
+ |
colr_color(ourbpict[i], ourpict[i]); |
987 |
+ |
else |
988 |
+ |
if (averaging) |
989 |
+ |
while (i--) { |
990 |
+ |
copycolor(cval, ourspict[i]); |
991 |
+ |
d = 1.0/ourweigh[i]; |
992 |
+ |
scalecolor(cval, d); |
993 |
+ |
addcolor(ourbpict[i], cval); |
994 |
+ |
} |
995 |
+ |
else |
996 |
+ |
while (i--) { |
997 |
+ |
colr_color(cval, ourpict[i]); |
998 |
+ |
addcolor(ourbpict[i], cval); |
999 |
+ |
} |
1000 |
+ |
/* print view */ |
1001 |
+ |
printf("VIEW%d:", nvavg); |
1002 |
+ |
fprintview(&ourview, stdout); |
1003 |
+ |
putchar('\n'); |
1004 |
+ |
return(1); |
1005 |
+ |
} |
1006 |
+ |
|
1007 |
+ |
|
1008 |
|
writepicture() /* write out picture (alters buffer) */ |
1009 |
|
{ |
1010 |
|
int y; |
1013 |
|
|
1014 |
|
fprtresolu(hresolu, vresolu, stdout); |
1015 |
|
for (y = vresolu-1; y >= 0; y--) |
1016 |
< |
if (averaging) { |
1016 |
> |
if (blurring) { |
1017 |
> |
for (x = 0; x < hresolu; x++) { /* compute avg. */ |
1018 |
> |
d = rexpadj/nvavg; |
1019 |
> |
scalecolor(bscan(y)[x], d); |
1020 |
> |
} |
1021 |
> |
if (fwritescan(bscan(y), hresolu, stdout) < 0) |
1022 |
> |
syserror(progname); |
1023 |
> |
} else if (averaging) { |
1024 |
|
for (x = 0; x < hresolu; x++) { /* average pixels */ |
1025 |
|
d = rexpadj/wscan(y)[x]; |
1026 |
|
scalecolor(sscan(y)[x], d); |