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" |
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 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 |
|
|
55 |
|
|
56 |
|
double zeps = .02; /* allowed z epsilon */ |
57 |
|
|
58 |
< |
COLR *ourpict; /* output picture */ |
58 |
> |
COLR *ourpict; /* output picture (COLR's) */ |
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 */ |
70 |
|
int fillsamp = 0; /* sample separation (0 == inf) */ |
56 |
– |
extern int backfill(), rcalfill(); /* fill functions */ |
57 |
– |
int (*fillfunc)() = backfill; /* selected fill function */ |
71 |
|
COLR backcolr = BLKCOLR; /* background color */ |
72 |
+ |
COLOR backcolor = BLKCOLOR; /* background color (float) */ |
73 |
|
double backz = 0.0; /* background z value */ |
74 |
< |
int normdist = 1; /* normalized distance? */ |
75 |
< |
double ourexp = -1; /* output picture exposure */ |
74 |
> |
int normdist = 1; /* i/o normalized distance? */ |
75 |
> |
char ourfmt[LPICFMT+1] = PICFMT; /* original picture format */ |
76 |
> |
double ourexp = -1; /* original picture exposure */ |
77 |
> |
int expadj = 0; /* exposure adjustment (f-stops) */ |
78 |
> |
double rexpadj = 1; /* real exposure adjustment */ |
79 |
|
|
80 |
< |
VIEW theirview = STDVIEW; /* input view */ |
80 |
> |
VIEW theirview; /* input view */ |
81 |
|
int gotview; /* got input view? */ |
82 |
|
int wrongformat = 0; /* input in another format? */ |
83 |
|
RESOLU tresolu; /* input resolution */ |
84 |
|
double theirexp; /* input picture exposure */ |
85 |
< |
double theirs2ours[4][4]; /* transformation matrix */ |
85 |
> |
MAT4 theirs2ours; /* transformation matrix */ |
86 |
|
int hasmatrix = 0; /* has transformation matrix */ |
87 |
|
|
88 |
< |
int PDesc[3] = {-1,-1,-1}; /* rtrace process descriptor */ |
72 |
< |
#define childpid (PDesc[2]) |
88 |
> |
static SUBPROC PDesc = SP_INACTIVE; /* rtrace process descriptor */ |
89 |
|
unsigned short queue[PACKSIZ][2]; /* pending pixels */ |
90 |
|
int packsiz; /* actual packet size */ |
91 |
< |
int queuesiz; /* number of pixels pending */ |
91 |
> |
int queuesiz = 0; /* number of pixels pending */ |
92 |
|
|
93 |
+ |
typedef void fillfunc_t(int x, int y); |
94 |
|
|
95 |
< |
main(argc, argv) /* interpolate pictures */ |
96 |
< |
int argc; |
97 |
< |
char *argv[]; |
95 |
> |
static gethfunc headline; |
96 |
> |
static int nextview(FILE *fp); |
97 |
> |
static void compavgview(void); |
98 |
> |
static void addpicture(char *pfile, char *zspec); |
99 |
> |
static int pixform(MAT4 xfmat, VIEW *vw1, VIEW *vw2); |
100 |
> |
static void addscanline(struct bound *xl, int y, |
101 |
> |
COLR *pline, float *zline, struct position *lasty); |
102 |
> |
static void addpixel(struct position *p0, struct position *p1, |
103 |
> |
struct position *p2, COLR pix, double w, double z); |
104 |
> |
static double movepixel(FVECT pos); |
105 |
> |
static int getperim(struct bound *xl, struct bound *yl, float *zline, int zfd); |
106 |
> |
static void backpicture(fillfunc_t *fill, int samp); |
107 |
> |
static void fillpicture(fillfunc_t *fill); |
108 |
> |
static int clipaft(void); |
109 |
> |
static int addblur(void); |
110 |
> |
static void writepicture(void); |
111 |
> |
static void writedistance(char *fname); |
112 |
> |
static fillfunc_t backfill; |
113 |
> |
static fillfunc_t rcalfill; |
114 |
> |
static void calstart(char *prog, char *args); |
115 |
> |
static void caldone(void); |
116 |
> |
static void clearqueue(void); |
117 |
> |
static void syserror(char *s); |
118 |
> |
|
119 |
> |
fillfunc_t *fillfunc = backfill; /* selected fill function */ |
120 |
> |
|
121 |
> |
int |
122 |
> |
main( /* interpolate pictures */ |
123 |
> |
int argc, |
124 |
> |
char *argv[] |
125 |
> |
) |
126 |
|
{ |
127 |
< |
#define check(ol,al) if (argv[i][ol] || \ |
128 |
< |
badarg(argc-i-1,argv+i+1,al)) \ |
127 |
> |
#define check(ol,al) if (argv[an][ol] || \ |
128 |
> |
badarg(argc-an-1,argv+an+1,al)) \ |
129 |
|
goto badopt |
130 |
|
int gotvfile = 0; |
131 |
+ |
int doavg = -1; |
132 |
+ |
int doblur = 0; |
133 |
|
char *zfile = NULL; |
134 |
< |
char *err; |
135 |
< |
int i, rval; |
134 |
> |
char *expcomp = NULL; |
135 |
> |
int i, an, rval; |
136 |
|
|
137 |
|
progname = argv[0]; |
138 |
|
|
139 |
< |
for (i = 1; i < argc && argv[i][0] == '-'; i++) { |
140 |
< |
rval = getviewopt(&ourview, argc-i, argv+i); |
139 |
> |
for (an = 1; an < argc && argv[an][0] == '-'; an++) { |
140 |
> |
rval = getviewopt(&ourview, argc-an, argv+an); |
141 |
|
if (rval >= 0) { |
142 |
< |
i += rval; |
142 |
> |
an += rval; |
143 |
|
continue; |
144 |
|
} |
145 |
< |
switch (argv[i][1]) { |
145 |
> |
switch (argv[an][1]) { |
146 |
> |
case 'e': /* exposure */ |
147 |
> |
check(2,"f"); |
148 |
> |
expcomp = argv[++an]; |
149 |
> |
break; |
150 |
|
case 't': /* threshold */ |
151 |
|
check(2,"f"); |
152 |
< |
zeps = atof(argv[++i]); |
152 |
> |
zeps = atof(argv[++an]); |
153 |
|
break; |
154 |
+ |
case 'a': /* average */ |
155 |
+ |
check(2,NULL); |
156 |
+ |
doavg = 1; |
157 |
+ |
break; |
158 |
+ |
case 'B': /* blur views */ |
159 |
+ |
check(2,NULL); |
160 |
+ |
doblur = 1; |
161 |
+ |
break; |
162 |
+ |
case 'q': /* quick (no avg.) */ |
163 |
+ |
check(2,NULL); |
164 |
+ |
doavg = 0; |
165 |
+ |
break; |
166 |
|
case 'n': /* dist. normalized? */ |
167 |
|
check(2,NULL); |
168 |
|
normdist = !normdist; |
169 |
|
break; |
170 |
|
case 'f': /* fill type */ |
171 |
< |
switch (argv[i][2]) { |
171 |
> |
switch (argv[an][2]) { |
172 |
|
case '0': /* none */ |
173 |
|
check(3,NULL); |
174 |
|
fillo = 0; |
187 |
|
break; |
188 |
|
case 's': /* sample */ |
189 |
|
check(3,"i"); |
190 |
< |
fillsamp = atoi(argv[++i]); |
190 |
> |
fillsamp = atoi(argv[++an]); |
191 |
|
break; |
192 |
|
case 'c': /* color */ |
193 |
|
check(3,"fff"); |
194 |
|
fillfunc = backfill; |
195 |
< |
setcolr(backcolr, atof(argv[i+1]), |
196 |
< |
atof(argv[i+2]), atof(argv[i+3])); |
197 |
< |
i += 3; |
195 |
> |
setcolor(backcolor, atof(argv[an+1]), |
196 |
> |
atof(argv[an+2]), atof(argv[an+3])); |
197 |
> |
setcolr(backcolr, colval(backcolor,RED), |
198 |
> |
colval(backcolor,GRN), |
199 |
> |
colval(backcolor,BLU)); |
200 |
> |
an += 3; |
201 |
|
break; |
202 |
|
case 'z': /* z value */ |
203 |
|
check(3,"f"); |
204 |
|
fillfunc = backfill; |
205 |
< |
backz = atof(argv[++i]); |
205 |
> |
backz = atof(argv[++an]); |
206 |
|
break; |
207 |
|
case 'r': /* rtrace */ |
208 |
|
check(3,"s"); |
209 |
|
fillfunc = rcalfill; |
210 |
< |
calstart(RTCOM, argv[++i]); |
210 |
> |
calstart(RTCOM, argv[++an]); |
211 |
|
break; |
212 |
|
default: |
213 |
|
goto badopt; |
215 |
|
break; |
216 |
|
case 'z': /* z file */ |
217 |
|
check(2,"s"); |
218 |
< |
zfile = argv[++i]; |
218 |
> |
zfile = argv[++an]; |
219 |
|
break; |
220 |
|
case 'x': /* x resolution */ |
221 |
|
check(2,"i"); |
222 |
< |
hresolu = atoi(argv[++i]); |
222 |
> |
hresolu = atoi(argv[++an]); |
223 |
|
break; |
224 |
|
case 'y': /* y resolution */ |
225 |
|
check(2,"i"); |
226 |
< |
vresolu = atoi(argv[++i]); |
226 |
> |
vresolu = atoi(argv[++an]); |
227 |
|
break; |
228 |
|
case 'p': /* pixel aspect */ |
229 |
< |
if (argv[i][2] != 'a') |
229 |
> |
if (argv[an][2] != 'a') |
230 |
|
goto badopt; |
231 |
|
check(3,"f"); |
232 |
< |
pixaspect = atof(argv[++i]); |
232 |
> |
pixaspect = atof(argv[++an]); |
233 |
|
break; |
234 |
|
case 'v': /* view file */ |
235 |
< |
if (argv[i][2] != 'f') |
235 |
> |
if (argv[an][2] != 'f') |
236 |
|
goto badopt; |
237 |
|
check(3,"s"); |
238 |
< |
gotvfile = viewfile(argv[++i], &ourview, 0, 0); |
238 |
> |
gotvfile = viewfile(argv[++an], &ourview, NULL); |
239 |
|
if (gotvfile < 0) |
240 |
< |
syserror(argv[i]); |
240 |
> |
syserror(argv[an]); |
241 |
|
else if (gotvfile == 0) { |
242 |
|
fprintf(stderr, "%s: bad view file\n", |
243 |
< |
argv[i]); |
243 |
> |
argv[an]); |
244 |
|
exit(1); |
245 |
|
} |
246 |
|
break; |
247 |
|
default: |
248 |
|
badopt: |
249 |
|
fprintf(stderr, "%s: command line error at '%s'\n", |
250 |
< |
progname, argv[i]); |
250 |
> |
progname, argv[an]); |
251 |
|
goto userr; |
252 |
|
} |
253 |
|
} |
254 |
|
/* check arguments */ |
255 |
< |
if ((argc-i)%2) |
255 |
> |
if ((argc-an)%2) |
256 |
|
goto userr; |
257 |
|
if (fillsamp == 1) |
258 |
|
fillo &= ~F_BACK; |
259 |
+ |
if (doavg < 0) |
260 |
+ |
doavg = (argc-an) > 2; |
261 |
+ |
if (expcomp != NULL) { |
262 |
+ |
if ((expcomp[0] == '+') | (expcomp[0] == '-')) { |
263 |
+ |
expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5); |
264 |
+ |
if (doavg | doblur) |
265 |
+ |
rexpadj = pow(2.0, atof(expcomp)); |
266 |
+ |
else |
267 |
+ |
rexpadj = pow(2.0, (double)expadj); |
268 |
+ |
} else { |
269 |
+ |
if (!isflt(expcomp)) |
270 |
+ |
goto userr; |
271 |
+ |
rexpadj = atof(expcomp); |
272 |
+ |
expadj = log(rexpadj)/LOG2 + (rexpadj>1 ? .5 : -.5); |
273 |
+ |
if (!(doavg | doblur)) |
274 |
+ |
rexpadj = pow(2.0, (double)expadj); |
275 |
+ |
} |
276 |
+ |
} |
277 |
|
/* set view */ |
278 |
< |
if ((err = setview(&ourview)) != NULL) { |
279 |
< |
fprintf(stderr, "%s: %s\n", progname, err); |
278 |
> |
if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) { |
279 |
> |
fprintf(stderr, "%s: no view on standard input!\n", |
280 |
> |
progname); |
281 |
|
exit(1); |
282 |
|
} |
283 |
|
normaspect(viewaspect(&ourview), &pixaspect, &hresolu, &vresolu); |
284 |
|
/* allocate frame */ |
285 |
< |
ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); |
285 |
> |
if (doavg) { |
286 |
> |
ourspict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); |
287 |
> |
ourweigh = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
288 |
> |
if ((ourspict == NULL) | (ourweigh == NULL)) |
289 |
> |
syserror(progname); |
290 |
> |
} else { |
291 |
> |
ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); |
292 |
> |
if (ourpict == NULL) |
293 |
> |
syserror(progname); |
294 |
> |
} |
295 |
> |
if (doblur) { |
296 |
> |
ourbpict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); |
297 |
> |
if (ourbpict == NULL) |
298 |
> |
syserror(progname); |
299 |
> |
} |
300 |
|
ourzbuf = (float *)bmalloc(hresolu*vresolu*sizeof(float)); |
301 |
< |
if (ourpict == NULL || ourzbuf == NULL) |
301 |
> |
if (ourzbuf == NULL) |
302 |
|
syserror(progname); |
204 |
– |
bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); |
303 |
|
/* new header */ |
304 |
|
newheader("RADIANCE", stdout); |
305 |
< |
/* get input */ |
306 |
< |
for ( ; i < argc; i += 2) |
307 |
< |
addpicture(argv[i], argv[i+1]); |
308 |
< |
/* fill in spaces */ |
309 |
< |
if (fillo&F_BACK) |
310 |
< |
backpicture(fillfunc, fillsamp); |
311 |
< |
else |
312 |
< |
fillpicture(fillfunc); |
305 |
> |
fputnow(stdout); |
306 |
> |
/* run pictures */ |
307 |
> |
do { |
308 |
> |
memset((char *)ourzbuf, '\0', hresolu*vresolu*sizeof(float)); |
309 |
> |
for (i = an; i < argc; i += 2) |
310 |
> |
addpicture(argv[i], argv[i+1]); |
311 |
> |
if (fillo&F_BACK) /* fill in spaces */ |
312 |
> |
backpicture(fillfunc, fillsamp); |
313 |
> |
else |
314 |
> |
fillpicture(fillfunc); |
315 |
> |
/* aft clipping */ |
316 |
> |
clipaft(); |
317 |
> |
} while (addblur() && nextview(stdin) != EOF); |
318 |
|
/* close calculation */ |
319 |
|
caldone(); |
217 |
– |
/* aft clipping */ |
218 |
– |
clipaft(); |
320 |
|
/* add to header */ |
321 |
|
printargs(argc, argv, stdout); |
322 |
< |
if (gotvfile) { |
322 |
> |
compavgview(); |
323 |
> |
if (doblur | gotvfile) { |
324 |
|
fputs(VIEWSTR, stdout); |
325 |
< |
fprintview(&ourview, stdout); |
325 |
> |
fprintview(&avgview, stdout); |
326 |
|
putc('\n', stdout); |
327 |
|
} |
328 |
< |
if (pixaspect < .99 || pixaspect > 1.01) |
328 |
> |
if ((pixaspect < .99) | (pixaspect > 1.01)) |
329 |
|
fputaspect(pixaspect, stdout); |
330 |
< |
if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005)) |
330 |
> |
if (ourexp > 0) |
331 |
> |
ourexp *= rexpadj; |
332 |
> |
else |
333 |
> |
ourexp = rexpadj; |
334 |
> |
if ((ourexp < .995) | (ourexp > 1.005)) |
335 |
|
fputexpos(ourexp, stdout); |
336 |
< |
fputformat(COLRFMT, stdout); |
336 |
> |
if (strcmp(ourfmt, PICFMT)) /* print format if known */ |
337 |
> |
fputformat(ourfmt, stdout); |
338 |
|
putc('\n', stdout); |
339 |
|
/* write picture */ |
340 |
|
writepicture(); |
345 |
|
exit(0); |
346 |
|
userr: |
347 |
|
fprintf(stderr, |
348 |
< |
"Usage: %s [view opts][-t eps][-z zout][-fT][-n] pfile zspec ..\n", |
348 |
> |
"Usage: %s [view opts][-t eps][-z zout][-e spec][-B][-a|-q][-fT][-n] pfile zspec ..\n", |
349 |
|
progname); |
350 |
|
exit(1); |
351 |
|
#undef check |
352 |
|
} |
353 |
|
|
354 |
|
|
355 |
< |
headline(s) /* process header string */ |
356 |
< |
char *s; |
355 |
> |
static int |
356 |
> |
headline( /* process header string */ |
357 |
> |
char *s, |
358 |
> |
void *p |
359 |
> |
) |
360 |
|
{ |
361 |
|
char fmt[32]; |
362 |
|
|
363 |
|
if (isheadid(s)) |
364 |
< |
return; |
364 |
> |
return(0); |
365 |
|
if (formatval(fmt, s)) { |
366 |
< |
wrongformat = strcmp(fmt, COLRFMT); |
367 |
< |
return; |
366 |
> |
if (globmatch(ourfmt, fmt)) { |
367 |
> |
wrongformat = 0; |
368 |
> |
strcpy(ourfmt, fmt); |
369 |
> |
} else |
370 |
> |
wrongformat = 1; |
371 |
> |
return(0); |
372 |
|
} |
373 |
< |
putc('\t', stdout); |
374 |
< |
fputs(s, stdout); |
375 |
< |
|
373 |
> |
if (nvavg < 2) { |
374 |
> |
putc('\t', stdout); |
375 |
> |
fputs(s, stdout); |
376 |
> |
} |
377 |
|
if (isexpos(s)) { |
378 |
|
theirexp *= exposval(s); |
379 |
< |
return; |
379 |
> |
return(0); |
380 |
|
} |
381 |
|
if (isview(s) && sscanview(&theirview, s) > 0) |
382 |
|
gotview++; |
383 |
+ |
return(0); |
384 |
|
} |
385 |
|
|
386 |
|
|
387 |
< |
addpicture(pfile, zspec) /* add picture to output */ |
388 |
< |
char *pfile, *zspec; |
387 |
> |
static int |
388 |
> |
nextview( /* get and set next view */ |
389 |
> |
FILE *fp |
390 |
> |
) |
391 |
|
{ |
392 |
+ |
char linebuf[256]; |
393 |
+ |
char *err; |
394 |
+ |
register int i; |
395 |
+ |
|
396 |
+ |
if (fp != NULL) { |
397 |
+ |
do /* get new view */ |
398 |
+ |
if (fgets(linebuf, sizeof(linebuf), fp) == NULL) |
399 |
+ |
return(EOF); |
400 |
+ |
while (!isview(linebuf) || !sscanview(&ourview, linebuf)); |
401 |
+ |
} |
402 |
+ |
/* set new view */ |
403 |
+ |
if ((err = setview(&ourview)) != NULL) { |
404 |
+ |
fprintf(stderr, "%s: %s\n", progname, err); |
405 |
+ |
exit(1); |
406 |
+ |
} |
407 |
+ |
if (!nvavg) { /* first view */ |
408 |
+ |
avgview = ourview; |
409 |
+ |
return(nvavg++); |
410 |
+ |
} |
411 |
+ |
/* add to average view */ |
412 |
+ |
for (i = 0; i < 3; i++) { |
413 |
+ |
avgview.vp[i] += ourview.vp[i]; |
414 |
+ |
avgview.vdir[i] += ourview.vdir[i]; |
415 |
+ |
avgview.vup[i] += ourview.vup[i]; |
416 |
+ |
} |
417 |
+ |
avgview.horiz += ourview.horiz; |
418 |
+ |
avgview.vert += ourview.vert; |
419 |
+ |
avgview.hoff += ourview.hoff; |
420 |
+ |
avgview.voff += ourview.voff; |
421 |
+ |
avgview.vfore += ourview.vfore; |
422 |
+ |
avgview.vaft += ourview.vaft; |
423 |
+ |
return(nvavg++); |
424 |
+ |
} |
425 |
+ |
|
426 |
+ |
|
427 |
+ |
static void |
428 |
+ |
compavgview(void) /* compute average view */ |
429 |
+ |
{ |
430 |
+ |
register int i; |
431 |
+ |
double f; |
432 |
+ |
|
433 |
+ |
if (nvavg < 2) |
434 |
+ |
return; |
435 |
+ |
f = 1.0/nvavg; |
436 |
+ |
for (i = 0; i < 3; i++) { |
437 |
+ |
avgview.vp[i] *= f; |
438 |
+ |
avgview.vdir[i] *= f; |
439 |
+ |
avgview.vup[i] *= f; |
440 |
+ |
} |
441 |
+ |
avgview.horiz *= f; |
442 |
+ |
avgview.vert *= f; |
443 |
+ |
avgview.hoff *= f; |
444 |
+ |
avgview.voff *= f; |
445 |
+ |
avgview.vfore *= f; |
446 |
+ |
avgview.vaft *= f; |
447 |
+ |
if (setview(&avgview) != NULL) /* in case of emergency... */ |
448 |
+ |
avgview = ourview; |
449 |
+ |
pixaspect = viewaspect(&avgview) * hresolu / vresolu; |
450 |
+ |
} |
451 |
+ |
|
452 |
+ |
|
453 |
+ |
static void |
454 |
+ |
addpicture( /* add picture to output */ |
455 |
+ |
char *pfile, |
456 |
+ |
char *zspec |
457 |
+ |
) |
458 |
+ |
{ |
459 |
|
FILE *pfp; |
460 |
|
int zfd; |
461 |
|
char *err; |
469 |
|
syserror(pfile); |
470 |
|
/* get header with exposure and view */ |
471 |
|
theirexp = 1.0; |
472 |
+ |
theirview = stdview; |
473 |
|
gotview = 0; |
474 |
< |
printf("%s:\n", pfile); |
474 |
> |
if (nvavg < 2) |
475 |
> |
printf("%s:\n", pfile); |
476 |
|
getheader(pfp, headline, NULL); |
477 |
|
if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) { |
478 |
|
fprintf(stderr, "%s: picture format error\n", pfile); |
482 |
|
ourexp = theirexp; |
483 |
|
else if (ABS(theirexp-ourexp) > .01*ourexp) |
484 |
|
fprintf(stderr, "%s: different exposure (warning)\n", pfile); |
485 |
< |
if (err = setview(&theirview)) { |
485 |
> |
if ( (err = setview(&theirview)) ) { |
486 |
|
fprintf(stderr, "%s: %s\n", pfile, err); |
487 |
|
exit(1); |
488 |
|
} |
495 |
|
if ((zfd = open(zspec, O_RDONLY)) == -1) { |
496 |
|
double zvalue; |
497 |
|
register int x; |
498 |
< |
if (!isfloat(zspec) || (zvalue = atof(zspec)) <= 0.0) |
498 |
> |
if (!isflt(zspec) || (zvalue = atof(zspec)) <= 0.0) |
499 |
|
syserror(zspec); |
500 |
|
for (x = scanlen(&tresolu); x-- > 0; ) |
501 |
|
zin[x] = zvalue; |
505 |
|
if (xlim == NULL) |
506 |
|
syserror(progname); |
507 |
|
if (!getperim(xlim, &ylim, zin, zfd)) { /* overlapping area? */ |
508 |
< |
free((char *)zin); |
509 |
< |
free((char *)xlim); |
508 |
> |
free((void *)zin); |
509 |
> |
free((void *)xlim); |
510 |
|
if (zfd != -1) |
511 |
|
close(zfd); |
512 |
|
fclose(pfp); |
516 |
|
scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); |
517 |
|
plast = (struct position *)calloc(scanlen(&tresolu), |
518 |
|
sizeof(struct position)); |
519 |
< |
if (scanin == NULL | plast == NULL) |
519 |
> |
if ((scanin == NULL) | (plast == NULL)) |
520 |
|
syserror(progname); |
521 |
|
/* skip to starting point */ |
522 |
|
for (y = 0; y < ylim.min; y++) |
525 |
|
exit(1); |
526 |
|
} |
527 |
|
if (zfd != -1 && lseek(zfd, |
528 |
< |
(long)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0) |
528 |
> |
(off_t)ylim.min*scanlen(&tresolu)*sizeof(float), |
529 |
> |
SEEK_SET) < 0) |
530 |
|
syserror(zspec); |
531 |
|
/* load image */ |
532 |
|
for (y = ylim.min; y <= ylim.max; y++) { |
541 |
|
addscanline(xlim+y, y, scanin, zin, plast); |
542 |
|
} |
543 |
|
/* clean up */ |
544 |
< |
free((char *)xlim); |
545 |
< |
free((char *)scanin); |
546 |
< |
free((char *)zin); |
547 |
< |
free((char *)plast); |
544 |
> |
free((void *)xlim); |
545 |
> |
free((void *)scanin); |
546 |
> |
free((void *)zin); |
547 |
> |
free((void *)plast); |
548 |
|
fclose(pfp); |
549 |
|
if (zfd != -1) |
550 |
|
close(zfd); |
551 |
|
} |
552 |
|
|
553 |
|
|
554 |
< |
pixform(xfmat, vw1, vw2) /* compute view1 to view2 matrix */ |
555 |
< |
register double xfmat[4][4]; |
556 |
< |
register VIEW *vw1, *vw2; |
554 |
> |
static int |
555 |
> |
pixform( /* compute view1 to view2 matrix */ |
556 |
> |
register MAT4 xfmat, |
557 |
> |
register VIEW *vw1, |
558 |
> |
register VIEW *vw2 |
559 |
> |
) |
560 |
|
{ |
561 |
|
double m4t[4][4]; |
562 |
|
|
563 |
< |
if (vw1->type != VT_PER && vw1->type != VT_PAR) |
563 |
> |
if ((vw1->type != VT_PER) & (vw1->type != VT_PAR)) |
564 |
|
return(0); |
565 |
< |
if (vw2->type != VT_PER && vw2->type != VT_PAR) |
565 |
> |
if ((vw2->type != VT_PER) & (vw2->type != VT_PAR)) |
566 |
|
return(0); |
567 |
|
setident4(xfmat); |
568 |
|
xfmat[0][0] = vw1->hvec[0]; |
595 |
|
} |
596 |
|
|
597 |
|
|
598 |
< |
addscanline(xl, y, pline, zline, lasty) /* add scanline to output */ |
599 |
< |
struct bound *xl; |
600 |
< |
int y; |
601 |
< |
COLR *pline; |
602 |
< |
float *zline; |
603 |
< |
struct position *lasty; /* input/output */ |
598 |
> |
static void |
599 |
> |
addscanline( /* add scanline to output */ |
600 |
> |
struct bound *xl, |
601 |
> |
int y, |
602 |
> |
COLR *pline, |
603 |
> |
float *zline, |
604 |
> |
struct position *lasty /* input/output */ |
605 |
> |
) |
606 |
|
{ |
607 |
|
FVECT pos; |
608 |
|
struct position lastx, newpos; |
609 |
+ |
double wt; |
610 |
|
register int x; |
611 |
|
|
612 |
|
lastx.z = 0; |
613 |
|
for (x = xl->max; x >= xl->min; x--) { |
614 |
|
pix2loc(pos, &tresolu, x, y); |
615 |
|
pos[2] = zline[x]; |
616 |
< |
if (movepixel(pos) < 0) { |
616 |
> |
if ((wt = movepixel(pos)) <= FTINY) { |
617 |
|
lasty[x].z = lastx.z = 0; /* mark invalid */ |
618 |
|
continue; |
619 |
|
} |
620 |
+ |
/* add pixel to our image */ |
621 |
|
newpos.x = pos[0] * hresolu; |
622 |
|
newpos.y = pos[1] * vresolu; |
623 |
|
newpos.z = zline[x]; |
624 |
< |
/* add pixel to our image */ |
625 |
< |
if (pos[0] >= 0 && newpos.x < hresolu |
626 |
< |
&& pos[1] >= 0 && newpos.y < vresolu) { |
627 |
< |
addpixel(&newpos, &lastx, &lasty[x], pline[x], pos[2]); |
433 |
< |
lasty[x].x = lastx.x = newpos.x; |
434 |
< |
lasty[x].y = lastx.y = newpos.y; |
435 |
< |
lasty[x].z = lastx.z = newpos.z; |
436 |
< |
} else |
437 |
< |
lasty[x].z = lastx.z = 0; /* mark invalid */ |
624 |
> |
addpixel(&newpos, &lastx, &lasty[x], pline[x], wt, pos[2]); |
625 |
> |
lasty[x].x = lastx.x = newpos.x; |
626 |
> |
lasty[x].y = lastx.y = newpos.y; |
627 |
> |
lasty[x].z = lastx.z = newpos.z; |
628 |
|
} |
629 |
|
} |
630 |
|
|
631 |
|
|
632 |
< |
addpixel(p0, p1, p2, pix, z) /* fill in pixel parallelogram */ |
633 |
< |
struct position *p0, *p1, *p2; |
634 |
< |
COLR pix; |
635 |
< |
double z; |
632 |
> |
static void |
633 |
> |
addpixel( /* fill in pixel parallelogram */ |
634 |
> |
struct position *p0, |
635 |
> |
struct position *p1, |
636 |
> |
struct position *p2, |
637 |
> |
COLR pix, |
638 |
> |
double w, |
639 |
> |
double z |
640 |
> |
) |
641 |
|
{ |
642 |
|
double zt = 2.*zeps*p0->z; /* threshold */ |
643 |
+ |
COLOR pval; /* converted+weighted pixel */ |
644 |
|
int s1x, s1y, s2x, s2y; /* step sizes */ |
645 |
|
int l1, l2, c1, c2; /* side lengths and counters */ |
646 |
|
int p1isy; /* p0p1 along y? */ |
652 |
|
s1x = p1->x - p0->x; |
653 |
|
s1y = p1->y - p0->y; |
654 |
|
l1 = ABS(s1x); |
655 |
< |
if (p1isy = (ABS(s1y) > l1)) |
655 |
> |
if ( (p1isy = (ABS(s1y) > l1)) ) |
656 |
|
l1 = ABS(s1y); |
657 |
+ |
else if (l1 < 1) |
658 |
+ |
l1 = 1; |
659 |
|
} else { |
660 |
|
l1 = s1x = s1y = 1; |
661 |
|
p1isy = -1; |
671 |
|
if (p1isy != 0 && ABS(s2x) > l2) |
672 |
|
l2 = ABS(s2x); |
673 |
|
} |
674 |
+ |
if (l2 < 1) |
675 |
+ |
l2 = 1; |
676 |
|
} else |
677 |
|
l2 = s2x = s2y = 1; |
678 |
|
/* fill the parallelogram */ |
679 |
+ |
if (averaging) { |
680 |
+ |
colr_color(pval, pix); |
681 |
+ |
scalecolor(pval, w); |
682 |
+ |
} |
683 |
|
for (c1 = l1; c1-- > 0; ) { |
684 |
|
x1 = p0->x + c1*s1x/l1; |
685 |
|
y1 = p0->y + c1*s1y/l1; |
686 |
|
for (c2 = l2; c2-- > 0; ) { |
687 |
|
x = x1 + c2*s2x/l2; |
688 |
< |
if (x < 0 || x >= hresolu) |
688 |
> |
if ((x < 0) | (x >= hresolu)) |
689 |
|
continue; |
690 |
|
y = y1 + c2*s2y/l2; |
691 |
< |
if (y < 0 || y >= vresolu) |
691 |
> |
if ((y < 0) | (y >= vresolu)) |
692 |
|
continue; |
693 |
< |
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
693 |
> |
if (averaging) { |
694 |
> |
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
695 |
|
> zeps*zscan(y)[x]) { |
696 |
< |
zscan(y)[x] = z; |
696 |
> |
copycolor(sscan(y)[x], pval); |
697 |
> |
wscan(y)[x] = w; |
698 |
> |
zscan(y)[x] = z; |
699 |
> |
} else if (z-zscan(y)[x] <= zeps*zscan(y)[x]) { |
700 |
> |
addcolor(sscan(y)[x], pval); |
701 |
> |
wscan(y)[x] += w; |
702 |
> |
} |
703 |
> |
} else if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
704 |
> |
> zeps*zscan(y)[x]) { |
705 |
|
copycolr(pscan(y)[x], pix); |
706 |
+ |
zscan(y)[x] = z; |
707 |
|
} |
708 |
|
} |
709 |
|
} |
710 |
|
} |
711 |
|
|
712 |
|
|
713 |
< |
getperim(xl, yl, zline, zfd) /* compute overlapping image area */ |
714 |
< |
register struct bound *xl; |
715 |
< |
struct bound *yl; |
716 |
< |
float *zline; |
503 |
< |
int zfd; |
713 |
> |
static double |
714 |
> |
movepixel( /* reposition image point */ |
715 |
> |
register FVECT pos |
716 |
> |
) |
717 |
|
{ |
718 |
+ |
FVECT pt, tdir, odir; |
719 |
+ |
double d; |
720 |
+ |
|
721 |
+ |
if (pos[2] <= 0) /* empty pixel */ |
722 |
+ |
return(0); |
723 |
+ |
if (usematrix) { |
724 |
+ |
pos[0] += theirview.hoff - .5; |
725 |
+ |
pos[1] += theirview.voff - .5; |
726 |
+ |
if (normdist & (theirview.type == VT_PER)) |
727 |
+ |
d = sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
728 |
+ |
+ pos[1]*pos[1]*theirview.vn2); |
729 |
+ |
else |
730 |
+ |
d = 1.; |
731 |
+ |
pos[2] += d*theirview.vfore; |
732 |
+ |
if (theirview.type == VT_PER) { |
733 |
+ |
pos[2] /= d; |
734 |
+ |
pos[0] *= pos[2]; |
735 |
+ |
pos[1] *= pos[2]; |
736 |
+ |
} |
737 |
+ |
multp3(pos, pos, theirs2ours); |
738 |
+ |
if (pos[2] <= ourview.vfore) |
739 |
+ |
return(0); |
740 |
+ |
if (ourview.type == VT_PER) { |
741 |
+ |
pos[0] /= pos[2]; |
742 |
+ |
pos[1] /= pos[2]; |
743 |
+ |
} |
744 |
+ |
pos[0] += .5 - ourview.hoff; |
745 |
+ |
pos[1] += .5 - ourview.voff; |
746 |
+ |
pos[2] -= ourview.vfore; |
747 |
+ |
} else { |
748 |
+ |
if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) |
749 |
+ |
return(0); |
750 |
+ |
if ((!normdist) & (theirview.type == VT_PER)) /* adjust */ |
751 |
+ |
pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
752 |
+ |
+ pos[1]*pos[1]*theirview.vn2); |
753 |
+ |
pt[0] += tdir[0]*pos[2]; |
754 |
+ |
pt[1] += tdir[1]*pos[2]; |
755 |
+ |
pt[2] += tdir[2]*pos[2]; |
756 |
+ |
viewloc(pos, &ourview, pt); |
757 |
+ |
if (pos[2] <= 0) |
758 |
+ |
return(0); |
759 |
+ |
} |
760 |
+ |
if ((pos[0] < 0) | (pos[0] >= 1-FTINY) | (pos[1] < 0) | (pos[1] >= 1-FTINY)) |
761 |
+ |
return(0); |
762 |
+ |
if (!averaging) |
763 |
+ |
return(1); |
764 |
+ |
/* compute pixel weight */ |
765 |
+ |
if (ourview.type == VT_PAR) { |
766 |
+ |
d = DOT(ourview.vdir,tdir); |
767 |
+ |
d = 1. - d*d; |
768 |
+ |
} else { |
769 |
+ |
VSUB(odir, pt, ourview.vp); |
770 |
+ |
d = DOT(odir,tdir); |
771 |
+ |
d = 1. - d*d/DOT(odir,odir); |
772 |
+ |
} |
773 |
+ |
if (d <= 1./MAXWT/MAXWT) |
774 |
+ |
return(MAXWT); /* clip to maximum weight */ |
775 |
+ |
return(1./sqrt(d)); |
776 |
+ |
} |
777 |
+ |
|
778 |
+ |
|
779 |
+ |
static int |
780 |
+ |
getperim( /* compute overlapping image area */ |
781 |
+ |
register struct bound *xl, |
782 |
+ |
struct bound *yl, |
783 |
+ |
float *zline, |
784 |
+ |
int zfd |
785 |
+ |
) |
786 |
+ |
{ |
787 |
|
int step; |
788 |
|
FVECT pos; |
789 |
|
register int x, y; |
805 |
|
yl->min = 32000; yl->max = 0; /* search for points on image */ |
806 |
|
for (y = step - 1; y < numscans(&tresolu); y += step) { |
807 |
|
if (zfd != -1) { |
808 |
< |
if (lseek(zfd, (long)y*scanlen(&tresolu)*sizeof(float), |
809 |
< |
0) < 0) |
808 |
> |
if (lseek(zfd, (off_t)y*scanlen(&tresolu)*sizeof(float), |
809 |
> |
SEEK_SET) < 0) |
810 |
|
syserror("lseek"); |
811 |
|
if (read(zfd, (char *)zline, |
812 |
|
scanlen(&tresolu)*sizeof(float)) |
817 |
|
for (x = scanlen(&tresolu); (x -= step) > 0; ) { |
818 |
|
pix2loc(pos, &tresolu, x, y); |
819 |
|
pos[2] = zline[x]; |
820 |
< |
if (movepixel(pos) == 0 && pos[0] >= 0 && |
539 |
< |
pos[0] < 1 && pos[1] >= 0 && |
540 |
< |
pos[1] < 1) { |
820 |
> |
if (movepixel(pos) > FTINY) { |
821 |
|
xl[y].max = x + step - 1; |
822 |
|
xl[y].min = x - step + 1; /* x min */ |
823 |
|
if (xl[y].min < 0) |
825 |
|
for (x = step - 1; x < xl[y].max; x += step) { |
826 |
|
pix2loc(pos, &tresolu, x, y); |
827 |
|
pos[2] = zline[x]; |
828 |
< |
if (movepixel(pos) == 0 && |
549 |
< |
pos[0] >= 0 && |
550 |
< |
pos[0] < 1 && |
551 |
< |
pos[1] >= 0 && |
552 |
< |
pos[1] < 1) { |
828 |
> |
if (movepixel(pos) > FTINY) { |
829 |
|
xl[y].min = x - step + 1; |
830 |
|
break; |
831 |
|
} |
837 |
|
} |
838 |
|
} |
839 |
|
/* fill in between */ |
840 |
< |
if (xl[y].min < xl[y-step].min) |
840 |
> |
if (y < step) { |
841 |
|
xl[y-1].min = xl[y].min; |
566 |
– |
else |
567 |
– |
xl[y-1].min = xl[y-step].min; |
568 |
– |
if (xl[y].max > xl[y-step].max) |
842 |
|
xl[y-1].max = xl[y].max; |
843 |
< |
else |
844 |
< |
xl[y-1].max = xl[y-step].max; |
843 |
> |
} else { |
844 |
> |
if (xl[y].min < xl[y-step].min) |
845 |
> |
xl[y-1].min = xl[y].min; |
846 |
> |
else |
847 |
> |
xl[y-1].min = xl[y-step].min; |
848 |
> |
if (xl[y].max > xl[y-step].max) |
849 |
> |
xl[y-1].max = xl[y].max; |
850 |
> |
else |
851 |
> |
xl[y-1].max = xl[y-step].max; |
852 |
> |
} |
853 |
|
for (x = 2; x < step; x++) |
854 |
< |
copystruct(xl+y-x, xl+y-1); |
854 |
> |
*(xl+y-x) = *(xl+y-1); |
855 |
|
} |
856 |
|
if (yl->max >= numscans(&tresolu)) |
857 |
|
yl->max = numscans(&tresolu) - 1; |
858 |
+ |
y -= step; |
859 |
|
for (x = numscans(&tresolu) - 1; x > y; x--) /* fill bottom rows */ |
860 |
< |
copystruct(xl+x, xl+y); |
860 |
> |
*(xl+x) = *(xl+y); |
861 |
|
return(yl->max >= yl->min); |
862 |
|
} |
863 |
|
|
864 |
|
|
865 |
< |
movepixel(pos) /* reposition image point */ |
866 |
< |
FVECT pos; |
865 |
> |
static void |
866 |
> |
backpicture( /* background fill algorithm */ |
867 |
> |
fillfunc_t *fill, |
868 |
> |
int samp |
869 |
> |
) |
870 |
|
{ |
586 |
– |
double d0, d1; |
587 |
– |
FVECT pt, direc; |
588 |
– |
|
589 |
– |
if (pos[2] <= 0) /* empty pixel */ |
590 |
– |
return(-1); |
591 |
– |
if (normdist && theirview.type == VT_PER) { /* adjust distance */ |
592 |
– |
d0 = pos[0] + theirview.hoff - .5; |
593 |
– |
d1 = pos[1] + theirview.voff - .5; |
594 |
– |
pos[2] /= sqrt(1. + d0*d0*theirview.hn2 + d1*d1*theirview.vn2); |
595 |
– |
} |
596 |
– |
if (hasmatrix) { |
597 |
– |
pos[0] += theirview.hoff - .5; |
598 |
– |
pos[1] += theirview.voff - .5; |
599 |
– |
if (theirview.type == VT_PER) { |
600 |
– |
pos[0] *= pos[2]; |
601 |
– |
pos[1] *= pos[2]; |
602 |
– |
} |
603 |
– |
multp3(pos, pos, theirs2ours); |
604 |
– |
if (pos[2] <= 0) |
605 |
– |
return(-1); |
606 |
– |
if (ourview.type == VT_PER) { |
607 |
– |
pos[0] /= pos[2]; |
608 |
– |
pos[1] /= pos[2]; |
609 |
– |
} |
610 |
– |
pos[0] += .5 - ourview.hoff; |
611 |
– |
pos[1] += .5 - ourview.voff; |
612 |
– |
return(0); |
613 |
– |
} |
614 |
– |
if (viewray(pt, direc, &theirview, pos[0], pos[1]) < -FTINY) |
615 |
– |
return(-1); |
616 |
– |
pt[0] += direc[0]*pos[2]; |
617 |
– |
pt[1] += direc[1]*pos[2]; |
618 |
– |
pt[2] += direc[2]*pos[2]; |
619 |
– |
viewloc(pos, &ourview, pt); |
620 |
– |
if (pos[2] <= 0) |
621 |
– |
return(-1); |
622 |
– |
return(0); |
623 |
– |
} |
624 |
– |
|
625 |
– |
|
626 |
– |
backpicture(fill, samp) /* background fill algorithm */ |
627 |
– |
int (*fill)(); |
628 |
– |
int samp; |
629 |
– |
{ |
871 |
|
int *yback, xback; |
872 |
|
int y; |
873 |
|
register int x, i; |
934 |
|
< zscan(y)[xback] ) ) { |
935 |
|
if (samp > 0 && ABS(x-xback) >= samp) |
936 |
|
goto fillit; |
937 |
< |
copycolr(pscan(y)[x],pscan(y)[xback]); |
937 |
> |
if (averaging) { |
938 |
> |
copycolor(sscan(y)[x], |
939 |
> |
sscan(y)[xback]); |
940 |
> |
wscan(y)[x] = wscan(y)[xback]; |
941 |
> |
} else |
942 |
> |
copycolr(pscan(y)[x], |
943 |
> |
pscan(y)[xback]); |
944 |
|
zscan(y)[x] = zscan(y)[xback]; |
945 |
|
} else { |
946 |
|
if (samp > 0 && ABS(y-yback[x]) > samp) |
947 |
|
goto fillit; |
948 |
< |
copycolr(pscan(y)[x],pscan(yback[x])[x]); |
948 |
> |
if (averaging) { |
949 |
> |
copycolor(sscan(y)[x], |
950 |
> |
sscan(yback[x])[x]); |
951 |
> |
wscan(y)[x] = |
952 |
> |
wscan(yback[x])[x]; |
953 |
> |
} else |
954 |
> |
copycolr(pscan(y)[x], |
955 |
> |
pscan(yback[x])[x]); |
956 |
|
zscan(y)[x] = zscan(yback[x])[x]; |
957 |
|
} |
958 |
|
continue; |
968 |
|
xback = -2; |
969 |
|
} |
970 |
|
} |
971 |
< |
free((char *)yback); |
971 |
> |
free((void *)yback); |
972 |
|
} |
973 |
|
|
974 |
|
|
975 |
< |
fillpicture(fill) /* paint in empty pixels using fill */ |
976 |
< |
int (*fill)(); |
975 |
> |
static void |
976 |
> |
fillpicture( /* paint in empty pixels using fill */ |
977 |
> |
fillfunc_t *fill |
978 |
> |
) |
979 |
|
{ |
980 |
|
register int x, y; |
981 |
|
|
983 |
|
for (x = 0; x < hresolu; x++) |
984 |
|
if (zscan(y)[x] <= 0) |
985 |
|
(*fill)(x,y); |
986 |
+ |
if (fill == rcalfill) |
987 |
+ |
clearqueue(); |
988 |
|
} |
989 |
|
|
990 |
|
|
991 |
< |
clipaft() /* perform aft clipping as indicated */ |
991 |
> |
static int |
992 |
> |
clipaft(void) /* perform aft clipping as indicated */ |
993 |
|
{ |
994 |
|
register int x, y; |
995 |
+ |
int adjtest = (ourview.type == VT_PER) & zisnorm; |
996 |
|
double tstdist; |
997 |
|
double yzn2, vx; |
998 |
|
|
999 |
|
if (ourview.vaft <= FTINY) |
1000 |
< |
return; |
1000 |
> |
return(0); |
1001 |
|
tstdist = ourview.vaft - ourview.vfore; |
1002 |
|
for (y = 0; y < vresolu; y++) { |
1003 |
< |
if (ourview.type == VT_PER) { /* adjust distance */ |
1003 |
> |
if (adjtest) { /* adjust test */ |
1004 |
|
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
1005 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
1006 |
|
tstdist = (ourview.vaft - ourview.vfore)*sqrt(yzn2); |
1007 |
|
} |
1008 |
|
for (x = 0; x < hresolu; x++) |
1009 |
|
if (zscan(y)[x] > tstdist) { |
1010 |
< |
if (ourview.type == VT_PER) { |
1010 |
> |
if (adjtest) { |
1011 |
|
vx = (x+.5)/hresolu + ourview.hoff - .5; |
1012 |
|
if (zscan(y)[x] <= (ourview.vaft - |
1013 |
|
ourview.vfore) * |
1014 |
|
sqrt(vx*vx*ourview.hn2 + yzn2)) |
1015 |
|
continue; |
1016 |
|
} |
1017 |
< |
bzero(pscan(y)[x], sizeof(COLR)); |
1017 |
> |
if (averaging) |
1018 |
> |
memset(sscan(y)[x], '\0', sizeof(COLOR)); |
1019 |
> |
else |
1020 |
> |
memset(pscan(y)[x], '\0', sizeof(COLR)); |
1021 |
|
zscan(y)[x] = 0.0; |
1022 |
|
} |
1023 |
|
} |
1024 |
+ |
return(1); |
1025 |
|
} |
1026 |
|
|
1027 |
|
|
1028 |
< |
writepicture() /* write out picture */ |
1028 |
> |
static int |
1029 |
> |
addblur(void) /* add to blurred picture */ |
1030 |
|
{ |
1031 |
+ |
COLOR cval; |
1032 |
+ |
double d; |
1033 |
+ |
register int i; |
1034 |
+ |
|
1035 |
+ |
if (!blurring) |
1036 |
+ |
return(0); |
1037 |
+ |
i = hresolu*vresolu; |
1038 |
+ |
if (nvavg < 2) |
1039 |
+ |
if (averaging) |
1040 |
+ |
while (i--) { |
1041 |
+ |
copycolor(ourbpict[i], ourspict[i]); |
1042 |
+ |
d = 1.0/ourweigh[i]; |
1043 |
+ |
scalecolor(ourbpict[i], d); |
1044 |
+ |
} |
1045 |
+ |
else |
1046 |
+ |
while (i--) |
1047 |
+ |
colr_color(ourbpict[i], ourpict[i]); |
1048 |
+ |
else |
1049 |
+ |
if (averaging) |
1050 |
+ |
while (i--) { |
1051 |
+ |
copycolor(cval, ourspict[i]); |
1052 |
+ |
d = 1.0/ourweigh[i]; |
1053 |
+ |
scalecolor(cval, d); |
1054 |
+ |
addcolor(ourbpict[i], cval); |
1055 |
+ |
} |
1056 |
+ |
else |
1057 |
+ |
while (i--) { |
1058 |
+ |
colr_color(cval, ourpict[i]); |
1059 |
+ |
addcolor(ourbpict[i], cval); |
1060 |
+ |
} |
1061 |
+ |
/* print view */ |
1062 |
+ |
printf("VIEW%d:", nvavg); |
1063 |
+ |
fprintview(&ourview, stdout); |
1064 |
+ |
putchar('\n'); |
1065 |
+ |
return(1); |
1066 |
+ |
} |
1067 |
+ |
|
1068 |
+ |
|
1069 |
+ |
static void |
1070 |
+ |
writepicture(void) /* write out picture (alters buffer) */ |
1071 |
+ |
{ |
1072 |
|
int y; |
1073 |
+ |
register int x; |
1074 |
+ |
double d; |
1075 |
|
|
1076 |
|
fprtresolu(hresolu, vresolu, stdout); |
1077 |
|
for (y = vresolu-1; y >= 0; y--) |
1078 |
< |
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
1079 |
< |
syserror(progname); |
1078 |
> |
if (blurring) { |
1079 |
> |
for (x = 0; x < hresolu; x++) { /* compute avg. */ |
1080 |
> |
d = rexpadj/nvavg; |
1081 |
> |
scalecolor(bscan(y)[x], d); |
1082 |
> |
} |
1083 |
> |
if (fwritescan(bscan(y), hresolu, stdout) < 0) |
1084 |
> |
syserror(progname); |
1085 |
> |
} else if (averaging) { |
1086 |
> |
for (x = 0; x < hresolu; x++) { /* average pixels */ |
1087 |
> |
d = rexpadj/wscan(y)[x]; |
1088 |
> |
scalecolor(sscan(y)[x], d); |
1089 |
> |
} |
1090 |
> |
if (fwritescan(sscan(y), hresolu, stdout) < 0) |
1091 |
> |
syserror(progname); |
1092 |
> |
} else { |
1093 |
> |
if (expadj) |
1094 |
> |
shiftcolrs(pscan(y), hresolu, expadj); |
1095 |
> |
if (fwritecolrs(pscan(y), hresolu, stdout) < 0) |
1096 |
> |
syserror(progname); |
1097 |
> |
} |
1098 |
|
} |
1099 |
|
|
1100 |
|
|
1101 |
< |
writedistance(fname) /* write out z file */ |
1102 |
< |
char *fname; |
1101 |
> |
static void |
1102 |
> |
writedistance( /* write out z file (alters buffer) */ |
1103 |
> |
char *fname |
1104 |
> |
) |
1105 |
|
{ |
1106 |
< |
int donorm = normdist && ourview.type == VT_PER; |
1106 |
> |
int donorm = normdist & !zisnorm ? 1 : |
1107 |
> |
(ourview.type == VT_PER) & !normdist & zisnorm ? -1 : 0; |
1108 |
|
int fd; |
1109 |
|
int y; |
781 |
– |
float *zout; |
1110 |
|
|
1111 |
|
if ((fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) == -1) |
1112 |
|
syserror(fname); |
785 |
– |
if (donorm |
786 |
– |
&& (zout = (float *)malloc(hresolu*sizeof(float))) == NULL) |
787 |
– |
syserror(progname); |
1113 |
|
for (y = vresolu-1; y >= 0; y--) { |
1114 |
|
if (donorm) { |
1115 |
< |
double vx, yzn2; |
1115 |
> |
double vx, yzn2, d; |
1116 |
|
register int x; |
1117 |
|
yzn2 = (y+.5)/vresolu + ourview.voff - .5; |
1118 |
|
yzn2 = 1. + yzn2*yzn2*ourview.vn2; |
1119 |
|
for (x = 0; x < hresolu; x++) { |
1120 |
|
vx = (x+.5)/hresolu + ourview.hoff - .5; |
1121 |
< |
zout[x] = zscan(y)[x] |
1122 |
< |
* sqrt(vx*vx*ourview.hn2 + yzn2); |
1121 |
> |
d = sqrt(vx*vx*ourview.hn2 + yzn2); |
1122 |
> |
if (donorm > 0) |
1123 |
> |
zscan(y)[x] *= d; |
1124 |
> |
else |
1125 |
> |
zscan(y)[x] /= d; |
1126 |
|
} |
1127 |
< |
} else |
1128 |
< |
zout = zscan(y); |
801 |
< |
if (write(fd, (char *)zout, hresolu*sizeof(float)) |
1127 |
> |
} |
1128 |
> |
if (write(fd, (char *)zscan(y), hresolu*sizeof(float)) |
1129 |
|
< hresolu*sizeof(float)) |
1130 |
|
syserror(fname); |
1131 |
|
} |
805 |
– |
if (donorm) |
806 |
– |
free((char *)zout); |
1132 |
|
close(fd); |
1133 |
|
} |
1134 |
|
|
1135 |
|
|
1136 |
< |
isfloat(s) /* see if string is floating number */ |
1137 |
< |
register char *s; |
1136 |
> |
static void |
1137 |
> |
backfill( /* fill pixel with background */ |
1138 |
> |
int x, |
1139 |
> |
int y |
1140 |
> |
) |
1141 |
|
{ |
1142 |
< |
for ( ; *s; s++) |
1143 |
< |
if ((*s < '0' || *s > '9') && *s != '.' && *s != '-' |
1144 |
< |
&& *s != 'e' && *s != 'E' && *s != '+') |
1145 |
< |
return(0); |
1146 |
< |
return(1); |
819 |
< |
} |
820 |
< |
|
821 |
< |
|
822 |
< |
backfill(x, y) /* fill pixel with background */ |
823 |
< |
int x, y; |
824 |
< |
{ |
825 |
< |
register BYTE *dest = pscan(y)[x]; |
826 |
< |
|
827 |
< |
copycolr(dest, backcolr); |
1142 |
> |
if (averaging) { |
1143 |
> |
copycolor(sscan(y)[x], backcolor); |
1144 |
> |
wscan(y)[x] = 1; |
1145 |
> |
} else |
1146 |
> |
copycolr(pscan(y)[x], backcolr); |
1147 |
|
zscan(y)[x] = backz; |
1148 |
|
} |
1149 |
|
|
1150 |
|
|
1151 |
< |
calstart(prog, args) /* start fill calculation */ |
1152 |
< |
char *prog, *args; |
1151 |
> |
static void |
1152 |
> |
calstart( /* start fill calculation */ |
1153 |
> |
char *prog, |
1154 |
> |
char *args |
1155 |
> |
) |
1156 |
|
{ |
1157 |
|
char combuf[512]; |
1158 |
|
char *argv[64]; |
1159 |
|
int rval; |
1160 |
|
register char **wp, *cp; |
1161 |
|
|
1162 |
< |
if (childpid != -1) { |
1162 |
> |
if (PDesc.running) { |
1163 |
|
fprintf(stderr, "%s: too many calculations\n", progname); |
1164 |
|
exit(1); |
1165 |
|
} |
1178 |
|
} |
1179 |
|
*wp = NULL; |
1180 |
|
/* start process */ |
1181 |
< |
if ((rval = open_process(PDesc, argv)) < 0) |
1181 |
> |
if ((rval = open_process(&PDesc, argv)) < 0) |
1182 |
|
syserror(progname); |
1183 |
|
if (rval == 0) { |
1184 |
|
fprintf(stderr, "%s: command not found\n", argv[0]); |
1191 |
|
} |
1192 |
|
|
1193 |
|
|
1194 |
< |
caldone() /* done with calculation */ |
1194 |
> |
static void |
1195 |
> |
caldone(void) /* done with calculation */ |
1196 |
|
{ |
1197 |
< |
if (childpid == -1) |
1197 |
> |
if (!PDesc.running) |
1198 |
|
return; |
1199 |
|
clearqueue(); |
1200 |
< |
close_process(PDesc); |
878 |
< |
childpid = -1; |
1200 |
> |
close_process(&PDesc); |
1201 |
|
} |
1202 |
|
|
1203 |
|
|
1204 |
< |
rcalfill(x, y) /* fill with ray-calculated pixel */ |
1205 |
< |
int x, y; |
1204 |
> |
static void |
1205 |
> |
rcalfill( /* fill with ray-calculated pixel */ |
1206 |
> |
int x, |
1207 |
> |
int y |
1208 |
> |
) |
1209 |
|
{ |
1210 |
|
if (queuesiz >= packsiz) /* flush queue if needed */ |
1211 |
|
clearqueue(); |
1216 |
|
} |
1217 |
|
|
1218 |
|
|
1219 |
< |
clearqueue() /* process queue */ |
1219 |
> |
static void |
1220 |
> |
clearqueue(void) /* process queue */ |
1221 |
|
{ |
1222 |
|
FVECT orig, dir; |
1223 |
|
float fbuf[6*(PACKSIZ+1)]; |
1224 |
|
register float *fbp; |
1225 |
|
register int i; |
1226 |
+ |
double vx, vy; |
1227 |
|
|
1228 |
|
if (queuesiz == 0) |
1229 |
|
return; |
1236 |
|
*fbp++ = dir[0]; *fbp++ = dir[1]; *fbp++ = dir[2]; |
1237 |
|
} |
1238 |
|
/* mark end and get results */ |
1239 |
< |
bzero((char *)fbp, 6*sizeof(float)); |
1240 |
< |
if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*queuesiz, |
1239 |
> |
memset((char *)fbp, '\0', 6*sizeof(float)); |
1240 |
> |
if (process(&PDesc, (char *)fbuf, (char *)fbuf, |
1241 |
> |
4*sizeof(float)*(queuesiz+1), |
1242 |
|
6*sizeof(float)*(queuesiz+1)) != |
1243 |
< |
4*sizeof(float)*queuesiz) { |
1243 |
> |
4*sizeof(float)*(queuesiz+1)) { |
1244 |
|
fprintf(stderr, "%s: error reading from rtrace process\n", |
1245 |
|
progname); |
1246 |
|
exit(1); |
1252 |
|
fbp[1] *= ourexp; |
1253 |
|
fbp[2] *= ourexp; |
1254 |
|
} |
1255 |
< |
setcolr(pscan(queue[i][1])[queue[i][0]], |
1256 |
< |
fbp[0], fbp[1], fbp[2]); |
1257 |
< |
zscan(queue[i][1])[queue[i][0]] = fbp[3]; |
1255 |
> |
if (averaging) { |
1256 |
> |
setcolor(sscan(queue[i][1])[queue[i][0]], |
1257 |
> |
fbp[0], fbp[1], fbp[2]); |
1258 |
> |
wscan(queue[i][1])[queue[i][0]] = 1; |
1259 |
> |
} else |
1260 |
> |
setcolr(pscan(queue[i][1])[queue[i][0]], |
1261 |
> |
fbp[0], fbp[1], fbp[2]); |
1262 |
> |
if (zisnorm) |
1263 |
> |
zscan(queue[i][1])[queue[i][0]] = fbp[3]; |
1264 |
> |
else { |
1265 |
> |
vx = (queue[i][0]+.5)/hresolu + ourview.hoff - .5; |
1266 |
> |
vy = (queue[i][1]+.5)/vresolu + ourview.voff - .5; |
1267 |
> |
zscan(queue[i][1])[queue[i][0]] = fbp[3] / sqrt(1. + |
1268 |
> |
vx*vx*ourview.hn2 + vy*vy*ourview.vn2); |
1269 |
> |
} |
1270 |
|
fbp += 4; |
1271 |
|
} |
1272 |
|
queuesiz = 0; |
1273 |
|
} |
1274 |
|
|
1275 |
|
|
1276 |
< |
syserror(s) /* report error and exit */ |
1277 |
< |
char *s; |
1276 |
> |
static void |
1277 |
> |
syserror( /* report error and exit */ |
1278 |
> |
char *s |
1279 |
> |
) |
1280 |
|
{ |
1281 |
|
perror(s); |
1282 |
|
exit(1); |