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 "platform.h" |
16 |
+ |
#include "standard.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" |
22 |
– |
|
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) |
31 |
> |
#define zisnorm ((!usematrix) | (ourview.type != VT_PER)) |
32 |
|
|
33 |
|
#define MAXWT 1000. /* maximum pixel weight (averaging) */ |
34 |
|
|
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 |
|
|
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 */ |
74 |
|
COLOR backcolor = BLKCOLOR; /* background color (float) */ |
75 |
|
double backz = 0.0; /* background z value */ |
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 */ |
86 |
< |
#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 |
|
|
97 |
+ |
static gethfunc headline; |
98 |
|
|
99 |
+ |
|
100 |
|
main(argc, argv) /* interpolate pictures */ |
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, NULL); |
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; |
238 |
< |
if (expcomp != NULL) |
239 |
< |
if (expcomp[0] == '+' | expcomp[0] == '-') { |
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 |
+ |
} |
254 |
|
/* set view */ |
255 |
< |
if ((err = setview(&ourview)) != NULL) { |
256 |
< |
fprintf(stderr, "%s: %s\n", progname, err); |
255 |
> |
if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) { |
256 |
> |
fprintf(stderr, "%s: no view on standard input!\n", |
257 |
> |
progname); |
258 |
|
exit(1); |
259 |
|
} |
260 |
|
normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); |
262 |
|
if (doavg) { |
263 |
|
ourspict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); |
264 |
|
ourweigh = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
265 |
< |
if (ourspict == NULL | ourweigh == NULL) |
265 |
> |
if ((ourspict == NULL) | (ourweigh == NULL)) |
266 |
|
syserror(progname); |
267 |
|
} else { |
268 |
|
ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); |
269 |
|
if (ourpict == NULL) |
270 |
|
syserror(progname); |
271 |
|
} |
272 |
+ |
if (doblur) { |
273 |
+ |
ourbpict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); |
274 |
+ |
if (ourbpict == NULL) |
275 |
+ |
syserror(progname); |
276 |
+ |
} |
277 |
|
ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
278 |
|
if (ourzbuf == NULL) |
279 |
|
syserror(progname); |
263 |
– |
bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); |
280 |
|
/* new header */ |
281 |
|
newheader("RADIANCE", stdout); |
282 |
< |
/* get input */ |
283 |
< |
for ( ; i < argc; i += 2) |
284 |
< |
addpicture(argv[i], argv[i+1]); |
285 |
< |
/* fill in spaces */ |
286 |
< |
if (fillo&F_BACK) |
287 |
< |
backpicture(fillfunc, fillsamp); |
288 |
< |
else |
289 |
< |
fillpicture(fillfunc); |
282 |
> |
fputnow(stdout); |
283 |
> |
/* run pictures */ |
284 |
> |
do { |
285 |
> |
memset((char *)ourzbuf, '\0', hresolu*vresolu*sizeof(float)); |
286 |
> |
for (i = an; i < argc; i += 2) |
287 |
> |
addpicture(argv[i], argv[i+1]); |
288 |
> |
if (fillo&F_BACK) /* fill in spaces */ |
289 |
> |
backpicture(fillfunc, fillsamp); |
290 |
> |
else |
291 |
> |
fillpicture(fillfunc); |
292 |
> |
/* aft clipping */ |
293 |
> |
clipaft(); |
294 |
> |
} while (addblur() && nextview(stdin) != EOF); |
295 |
|
/* close calculation */ |
296 |
|
caldone(); |
276 |
– |
/* aft clipping */ |
277 |
– |
clipaft(); |
297 |
|
/* add to header */ |
298 |
|
printargs(argc, argv, stdout); |
299 |
< |
if (gotvfile) { |
299 |
> |
compavgview(); |
300 |
> |
if (doblur | gotvfile) { |
301 |
|
fputs(VIEWSTR, stdout); |
302 |
< |
fprintview(&ourview, stdout); |
302 |
> |
fprintview(&avgview, stdout); |
303 |
|
putc('\n', stdout); |
304 |
|
} |
305 |
< |
if (pixaspect < .99 | pixaspect > 1.01) |
305 |
> |
if ((pixaspect < .99) | (pixaspect > 1.01)) |
306 |
|
fputaspect(pixaspect, stdout); |
307 |
|
if (ourexp > 0) |
308 |
|
ourexp *= rexpadj; |
309 |
|
else |
310 |
|
ourexp = rexpadj; |
311 |
< |
if (ourexp < .995 | ourexp > 1.005) |
311 |
> |
if ((ourexp < .995) | (ourexp > 1.005)) |
312 |
|
fputexpos(ourexp, stdout); |
313 |
< |
fputformat(COLRFMT, stdout); |
313 |
> |
if (strcmp(ourfmt, PICFMT)) /* print format if known */ |
314 |
> |
fputformat(ourfmt, stdout); |
315 |
|
putc('\n', stdout); |
316 |
|
/* write picture */ |
317 |
|
writepicture(); |
322 |
|
exit(0); |
323 |
|
userr: |
324 |
|
fprintf(stderr, |
325 |
< |
"Usage: %s [view opts][-t eps][-z zout][-e spec][-a|-q][-fT][-n] pfile zspec ..\n", |
325 |
> |
"Usage: %s [view opts][-t eps][-z zout][-e spec][-B][-a|-q][-fT][-n] pfile zspec ..\n", |
326 |
|
progname); |
327 |
|
exit(1); |
328 |
|
#undef check |
329 |
|
} |
330 |
|
|
331 |
|
|
332 |
< |
headline(s) /* process header string */ |
333 |
< |
char *s; |
332 |
> |
static int |
333 |
> |
headline( /* process header string */ |
334 |
> |
char *s, |
335 |
> |
void *p |
336 |
> |
) |
337 |
|
{ |
338 |
|
char fmt[32]; |
339 |
|
|
340 |
|
if (isheadid(s)) |
341 |
< |
return; |
341 |
> |
return(0); |
342 |
|
if (formatval(fmt, s)) { |
343 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
344 |
< |
return; |
343 |
> |
if (globmatch(ourfmt, fmt)) { |
344 |
> |
wrongformat = 0; |
345 |
> |
strcpy(ourfmt, fmt); |
346 |
> |
} else |
347 |
> |
wrongformat = 1; |
348 |
> |
return(0); |
349 |
|
} |
350 |
< |
putc('\t', stdout); |
351 |
< |
fputs(s, stdout); |
352 |
< |
|
350 |
> |
if (nvavg < 2) { |
351 |
> |
putc('\t', stdout); |
352 |
> |
fputs(s, stdout); |
353 |
> |
} |
354 |
|
if (isexpos(s)) { |
355 |
|
theirexp *= exposval(s); |
356 |
< |
return; |
356 |
> |
return(0); |
357 |
|
} |
358 |
|
if (isview(s) && sscanview(&theirview, s) > 0) |
359 |
|
gotview++; |
360 |
+ |
return(0); |
361 |
|
} |
362 |
|
|
363 |
|
|
364 |
+ |
nextview(fp) /* get and set next view */ |
365 |
+ |
FILE *fp; |
366 |
+ |
{ |
367 |
+ |
char linebuf[256]; |
368 |
+ |
char *err; |
369 |
+ |
register int i; |
370 |
+ |
|
371 |
+ |
if (fp != NULL) { |
372 |
+ |
do /* get new view */ |
373 |
+ |
if (fgets(linebuf, sizeof(linebuf), fp) == NULL) |
374 |
+ |
return(EOF); |
375 |
+ |
while (!isview(linebuf) || !sscanview(&ourview, linebuf)); |
376 |
+ |
} |
377 |
+ |
/* set new view */ |
378 |
+ |
if ((err = setview(&ourview)) != NULL) { |
379 |
+ |
fprintf(stderr, "%s: %s\n", progname, err); |
380 |
+ |
exit(1); |
381 |
+ |
} |
382 |
+ |
if (!nvavg) { /* first view */ |
383 |
+ |
avgview = ourview; |
384 |
+ |
return(nvavg++); |
385 |
+ |
} |
386 |
+ |
/* add to average view */ |
387 |
+ |
for (i = 0; i < 3; i++) { |
388 |
+ |
avgview.vp[i] += ourview.vp[i]; |
389 |
+ |
avgview.vdir[i] += ourview.vdir[i]; |
390 |
+ |
avgview.vup[i] += ourview.vup[i]; |
391 |
+ |
} |
392 |
+ |
avgview.horiz += ourview.horiz; |
393 |
+ |
avgview.vert += ourview.vert; |
394 |
+ |
avgview.hoff += ourview.hoff; |
395 |
+ |
avgview.voff += ourview.voff; |
396 |
+ |
avgview.vfore += ourview.vfore; |
397 |
+ |
avgview.vaft += ourview.vaft; |
398 |
+ |
return(nvavg++); |
399 |
+ |
} |
400 |
+ |
|
401 |
+ |
|
402 |
+ |
compavgview() /* compute average view */ |
403 |
+ |
{ |
404 |
+ |
register int i; |
405 |
+ |
double f; |
406 |
+ |
|
407 |
+ |
if (nvavg < 2) |
408 |
+ |
return; |
409 |
+ |
f = 1.0/nvavg; |
410 |
+ |
for (i = 0; i < 3; i++) { |
411 |
+ |
avgview.vp[i] *= f; |
412 |
+ |
avgview.vdir[i] *= f; |
413 |
+ |
avgview.vup[i] *= f; |
414 |
+ |
} |
415 |
+ |
avgview.horiz *= f; |
416 |
+ |
avgview.vert *= f; |
417 |
+ |
avgview.hoff *= f; |
418 |
+ |
avgview.voff *= f; |
419 |
+ |
avgview.vfore *= f; |
420 |
+ |
avgview.vaft *= f; |
421 |
+ |
if (setview(&avgview) != NULL) /* in case of emergency... */ |
422 |
+ |
avgview = ourview; |
423 |
+ |
pixaspect = viewaspect(&avgview) * hresolu / vresolu; |
424 |
+ |
} |
425 |
+ |
|
426 |
+ |
|
427 |
|
addpicture(pfile, zspec) /* add picture to output */ |
428 |
|
char *pfile, *zspec; |
429 |
|
{ |
440 |
|
syserror(pfile); |
441 |
|
/* get header with exposure and view */ |
442 |
|
theirexp = 1.0; |
443 |
+ |
theirview = stdview; |
444 |
|
gotview = 0; |
445 |
< |
printf("%s:\n", pfile); |
445 |
> |
if (nvavg < 2) |
446 |
> |
printf("%s:\n", pfile); |
447 |
|
getheader(pfp, headline, NULL); |
448 |
|
if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { |
449 |
|
fprintf(stderr, "%s: picture format error\n", pfile); |
453 |
|
ourexp = theirexp; |
454 |
|
else if (ABS(theirexp-ourexp) > .01*ourexp) |
455 |
|
fprintf(stderr, "%s: different exposure (warning)\n", pfile); |
456 |
< |
if (err = setview(&theirview)) { |
456 |
> |
if ( (err = setview(&theirview)) ) { |
457 |
|
fprintf(stderr, "%s: %s\n", pfile, err); |
458 |
|
exit(1); |
459 |
|
} |
476 |
|
if (xlim == NULL) |
477 |
|
syserror(progname); |
478 |
|
if (!getperim(xlim, &ylim, zin, zfd)) { /* overlapping area? */ |
479 |
< |
free((char *)zin); |
480 |
< |
free((char *)xlim); |
479 |
> |
free((void *)zin); |
480 |
> |
free((void *)xlim); |
481 |
|
if (zfd != -1) |
482 |
|
close(zfd); |
483 |
|
fclose(pfp); |
487 |
|
scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); |
488 |
|
plast = (struct position *)calloc(scanlen(&tresolu), |
489 |
|
sizeof(struct position)); |
490 |
< |
if (scanin == NULL | plast == NULL) |
490 |
> |
if ((scanin == NULL) | (plast == NULL)) |
491 |
|
syserror(progname); |
492 |
|
/* skip to starting point */ |
493 |
|
for (y = 0; y < ylim.min; y++) |
496 |
|
exit(1); |
497 |
|
} |
498 |
|
if (zfd != -1 && lseek(zfd, |
499 |
< |
(long)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0) |
499 |
> |
(off_t)ylim.min*scanlen(&tresolu)*sizeof(float), |
500 |
> |
SEEK_SET) < 0) |
501 |
|
syserror(zspec); |
502 |
|
/* load image */ |
503 |
|
for (y = ylim.min; y <= ylim.max; y++) { |
512 |
|
addscanline(xlim+y, y, scanin, zin, plast); |
513 |
|
} |
514 |
|
/* clean up */ |
515 |
< |
free((char *)xlim); |
516 |
< |
free((char *)scanin); |
517 |
< |
free((char *)zin); |
518 |
< |
free((char *)plast); |
515 |
> |
free((void *)xlim); |
516 |
> |
free((void *)scanin); |
517 |
> |
free((void *)zin); |
518 |
> |
free((void *)plast); |
519 |
|
fclose(pfp); |
520 |
|
if (zfd != -1) |
521 |
|
close(zfd); |
528 |
|
{ |
529 |
|
double m4t[4][4]; |
530 |
|
|
531 |
< |
if (vw1->type != VT_PER && vw1->type != VT_PAR) |
531 |
> |
if ((vw1->type != VT_PER) & (vw1->type != VT_PAR)) |
532 |
|
return(0); |
533 |
< |
if (vw2->type != VT_PER && vw2->type != VT_PAR) |
533 |
> |
if ((vw2->type != VT_PER) & (vw2->type != VT_PAR)) |
534 |
|
return(0); |
535 |
|
setident4(xfmat); |
536 |
|
xfmat[0][0] = vw1->hvec[0]; |
614 |
|
s1x = p1->x - p0->x; |
615 |
|
s1y = p1->y - p0->y; |
616 |
|
l1 = ABS(s1x); |
617 |
< |
if (p1isy = (ABS(s1y) > l1)) |
617 |
> |
if ( (p1isy = (ABS(s1y) > l1)) ) |
618 |
|
l1 = ABS(s1y); |
619 |
|
else if (l1 < 1) |
620 |
|
l1 = 1; |
647 |
|
y1 = p0->y + c1*s1y/l1; |
648 |
|
for (c2 = l2; c2-- > 0; ) { |
649 |
|
x = x1 + c2*s2x/l2; |
650 |
< |
if (x < 0 || x >= hresolu) |
650 |
> |
if ((x < 0) | (x >= hresolu)) |
651 |
|
continue; |
652 |
|
y = y1 + c2*s2y/l2; |
653 |
< |
if (y < 0 || y >= vresolu) |
653 |
> |
if ((y < 0) | (y >= vresolu)) |
654 |
|
continue; |
655 |
|
if (averaging) { |
656 |
|
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
678 |
|
{ |
679 |
|
FVECT pt, tdir, odir; |
680 |
|
double d; |
585 |
– |
register int i; |
681 |
|
|
682 |
|
if (pos[2] <= 0) /* empty pixel */ |
683 |
|
return(0); |
684 |
|
if (usematrix) { |
685 |
|
pos[0] += theirview.hoff - .5; |
686 |
|
pos[1] += theirview.voff - .5; |
687 |
+ |
if (normdist & (theirview.type == VT_PER)) |
688 |
+ |
d = sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
689 |
+ |
+ pos[1]*pos[1]*theirview.vn2); |
690 |
+ |
else |
691 |
+ |
d = 1.; |
692 |
+ |
pos[2] += d*theirview.vfore; |
693 |
|
if (theirview.type == VT_PER) { |
694 |
< |
if (normdist) /* adjust distance */ |
594 |
< |
pos[2] /= sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
595 |
< |
+ pos[1]*pos[1]*theirview.vn2); |
694 |
> |
pos[2] /= d; |
695 |
|
pos[0] *= pos[2]; |
696 |
|
pos[1] *= pos[2]; |
697 |
|
} |
698 |
|
multp3(pos, pos, theirs2ours); |
699 |
< |
if (pos[2] <= 0) |
699 |
> |
if (pos[2] <= ourview.vfore) |
700 |
|
return(0); |
701 |
|
if (ourview.type == VT_PER) { |
702 |
|
pos[0] /= pos[2]; |
704 |
|
} |
705 |
|
pos[0] += .5 - ourview.hoff; |
706 |
|
pos[1] += .5 - ourview.voff; |
707 |
+ |
pos[2] -= ourview.vfore; |
708 |
|
} else { |
709 |
|
if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) |
710 |
|
return(0); |
711 |
< |
if (!normdist & theirview.type == VT_PER) /* adjust */ |
711 |
> |
if ((!normdist) & (theirview.type == VT_PER)) /* adjust */ |
712 |
|
pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
713 |
|
+ pos[1]*pos[1]*theirview.vn2); |
714 |
|
pt[0] += tdir[0]*pos[2]; |
718 |
|
if (pos[2] <= 0) |
719 |
|
return(0); |
720 |
|
} |
721 |
< |
if (pos[0] < 0 || pos[0] >= 1-FTINY || pos[1] < 0 || pos[1] >= 1-FTINY) |
721 |
> |
if ((pos[0] < 0) | (pos[0] >= 1-FTINY) | (pos[1] < 0) | (pos[1] >= 1-FTINY)) |
722 |
|
return(0); |
723 |
|
if (!averaging) |
724 |
|
return(1); |
725 |
< |
if (ourview.type == VT_PAR) /* compute our direction */ |
726 |
< |
VCOPY(odir, ourview.vdir); |
727 |
< |
else |
728 |
< |
for (i = 0; i < 3; i++) |
729 |
< |
odir[i] = (pt[i] - ourview.vp[i])/pos[2]; |
730 |
< |
d = DOT(odir,tdir); /* compute pixel weight */ |
731 |
< |
if (d >= 1.-1./MAXWT/MAXWT) |
725 |
> |
/* compute pixel weight */ |
726 |
> |
if (ourview.type == VT_PAR) { |
727 |
> |
d = DOT(ourview.vdir,tdir); |
728 |
> |
d = 1. - d*d; |
729 |
> |
} else { |
730 |
> |
VSUB(odir, pt, ourview.vp); |
731 |
> |
d = DOT(odir,tdir); |
732 |
> |
d = 1. - d*d/DOT(odir,odir); |
733 |
> |
} |
734 |
> |
if (d <= 1./MAXWT/MAXWT) |
735 |
|
return(MAXWT); /* clip to maximum weight */ |
736 |
< |
return(1./sqrt(1.-d)); |
736 |
> |
return(1./sqrt(d)); |
737 |
|
} |
738 |
|
|
739 |
|
|
764 |
|
yl->min = 32000; yl->max = 0; /* search for points on image */ |
765 |
|
for (y = step - 1; y < numscans(&tresolu); y += step) { |
766 |
|
if (zfd != -1) { |
767 |
< |
if (lseek(zfd, (long)y*scanlen(&tresolu)*sizeof(float), |
768 |
< |
0) < 0) |
767 |
> |
if (lseek(zfd, (off_t)y*scanlen(&tresolu)*sizeof(float), |
768 |
> |
SEEK_SET) < 0) |
769 |
|
syserror("lseek"); |
770 |
|
if (read(zfd, (char *)zline, |
771 |
|
scanlen(&tresolu)*sizeof(float)) |
810 |
|
xl[y-1].max = xl[y-step].max; |
811 |
|
} |
812 |
|
for (x = 2; x < step; x++) |
813 |
< |
copystruct(xl+y-x, xl+y-1); |
813 |
> |
*(xl+y-x) = *(xl+y-1); |
814 |
|
} |
815 |
|
if (yl->max >= numscans(&tresolu)) |
816 |
|
yl->max = numscans(&tresolu) - 1; |
817 |
|
y -= step; |
818 |
|
for (x = numscans(&tresolu) - 1; x > y; x--) /* fill bottom rows */ |
819 |
< |
copystruct(xl+x, xl+y); |
819 |
> |
*(xl+x) = *(xl+y); |
820 |
|
return(yl->max >= yl->min); |
821 |
|
} |
822 |
|
|
925 |
|
xback = -2; |
926 |
|
} |
927 |
|
} |
928 |
< |
free((char *)yback); |
928 |
> |
free((void *)yback); |
929 |
|
} |
930 |
|
|
931 |
|
|
938 |
|
for (x = 0; x < hresolu; x++) |
939 |
|
if (zscan(y)[x] <= 0) |
940 |
|
(*fill)(x,y); |
941 |
+ |
if (fill == rcalfill) |
942 |
+ |
clearqueue(); |
943 |
|
} |
944 |
|
|
945 |
|
|
946 |
|
clipaft() /* perform aft clipping as indicated */ |
947 |
|
{ |
948 |
|
register int x, y; |
949 |
< |
int adjtest = ourview.type == VT_PER & zisnorm; |
949 |
> |
int adjtest = (ourview.type == VT_PER) & zisnorm; |
950 |
|
double tstdist; |
951 |
|
double yzn2, vx; |
952 |
|
|
953 |
|
if (ourview.vaft <= FTINY) |
954 |
< |
return; |
954 |
> |
return(0); |
955 |
|
tstdist = ourview.vaft - ourview.vfore; |
956 |
|
for (y = 0; y < vresolu; y++) { |
957 |
|
if (adjtest) { /* adjust test */ |
969 |
|
continue; |
970 |
|
} |
971 |
|
if (averaging) |
972 |
< |
bzero(sscan(y)[x], sizeof(COLOR)); |
972 |
> |
memset(sscan(y)[x], '\0', sizeof(COLOR)); |
973 |
|
else |
974 |
< |
bzero(pscan(y)[x], sizeof(COLR)); |
974 |
> |
memset(pscan(y)[x], '\0', sizeof(COLR)); |
975 |
|
zscan(y)[x] = 0.0; |
976 |
|
} |
977 |
|
} |
978 |
+ |
return(1); |
979 |
|
} |
980 |
|
|
981 |
|
|
982 |
+ |
addblur() /* add to blurred picture */ |
983 |
+ |
{ |
984 |
+ |
COLOR cval; |
985 |
+ |
double d; |
986 |
+ |
register int i; |
987 |
+ |
|
988 |
+ |
if (!blurring) |
989 |
+ |
return(0); |
990 |
+ |
i = hresolu*vresolu; |
991 |
+ |
if (nvavg < 2) |
992 |
+ |
if (averaging) |
993 |
+ |
while (i--) { |
994 |
+ |
copycolor(ourbpict[i], ourspict[i]); |
995 |
+ |
d = 1.0/ourweigh[i]; |
996 |
+ |
scalecolor(ourbpict[i], d); |
997 |
+ |
} |
998 |
+ |
else |
999 |
+ |
while (i--) |
1000 |
+ |
colr_color(ourbpict[i], ourpict[i]); |
1001 |
+ |
else |
1002 |
+ |
if (averaging) |
1003 |
+ |
while (i--) { |
1004 |
+ |
copycolor(cval, ourspict[i]); |
1005 |
+ |
d = 1.0/ourweigh[i]; |
1006 |
+ |
scalecolor(cval, d); |
1007 |
+ |
addcolor(ourbpict[i], cval); |
1008 |
+ |
} |
1009 |
+ |
else |
1010 |
+ |
while (i--) { |
1011 |
+ |
colr_color(cval, ourpict[i]); |
1012 |
+ |
addcolor(ourbpict[i], cval); |
1013 |
+ |
} |
1014 |
+ |
/* print view */ |
1015 |
+ |
printf("VIEW%d:", nvavg); |
1016 |
+ |
fprintview(&ourview, stdout); |
1017 |
+ |
putchar('\n'); |
1018 |
+ |
return(1); |
1019 |
+ |
} |
1020 |
+ |
|
1021 |
+ |
|
1022 |
|
writepicture() /* write out picture (alters buffer) */ |
1023 |
|
{ |
1024 |
|
int y; |
1027 |
|
|
1028 |
|
fprtresolu(hresolu, vresolu, stdout); |
1029 |
|
for (y = vresolu-1; y >= 0; y--) |
1030 |
< |
if (averaging) { |
1030 |
> |
if (blurring) { |
1031 |
> |
for (x = 0; x < hresolu; x++) { /* compute avg. */ |
1032 |
> |
d = rexpadj/nvavg; |
1033 |
> |
scalecolor(bscan(y)[x], d); |
1034 |
> |
} |
1035 |
> |
if (fwritescan(bscan(y), hresolu, stdout) < 0) |
1036 |
> |
syserror(progname); |
1037 |
> |
} else if (averaging) { |
1038 |
|
for (x = 0; x < hresolu; x++) { /* average pixels */ |
1039 |
|
d = rexpadj/wscan(y)[x]; |
1040 |
|
scalecolor(sscan(y)[x], d); |
1054 |
|
char *fname; |
1055 |
|
{ |
1056 |
|
int donorm = normdist & !zisnorm ? 1 : |
1057 |
< |
ourview.type == VT_PER & !normdist & zisnorm ? -1 : 0; |
1057 |
> |
(ourview.type == VT_PER) & !normdist & zisnorm ? -1 : 0; |
1058 |
|
int fd; |
1059 |
|
int y; |
1060 |
|
|
1103 |
|
int rval; |
1104 |
|
register char **wp, *cp; |
1105 |
|
|
1106 |
< |
if (childpid != -1) { |
1106 |
> |
if (PDesc.running) { |
1107 |
|
fprintf(stderr, "%s: too many calculations\n", progname); |
1108 |
|
exit(1); |
1109 |
|
} |
1122 |
|
} |
1123 |
|
*wp = NULL; |
1124 |
|
/* start process */ |
1125 |
< |
if ((rval = open_process(PDesc, argv)) < 0) |
1125 |
> |
if ((rval = open_process(&PDesc, argv)) < 0) |
1126 |
|
syserror(progname); |
1127 |
|
if (rval == 0) { |
1128 |
|
fprintf(stderr, "%s: command not found\n", argv[0]); |
1137 |
|
|
1138 |
|
caldone() /* done with calculation */ |
1139 |
|
{ |
1140 |
< |
if (childpid == -1) |
1140 |
> |
if (!PDesc.running) |
1141 |
|
return; |
1142 |
|
clearqueue(); |
1143 |
< |
close_process(PDesc); |
991 |
< |
childpid = -1; |
1143 |
> |
close_process(&PDesc); |
1144 |
|
} |
1145 |
|
|
1146 |
|
|
1175 |
|
*fbp++ = dir[0]; *fbp++ = dir[1]; *fbp++ = dir[2]; |
1176 |
|
} |
1177 |
|
/* mark end and get results */ |
1178 |
< |
bzero((char *)fbp, 6*sizeof(float)); |
1179 |
< |
if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*queuesiz, |
1178 |
> |
memset((char *)fbp, '\0', 6*sizeof(float)); |
1179 |
> |
if (process(&PDesc, (char *)fbuf, (char *)fbuf, |
1180 |
> |
4*sizeof(float)*(queuesiz+1), |
1181 |
|
6*sizeof(float)*(queuesiz+1)) != |
1182 |
< |
4*sizeof(float)*queuesiz) { |
1182 |
> |
4*sizeof(float)*(queuesiz+1)) { |
1183 |
|
fprintf(stderr, "%s: error reading from rtrace process\n", |
1184 |
|
progname); |
1185 |
|
exit(1); |