1 |
– |
/* Copyright (c) 1995 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) |
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 |
|
|
68 |
|
|
69 |
|
int fillo = F_FORE|F_BACK; /* selected fill options */ |
70 |
|
int fillsamp = 0; /* sample separation (0 == inf) */ |
73 |
– |
extern int backfill(), rcalfill(); /* fill functions */ |
74 |
– |
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; /* 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 */ |
85 |
|
MAT4 theirs2ours; /* transformation matrix */ |
86 |
|
int hasmatrix = 0; /* has transformation matrix */ |
87 |
|
|
88 |
< |
int PDesc[3] = {-1,-1,-1}; /* rtrace process descriptor */ |
92 |
< |
#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 |
< |
extern double movepixel(); |
93 |
> |
typedef void fillfunc_t(int x, int y); |
94 |
|
|
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 |
< |
main(argc, argv) /* interpolate pictures */ |
120 |
< |
int argc; |
121 |
< |
char *argv[]; |
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[an][ol] || \ |
128 |
|
badarg(argc-an-1,argv+an+1,al)) \ |
235 |
|
if (argv[an][2] != 'f') |
236 |
|
goto badopt; |
237 |
|
check(3,"s"); |
238 |
< |
gotvfile = viewfile(argv[++an], &ourview, 0, 0); |
238 |
> |
gotvfile = viewfile(argv[++an], &ourview, NULL); |
239 |
|
if (gotvfile < 0) |
240 |
|
syserror(argv[an]); |
241 |
|
else if (gotvfile == 0) { |
258 |
|
fillo &= ~F_BACK; |
259 |
|
if (doavg < 0) |
260 |
|
doavg = (argc-an) > 2; |
261 |
< |
if (expcomp != NULL) |
262 |
< |
if (expcomp[0] == '+' | expcomp[0] == '-') { |
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)); |
273 |
|
if (!(doavg | doblur)) |
274 |
|
rexpadj = pow(2.0, (double)expadj); |
275 |
|
} |
276 |
+ |
} |
277 |
|
/* set view */ |
278 |
< |
if (nextview(doblur ? stdin : NULL) == EOF) { |
278 |
> |
if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) { |
279 |
|
fprintf(stderr, "%s: no view on standard input!\n", |
280 |
|
progname); |
281 |
|
exit(1); |
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) |
288 |
> |
if ((ourspict == NULL) | (ourweigh == NULL)) |
289 |
|
syserror(progname); |
290 |
|
} else { |
291 |
|
ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); |
302 |
|
syserror(progname); |
303 |
|
/* new header */ |
304 |
|
newheader("RADIANCE", stdout); |
305 |
+ |
fputnow(stdout); |
306 |
|
/* run pictures */ |
307 |
|
do { |
308 |
< |
bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); |
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 */ |
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) |
331 |
|
ourexp *= rexpadj; |
332 |
|
else |
333 |
|
ourexp = rexpadj; |
334 |
< |
if (ourexp < .995 | ourexp > 1.005) |
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(); |
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 |
|
if (nvavg < 2) { |
374 |
|
putc('\t', 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 |
< |
nextview(fp) /* get and set next view */ |
388 |
< |
FILE *fp; |
387 |
> |
static int |
388 |
> |
nextview( /* get and set next view */ |
389 |
> |
FILE *fp |
390 |
> |
) |
391 |
|
{ |
392 |
|
char linebuf[256]; |
393 |
|
char *err; |
405 |
|
exit(1); |
406 |
|
} |
407 |
|
if (!nvavg) { /* first view */ |
408 |
< |
copystruct(&avgview, &ourview); |
408 |
> |
avgview = ourview; |
409 |
|
return(nvavg++); |
410 |
|
} |
411 |
|
/* add to average view */ |
414 |
|
avgview.vdir[i] += ourview.vdir[i]; |
415 |
|
avgview.vup[i] += ourview.vup[i]; |
416 |
|
} |
417 |
+ |
avgview.vdist += ourview.vdist; |
418 |
|
avgview.horiz += ourview.horiz; |
419 |
|
avgview.vert += ourview.vert; |
420 |
|
avgview.hoff += ourview.hoff; |
425 |
|
} |
426 |
|
|
427 |
|
|
428 |
< |
compavgview() /* compute average view */ |
428 |
> |
static void |
429 |
> |
compavgview(void) /* compute average view */ |
430 |
|
{ |
431 |
|
register int i; |
432 |
|
double f; |
439 |
|
avgview.vdir[i] *= f; |
440 |
|
avgview.vup[i] *= f; |
441 |
|
} |
442 |
+ |
avgview.vdist *= f; |
443 |
|
avgview.horiz *= f; |
444 |
|
avgview.vert *= f; |
445 |
|
avgview.hoff *= f; |
447 |
|
avgview.vfore *= f; |
448 |
|
avgview.vaft *= f; |
449 |
|
if (setview(&avgview) != NULL) /* in case of emergency... */ |
450 |
< |
copystruct(&avgview, &ourview); |
450 |
> |
avgview = ourview; |
451 |
|
pixaspect = viewaspect(&avgview) * hresolu / vresolu; |
452 |
|
} |
453 |
|
|
454 |
|
|
455 |
< |
addpicture(pfile, zspec) /* add picture to output */ |
456 |
< |
char *pfile, *zspec; |
455 |
> |
static void |
456 |
> |
addpicture( /* add picture to output */ |
457 |
> |
char *pfile, |
458 |
> |
char *zspec |
459 |
> |
) |
460 |
|
{ |
461 |
|
FILE *pfp; |
462 |
|
int zfd; |
471 |
|
syserror(pfile); |
472 |
|
/* get header with exposure and view */ |
473 |
|
theirexp = 1.0; |
474 |
< |
copystruct(&theirview, &stdview); |
474 |
> |
theirview = stdview; |
475 |
|
gotview = 0; |
476 |
|
if (nvavg < 2) |
477 |
|
printf("%s:\n", pfile); |
484 |
|
ourexp = theirexp; |
485 |
|
else if (ABS(theirexp-ourexp) > .01*ourexp) |
486 |
|
fprintf(stderr, "%s: different exposure (warning)\n", pfile); |
487 |
< |
if (err = setview(&theirview)) { |
487 |
> |
if ( (err = setview(&theirview)) ) { |
488 |
|
fprintf(stderr, "%s: %s\n", pfile, err); |
489 |
|
exit(1); |
490 |
|
} |
507 |
|
if (xlim == NULL) |
508 |
|
syserror(progname); |
509 |
|
if (!getperim(xlim, &ylim, zin, zfd)) { /* overlapping area? */ |
510 |
< |
free((char *)zin); |
511 |
< |
free((char *)xlim); |
510 |
> |
free((void *)zin); |
511 |
> |
free((void *)xlim); |
512 |
|
if (zfd != -1) |
513 |
|
close(zfd); |
514 |
|
fclose(pfp); |
518 |
|
scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); |
519 |
|
plast = (struct position *)calloc(scanlen(&tresolu), |
520 |
|
sizeof(struct position)); |
521 |
< |
if (scanin == NULL | plast == NULL) |
521 |
> |
if ((scanin == NULL) | (plast == NULL)) |
522 |
|
syserror(progname); |
523 |
|
/* skip to starting point */ |
524 |
|
for (y = 0; y < ylim.min; y++) |
527 |
|
exit(1); |
528 |
|
} |
529 |
|
if (zfd != -1 && lseek(zfd, |
530 |
< |
(long)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0) |
530 |
> |
(off_t)ylim.min*scanlen(&tresolu)*sizeof(float), |
531 |
> |
SEEK_SET) < 0) |
532 |
|
syserror(zspec); |
533 |
|
/* load image */ |
534 |
|
for (y = ylim.min; y <= ylim.max; y++) { |
543 |
|
addscanline(xlim+y, y, scanin, zin, plast); |
544 |
|
} |
545 |
|
/* clean up */ |
546 |
< |
free((char *)xlim); |
547 |
< |
free((char *)scanin); |
548 |
< |
free((char *)zin); |
549 |
< |
free((char *)plast); |
546 |
> |
free((void *)xlim); |
547 |
> |
free((void *)scanin); |
548 |
> |
free((void *)zin); |
549 |
> |
free((void *)plast); |
550 |
|
fclose(pfp); |
551 |
|
if (zfd != -1) |
552 |
|
close(zfd); |
553 |
|
} |
554 |
|
|
555 |
|
|
556 |
< |
pixform(xfmat, vw1, vw2) /* compute view1 to view2 matrix */ |
557 |
< |
register MAT4 xfmat; |
558 |
< |
register VIEW *vw1, *vw2; |
556 |
> |
static int |
557 |
> |
pixform( /* compute view1 to view2 matrix */ |
558 |
> |
register MAT4 xfmat, |
559 |
> |
register VIEW *vw1, |
560 |
> |
register VIEW *vw2 |
561 |
> |
) |
562 |
|
{ |
563 |
|
double m4t[4][4]; |
564 |
|
|
565 |
< |
if (vw1->type != VT_PER & vw1->type != VT_PAR) |
565 |
> |
if ((vw1->type != VT_PER) & (vw1->type != VT_PAR)) |
566 |
|
return(0); |
567 |
< |
if (vw2->type != VT_PER & vw2->type != VT_PAR) |
567 |
> |
if ((vw2->type != VT_PER) & (vw2->type != VT_PAR)) |
568 |
|
return(0); |
569 |
|
setident4(xfmat); |
570 |
|
xfmat[0][0] = vw1->hvec[0]; |
597 |
|
} |
598 |
|
|
599 |
|
|
600 |
< |
addscanline(xl, y, pline, zline, lasty) /* add scanline to output */ |
601 |
< |
struct bound *xl; |
602 |
< |
int y; |
603 |
< |
COLR *pline; |
604 |
< |
float *zline; |
605 |
< |
struct position *lasty; /* input/output */ |
600 |
> |
static void |
601 |
> |
addscanline( /* add scanline to output */ |
602 |
> |
struct bound *xl, |
603 |
> |
int y, |
604 |
> |
COLR *pline, |
605 |
> |
float *zline, |
606 |
> |
struct position *lasty /* input/output */ |
607 |
> |
) |
608 |
|
{ |
609 |
|
FVECT pos; |
610 |
|
struct position lastx, newpos; |
631 |
|
} |
632 |
|
|
633 |
|
|
634 |
< |
addpixel(p0, p1, p2, pix, w, z) /* fill in pixel parallelogram */ |
635 |
< |
struct position *p0, *p1, *p2; |
636 |
< |
COLR pix; |
637 |
< |
double w; |
638 |
< |
double z; |
634 |
> |
static void |
635 |
> |
addpixel( /* fill in pixel parallelogram */ |
636 |
> |
struct position *p0, |
637 |
> |
struct position *p1, |
638 |
> |
struct position *p2, |
639 |
> |
COLR pix, |
640 |
> |
double w, |
641 |
> |
double z |
642 |
> |
) |
643 |
|
{ |
644 |
|
double zt = 2.*zeps*p0->z; /* threshold */ |
645 |
|
COLOR pval; /* converted+weighted pixel */ |
654 |
|
s1x = p1->x - p0->x; |
655 |
|
s1y = p1->y - p0->y; |
656 |
|
l1 = ABS(s1x); |
657 |
< |
if (p1isy = (ABS(s1y) > l1)) |
657 |
> |
if ( (p1isy = (ABS(s1y) > l1)) ) |
658 |
|
l1 = ABS(s1y); |
659 |
|
else if (l1 < 1) |
660 |
|
l1 = 1; |
687 |
|
y1 = p0->y + c1*s1y/l1; |
688 |
|
for (c2 = l2; c2-- > 0; ) { |
689 |
|
x = x1 + c2*s2x/l2; |
690 |
< |
if (x < 0 | x >= hresolu) |
690 |
> |
if ((x < 0) | (x >= hresolu)) |
691 |
|
continue; |
692 |
|
y = y1 + c2*s2y/l2; |
693 |
< |
if (y < 0 | y >= vresolu) |
693 |
> |
if ((y < 0) | (y >= vresolu)) |
694 |
|
continue; |
695 |
|
if (averaging) { |
696 |
|
if (zscan(y)[x] <= 0 || zscan(y)[x]-z |
712 |
|
} |
713 |
|
|
714 |
|
|
715 |
< |
double |
716 |
< |
movepixel(pos) /* reposition image point */ |
717 |
< |
register FVECT pos; |
715 |
> |
static double |
716 |
> |
movepixel( /* reposition image point */ |
717 |
> |
register FVECT pos |
718 |
> |
) |
719 |
|
{ |
720 |
|
FVECT pt, tdir, odir; |
721 |
|
double d; |
669 |
– |
register int i; |
722 |
|
|
723 |
|
if (pos[2] <= 0) /* empty pixel */ |
724 |
|
return(0); |
725 |
|
if (usematrix) { |
726 |
|
pos[0] += theirview.hoff - .5; |
727 |
|
pos[1] += theirview.voff - .5; |
728 |
< |
if (normdist & theirview.type == VT_PER) |
728 |
> |
if (normdist & (theirview.type == VT_PER)) |
729 |
|
d = sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
730 |
|
+ pos[1]*pos[1]*theirview.vn2); |
731 |
|
else |
749 |
|
} else { |
750 |
|
if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) |
751 |
|
return(0); |
752 |
< |
if (!normdist & theirview.type == VT_PER) /* adjust */ |
752 |
> |
if ((!normdist) & (theirview.type == VT_PER)) /* adjust */ |
753 |
|
pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2 |
754 |
|
+ pos[1]*pos[1]*theirview.vn2); |
755 |
|
pt[0] += tdir[0]*pos[2]; |
759 |
|
if (pos[2] <= 0) |
760 |
|
return(0); |
761 |
|
} |
762 |
< |
if (pos[0] < 0 | pos[0] >= 1-FTINY | pos[1] < 0 | pos[1] >= 1-FTINY) |
762 |
> |
if ((pos[0] < 0) | (pos[0] >= 1-FTINY) | (pos[1] < 0) | (pos[1] >= 1-FTINY)) |
763 |
|
return(0); |
764 |
|
if (!averaging) |
765 |
|
return(1); |
766 |
< |
if (ourview.type == VT_PAR) /* compute our direction */ |
767 |
< |
VCOPY(odir, ourview.vdir); |
768 |
< |
else |
769 |
< |
for (i = 0; i < 3; i++) |
770 |
< |
odir[i] = (pt[i] - ourview.vp[i])/pos[2]; |
771 |
< |
d = DOT(odir,tdir); /* compute pixel weight */ |
772 |
< |
if (d >= 1.-1./MAXWT/MAXWT) |
766 |
> |
/* compute pixel weight */ |
767 |
> |
if (ourview.type == VT_PAR) { |
768 |
> |
d = DOT(ourview.vdir,tdir); |
769 |
> |
d = 1. - d*d; |
770 |
> |
} else { |
771 |
> |
VSUB(odir, pt, ourview.vp); |
772 |
> |
d = DOT(odir,tdir); |
773 |
> |
d = 1. - d*d/DOT(odir,odir); |
774 |
> |
} |
775 |
> |
if (d <= 1./MAXWT/MAXWT) |
776 |
|
return(MAXWT); /* clip to maximum weight */ |
777 |
< |
return(1./sqrt(1.-d)); |
777 |
> |
return(1./sqrt(d)); |
778 |
|
} |
779 |
|
|
780 |
|
|
781 |
< |
getperim(xl, yl, zline, zfd) /* compute overlapping image area */ |
782 |
< |
register struct bound *xl; |
783 |
< |
struct bound *yl; |
784 |
< |
float *zline; |
785 |
< |
int zfd; |
781 |
> |
static int |
782 |
> |
getperim( /* compute overlapping image area */ |
783 |
> |
register struct bound *xl, |
784 |
> |
struct bound *yl, |
785 |
> |
float *zline, |
786 |
> |
int zfd |
787 |
> |
) |
788 |
|
{ |
789 |
|
int step; |
790 |
|
FVECT pos; |
807 |
|
yl->min = 32000; yl->max = 0; /* search for points on image */ |
808 |
|
for (y = step - 1; y < numscans(&tresolu); y += step) { |
809 |
|
if (zfd != -1) { |
810 |
< |
if (lseek(zfd, (long)y*scanlen(&tresolu)*sizeof(float), |
811 |
< |
0) < 0) |
810 |
> |
if (lseek(zfd, (off_t)y*scanlen(&tresolu)*sizeof(float), |
811 |
> |
SEEK_SET) < 0) |
812 |
|
syserror("lseek"); |
813 |
|
if (read(zfd, (char *)zline, |
814 |
|
scanlen(&tresolu)*sizeof(float)) |
853 |
|
xl[y-1].max = xl[y-step].max; |
854 |
|
} |
855 |
|
for (x = 2; x < step; x++) |
856 |
< |
copystruct(xl+y-x, xl+y-1); |
856 |
> |
*(xl+y-x) = *(xl+y-1); |
857 |
|
} |
858 |
|
if (yl->max >= numscans(&tresolu)) |
859 |
|
yl->max = numscans(&tresolu) - 1; |
860 |
|
y -= step; |
861 |
|
for (x = numscans(&tresolu) - 1; x > y; x--) /* fill bottom rows */ |
862 |
< |
copystruct(xl+x, xl+y); |
862 |
> |
*(xl+x) = *(xl+y); |
863 |
|
return(yl->max >= yl->min); |
864 |
|
} |
865 |
|
|
866 |
|
|
867 |
< |
backpicture(fill, samp) /* background fill algorithm */ |
868 |
< |
int (*fill)(); |
869 |
< |
int samp; |
867 |
> |
static void |
868 |
> |
backpicture( /* background fill algorithm */ |
869 |
> |
fillfunc_t *fill, |
870 |
> |
int samp |
871 |
> |
) |
872 |
|
{ |
873 |
|
int *yback, xback; |
874 |
|
int y; |
970 |
|
xback = -2; |
971 |
|
} |
972 |
|
} |
973 |
< |
free((char *)yback); |
973 |
> |
free((void *)yback); |
974 |
|
} |
975 |
|
|
976 |
|
|
977 |
< |
fillpicture(fill) /* paint in empty pixels using fill */ |
978 |
< |
int (*fill)(); |
977 |
> |
static void |
978 |
> |
fillpicture( /* paint in empty pixels using fill */ |
979 |
> |
fillfunc_t *fill |
980 |
> |
) |
981 |
|
{ |
982 |
|
register int x, y; |
983 |
|
|
985 |
|
for (x = 0; x < hresolu; x++) |
986 |
|
if (zscan(y)[x] <= 0) |
987 |
|
(*fill)(x,y); |
988 |
+ |
if (fill == rcalfill) |
989 |
+ |
clearqueue(); |
990 |
|
} |
991 |
|
|
992 |
|
|
993 |
< |
clipaft() /* perform aft clipping as indicated */ |
993 |
> |
static int |
994 |
> |
clipaft(void) /* perform aft clipping as indicated */ |
995 |
|
{ |
996 |
|
register int x, y; |
997 |
< |
int adjtest = ourview.type == VT_PER & zisnorm; |
997 |
> |
int adjtest = (ourview.type == VT_PER) & zisnorm; |
998 |
|
double tstdist; |
999 |
|
double yzn2, vx; |
1000 |
|
|
1017 |
|
continue; |
1018 |
|
} |
1019 |
|
if (averaging) |
1020 |
< |
bzero(sscan(y)[x], sizeof(COLOR)); |
1020 |
> |
memset(sscan(y)[x], '\0', sizeof(COLOR)); |
1021 |
|
else |
1022 |
< |
bzero(pscan(y)[x], sizeof(COLR)); |
1022 |
> |
memset(pscan(y)[x], '\0', sizeof(COLR)); |
1023 |
|
zscan(y)[x] = 0.0; |
1024 |
|
} |
1025 |
|
} |
1027 |
|
} |
1028 |
|
|
1029 |
|
|
1030 |
< |
addblur() /* add to blurred picture */ |
1030 |
> |
static int |
1031 |
> |
addblur(void) /* add to blurred picture */ |
1032 |
|
{ |
1033 |
|
COLOR cval; |
1034 |
|
double d; |
1068 |
|
} |
1069 |
|
|
1070 |
|
|
1071 |
< |
writepicture() /* write out picture (alters buffer) */ |
1071 |
> |
static void |
1072 |
> |
writepicture(void) /* write out picture (alters buffer) */ |
1073 |
|
{ |
1074 |
|
int y; |
1075 |
|
register int x; |
1100 |
|
} |
1101 |
|
|
1102 |
|
|
1103 |
< |
writedistance(fname) /* write out z file (alters buffer) */ |
1104 |
< |
char *fname; |
1103 |
> |
static void |
1104 |
> |
writedistance( /* write out z file (alters buffer) */ |
1105 |
> |
char *fname |
1106 |
> |
) |
1107 |
|
{ |
1108 |
|
int donorm = normdist & !zisnorm ? 1 : |
1109 |
< |
ourview.type == VT_PER & !normdist & zisnorm ? -1 : 0; |
1109 |
> |
(ourview.type == VT_PER) & !normdist & zisnorm ? -1 : 0; |
1110 |
|
int fd; |
1111 |
|
int y; |
1112 |
|
|
1135 |
|
} |
1136 |
|
|
1137 |
|
|
1138 |
< |
backfill(x, y) /* fill pixel with background */ |
1139 |
< |
int x, y; |
1138 |
> |
static void |
1139 |
> |
backfill( /* fill pixel with background */ |
1140 |
> |
int x, |
1141 |
> |
int y |
1142 |
> |
) |
1143 |
|
{ |
1144 |
|
if (averaging) { |
1145 |
|
copycolor(sscan(y)[x], backcolor); |
1150 |
|
} |
1151 |
|
|
1152 |
|
|
1153 |
< |
calstart(prog, args) /* start fill calculation */ |
1154 |
< |
char *prog, *args; |
1153 |
> |
static void |
1154 |
> |
calstart( /* start fill calculation */ |
1155 |
> |
char *prog, |
1156 |
> |
char *args |
1157 |
> |
) |
1158 |
|
{ |
1159 |
|
char combuf[512]; |
1160 |
|
char *argv[64]; |
1161 |
|
int rval; |
1162 |
|
register char **wp, *cp; |
1163 |
|
|
1164 |
< |
if (childpid != -1) { |
1164 |
> |
if (PDesc.running) { |
1165 |
|
fprintf(stderr, "%s: too many calculations\n", progname); |
1166 |
|
exit(1); |
1167 |
|
} |
1180 |
|
} |
1181 |
|
*wp = NULL; |
1182 |
|
/* start process */ |
1183 |
< |
if ((rval = open_process(PDesc, argv)) < 0) |
1183 |
> |
if ((rval = open_process(&PDesc, argv)) < 0) |
1184 |
|
syserror(progname); |
1185 |
|
if (rval == 0) { |
1186 |
|
fprintf(stderr, "%s: command not found\n", argv[0]); |
1193 |
|
} |
1194 |
|
|
1195 |
|
|
1196 |
< |
caldone() /* done with calculation */ |
1196 |
> |
static void |
1197 |
> |
caldone(void) /* done with calculation */ |
1198 |
|
{ |
1199 |
< |
if (childpid == -1) |
1199 |
> |
if (!PDesc.running) |
1200 |
|
return; |
1201 |
|
clearqueue(); |
1202 |
< |
close_process(PDesc); |
1128 |
< |
childpid = -1; |
1202 |
> |
close_process(&PDesc); |
1203 |
|
} |
1204 |
|
|
1205 |
|
|
1206 |
< |
rcalfill(x, y) /* fill with ray-calculated pixel */ |
1207 |
< |
int x, y; |
1206 |
> |
static void |
1207 |
> |
rcalfill( /* fill with ray-calculated pixel */ |
1208 |
> |
int x, |
1209 |
> |
int y |
1210 |
> |
) |
1211 |
|
{ |
1212 |
|
if (queuesiz >= packsiz) /* flush queue if needed */ |
1213 |
|
clearqueue(); |
1218 |
|
} |
1219 |
|
|
1220 |
|
|
1221 |
< |
clearqueue() /* process queue */ |
1221 |
> |
static void |
1222 |
> |
clearqueue(void) /* process queue */ |
1223 |
|
{ |
1224 |
|
FVECT orig, dir; |
1225 |
|
float fbuf[6*(PACKSIZ+1)]; |
1238 |
|
*fbp++ = dir[0]; *fbp++ = dir[1]; *fbp++ = dir[2]; |
1239 |
|
} |
1240 |
|
/* mark end and get results */ |
1241 |
< |
bzero((char *)fbp, 6*sizeof(float)); |
1242 |
< |
if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*queuesiz, |
1241 |
> |
memset((char *)fbp, '\0', 6*sizeof(float)); |
1242 |
> |
if (process(&PDesc, (char *)fbuf, (char *)fbuf, |
1243 |
> |
4*sizeof(float)*(queuesiz+1), |
1244 |
|
6*sizeof(float)*(queuesiz+1)) != |
1245 |
< |
4*sizeof(float)*queuesiz) { |
1245 |
> |
4*sizeof(float)*(queuesiz+1)) { |
1246 |
|
fprintf(stderr, "%s: error reading from rtrace process\n", |
1247 |
|
progname); |
1248 |
|
exit(1); |
1257 |
|
if (averaging) { |
1258 |
|
setcolor(sscan(queue[i][1])[queue[i][0]], |
1259 |
|
fbp[0], fbp[1], fbp[2]); |
1260 |
< |
wscan(queue[i][1])[queue[i][0]] = MAXWT; |
1260 |
> |
wscan(queue[i][1])[queue[i][0]] = 1; |
1261 |
|
} else |
1262 |
|
setcolr(pscan(queue[i][1])[queue[i][0]], |
1263 |
|
fbp[0], fbp[1], fbp[2]); |
1275 |
|
} |
1276 |
|
|
1277 |
|
|
1278 |
< |
syserror(s) /* report error and exit */ |
1279 |
< |
char *s; |
1278 |
> |
static void |
1279 |
> |
syserror( /* report error and exit */ |
1280 |
> |
char *s |
1281 |
> |
) |
1282 |
|
{ |
1283 |
|
perror(s); |
1284 |
|
exit(1); |