1 |
– |
/* Copyright (c) 1991 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 |
|
|
15 |
– |
#include <fcntl.h> |
16 |
– |
|
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" |
20 |
– |
|
18 |
|
#include "color.h" |
19 |
|
|
20 |
< |
#include "resolu.h" |
20 |
> |
#define LOG2 0.69314718055994530942 |
21 |
|
|
25 |
– |
#ifndef BSD |
26 |
– |
#define vfork fork |
27 |
– |
#endif |
28 |
– |
|
22 |
|
#define pscan(y) (ourpict+(y)*hresolu) |
23 |
+ |
#define sscan(y) (ourspict+(y)*hresolu) |
24 |
+ |
#define wscan(y) (ourweigh+(y)*hresolu) |
25 |
|
#define zscan(y) (ourzbuf+(y)*hresolu) |
26 |
+ |
#define bscan(y) (ourbpict+(y)*hresolu) |
27 |
+ |
#define averaging (ourweigh != NULL) |
28 |
+ |
#define blurring (ourbpict != NULL) |
29 |
+ |
#define usematrix (hasmatrix & !averaging) |
30 |
+ |
#define zisnorm ((!usematrix) | (ourview.type != VT_PER)) |
31 |
|
|
32 |
+ |
#define MAXWT 1000. /* maximum pixel weight (averaging) */ |
33 |
+ |
|
34 |
|
#define F_FORE 1 /* fill foreground */ |
35 |
|
#define F_BACK 2 /* fill background */ |
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 |
|
|
43 |
|
struct position {int x,y; float z;}; |
44 |
|
|
45 |
+ |
#define NSTEPS 64 /* number steps in overlap prescan */ |
46 |
+ |
#define MINSTEP 4 /* minimum worthwhile preview step */ |
47 |
+ |
|
48 |
+ |
struct bound {int min,max;}; |
49 |
+ |
|
50 |
|
VIEW ourview = STDVIEW; /* desired view */ |
51 |
|
int hresolu = 512; /* horizontal resolution */ |
52 |
|
int vresolu = 512; /* vertical resolution */ |
54 |
|
|
55 |
|
double zeps = .02; /* allowed z epsilon */ |
56 |
|
|
57 |
< |
COLR *ourpict; /* output picture */ |
57 |
> |
COLR *ourpict; /* output picture (COLR's) */ |
58 |
> |
COLOR *ourspict; /* output pixel sums (averaging) */ |
59 |
> |
float *ourweigh = NULL; /* output pixel weights (averaging) */ |
60 |
|
float *ourzbuf; /* corresponding z-buffer */ |
61 |
+ |
COLOR *ourbpict = NULL; /* blurred picture (view averaging) */ |
62 |
|
|
63 |
+ |
VIEW avgview; /* average view for -B option */ |
64 |
+ |
int nvavg; /* number of views averaged */ |
65 |
+ |
|
66 |
|
char *progname; |
67 |
|
|
68 |
|
int fillo = F_FORE|F_BACK; /* selected fill options */ |
70 |
|
extern int backfill(), rcalfill(); /* fill functions */ |
71 |
|
int (*fillfunc)() = backfill; /* selected fill function */ |
72 |
|
COLR backcolr = BLKCOLR; /* background color */ |
73 |
+ |
COLOR backcolor = BLKCOLOR; /* background color (float) */ |
74 |
|
double backz = 0.0; /* background z value */ |
75 |
< |
int normdist = 1; /* normalized distance? */ |
76 |
< |
double ourexp = -1; /* output picture exposure */ |
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 */ |
80 |
|
|
81 |
< |
VIEW theirview = STDVIEW; /* input view */ |
81 |
> |
VIEW theirview; /* input view */ |
82 |
|
int gotview; /* got input view? */ |
83 |
|
int wrongformat = 0; /* input in another format? */ |
84 |
|
RESOLU tresolu; /* input resolution */ |
85 |
|
double theirexp; /* input picture exposure */ |
86 |
< |
double theirs2ours[4][4]; /* transformation matrix */ |
86 |
> |
MAT4 theirs2ours; /* transformation matrix */ |
87 |
|
int hasmatrix = 0; /* has transformation matrix */ |
88 |
|
|
89 |
< |
int PDesc[3] = {-1,-1,-1}; /* rtrace process descriptor */ |
73 |
< |
#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 |
|
|
96 |
+ |
|
97 |
|
main(argc, argv) /* interpolate pictures */ |
98 |
|
int argc; |
99 |
|
char *argv[]; |
100 |
|
{ |
101 |
< |
#define check(ol,al) if (argv[i][ol] || \ |
102 |
< |
badarg(argc-i-1,argv+i+1,al)) \ |
101 |
> |
#define check(ol,al) if (argv[an][ol] || \ |
102 |
> |
badarg(argc-an-1,argv+an+1,al)) \ |
103 |
|
goto badopt |
104 |
|
int gotvfile = 0; |
105 |
+ |
int doavg = -1; |
106 |
+ |
int doblur = 0; |
107 |
|
char *zfile = NULL; |
108 |
< |
char *err; |
109 |
< |
int i, rval; |
108 |
> |
char *expcomp = NULL; |
109 |
> |
int i, an, rval; |
110 |
|
|
111 |
|
progname = argv[0]; |
112 |
|
|
113 |
< |
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
114 |
< |
rval = getviewopt(&ourview, argc-i, argv+i); |
113 |
> |
for (an = 1; an < argc && argv[an][0] == '-'; an++) { |
114 |
> |
rval = getviewopt(&ourview, argc-an, argv+an); |
115 |
|
if (rval >= 0) { |
116 |
< |
i += rval; |
116 |
> |
an += rval; |
117 |
|
continue; |
118 |
|
} |
119 |
< |
switch (argv[i][1]) { |
119 |
> |
switch (argv[an][1]) { |
120 |
> |
case 'e': /* exposure */ |
121 |
> |
check(2,"f"); |
122 |
> |
expcomp = argv[++an]; |
123 |
> |
break; |
124 |
|
case 't': /* threshold */ |
125 |
|
check(2,"f"); |
126 |
< |
zeps = atof(argv[++i]); |
126 |
> |
zeps = atof(argv[++an]); |
127 |
|
break; |
128 |
+ |
case 'a': /* average */ |
129 |
+ |
check(2,NULL); |
130 |
+ |
doavg = 1; |
131 |
+ |
break; |
132 |
+ |
case 'B': /* blur views */ |
133 |
+ |
check(2,NULL); |
134 |
+ |
doblur = 1; |
135 |
+ |
break; |
136 |
+ |
case 'q': /* quick (no avg.) */ |
137 |
+ |
check(2,NULL); |
138 |
+ |
doavg = 0; |
139 |
+ |
break; |
140 |
|
case 'n': /* dist. normalized? */ |
141 |
|
check(2,NULL); |
142 |
|
normdist = !normdist; |
143 |
|
break; |
144 |
|
case 'f': /* fill type */ |
145 |
< |
switch (argv[i][2]) { |
145 |
> |
switch (argv[an][2]) { |
146 |
|
case '0': /* none */ |
147 |
|
check(3,NULL); |
148 |
|
fillo = 0; |
161 |
|
break; |
162 |
|
case 's': /* sample */ |
163 |
|
check(3,"i"); |
164 |
< |
fillsamp = atoi(argv[++i]); |
164 |
> |
fillsamp = atoi(argv[++an]); |
165 |
|
break; |
166 |
|
case 'c': /* color */ |
167 |
|
check(3,"fff"); |
168 |
|
fillfunc = backfill; |
169 |
< |
setcolr(backcolr, atof(argv[i+1]), |
170 |
< |
atof(argv[i+2]), atof(argv[i+3])); |
171 |
< |
i += 3; |
169 |
> |
setcolor(backcolor, atof(argv[an+1]), |
170 |
> |
atof(argv[an+2]), atof(argv[an+3])); |
171 |
> |
setcolr(backcolr, colval(backcolor,RED), |
172 |
> |
colval(backcolor,GRN), |
173 |
> |
colval(backcolor,BLU)); |
174 |
> |
an += 3; |
175 |
|
break; |
176 |
|
case 'z': /* z value */ |
177 |
|
check(3,"f"); |
178 |
|
fillfunc = backfill; |
179 |
< |
backz = atof(argv[++i]); |
179 |
> |
backz = atof(argv[++an]); |
180 |
|
break; |
181 |
|
case 'r': /* rtrace */ |
182 |
|
check(3,"s"); |
183 |
|
fillfunc = rcalfill; |
184 |
< |
calstart(RTCOM, argv[++i]); |
184 |
> |
calstart(RTCOM, argv[++an]); |
185 |
|
break; |
186 |
|
default: |
187 |
|
goto badopt; |
189 |
|
break; |
190 |
|
case 'z': /* z file */ |
191 |
|
check(2,"s"); |
192 |
< |
zfile = argv[++i]; |
192 |
> |
zfile = argv[++an]; |
193 |
|
break; |
194 |
|
case 'x': /* x resolution */ |
195 |
|
check(2,"i"); |
196 |
< |
hresolu = atoi(argv[++i]); |
196 |
> |
hresolu = atoi(argv[++an]); |
197 |
|
break; |
198 |
|
case 'y': /* y resolution */ |
199 |
|
check(2,"i"); |
200 |
< |
vresolu = atoi(argv[++i]); |
200 |
> |
vresolu = atoi(argv[++an]); |
201 |
|
break; |
202 |
|
case 'p': /* pixel aspect */ |
203 |
< |
check(2,"f"); |
204 |
< |
pixaspect = atof(argv[++i]); |
203 |
> |
if (argv[an][2] != 'a') |
204 |
> |
goto badopt; |
205 |
> |
check(3,"f"); |
206 |
> |
pixaspect = atof(argv[++an]); |
207 |
|
break; |
208 |
|
case 'v': /* view file */ |
209 |
< |
if (argv[i][2] != 'f') |
209 |
> |
if (argv[an][2] != 'f') |
210 |
|
goto badopt; |
211 |
|
check(3,"s"); |
212 |
< |
gotvfile = viewfile(argv[++i], &ourview, 0, 0); |
213 |
< |
if (gotvfile < 0) { |
214 |
< |
perror(argv[i]); |
215 |
< |
exit(1); |
175 |
< |
} else if (gotvfile == 0) { |
212 |
> |
gotvfile = viewfile(argv[++an], &ourview, NULL); |
213 |
> |
if (gotvfile < 0) |
214 |
> |
syserror(argv[an]); |
215 |
> |
else if (gotvfile == 0) { |
216 |
|
fprintf(stderr, "%s: bad view file\n", |
217 |
< |
argv[i]); |
217 |
> |
argv[an]); |
218 |
|
exit(1); |
219 |
|
} |
220 |
|
break; |
221 |
|
default: |
222 |
|
badopt: |
223 |
|
fprintf(stderr, "%s: command line error at '%s'\n", |
224 |
< |
progname, argv[i]); |
224 |
> |
progname, argv[an]); |
225 |
|
goto userr; |
226 |
|
} |
227 |
|
} |
228 |
|
/* check arguments */ |
229 |
< |
if ((argc-i)%2) |
229 |
> |
if ((argc-an)%2) |
230 |
|
goto userr; |
231 |
|
if (fillsamp == 1) |
232 |
|
fillo &= ~F_BACK; |
233 |
+ |
if (doavg < 0) |
234 |
+ |
doavg = (argc-an) > 2; |
235 |
+ |
if (expcomp != NULL) { |
236 |
+ |
if ((expcomp[0] == '+') | (expcomp[0] == '-')) { |
237 |
+ |
expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5); |
238 |
+ |
if (doavg | doblur) |
239 |
+ |
rexpadj = pow(2.0, atof(expcomp)); |
240 |
+ |
else |
241 |
+ |
rexpadj = pow(2.0, (double)expadj); |
242 |
+ |
} else { |
243 |
+ |
if (!isflt(expcomp)) |
244 |
+ |
goto userr; |
245 |
+ |
rexpadj = atof(expcomp); |
246 |
+ |
expadj = log(rexpadj)/LOG2 + (rexpadj>1 ? .5 : -.5); |
247 |
+ |
if (!(doavg | doblur)) |
248 |
+ |
rexpadj = pow(2.0, (double)expadj); |
249 |
+ |
} |
250 |
+ |
} |
251 |
|
/* set view */ |
252 |
< |
if (err = setview(&ourview)) { |
253 |
< |
fprintf(stderr, "%s: %s\n", progname, err); |
252 |
> |
if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) { |
253 |
> |
fprintf(stderr, "%s: no view on standard input!\n", |
254 |
> |
progname); |
255 |
|
exit(1); |
256 |
|
} |
257 |
|
normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); |
258 |
|
/* allocate frame */ |
259 |
< |
ourpict = (COLR *)malloc(hresolu*vresolu*sizeof(COLR)); |
260 |
< |
ourzbuf = (float *)calloc(hresolu*vresolu,sizeof(float)); |
261 |
< |
if (ourpict == NULL || ourzbuf == NULL) |
262 |
< |
syserror(); |
263 |
< |
/* get input */ |
264 |
< |
for ( ; i < argc; i += 2) |
265 |
< |
addpicture(argv[i], argv[i+1]); |
266 |
< |
/* fill in spaces */ |
267 |
< |
if (fillo&F_BACK) |
268 |
< |
backpicture(fillfunc, fillsamp); |
269 |
< |
else |
270 |
< |
fillpicture(fillfunc); |
259 |
> |
if (doavg) { |
260 |
> |
ourspict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); |
261 |
> |
ourweigh = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
262 |
> |
if ((ourspict == NULL) | (ourweigh == NULL)) |
263 |
> |
syserror(progname); |
264 |
> |
} else { |
265 |
> |
ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); |
266 |
> |
if (ourpict == NULL) |
267 |
> |
syserror(progname); |
268 |
> |
} |
269 |
> |
if (doblur) { |
270 |
> |
ourbpict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); |
271 |
> |
if (ourbpict == NULL) |
272 |
> |
syserror(progname); |
273 |
> |
} |
274 |
> |
ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
275 |
> |
if (ourzbuf == NULL) |
276 |
> |
syserror(progname); |
277 |
> |
/* new header */ |
278 |
> |
newheader("RADIANCE", stdout); |
279 |
> |
fputnow(stdout); |
280 |
> |
/* run pictures */ |
281 |
> |
do { |
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 */ |
286 |
> |
backpicture(fillfunc, fillsamp); |
287 |
> |
else |
288 |
> |
fillpicture(fillfunc); |
289 |
> |
/* aft clipping */ |
290 |
> |
clipaft(); |
291 |
> |
} while (addblur() && nextview(stdin) != EOF); |
292 |
|
/* close calculation */ |
293 |
|
caldone(); |
294 |
|
/* add to header */ |
295 |
|
printargs(argc, argv, stdout); |
296 |
< |
if (gotvfile) { |
296 |
> |
compavgview(); |
297 |
> |
if (doblur | gotvfile) { |
298 |
|
fputs(VIEWSTR, stdout); |
299 |
< |
fprintview(&ourview, stdout); |
299 |
> |
fprintview(&avgview, stdout); |
300 |
|
putc('\n', stdout); |
301 |
|
} |
302 |
< |
if (pixaspect < .99 || pixaspect > 1.01) |
302 |
> |
if ((pixaspect < .99) | (pixaspect > 1.01)) |
303 |
|
fputaspect(pixaspect, stdout); |
304 |
< |
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
304 |
> |
if (ourexp > 0) |
305 |
> |
ourexp *= rexpadj; |
306 |
> |
else |
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(); |
319 |
|
exit(0); |
320 |
|
userr: |
321 |
|
fprintf(stderr, |
322 |
< |
"Usage: %s [view opts][-t eps][-z zout][-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 |
326 |
|
} |
327 |
|
|
328 |
|
|
329 |
+ |
int |
330 |
|
headline(s) /* process header string */ |
331 |
|
char *s; |
332 |
|
{ |
333 |
|
char fmt[32]; |
334 |
|
|
335 |
< |
if (isformat(s)) { |
336 |
< |
formatval(fmt, s); |
337 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
338 |
< |
return; |
335 |
> |
if (isheadid(s)) |
336 |
> |
return(0); |
337 |
> |
if (formatval(fmt, s)) { |
338 |
> |
if (globmatch(ourfmt, fmt)) { |
339 |
> |
wrongformat = 0; |
340 |
> |
strcpy(ourfmt, fmt); |
341 |
> |
} else |
342 |
> |
wrongformat = 1; |
343 |
> |
return(0); |
344 |
|
} |
345 |
< |
putc('\t', stdout); |
346 |
< |
fputs(s, stdout); |
347 |
< |
|
345 |
> |
if (nvavg < 2) { |
346 |
> |
putc('\t', stdout); |
347 |
> |
fputs(s, 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 |
|
|
359 |
+ |
nextview(fp) /* get and set next view */ |
360 |
+ |
FILE *fp; |
361 |
+ |
{ |
362 |
+ |
char linebuf[256]; |
363 |
+ |
char *err; |
364 |
+ |
register int i; |
365 |
+ |
|
366 |
+ |
if (fp != NULL) { |
367 |
+ |
do /* get new view */ |
368 |
+ |
if (fgets(linebuf, sizeof(linebuf), fp) == NULL) |
369 |
+ |
return(EOF); |
370 |
+ |
while (!isview(linebuf) || !sscanview(&ourview, linebuf)); |
371 |
+ |
} |
372 |
+ |
/* set new view */ |
373 |
+ |
if ((err = setview(&ourview)) != NULL) { |
374 |
+ |
fprintf(stderr, "%s: %s\n", progname, err); |
375 |
+ |
exit(1); |
376 |
+ |
} |
377 |
+ |
if (!nvavg) { /* first view */ |
378 |
+ |
avgview = ourview; |
379 |
+ |
return(nvavg++); |
380 |
+ |
} |
381 |
+ |
/* add to average view */ |
382 |
+ |
for (i = 0; i < 3; i++) { |
383 |
+ |
avgview.vp[i] += ourview.vp[i]; |
384 |
+ |
avgview.vdir[i] += ourview.vdir[i]; |
385 |
+ |
avgview.vup[i] += ourview.vup[i]; |
386 |
+ |
} |
387 |
+ |
avgview.horiz += ourview.horiz; |
388 |
+ |
avgview.vert += ourview.vert; |
389 |
+ |
avgview.hoff += ourview.hoff; |
390 |
+ |
avgview.voff += ourview.voff; |
391 |
+ |
avgview.vfore += ourview.vfore; |
392 |
+ |
avgview.vaft += ourview.vaft; |
393 |
+ |
return(nvavg++); |
394 |
+ |
} |
395 |
+ |
|
396 |
+ |
|
397 |
+ |
compavgview() /* compute average view */ |
398 |
+ |
{ |
399 |
+ |
register int i; |
400 |
+ |
double f; |
401 |
+ |
|
402 |
+ |
if (nvavg < 2) |
403 |
+ |
return; |
404 |
+ |
f = 1.0/nvavg; |
405 |
+ |
for (i = 0; i < 3; i++) { |
406 |
+ |
avgview.vp[i] *= f; |
407 |
+ |
avgview.vdir[i] *= f; |
408 |
+ |
avgview.vup[i] *= f; |
409 |
+ |
} |
410 |
+ |
avgview.horiz *= f; |
411 |
+ |
avgview.vert *= f; |
412 |
+ |
avgview.hoff *= f; |
413 |
+ |
avgview.voff *= f; |
414 |
+ |
avgview.vfore *= f; |
415 |
+ |
avgview.vaft *= f; |
416 |
+ |
if (setview(&avgview) != NULL) /* in case of emergency... */ |
417 |
+ |
avgview = ourview; |
418 |
+ |
pixaspect = viewaspect(&avgview) * hresolu / vresolu; |
419 |
+ |
} |
420 |
+ |
|
421 |
+ |
|
422 |
|
addpicture(pfile, zspec) /* add picture to output */ |
423 |
|
char *pfile, *zspec; |
424 |
|
{ |
428 |
|
COLR *scanin; |
429 |
|
float *zin; |
430 |
|
struct position *plast; |
431 |
+ |
struct bound *xlim, ylim; |
432 |
|
int y; |
433 |
|
/* open picture file */ |
434 |
< |
if ((pfp = fopen(pfile, "r")) == NULL) { |
435 |
< |
perror(pfile); |
278 |
< |
exit(1); |
279 |
< |
} |
434 |
> |
if ((pfp = fopen(pfile, "r")) == NULL) |
435 |
> |
syserror(pfile); |
436 |
|
/* get header with exposure and view */ |
437 |
|
theirexp = 1.0; |
438 |
+ |
theirview = stdview; |
439 |
|
gotview = 0; |
440 |
< |
printf("%s:\n", pfile); |
440 |
> |
if (nvavg < 2) |
441 |
> |
printf("%s:\n", pfile); |
442 |
|
getheader(pfp, headline, NULL); |
443 |
|
if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { |
444 |
|
fprintf(stderr, "%s: picture format error\n", pfile); |
448 |
|
ourexp = theirexp; |
449 |
|
else if (ABS(theirexp-ourexp) > .01*ourexp) |
450 |
|
fprintf(stderr, "%s: different exposure (warning)\n", pfile); |
451 |
< |
if (err = setview(&theirview)) { |
451 |
> |
if ( (err = setview(&theirview)) ) { |
452 |
|
fprintf(stderr, "%s: %s\n", pfile, err); |
453 |
|
exit(1); |
454 |
|
} |
455 |
|
/* compute transformation */ |
456 |
|
hasmatrix = pixform(theirs2ours, &theirview, &ourview); |
299 |
– |
/* allocate scanlines */ |
300 |
– |
scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); |
301 |
– |
zin = (float *)malloc(scanlen(&tresolu)*sizeof(float)); |
302 |
– |
plast = (struct position *)calloc(scanlen(&tresolu), |
303 |
– |
sizeof(struct position)); |
304 |
– |
if (scanin == NULL || zin == NULL || plast == NULL) |
305 |
– |
syserror(); |
457 |
|
/* get z specification or file */ |
458 |
+ |
zin = (float *)malloc(scanlen(&tresolu)*sizeof(float)); |
459 |
+ |
if (zin == NULL) |
460 |
+ |
syserror(progname); |
461 |
|
if ((zfd = open(zspec, O_RDONLY)) == -1) { |
462 |
|
double zvalue; |
463 |
|
register int x; |
464 |
< |
if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) { |
465 |
< |
perror(zspec); |
312 |
< |
exit(1); |
313 |
< |
} |
464 |
> |
if (!isflt(zspec) || (zvalue = atof(zspec)) <= 0.0) |
465 |
> |
syserror(zspec); |
466 |
|
for (x = scanlen(&tresolu); x-- > 0; ) |
467 |
|
zin[x] = zvalue; |
468 |
|
} |
469 |
< |
/* load image */ |
470 |
< |
for (y = 0; y < numscans(&tresolu); y++) { |
469 |
> |
/* compute transferrable perimeter */ |
470 |
> |
xlim = (struct bound *)malloc(numscans(&tresolu)*sizeof(struct bound)); |
471 |
> |
if (xlim == NULL) |
472 |
> |
syserror(progname); |
473 |
> |
if (!getperim(xlim, &ylim, zin, zfd)) { /* overlapping area? */ |
474 |
> |
free((void *)zin); |
475 |
> |
free((void *)xlim); |
476 |
> |
if (zfd != -1) |
477 |
> |
close(zfd); |
478 |
> |
fclose(pfp); |
479 |
> |
return; |
480 |
> |
} |
481 |
> |
/* allocate scanlines */ |
482 |
> |
scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); |
483 |
> |
plast = (struct position *)calloc(scanlen(&tresolu), |
484 |
> |
sizeof(struct position)); |
485 |
> |
if ((scanin == NULL) | (plast == NULL)) |
486 |
> |
syserror(progname); |
487 |
> |
/* skip to starting point */ |
488 |
> |
for (y = 0; y < ylim.min; y++) |
489 |
|
if (freadcolrs(scanin, scanlen(&tresolu), pfp) < 0) { |
490 |
|
fprintf(stderr, "%s: read error\n", pfile); |
491 |
|
exit(1); |
492 |
|
} |
493 |
< |
if (zfd != -1 && read(zfd,(char *)zin, |
494 |
< |
scanlen(&tresolu)*sizeof(float)) |
495 |
< |
< scanlen(&tresolu)*sizeof(float)) { |
496 |
< |
fprintf(stderr, "%s: read error\n", zspec); |
493 |
> |
if (zfd != -1 && lseek(zfd, |
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++) { |
498 |
> |
if (freadcolrs(scanin, scanlen(&tresolu), pfp) < 0) { |
499 |
> |
fprintf(stderr, "%s: read error\n", pfile); |
500 |
|
exit(1); |
501 |
|
} |
502 |
< |
addscanline(y, scanin, zin, plast); |
502 |
> |
if (zfd != -1 && read(zfd, (char *)zin, |
503 |
> |
scanlen(&tresolu)*sizeof(float)) |
504 |
> |
< scanlen(&tresolu)*sizeof(float)) |
505 |
> |
syserror(zspec); |
506 |
> |
addscanline(xlim+y, y, scanin, zin, plast); |
507 |
|
} |
508 |
|
/* clean up */ |
509 |
< |
free((char *)scanin); |
510 |
< |
free((char *)zin); |
511 |
< |
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); |
517 |
|
|
518 |
|
|
519 |
|
pixform(xfmat, vw1, vw2) /* compute view1 to view2 matrix */ |
520 |
< |
register double xfmat[4][4]; |
520 |
> |
register MAT4 xfmat; |
521 |
|
register VIEW *vw1, *vw2; |
522 |
|
{ |
523 |
|
double m4t[4][4]; |
524 |
|
|
525 |
< |
if (vw1->type != VT_PER && vw1->type != VT_PAR) |
525 |
> |
if ((vw1->type != VT_PER) & (vw1->type != VT_PAR)) |
526 |
|
return(0); |
527 |
< |
if (vw2->type != VT_PER && vw2->type != VT_PAR) |
527 |
> |
if ((vw2->type != VT_PER) & (vw2->type != VT_PAR)) |
528 |
|
return(0); |
529 |
|
setident4(xfmat); |
530 |
|
xfmat[0][0] = vw1->hvec[0]; |
557 |
|
} |
558 |
|
|
559 |
|
|
560 |
< |
addscanline(y, pline, zline, lasty) /* add scanline to output */ |
560 |
> |
addscanline(xl, y, pline, zline, lasty) /* add scanline to output */ |
561 |
> |
struct bound *xl; |
562 |
|
int y; |
563 |
|
COLR *pline; |
564 |
|
float *zline; |
565 |
|
struct position *lasty; /* input/output */ |
566 |
|
{ |
388 |
– |
extern double sqrt(); |
567 |
|
FVECT pos; |
568 |
|
struct position lastx, newpos; |
569 |
+ |
double wt; |
570 |
|
register int x; |
571 |
|
|
572 |
|
lastx.z = 0; |
573 |
< |
for (x = scanlen(&tresolu); x-- > 0; ) { |
573 |
> |
for (x = xl->max; x >= xl->min; x--) { |
574 |
|
pix2loc(pos, &tresolu, x, y); |
575 |
|
pos[2] = zline[x]; |
576 |
< |
if (movepixel(pos) < 0) { |
576 |
> |
if ((wt = movepixel(pos)) <= FTINY) { |
577 |
|
lasty[x].z = lastx.z = 0; /* mark invalid */ |
578 |
|
continue; |
579 |
|
} |
580 |
+ |
/* add pixel to our image */ |
581 |
|
newpos.x = pos[0] * hresolu; |
582 |
|
newpos.y = pos[1] * vresolu; |
583 |
|
newpos.z = zline[x]; |
584 |
< |
/* add pixel to our image */ |
585 |
< |
if (pos[0] >= 0 && newpos.x < hresolu |
586 |
< |
&& pos[1] >= 0 && newpos.y < vresolu) { |
587 |
< |
addpixel(&newpos, &lastx, &lasty[x], pline[x], pos[2]); |
408 |
< |
lasty[x].x = lastx.x = newpos.x; |
409 |
< |
lasty[x].y = lastx.y = newpos.y; |
410 |
< |
lasty[x].z = lastx.z = newpos.z; |
411 |
< |
} else |
412 |
< |
lasty[x].z = lastx.z = 0; /* mark invalid */ |
584 |
> |
addpixel(&newpos, &lastx, &lasty[x], pline[x], wt, pos[2]); |
585 |
> |
lasty[x].x = lastx.x = newpos.x; |
586 |
> |
lasty[x].y = lastx.y = newpos.y; |
587 |
> |
lasty[x].z = lastx.z = newpos.z; |
588 |
|
} |
589 |
|
} |
590 |
|
|
591 |
|
|
592 |
< |
addpixel(p0, p1, p2, pix, z) /* fill in pixel parallelogram */ |
592 |
> |
addpixel(p0, p1, p2, pix, w, z) /* fill in pixel parallelogram */ |
593 |
|
struct position *p0, *p1, *p2; |
594 |
|
COLR pix; |
595 |
+ |
double w; |
596 |
|
double z; |
597 |
|
{ |
598 |
|
double zt = 2.*zeps*p0->z; /* threshold */ |
599 |
+ |
COLOR pval; /* converted+weighted pixel */ |
600 |
|
int s1x, s1y, s2x, s2y; /* step sizes */ |
601 |
|
int l1, l2, c1, c2; /* side lengths and counters */ |
602 |
|
int p1isy; /* p0p1 along y? */ |
608 |
|
s1x = p1->x - p0->x; |
609 |
|
s1y = p1->y - p0->y; |
610 |
|
l1 = ABS(s1x); |
611 |
< |
if (p1isy = (ABS(s1y) > l1)) |
611 |
> |
if ( (p1isy = (ABS(s1y) > l1)) ) |
612 |
|
l1 = ABS(s1y); |
613 |
+ |
else if (l1 < 1) |
614 |
+ |
l1 = 1; |
615 |
|
} else { |
616 |
|
l1 = s1x = s1y = 1; |
617 |
|
p1isy = -1; |
627 |
|
if (p1isy != 0 && ABS(s2x) > l2) |
628 |
|
l2 = ABS(s2x); |
629 |
|
} |
630 |
+ |
if (l2 < 1) |
631 |
+ |
l2 = 1; |
632 |
|
} else |
633 |
|
l2 = s2x = s2y = 1; |
634 |
|
/* fill the parallelogram */ |
635 |
+ |
if (averaging) { |
636 |
+ |
colr_color(pval, pix); |
637 |
+ |
scalecolor(pval, w); |
638 |
+ |
} |
639 |
|
for (c1 = l1; c1-- > 0; ) { |
640 |
|
x1 = p0->x + c1*s1x/l1; |
641 |
|
y1 = p0->y + c1*s1y/l1; |
642 |
|
for (c2 = l2; c2-- > 0; ) { |
643 |
|
x = x1 + c2*s2x/l2; |
644 |
< |
if (x < 0 || x >= hresolu) |
644 |
> |
if ((x < 0) | (x >= hresolu)) |
645 |
|
continue; |
646 |
|
y = y1 + c2*s2y/l2; |
647 |
< |
if (y < 0 || y >= vresolu) |
647 |
> |
if ((y < 0) | (y >= vresolu)) |
648 |
|
continue; |
649 |
< |
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
649 |
> |
if (averaging) { |
650 |
> |
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
651 |
|
> zeps*zscan(y)[x]) { |
652 |
< |
zscan(y)[x] = z; |
652 |
> |
copycolor(sscan(y)[x], pval); |
653 |
> |
wscan(y)[x] = w; |
654 |
> |
zscan(y)[x] = z; |
655 |
> |
} else if (z-zscan(y)[x] <= zeps*zscan(y)[x]) { |
656 |
> |
addcolor(sscan(y)[x], pval); |
657 |
> |
wscan(y)[x] += w; |
658 |
> |
} |
659 |
> |
} else if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
660 |
> |
> zeps*zscan(y)[x]) { |
661 |
|
copycolr(pscan(y)[x], pix); |
662 |
+ |
zscan(y)[x] = z; |
663 |
|
} |
664 |
|
} |
665 |
|
} |
666 |
|
} |
667 |
|
|
668 |
|
|
669 |
+ |
double |
670 |
|
movepixel(pos) /* reposition image point */ |
671 |
< |
FVECT pos; |
671 |
> |
register FVECT pos; |
672 |
|
{ |
673 |
< |
FVECT pt, direc; |
673 |
> |
FVECT pt, tdir, odir; |
674 |
> |
double d; |
675 |
|
|
676 |
|
if (pos[2] <= 0) /* empty pixel */ |
677 |
< |
return(-1); |
678 |
< |
if (hasmatrix) { |
677 |
> |
return(0); |
678 |
> |
if (usematrix) { |
679 |
|
pos[0] += theirview.hoff - .5; |
680 |
|
pos[1] += theirview.voff - .5; |
681 |
+ |
if (normdist & (theirview.type == VT_PER)) |
682 |
+ |
d = sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
683 |
+ |
+ pos[1]*pos[1]*theirview.vn2); |
684 |
+ |
else |
685 |
+ |
d = 1.; |
686 |
+ |
pos[2] += d*theirview.vfore; |
687 |
|
if (theirview.type == VT_PER) { |
688 |
< |
if (normdist) /* adjust for eye-ray distance */ |
486 |
< |
pos[2] /= sqrt( 1. |
487 |
< |
+ pos[0]*pos[0]*theirview.hn2 |
488 |
< |
+ pos[1]*pos[1]*theirview.vn2 ); |
688 |
> |
pos[2] /= d; |
689 |
|
pos[0] *= pos[2]; |
690 |
|
pos[1] *= pos[2]; |
691 |
|
} |
692 |
|
multp3(pos, pos, theirs2ours); |
693 |
< |
if (pos[2] <= 0) |
694 |
< |
return(-1); |
693 |
> |
if (pos[2] <= ourview.vfore) |
694 |
> |
return(0); |
695 |
|
if (ourview.type == VT_PER) { |
696 |
|
pos[0] /= pos[2]; |
697 |
|
pos[1] /= pos[2]; |
698 |
|
} |
699 |
|
pos[0] += .5 - ourview.hoff; |
700 |
|
pos[1] += .5 - ourview.voff; |
701 |
+ |
pos[2] -= ourview.vfore; |
702 |
+ |
} else { |
703 |
+ |
if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) |
704 |
+ |
return(0); |
705 |
+ |
if ((!normdist) & (theirview.type == VT_PER)) /* adjust */ |
706 |
+ |
pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
707 |
+ |
+ pos[1]*pos[1]*theirview.vn2); |
708 |
+ |
pt[0] += tdir[0]*pos[2]; |
709 |
+ |
pt[1] += tdir[1]*pos[2]; |
710 |
+ |
pt[2] += tdir[2]*pos[2]; |
711 |
+ |
viewloc(pos, &ourview, pt); |
712 |
+ |
if (pos[2] <= 0) |
713 |
+ |
return(0); |
714 |
+ |
} |
715 |
+ |
if ((pos[0] < 0) | (pos[0] >= 1-FTINY) | (pos[1] < 0) | (pos[1] >= 1-FTINY)) |
716 |
|
return(0); |
717 |
+ |
if (!averaging) |
718 |
+ |
return(1); |
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 (viewray(pt, direc, &theirview, pos[0], pos[1]) < 0) |
729 |
< |
return(-1); |
730 |
< |
pt[0] += direc[0]*pos[2]; |
506 |
< |
pt[1] += direc[1]*pos[2]; |
507 |
< |
pt[2] += direc[2]*pos[2]; |
508 |
< |
viewloc(pos, &ourview, pt); |
509 |
< |
if (pos[2] <= 0) |
510 |
< |
return(-1); |
511 |
< |
return(0); |
728 |
> |
if (d <= 1./MAXWT/MAXWT) |
729 |
> |
return(MAXWT); /* clip to maximum weight */ |
730 |
> |
return(1./sqrt(d)); |
731 |
|
} |
732 |
|
|
733 |
|
|
734 |
+ |
getperim(xl, yl, zline, zfd) /* compute overlapping image area */ |
735 |
+ |
register struct bound *xl; |
736 |
+ |
struct bound *yl; |
737 |
+ |
float *zline; |
738 |
+ |
int zfd; |
739 |
+ |
{ |
740 |
+ |
int step; |
741 |
+ |
FVECT pos; |
742 |
+ |
register int x, y; |
743 |
+ |
/* set up step size */ |
744 |
+ |
if (scanlen(&tresolu) < numscans(&tresolu)) |
745 |
+ |
step = scanlen(&tresolu)/NSTEPS; |
746 |
+ |
else |
747 |
+ |
step = numscans(&tresolu)/NSTEPS; |
748 |
+ |
if (step < MINSTEP) { /* not worth cropping? */ |
749 |
+ |
yl->min = 0; |
750 |
+ |
yl->max = numscans(&tresolu) - 1; |
751 |
+ |
x = scanlen(&tresolu) - 1; |
752 |
+ |
for (y = numscans(&tresolu); y--; ) { |
753 |
+ |
xl[y].min = 0; |
754 |
+ |
xl[y].max = x; |
755 |
+ |
} |
756 |
+ |
return(1); |
757 |
+ |
} |
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, (off_t)y*scanlen(&tresolu)*sizeof(float), |
762 |
+ |
0) < 0) |
763 |
+ |
syserror("lseek"); |
764 |
+ |
if (read(zfd, (char *)zline, |
765 |
+ |
scanlen(&tresolu)*sizeof(float)) |
766 |
+ |
< scanlen(&tresolu)*sizeof(float)) |
767 |
+ |
syserror("read"); |
768 |
+ |
} |
769 |
+ |
xl[y].min = 32000; xl[y].max = 0; /* x max */ |
770 |
+ |
for (x = scanlen(&tresolu); (x -= step) > 0; ) { |
771 |
+ |
pix2loc(pos, &tresolu, x, y); |
772 |
+ |
pos[2] = zline[x]; |
773 |
+ |
if (movepixel(pos) > FTINY) { |
774 |
+ |
xl[y].max = x + step - 1; |
775 |
+ |
xl[y].min = x - step + 1; /* x min */ |
776 |
+ |
if (xl[y].min < 0) |
777 |
+ |
xl[y].min = 0; |
778 |
+ |
for (x = step - 1; x < xl[y].max; x += step) { |
779 |
+ |
pix2loc(pos, &tresolu, x, y); |
780 |
+ |
pos[2] = zline[x]; |
781 |
+ |
if (movepixel(pos) > FTINY) { |
782 |
+ |
xl[y].min = x - step + 1; |
783 |
+ |
break; |
784 |
+ |
} |
785 |
+ |
} |
786 |
+ |
if (y < yl->min) /* y limits */ |
787 |
+ |
yl->min = y - step + 1; |
788 |
+ |
yl->max = y + step - 1; |
789 |
+ |
break; |
790 |
+ |
} |
791 |
+ |
} |
792 |
+ |
/* fill in between */ |
793 |
+ |
if (y < step) { |
794 |
+ |
xl[y-1].min = xl[y].min; |
795 |
+ |
xl[y-1].max = xl[y].max; |
796 |
+ |
} else { |
797 |
+ |
if (xl[y].min < xl[y-step].min) |
798 |
+ |
xl[y-1].min = xl[y].min; |
799 |
+ |
else |
800 |
+ |
xl[y-1].min = xl[y-step].min; |
801 |
+ |
if (xl[y].max > xl[y-step].max) |
802 |
+ |
xl[y-1].max = xl[y].max; |
803 |
+ |
else |
804 |
+ |
xl[y-1].max = xl[y-step].max; |
805 |
+ |
} |
806 |
+ |
for (x = 2; x < step; x++) |
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 |
+ |
*(xl+x) = *(xl+y); |
814 |
+ |
return(yl->max >= yl->min); |
815 |
+ |
} |
816 |
+ |
|
817 |
+ |
|
818 |
|
backpicture(fill, samp) /* background fill algorithm */ |
819 |
|
int (*fill)(); |
820 |
|
int samp; |
825 |
|
/* get back buffer */ |
826 |
|
yback = (int *)malloc(hresolu*sizeof(int)); |
827 |
|
if (yback == NULL) |
828 |
< |
syserror(); |
828 |
> |
syserror(progname); |
829 |
|
for (x = 0; x < hresolu; x++) |
830 |
|
yback[x] = -2; |
831 |
|
/* |
885 |
|
< zscan(y)[xback] ) ) { |
886 |
|
if (samp > 0 && ABS(x-xback) >= samp) |
887 |
|
goto fillit; |
888 |
< |
copycolr(pscan(y)[x],pscan(y)[xback]); |
888 |
> |
if (averaging) { |
889 |
> |
copycolor(sscan(y)[x], |
890 |
> |
sscan(y)[xback]); |
891 |
> |
wscan(y)[x] = wscan(y)[xback]; |
892 |
> |
} else |
893 |
> |
copycolr(pscan(y)[x], |
894 |
> |
pscan(y)[xback]); |
895 |
|
zscan(y)[x] = zscan(y)[xback]; |
896 |
|
} else { |
897 |
|
if (samp > 0 && ABS(y-yback[x]) > samp) |
898 |
|
goto fillit; |
899 |
< |
copycolr(pscan(y)[x],pscan(yback[x])[x]); |
899 |
> |
if (averaging) { |
900 |
> |
copycolor(sscan(y)[x], |
901 |
> |
sscan(yback[x])[x]); |
902 |
> |
wscan(y)[x] = |
903 |
> |
wscan(yback[x])[x]; |
904 |
> |
} else |
905 |
> |
copycolr(pscan(y)[x], |
906 |
> |
pscan(yback[x])[x]); |
907 |
|
zscan(y)[x] = zscan(yback[x])[x]; |
908 |
|
} |
909 |
|
continue; |
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 |
|
|
940 |
< |
writepicture() /* write out picture */ |
940 |
> |
clipaft() /* perform aft clipping as indicated */ |
941 |
|
{ |
942 |
+ |
register int x, y; |
943 |
+ |
int adjtest = (ourview.type == VT_PER) & zisnorm; |
944 |
+ |
double tstdist; |
945 |
+ |
double yzn2, vx; |
946 |
+ |
|
947 |
+ |
if (ourview.vaft <= FTINY) |
948 |
+ |
return(0); |
949 |
+ |
tstdist = ourview.vaft - ourview.vfore; |
950 |
+ |
for (y = 0; y < vresolu; y++) { |
951 |
+ |
if (adjtest) { /* adjust test */ |
952 |
+ |
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
953 |
+ |
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
954 |
+ |
tstdist = (ourview.vaft - ourview.vfore)*sqrt(yzn2); |
955 |
+ |
} |
956 |
+ |
for (x = 0; x < hresolu; x++) |
957 |
+ |
if (zscan(y)[x] > tstdist) { |
958 |
+ |
if (adjtest) { |
959 |
+ |
vx = (x+.5)/hresolu + ourview.hoff - .5; |
960 |
+ |
if (zscan(y)[x] <= (ourview.vaft - |
961 |
+ |
ourview.vfore) * |
962 |
+ |
sqrt(vx*vx*ourview.hn2 + yzn2)) |
963 |
+ |
continue; |
964 |
+ |
} |
965 |
+ |
if (averaging) |
966 |
+ |
memset(sscan(y)[x], '\0', sizeof(COLOR)); |
967 |
+ |
else |
968 |
+ |
memset(pscan(y)[x], '\0', sizeof(COLR)); |
969 |
+ |
zscan(y)[x] = 0.0; |
970 |
+ |
} |
971 |
+ |
} |
972 |
+ |
return(1); |
973 |
+ |
} |
974 |
+ |
|
975 |
+ |
|
976 |
+ |
addblur() /* add to blurred picture */ |
977 |
+ |
{ |
978 |
+ |
COLOR cval; |
979 |
+ |
double d; |
980 |
+ |
register int i; |
981 |
+ |
|
982 |
+ |
if (!blurring) |
983 |
+ |
return(0); |
984 |
+ |
i = hresolu*vresolu; |
985 |
+ |
if (nvavg < 2) |
986 |
+ |
if (averaging) |
987 |
+ |
while (i--) { |
988 |
+ |
copycolor(ourbpict[i], ourspict[i]); |
989 |
+ |
d = 1.0/ourweigh[i]; |
990 |
+ |
scalecolor(ourbpict[i], d); |
991 |
+ |
} |
992 |
+ |
else |
993 |
+ |
while (i--) |
994 |
+ |
colr_color(ourbpict[i], ourpict[i]); |
995 |
+ |
else |
996 |
+ |
if (averaging) |
997 |
+ |
while (i--) { |
998 |
+ |
copycolor(cval, ourspict[i]); |
999 |
+ |
d = 1.0/ourweigh[i]; |
1000 |
+ |
scalecolor(cval, d); |
1001 |
+ |
addcolor(ourbpict[i], cval); |
1002 |
+ |
} |
1003 |
+ |
else |
1004 |
+ |
while (i--) { |
1005 |
+ |
colr_color(cval, ourpict[i]); |
1006 |
+ |
addcolor(ourbpict[i], cval); |
1007 |
+ |
} |
1008 |
+ |
/* print view */ |
1009 |
+ |
printf("VIEW%d:", nvavg); |
1010 |
+ |
fprintview(&ourview, stdout); |
1011 |
+ |
putchar('\n'); |
1012 |
+ |
return(1); |
1013 |
+ |
} |
1014 |
+ |
|
1015 |
+ |
|
1016 |
+ |
writepicture() /* write out picture (alters buffer) */ |
1017 |
+ |
{ |
1018 |
|
int y; |
1019 |
+ |
register int x; |
1020 |
+ |
double d; |
1021 |
|
|
1022 |
|
fprtresolu(hresolu, vresolu, stdout); |
1023 |
|
for (y = vresolu-1; y >= 0; y--) |
1024 |
< |
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
1025 |
< |
syserror(); |
1024 |
> |
if (blurring) { |
1025 |
> |
for (x = 0; x < hresolu; x++) { /* compute avg. */ |
1026 |
> |
d = rexpadj/nvavg; |
1027 |
> |
scalecolor(bscan(y)[x], d); |
1028 |
> |
} |
1029 |
> |
if (fwritescan(bscan(y), hresolu, stdout) < 0) |
1030 |
> |
syserror(progname); |
1031 |
> |
} else if (averaging) { |
1032 |
> |
for (x = 0; x < hresolu; x++) { /* average pixels */ |
1033 |
> |
d = rexpadj/wscan(y)[x]; |
1034 |
> |
scalecolor(sscan(y)[x], d); |
1035 |
> |
} |
1036 |
> |
if (fwritescan(sscan(y), hresolu, stdout) < 0) |
1037 |
> |
syserror(progname); |
1038 |
> |
} else { |
1039 |
> |
if (expadj) |
1040 |
> |
shiftcolrs(pscan(y), hresolu, expadj); |
1041 |
> |
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
1042 |
> |
syserror(progname); |
1043 |
> |
} |
1044 |
|
} |
1045 |
|
|
1046 |
|
|
1047 |
< |
writedistance(fname) /* write out z file */ |
1047 |
> |
writedistance(fname) /* write out z file (alters buffer) */ |
1048 |
|
char *fname; |
1049 |
|
{ |
1050 |
< |
extern double sqrt(); |
1051 |
< |
int donorm = normdist && ourview.type == VT_PER; |
1050 |
> |
int donorm = normdist & !zisnorm ? 1 : |
1051 |
> |
(ourview.type == VT_PER) & !normdist & zisnorm ? -1 : 0; |
1052 |
|
int fd; |
1053 |
|
int y; |
640 |
– |
float *zout; |
1054 |
|
|
1055 |
< |
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) { |
1056 |
< |
perror(fname); |
644 |
< |
exit(1); |
645 |
< |
} |
646 |
< |
if (donorm |
647 |
< |
&& (zout = (float *)malloc(hresolu*sizeof(float))) == NULL) |
648 |
< |
syserror(); |
1055 |
> |
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) |
1056 |
> |
syserror(fname); |
1057 |
|
for (y = vresolu-1; y >= 0; y--) { |
1058 |
|
if (donorm) { |
1059 |
< |
double vx, yzn2; |
1059 |
> |
double vx, yzn2, d; |
1060 |
|
register int x; |
1061 |
|
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
1062 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
1063 |
|
for (x = 0; x < hresolu; x++) { |
1064 |
|
vx = (x+.5)/hresolu + ourview.hoff - .5; |
1065 |
< |
zout[x] = zscan(y)[x] |
1066 |
< |
* sqrt(vx*vx*ourview.hn2 + yzn2); |
1065 |
> |
d = sqrt(vx*vx*ourview.hn2 + yzn2); |
1066 |
> |
if (donorm > 0) |
1067 |
> |
zscan(y)[x] *= d; |
1068 |
> |
else |
1069 |
> |
zscan(y)[x] /= d; |
1070 |
|
} |
660 |
– |
} else |
661 |
– |
zout = zscan(y); |
662 |
– |
if (write(fd, (char *)zout, hresolu*sizeof(float)) |
663 |
– |
< hresolu*sizeof(float)) { |
664 |
– |
perror(fname); |
665 |
– |
exit(1); |
1071 |
|
} |
1072 |
+ |
if (write(fd, (char *)zscan(y), hresolu*sizeof(float)) |
1073 |
+ |
< hresolu*sizeof(float)) |
1074 |
+ |
syserror(fname); |
1075 |
|
} |
668 |
– |
if (donorm) |
669 |
– |
free((char *)zout); |
1076 |
|
close(fd); |
1077 |
|
} |
1078 |
|
|
1079 |
|
|
674 |
– |
isfloat(s) /* see if string is floating number */ |
675 |
– |
register char *s; |
676 |
– |
{ |
677 |
– |
for ( ; *s; s++) |
678 |
– |
if ((*s < '0' || *s > '9') && *s != '.' && *s != '-' |
679 |
– |
&& *s != 'e' && *s != 'E' && *s != '+') |
680 |
– |
return(0); |
681 |
– |
return(1); |
682 |
– |
} |
683 |
– |
|
684 |
– |
|
1080 |
|
backfill(x, y) /* fill pixel with background */ |
1081 |
|
int x, y; |
1082 |
|
{ |
1083 |
< |
register BYTE *dest = pscan(y)[x]; |
1084 |
< |
|
1085 |
< |
copycolr(dest, backcolr); |
1083 |
> |
if (averaging) { |
1084 |
> |
copycolor(sscan(y)[x], backcolor); |
1085 |
> |
wscan(y)[x] = 1; |
1086 |
> |
} else |
1087 |
> |
copycolr(pscan(y)[x], backcolr); |
1088 |
|
zscan(y)[x] = backz; |
1089 |
|
} |
1090 |
|
|
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 |
|
} |
1106 |
|
cp = combuf; |
1107 |
|
wp = argv; |
1108 |
|
for ( ; ; ) { |
1109 |
< |
while (isspace(*cp)) cp++; |
1110 |
< |
if (!*cp) break; |
1111 |
< |
*wp++ = cp; |
1112 |
< |
while (!isspace(*cp)) |
1113 |
< |
if (!*cp++) goto done; |
1114 |
< |
*cp++ = '\0'; |
1109 |
> |
while (isspace(*cp)) /* nullify spaces */ |
1110 |
> |
*cp++ = '\0'; |
1111 |
> |
if (!*cp) /* all done? */ |
1112 |
> |
break; |
1113 |
> |
*wp++ = cp; /* add argument to list */ |
1114 |
> |
while (*++cp && !isspace(*cp)) |
1115 |
> |
; |
1116 |
|
} |
719 |
– |
done: |
1117 |
|
*wp = NULL; |
1118 |
|
/* start process */ |
1119 |
< |
if ((rval = open_process(PDesc, argv)) < 0) |
1120 |
< |
syserror(); |
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]); |
1123 |
|
exit(1); |
1131 |
|
|
1132 |
|
caldone() /* done with calculation */ |
1133 |
|
{ |
1134 |
< |
if (childpid == -1) |
1134 |
> |
if (!PDesc.running) |
1135 |
|
return; |
1136 |
|
clearqueue(); |
1137 |
< |
close_process(PDesc); |
741 |
< |
childpid = -1; |
1137 |
> |
close_process(&PDesc); |
1138 |
|
} |
1139 |
|
|
1140 |
|
|
1156 |
|
float fbuf[6*(PACKSIZ+1)]; |
1157 |
|
register float *fbp; |
1158 |
|
register int i; |
1159 |
+ |
double vx, vy; |
1160 |
|
|
1161 |
+ |
if (queuesiz == 0) |
1162 |
+ |
return; |
1163 |
|
fbp = fbuf; |
1164 |
|
for (i = 0; i < queuesiz; i++) { |
1165 |
|
viewray(orig, dir, &ourview, |
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); |
1185 |
|
fbp[1] *= ourexp; |
1186 |
|
fbp[2] *= ourexp; |
1187 |
|
} |
1188 |
< |
setcolr(pscan(queue[i][1])[queue[i][0]], |
1189 |
< |
fbp[0], fbp[1], fbp[2]); |
1190 |
< |
zscan(queue[i][1])[queue[i][0]] = fbp[3]; |
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]] = 1; |
1192 |
> |
} else |
1193 |
> |
setcolr(pscan(queue[i][1])[queue[i][0]], |
1194 |
> |
fbp[0], fbp[1], fbp[2]); |
1195 |
> |
if (zisnorm) |
1196 |
> |
zscan(queue[i][1])[queue[i][0]] = fbp[3]; |
1197 |
> |
else { |
1198 |
> |
vx = (queue[i][0]+.5)/hresolu + ourview.hoff - .5; |
1199 |
> |
vy = (queue[i][1]+.5)/vresolu + ourview.voff - .5; |
1200 |
> |
zscan(queue[i][1])[queue[i][0]] = fbp[3] / sqrt(1. + |
1201 |
> |
vx*vx*ourview.hn2 + vy*vy*ourview.vn2); |
1202 |
> |
} |
1203 |
|
fbp += 4; |
1204 |
|
} |
1205 |
|
queuesiz = 0; |
1206 |
|
} |
1207 |
|
|
1208 |
|
|
1209 |
< |
syserror() /* report error and exit */ |
1209 |
> |
syserror(s) /* report error and exit */ |
1210 |
> |
char *s; |
1211 |
|
{ |
1212 |
< |
perror(progname); |
1212 |
> |
perror(s); |
1213 |
|
exit(1); |
1214 |
|
} |