1 |
– |
/* Copyright (c) 1994 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 "platform.h" |
17 |
+ |
#include "rtprocess.h" /* Windows: must come before color.h */ |
18 |
|
#include "view.h" |
18 |
– |
|
19 |
|
#include "color.h" |
20 |
|
|
21 |
< |
#include "resolu.h" |
21 |
> |
#define LOG2 0.69314718055994530942 |
22 |
|
|
23 |
|
#define pscan(y) (ourpict+(y)*hresolu) |
24 |
|
#define sscan(y) (ourspict+(y)*hresolu) |
25 |
|
#define wscan(y) (ourweigh+(y)*hresolu) |
26 |
|
#define zscan(y) (ourzbuf+(y)*hresolu) |
27 |
+ |
#define bscan(y) (ourbpict+(y)*hresolu) |
28 |
|
#define averaging (ourweigh != NULL) |
29 |
+ |
#define blurring (ourbpict != 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 */ |
37 |
|
|
38 |
|
#define PACKSIZ 256 /* max. calculation packet size */ |
39 |
|
|
40 |
< |
#define RTCOM "rtrace -h- -ovl -fff " |
40 |
> |
#define RTCOM "rtrace -h- -ovl -fff -ld- -i- -I- " |
41 |
|
|
42 |
|
#define ABS(x) ((x)>0?(x):-(x)) |
43 |
|
|
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 |
+ |
COLOR *ourbpict = NULL; /* blurred picture (view averaging) */ |
63 |
|
|
64 |
+ |
VIEW avgview; /* average view for -B option */ |
65 |
+ |
int nvavg; /* number of views averaged */ |
66 |
+ |
|
67 |
|
char *progname; |
68 |
|
|
69 |
|
int fillo = F_FORE|F_BACK; /* selected fill options */ |
73 |
|
COLR backcolr = BLKCOLR; /* background color */ |
74 |
|
COLOR backcolor = BLKCOLOR; /* background color (float) */ |
75 |
|
double backz = 0.0; /* background z value */ |
76 |
< |
int normdist = 1; /* normalized distance? */ |
77 |
< |
double ourexp = -1; /* output picture exposure */ |
76 |
> |
int normdist = 1; /* i/o normalized distance? */ |
77 |
> |
char ourfmt[LPICFMT+1] = PICFMT; /* original picture format */ |
78 |
> |
double ourexp = -1; /* original picture exposure */ |
79 |
> |
int expadj = 0; /* exposure adjustment (f-stops) */ |
80 |
> |
double rexpadj = 1; /* real exposure adjustment */ |
81 |
|
|
82 |
< |
VIEW theirview = STDVIEW; /* input view */ |
82 |
> |
VIEW theirview; /* input view */ |
83 |
|
int gotview; /* got input view? */ |
84 |
|
int wrongformat = 0; /* input in another format? */ |
85 |
|
RESOLU tresolu; /* input resolution */ |
87 |
|
MAT4 theirs2ours; /* transformation matrix */ |
88 |
|
int hasmatrix = 0; /* has transformation matrix */ |
89 |
|
|
90 |
< |
int PDesc[3] = {-1,-1,-1}; /* rtrace process descriptor */ |
80 |
< |
#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; /* number of pixels pending */ |
93 |
> |
int queuesiz = 0; /* number of pixels pending */ |
94 |
|
|
95 |
|
extern double movepixel(); |
96 |
|
|
99 |
|
int argc; |
100 |
|
char *argv[]; |
101 |
|
{ |
102 |
< |
#define check(ol,al) if (argv[i][ol] || \ |
103 |
< |
badarg(argc-i-1,argv+i+1,al)) \ |
102 |
> |
#define check(ol,al) if (argv[an][ol] || \ |
103 |
> |
badarg(argc-an-1,argv+an+1,al)) \ |
104 |
|
goto badopt |
105 |
|
int gotvfile = 0; |
106 |
|
int doavg = -1; |
107 |
+ |
int doblur = 0; |
108 |
|
char *zfile = NULL; |
109 |
< |
char *err; |
110 |
< |
int i, rval; |
109 |
> |
char *expcomp = NULL; |
110 |
> |
int i, an, rval; |
111 |
|
|
112 |
|
progname = argv[0]; |
113 |
|
|
114 |
< |
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
115 |
< |
rval = getviewopt(&ourview, argc-i, argv+i); |
114 |
> |
for (an = 1; an < argc && argv[an][0] == '-'; an++) { |
115 |
> |
rval = getviewopt(&ourview, argc-an, argv+an); |
116 |
|
if (rval >= 0) { |
117 |
< |
i += rval; |
117 |
> |
an += rval; |
118 |
|
continue; |
119 |
|
} |
120 |
< |
switch (argv[i][1]) { |
120 |
> |
switch (argv[an][1]) { |
121 |
> |
case 'e': /* exposure */ |
122 |
> |
check(2,"f"); |
123 |
> |
expcomp = argv[++an]; |
124 |
> |
break; |
125 |
|
case 't': /* threshold */ |
126 |
|
check(2,"f"); |
127 |
< |
zeps = atof(argv[++i]); |
127 |
> |
zeps = atof(argv[++an]); |
128 |
|
break; |
129 |
|
case 'a': /* average */ |
130 |
|
check(2,NULL); |
131 |
|
doavg = 1; |
132 |
|
break; |
133 |
+ |
case 'B': /* blur views */ |
134 |
+ |
check(2,NULL); |
135 |
+ |
doblur = 1; |
136 |
+ |
break; |
137 |
|
case 'q': /* quick (no avg.) */ |
138 |
|
check(2,NULL); |
139 |
|
doavg = 0; |
143 |
|
normdist = !normdist; |
144 |
|
break; |
145 |
|
case 'f': /* fill type */ |
146 |
< |
switch (argv[i][2]) { |
146 |
> |
switch (argv[an][2]) { |
147 |
|
case '0': /* none */ |
148 |
|
check(3,NULL); |
149 |
|
fillo = 0; |
162 |
|
break; |
163 |
|
case 's': /* sample */ |
164 |
|
check(3,"i"); |
165 |
< |
fillsamp = atoi(argv[++i]); |
165 |
> |
fillsamp = atoi(argv[++an]); |
166 |
|
break; |
167 |
|
case 'c': /* color */ |
168 |
|
check(3,"fff"); |
169 |
|
fillfunc = backfill; |
170 |
< |
setcolor(backcolor, atof(argv[i+1]), |
171 |
< |
atof(argv[i+2]), atof(argv[i+3])); |
170 |
> |
setcolor(backcolor, atof(argv[an+1]), |
171 |
> |
atof(argv[an+2]), atof(argv[an+3])); |
172 |
|
setcolr(backcolr, colval(backcolor,RED), |
173 |
|
colval(backcolor,GRN), |
174 |
|
colval(backcolor,BLU)); |
175 |
< |
i += 3; |
175 |
> |
an += 3; |
176 |
|
break; |
177 |
|
case 'z': /* z value */ |
178 |
|
check(3,"f"); |
179 |
|
fillfunc = backfill; |
180 |
< |
backz = atof(argv[++i]); |
180 |
> |
backz = atof(argv[++an]); |
181 |
|
break; |
182 |
|
case 'r': /* rtrace */ |
183 |
|
check(3,"s"); |
184 |
|
fillfunc = rcalfill; |
185 |
< |
calstart(RTCOM, argv[++i]); |
185 |
> |
calstart(RTCOM, argv[++an]); |
186 |
|
break; |
187 |
|
default: |
188 |
|
goto badopt; |
190 |
|
break; |
191 |
|
case 'z': /* z file */ |
192 |
|
check(2,"s"); |
193 |
< |
zfile = argv[++i]; |
193 |
> |
zfile = argv[++an]; |
194 |
|
break; |
195 |
|
case 'x': /* x resolution */ |
196 |
|
check(2,"i"); |
197 |
< |
hresolu = atoi(argv[++i]); |
197 |
> |
hresolu = atoi(argv[++an]); |
198 |
|
break; |
199 |
|
case 'y': /* y resolution */ |
200 |
|
check(2,"i"); |
201 |
< |
vresolu = atoi(argv[++i]); |
201 |
> |
vresolu = atoi(argv[++an]); |
202 |
|
break; |
203 |
|
case 'p': /* pixel aspect */ |
204 |
< |
if (argv[i][2] != 'a') |
204 |
> |
if (argv[an][2] != 'a') |
205 |
|
goto badopt; |
206 |
|
check(3,"f"); |
207 |
< |
pixaspect = atof(argv[++i]); |
207 |
> |
pixaspect = atof(argv[++an]); |
208 |
|
break; |
209 |
|
case 'v': /* view file */ |
210 |
< |
if (argv[i][2] != 'f') |
210 |
> |
if (argv[an][2] != 'f') |
211 |
|
goto badopt; |
212 |
|
check(3,"s"); |
213 |
< |
gotvfile = viewfile(argv[++i], &ourview, 0, 0); |
213 |
> |
gotvfile = viewfile(argv[++an], &ourview, NULL); |
214 |
|
if (gotvfile < 0) |
215 |
< |
syserror(argv[i]); |
215 |
> |
syserror(argv[an]); |
216 |
|
else if (gotvfile == 0) { |
217 |
|
fprintf(stderr, "%s: bad view file\n", |
218 |
< |
argv[i]); |
218 |
> |
argv[an]); |
219 |
|
exit(1); |
220 |
|
} |
221 |
|
break; |
222 |
|
default: |
223 |
|
badopt: |
224 |
|
fprintf(stderr, "%s: command line error at '%s'\n", |
225 |
< |
progname, argv[i]); |
225 |
> |
progname, argv[an]); |
226 |
|
goto userr; |
227 |
|
} |
228 |
|
} |
229 |
|
/* check arguments */ |
230 |
< |
if ((argc-i)%2) |
230 |
> |
if ((argc-an)%2) |
231 |
|
goto userr; |
232 |
|
if (fillsamp == 1) |
233 |
|
fillo &= ~F_BACK; |
234 |
+ |
if (doavg < 0) |
235 |
+ |
doavg = (argc-an) > 2; |
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)); |
241 |
+ |
else |
242 |
+ |
rexpadj = pow(2.0, (double)expadj); |
243 |
+ |
} else { |
244 |
+ |
if (!isflt(expcomp)) |
245 |
+ |
goto userr; |
246 |
+ |
rexpadj = atof(expcomp); |
247 |
+ |
expadj = log(rexpadj)/LOG2 + (rexpadj>1 ? .5 : -.5); |
248 |
+ |
if (!(doavg | doblur)) |
249 |
+ |
rexpadj = pow(2.0, (double)expadj); |
250 |
+ |
} |
251 |
+ |
} |
252 |
|
/* set view */ |
253 |
< |
if ((err = setview(&ourview)) != NULL) { |
254 |
< |
fprintf(stderr, "%s: %s\n", progname, err); |
253 |
> |
if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) { |
254 |
> |
fprintf(stderr, "%s: no view on standard input!\n", |
255 |
> |
progname); |
256 |
|
exit(1); |
257 |
|
} |
258 |
|
normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); |
259 |
|
/* allocate frame */ |
222 |
– |
if (doavg < 0) |
223 |
– |
doavg = (argc-i) > 2; |
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)); |
267 |
|
if (ourpict == NULL) |
268 |
|
syserror(progname); |
269 |
|
} |
270 |
+ |
if (doblur) { |
271 |
+ |
ourbpict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); |
272 |
+ |
if (ourbpict == NULL) |
273 |
+ |
syserror(progname); |
274 |
+ |
} |
275 |
|
ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
276 |
|
if (ourzbuf == NULL) |
277 |
|
syserror(progname); |
237 |
– |
bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); |
278 |
|
/* new header */ |
279 |
|
newheader("RADIANCE", stdout); |
280 |
< |
/* get input */ |
281 |
< |
for ( ; i < argc; i += 2) |
282 |
< |
addpicture(argv[i], argv[i+1]); |
283 |
< |
/* fill in spaces */ |
284 |
< |
if (fillo&F_BACK) |
285 |
< |
backpicture(fillfunc, fillsamp); |
286 |
< |
else |
287 |
< |
fillpicture(fillfunc); |
280 |
> |
fputnow(stdout); |
281 |
> |
/* run pictures */ |
282 |
> |
do { |
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 */ |
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(); |
250 |
– |
/* aft clipping */ |
251 |
– |
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) |
303 |
> |
if ((pixaspect < .99) | (pixaspect > 1.01)) |
304 |
|
fputaspect(pixaspect, stdout); |
305 |
< |
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
305 |
> |
if (ourexp > 0) |
306 |
> |
ourexp *= rexpadj; |
307 |
> |
else |
308 |
> |
ourexp = rexpadj; |
309 |
> |
if ((ourexp < .995) | (ourexp > 1.005)) |
310 |
|
fputexpos(ourexp, stdout); |
311 |
< |
fputformat(COLRFMT, stdout); |
311 |
> |
if (strcmp(ourfmt, PICFMT)) /* print format if known */ |
312 |
> |
fputformat(ourfmt, stdout); |
313 |
|
putc('\n', stdout); |
314 |
|
/* write picture */ |
315 |
|
writepicture(); |
320 |
|
exit(0); |
321 |
|
userr: |
322 |
|
fprintf(stderr, |
323 |
< |
"Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n", |
323 |
> |
"Usage: %s [view opts][-t eps][-z zout][-e spec][-B][-a|-q][-fT][-n] pfile zspec ..\n", |
324 |
|
progname); |
325 |
|
exit(1); |
326 |
|
#undef check |
327 |
|
} |
328 |
|
|
329 |
|
|
330 |
+ |
int |
331 |
|
headline(s) /* process header string */ |
332 |
|
char *s; |
333 |
|
{ |
334 |
|
char fmt[32]; |
335 |
|
|
336 |
|
if (isheadid(s)) |
337 |
< |
return; |
337 |
> |
return(0); |
338 |
|
if (formatval(fmt, s)) { |
339 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
340 |
< |
return; |
339 |
> |
if (globmatch(ourfmt, fmt)) { |
340 |
> |
wrongformat = 0; |
341 |
> |
strcpy(ourfmt, fmt); |
342 |
> |
} else |
343 |
> |
wrongformat = 1; |
344 |
> |
return(0); |
345 |
|
} |
346 |
< |
putc('\t', stdout); |
347 |
< |
fputs(s, stdout); |
348 |
< |
|
346 |
> |
if (nvavg < 2) { |
347 |
> |
putc('\t', stdout); |
348 |
> |
fputs(s, stdout); |
349 |
> |
} |
350 |
|
if (isexpos(s)) { |
351 |
|
theirexp *= exposval(s); |
352 |
< |
return; |
352 |
> |
return(0); |
353 |
|
} |
354 |
|
if (isview(s) && sscanview(&theirview, s) > 0) |
355 |
|
gotview++; |
356 |
+ |
return(0); |
357 |
|
} |
358 |
|
|
359 |
|
|
360 |
+ |
nextview(fp) /* get and set next view */ |
361 |
+ |
FILE *fp; |
362 |
+ |
{ |
363 |
+ |
char linebuf[256]; |
364 |
+ |
char *err; |
365 |
+ |
register int i; |
366 |
+ |
|
367 |
+ |
if (fp != NULL) { |
368 |
+ |
do /* get new view */ |
369 |
+ |
if (fgets(linebuf, sizeof(linebuf), fp) == NULL) |
370 |
+ |
return(EOF); |
371 |
+ |
while (!isview(linebuf) || !sscanview(&ourview, linebuf)); |
372 |
+ |
} |
373 |
+ |
/* set new view */ |
374 |
+ |
if ((err = setview(&ourview)) != NULL) { |
375 |
+ |
fprintf(stderr, "%s: %s\n", progname, err); |
376 |
+ |
exit(1); |
377 |
+ |
} |
378 |
+ |
if (!nvavg) { /* first view */ |
379 |
+ |
avgview = ourview; |
380 |
+ |
return(nvavg++); |
381 |
+ |
} |
382 |
+ |
/* add to average view */ |
383 |
+ |
for (i = 0; i < 3; i++) { |
384 |
+ |
avgview.vp[i] += ourview.vp[i]; |
385 |
+ |
avgview.vdir[i] += ourview.vdir[i]; |
386 |
+ |
avgview.vup[i] += ourview.vup[i]; |
387 |
+ |
} |
388 |
+ |
avgview.horiz += ourview.horiz; |
389 |
+ |
avgview.vert += ourview.vert; |
390 |
+ |
avgview.hoff += ourview.hoff; |
391 |
+ |
avgview.voff += ourview.voff; |
392 |
+ |
avgview.vfore += ourview.vfore; |
393 |
+ |
avgview.vaft += ourview.vaft; |
394 |
+ |
return(nvavg++); |
395 |
+ |
} |
396 |
+ |
|
397 |
+ |
|
398 |
+ |
compavgview() /* compute average view */ |
399 |
+ |
{ |
400 |
+ |
register int i; |
401 |
+ |
double f; |
402 |
+ |
|
403 |
+ |
if (nvavg < 2) |
404 |
+ |
return; |
405 |
+ |
f = 1.0/nvavg; |
406 |
+ |
for (i = 0; i < 3; i++) { |
407 |
+ |
avgview.vp[i] *= f; |
408 |
+ |
avgview.vdir[i] *= f; |
409 |
+ |
avgview.vup[i] *= f; |
410 |
+ |
} |
411 |
+ |
avgview.horiz *= f; |
412 |
+ |
avgview.vert *= f; |
413 |
+ |
avgview.hoff *= f; |
414 |
+ |
avgview.voff *= f; |
415 |
+ |
avgview.vfore *= f; |
416 |
+ |
avgview.vaft *= f; |
417 |
+ |
if (setview(&avgview) != NULL) /* in case of emergency... */ |
418 |
+ |
avgview = ourview; |
419 |
+ |
pixaspect = viewaspect(&avgview) * hresolu / vresolu; |
420 |
+ |
} |
421 |
+ |
|
422 |
+ |
|
423 |
|
addpicture(pfile, zspec) /* add picture to output */ |
424 |
|
char *pfile, *zspec; |
425 |
|
{ |
436 |
|
syserror(pfile); |
437 |
|
/* get header with exposure and view */ |
438 |
|
theirexp = 1.0; |
439 |
+ |
theirview = stdview; |
440 |
|
gotview = 0; |
441 |
< |
printf("%s:\n", pfile); |
441 |
> |
if (nvavg < 2) |
442 |
> |
printf("%s:\n", pfile); |
443 |
|
getheader(pfp, headline, NULL); |
444 |
|
if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { |
445 |
|
fprintf(stderr, "%s: picture format error\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 |
|
} |
472 |
|
if (xlim == NULL) |
473 |
|
syserror(progname); |
474 |
|
if (!getperim(xlim, &ylim, zin, zfd)) { /* overlapping area? */ |
475 |
< |
free((char *)zin); |
476 |
< |
free((char *)xlim); |
475 |
> |
free((void *)zin); |
476 |
> |
free((void *)xlim); |
477 |
|
if (zfd != -1) |
478 |
|
close(zfd); |
479 |
|
fclose(pfp); |
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 |
< |
(long)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++) { |
508 |
|
addscanline(xlim+y, y, scanin, zin, plast); |
509 |
|
} |
510 |
|
/* clean up */ |
511 |
< |
free((char *)xlim); |
512 |
< |
free((char *)scanin); |
513 |
< |
free((char *)zin); |
514 |
< |
free((char *)plast); |
511 |
> |
free((void *)xlim); |
512 |
> |
free((void *)scanin); |
513 |
> |
free((void *)zin); |
514 |
> |
free((void *)plast); |
515 |
|
fclose(pfp); |
516 |
|
if (zfd != -1) |
517 |
|
close(zfd); |
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 |
< |
if (l1 < 1) |
615 |
> |
else if (l1 < 1) |
616 |
|
l1 = 1; |
617 |
|
} else { |
618 |
|
l1 = s1x = s1y = 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 |
670 |
|
|
671 |
|
double |
672 |
|
movepixel(pos) /* reposition image point */ |
673 |
< |
FVECT pos; |
673 |
> |
register FVECT pos; |
674 |
|
{ |
553 |
– |
double d0, d1; |
675 |
|
FVECT pt, tdir, odir; |
676 |
< |
register int i; |
676 |
> |
double d; |
677 |
|
|
678 |
|
if (pos[2] <= 0) /* empty pixel */ |
679 |
|
return(0); |
680 |
< |
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) { |
680 |
> |
if (usematrix) { |
681 |
|
pos[0] += theirview.hoff - .5; |
682 |
|
pos[1] += theirview.voff - .5; |
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 |
687 |
+ |
d = 1.; |
688 |
+ |
pos[2] += d*theirview.vfore; |
689 |
|
if (theirview.type == VT_PER) { |
690 |
+ |
pos[2] /= d; |
691 |
|
pos[0] *= pos[2]; |
692 |
|
pos[1] *= pos[2]; |
693 |
|
} |
694 |
|
multp3(pos, pos, theirs2ours); |
695 |
< |
if (pos[2] <= 0) |
695 |
> |
if (pos[2] <= ourview.vfore) |
696 |
|
return(0); |
697 |
|
if (ourview.type == VT_PER) { |
698 |
|
pos[0] /= pos[2]; |
700 |
|
} |
701 |
|
pos[0] += .5 - ourview.hoff; |
702 |
|
pos[1] += .5 - ourview.voff; |
703 |
+ |
pos[2] -= ourview.vfore; |
704 |
|
} else { |
705 |
|
if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) |
706 |
|
return(0); |
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]; |
711 |
|
pt[1] += tdir[1]*pos[2]; |
712 |
|
pt[2] += tdir[2]*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); |
721 |
< |
if (ourview.type == VT_PAR) /* compute our direction */ |
722 |
< |
VCOPY(odir, ourview.vdir); |
723 |
< |
else |
724 |
< |
for (i = 0; i < 3; i++) |
725 |
< |
odir[i] = (pt[i] - ourview.vp[i])/pos[2]; |
726 |
< |
d0 = DOT(odir,tdir); /* compute pixel weight */ |
727 |
< |
if (d0 <= FTINY) |
728 |
< |
return(0); /* relative angle >= 90 degrees */ |
729 |
< |
if (d0 >= 1.-1./MAXWT/MAXWT) |
721 |
> |
/* compute pixel weight */ |
722 |
> |
if (ourview.type == VT_PAR) { |
723 |
> |
d = DOT(ourview.vdir,tdir); |
724 |
> |
d = 1. - d*d; |
725 |
> |
} else { |
726 |
> |
VSUB(odir, pt, ourview.vp); |
727 |
> |
d = DOT(odir,tdir); |
728 |
> |
d = 1. - d*d/DOT(odir,odir); |
729 |
> |
} |
730 |
> |
if (d <= 1./MAXWT/MAXWT) |
731 |
|
return(MAXWT); /* clip to maximum weight */ |
732 |
< |
return(1./sqrt(1.-d0)); |
732 |
> |
return(1./sqrt(d)); |
733 |
|
} |
734 |
|
|
735 |
|
|
760 |
|
yl->min = 32000; yl->max = 0; /* search for points on image */ |
761 |
|
for (y = step - 1; y < numscans(&tresolu); y += step) { |
762 |
|
if (zfd != -1) { |
763 |
< |
if (lseek(zfd, (long)y*scanlen(&tresolu)*sizeof(float), |
764 |
< |
0) < 0) |
763 |
> |
if (lseek(zfd, (off_t)y*scanlen(&tresolu)*sizeof(float), |
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 |
|
|
921 |
|
xback = -2; |
922 |
|
} |
923 |
|
} |
924 |
< |
free((char *)yback); |
924 |
> |
free((void *)yback); |
925 |
|
} |
926 |
|
|
927 |
|
|
934 |
|
for (x = 0; x < hresolu; x++) |
935 |
|
if (zscan(y)[x] <= 0) |
936 |
|
(*fill)(x,y); |
937 |
+ |
if (fill == rcalfill) |
938 |
+ |
clearqueue(); |
939 |
|
} |
940 |
|
|
941 |
|
|
942 |
|
clipaft() /* perform aft clipping as indicated */ |
943 |
|
{ |
944 |
|
register int x, y; |
945 |
+ |
int adjtest = (ourview.type == VT_PER) & zisnorm; |
946 |
|
double tstdist; |
947 |
|
double yzn2, vx; |
948 |
|
|
949 |
|
if (ourview.vaft <= FTINY) |
950 |
< |
return; |
950 |
> |
return(0); |
951 |
|
tstdist = ourview.vaft - ourview.vfore; |
952 |
|
for (y = 0; y < vresolu; y++) { |
953 |
< |
if (ourview.type == VT_PER) { /* adjust distance */ |
953 |
> |
if (adjtest) { /* adjust test */ |
954 |
|
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
955 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
956 |
|
tstdist = (ourview.vaft - ourview.vfore)*sqrt(yzn2); |
957 |
|
} |
958 |
|
for (x = 0; x < hresolu; x++) |
959 |
|
if (zscan(y)[x] > tstdist) { |
960 |
< |
if (ourview.type == VT_PER) { |
960 |
> |
if (adjtest) { |
961 |
|
vx = (x+.5)/hresolu + ourview.hoff - .5; |
962 |
|
if (zscan(y)[x] <= (ourview.vaft - |
963 |
|
ourview.vfore) * |
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 |
|
} |
974 |
+ |
return(1); |
975 |
|
} |
976 |
|
|
977 |
|
|
978 |
< |
writepicture() /* write out picture */ |
978 |
> |
addblur() /* add to blurred picture */ |
979 |
|
{ |
980 |
+ |
COLOR cval; |
981 |
+ |
double d; |
982 |
+ |
register int i; |
983 |
+ |
|
984 |
+ |
if (!blurring) |
985 |
+ |
return(0); |
986 |
+ |
i = hresolu*vresolu; |
987 |
+ |
if (nvavg < 2) |
988 |
+ |
if (averaging) |
989 |
+ |
while (i--) { |
990 |
+ |
copycolor(ourbpict[i], ourspict[i]); |
991 |
+ |
d = 1.0/ourweigh[i]; |
992 |
+ |
scalecolor(ourbpict[i], d); |
993 |
+ |
} |
994 |
+ |
else |
995 |
+ |
while (i--) |
996 |
+ |
colr_color(ourbpict[i], ourpict[i]); |
997 |
+ |
else |
998 |
+ |
if (averaging) |
999 |
+ |
while (i--) { |
1000 |
+ |
copycolor(cval, ourspict[i]); |
1001 |
+ |
d = 1.0/ourweigh[i]; |
1002 |
+ |
scalecolor(cval, d); |
1003 |
+ |
addcolor(ourbpict[i], cval); |
1004 |
+ |
} |
1005 |
+ |
else |
1006 |
+ |
while (i--) { |
1007 |
+ |
colr_color(cval, ourpict[i]); |
1008 |
+ |
addcolor(ourbpict[i], cval); |
1009 |
+ |
} |
1010 |
+ |
/* print view */ |
1011 |
+ |
printf("VIEW%d:", nvavg); |
1012 |
+ |
fprintview(&ourview, stdout); |
1013 |
+ |
putchar('\n'); |
1014 |
+ |
return(1); |
1015 |
+ |
} |
1016 |
+ |
|
1017 |
+ |
|
1018 |
+ |
writepicture() /* write out picture (alters buffer) */ |
1019 |
+ |
{ |
1020 |
|
int y; |
1021 |
|
register int x; |
1022 |
|
double d; |
1023 |
|
|
1024 |
|
fprtresolu(hresolu, vresolu, stdout); |
1025 |
|
for (y = vresolu-1; y >= 0; y--) |
1026 |
< |
if (averaging) { |
1026 |
> |
if (blurring) { |
1027 |
> |
for (x = 0; x < hresolu; x++) { /* compute avg. */ |
1028 |
> |
d = rexpadj/nvavg; |
1029 |
> |
scalecolor(bscan(y)[x], d); |
1030 |
> |
} |
1031 |
> |
if (fwritescan(bscan(y), hresolu, stdout) < 0) |
1032 |
> |
syserror(progname); |
1033 |
> |
} else if (averaging) { |
1034 |
|
for (x = 0; x < hresolu; x++) { /* average pixels */ |
1035 |
< |
d = 1./wscan(y)[x]; |
1035 |
> |
d = rexpadj/wscan(y)[x]; |
1036 |
|
scalecolor(sscan(y)[x], d); |
1037 |
|
} |
1038 |
|
if (fwritescan(sscan(y), hresolu, stdout) < 0) |
1039 |
|
syserror(progname); |
1040 |
< |
} else if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
1041 |
< |
syserror(progname); |
1040 |
> |
} else { |
1041 |
> |
if (expadj) |
1042 |
> |
shiftcolrs(pscan(y), hresolu, expadj); |
1043 |
> |
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
1044 |
> |
syserror(progname); |
1045 |
> |
} |
1046 |
|
} |
1047 |
|
|
1048 |
|
|
1049 |
< |
writedistance(fname) /* write out z file */ |
1049 |
> |
writedistance(fname) /* write out z file (alters buffer) */ |
1050 |
|
char *fname; |
1051 |
|
{ |
1052 |
< |
int donorm = normdist && ourview.type == VT_PER; |
1052 |
> |
int donorm = normdist & !zisnorm ? 1 : |
1053 |
> |
(ourview.type == VT_PER) & !normdist & zisnorm ? -1 : 0; |
1054 |
|
int fd; |
1055 |
|
int y; |
871 |
– |
float *zout; |
1056 |
|
|
1057 |
|
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) |
1058 |
|
syserror(fname); |
875 |
– |
if (donorm |
876 |
– |
&& (zout = (float *)malloc(hresolu*sizeof(float))) == NULL) |
877 |
– |
syserror(progname); |
1059 |
|
for (y = vresolu-1; y >= 0; y--) { |
1060 |
|
if (donorm) { |
1061 |
< |
double vx, yzn2; |
1061 |
> |
double vx, yzn2, d; |
1062 |
|
register int x; |
1063 |
|
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
1064 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
1065 |
|
for (x = 0; x < hresolu; x++) { |
1066 |
|
vx = (x+.5)/hresolu + ourview.hoff - .5; |
1067 |
< |
zout[x] = zscan(y)[x] |
1068 |
< |
* sqrt(vx*vx*ourview.hn2 + yzn2); |
1067 |
> |
d = sqrt(vx*vx*ourview.hn2 + yzn2); |
1068 |
> |
if (donorm > 0) |
1069 |
> |
zscan(y)[x] *= d; |
1070 |
> |
else |
1071 |
> |
zscan(y)[x] /= d; |
1072 |
|
} |
1073 |
< |
} else |
1074 |
< |
zout = zscan(y); |
891 |
< |
if (write(fd, (char *)zout, hresolu*sizeof(float)) |
1073 |
> |
} |
1074 |
> |
if (write(fd, (char *)zscan(y), hresolu*sizeof(float)) |
1075 |
|
< hresolu*sizeof(float)) |
1076 |
|
syserror(fname); |
1077 |
|
} |
895 |
– |
if (donorm) |
896 |
– |
free((char *)zout); |
1078 |
|
close(fd); |
1079 |
|
} |
1080 |
|
|
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); |
959 |
< |
childpid = -1; |
1139 |
> |
close_process(&PDesc); |
1140 |
|
} |
1141 |
|
|
1142 |
|
|
1158 |
|
float fbuf[6*(PACKSIZ+1)]; |
1159 |
|
register float *fbp; |
1160 |
|
register int i; |
1161 |
+ |
double vx, vy; |
1162 |
|
|
1163 |
|
if (queuesiz == 0) |
1164 |
|
return; |
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, fbuf, fbuf, 4*sizeof(float)*queuesiz, |
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) { |
1178 |
> |
4*sizeof(float)*(queuesiz+1)) { |
1179 |
|
fprintf(stderr, "%s: error reading from rtrace process\n", |
1180 |
|
progname); |
1181 |
|
exit(1); |
1194 |
|
} else |
1195 |
|
setcolr(pscan(queue[i][1])[queue[i][0]], |
1196 |
|
fbp[0], fbp[1], fbp[2]); |
1197 |
< |
zscan(queue[i][1])[queue[i][0]] = fbp[3]; |
1197 |
> |
if (zisnorm) |
1198 |
> |
zscan(queue[i][1])[queue[i][0]] = fbp[3]; |
1199 |
> |
else { |
1200 |
> |
vx = (queue[i][0]+.5)/hresolu + ourview.hoff - .5; |
1201 |
> |
vy = (queue[i][1]+.5)/vresolu + ourview.voff - .5; |
1202 |
> |
zscan(queue[i][1])[queue[i][0]] = fbp[3] / sqrt(1. + |
1203 |
> |
vx*vx*ourview.hn2 + vy*vy*ourview.vn2); |
1204 |
> |
} |
1205 |
|
fbp += 4; |
1206 |
|
} |
1207 |
|
queuesiz = 0; |