| 1 | – | /* Copyright (c) 1999 Silicon Graphics, Inc. */ | 
| 2 | – |  | 
| 1 |  | #ifndef lint | 
| 2 | < | static char SCCSid[] = "$SunId$ SGI"; | 
| 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 |  |  | 
| 64 |  | VIEW    avgview;                        /* average view for -B option */ | 
| 65 |  | int     nvavg;                          /* number of views averaged */ | 
| 66 |  |  | 
| 69 | – | char    *progname; | 
| 70 | – |  | 
| 67 |  | int     fillo = F_FORE|F_BACK;          /* selected fill options */ | 
| 68 |  | int     fillsamp = 0;                   /* sample separation (0 == inf) */ | 
| 73 | – | extern int      backfill(), rcalfill(); /* fill functions */ | 
| 74 | – | int     (*fillfunc)() = backfill;       /* selected fill function */ | 
| 69 |  | COLR    backcolr = BLKCOLR;             /* background color */ | 
| 70 |  | COLOR   backcolor = BLKCOLOR;           /* background color (float) */ | 
| 71 |  | double  backz = 0.0;                    /* background z value */ | 
| 72 |  | int     normdist = 1;                   /* i/o normalized distance? */ | 
| 73 | < | char    ourfmt[LPICFMT+1] = PICFMT;     /* original picture format */ | 
| 73 | > | char    ourfmt[MAXFMTLEN] = PICFMT;     /* original picture format */ | 
| 74 |  | double  ourexp = -1;                    /* original picture exposure */ | 
| 75 |  | int     expadj = 0;                     /* exposure adjustment (f-stops) */ | 
| 76 |  | double  rexpadj = 1;                    /* real exposure adjustment */ | 
| 83 |  | MAT4    theirs2ours;                    /* transformation matrix */ | 
| 84 |  | int     hasmatrix = 0;                  /* has transformation matrix */ | 
| 85 |  |  | 
| 86 | < | int     PDesc[3] = {-1,-1,-1};          /* rtrace process descriptor */ | 
| 93 | < | #define childpid        (PDesc[2]) | 
| 86 | > | static SUBPROC PDesc = SP_INACTIVE; /* rtrace process descriptor */ | 
| 87 |  | unsigned short  queue[PACKSIZ][2];      /* pending pixels */ | 
| 88 |  | int     packsiz;                        /* actual packet size */ | 
| 89 |  | int     queuesiz = 0;                   /* number of pixels pending */ | 
| 90 |  |  | 
| 91 | < | extern double   movepixel(); | 
| 91 | > | typedef void fillfunc_t(int x, int y); | 
| 92 |  |  | 
| 93 | + | static gethfunc headline; | 
| 94 | + | static int nextview(FILE *fp); | 
| 95 | + | static void compavgview(void); | 
| 96 | + | static void addpicture(char *pfile, char *zspec); | 
| 97 | + | static int pixform(MAT4 xfmat, VIEW *vw1, VIEW *vw2); | 
| 98 | + | static void addscanline(struct bound *xl, int y, | 
| 99 | + | COLR *pline, float *zline, struct position *lasty); | 
| 100 | + | static void addpixel(struct position *p0, struct position *p1, | 
| 101 | + | struct position *p2, COLR pix, double w, double z); | 
| 102 | + | static double movepixel(FVECT pos); | 
| 103 | + | static int getperim(struct bound *xl, struct bound *yl, float *zline, int zfd); | 
| 104 | + | static void backpicture(fillfunc_t *fill, int samp); | 
| 105 | + | static void fillpicture(fillfunc_t *fill); | 
| 106 | + | static int clipaft(void); | 
| 107 | + | static int addblur(void); | 
| 108 | + | static void writepicture(void); | 
| 109 | + | static void writedistance(char *fname); | 
| 110 | + | static fillfunc_t backfill; | 
| 111 | + | static fillfunc_t rcalfill; | 
| 112 | + | static void calstart(char *prog, char *args); | 
| 113 | + | static void caldone(void); | 
| 114 | + | static void clearqueue(void); | 
| 115 | + | static void syserror(char *s); | 
| 116 |  |  | 
| 117 | < | main(argc, argv)                        /* interpolate pictures */ | 
| 118 | < | int     argc; | 
| 119 | < | char    *argv[]; | 
| 117 | > | fillfunc_t *fillfunc = backfill;        /* selected fill function */ | 
| 118 | > |  | 
| 119 | > | int | 
| 120 | > | main(                   /* interpolate pictures */ | 
| 121 | > | int     argc, | 
| 122 | > | char    *argv[] | 
| 123 | > | ) | 
| 124 |  | { | 
| 125 |  | #define  check(ol,al)           if (argv[an][ol] || \ | 
| 126 |  | badarg(argc-an-1,argv+an+1,al)) \ | 
| 132 |  | char    *expcomp = NULL; | 
| 133 |  | int     i, an, rval; | 
| 134 |  |  | 
| 135 | < | progname = argv[0]; | 
| 135 | > | SET_DEFAULT_BINARY(); | 
| 136 | > | SET_FILE_BINARY(stdout); | 
| 137 |  |  | 
| 138 | + | fixargv0(argv[0]);              /* sets global progname */ | 
| 139 | + |  | 
| 140 |  | for (an = 1; an < argc && argv[an][0] == '-'; an++) { | 
| 141 |  | rval = getviewopt(&ourview, argc-an, argv+an); | 
| 142 |  | if (rval >= 0) { | 
| 236 |  | if (argv[an][2] != 'f') | 
| 237 |  | goto badopt; | 
| 238 |  | check(3,"s"); | 
| 239 | < | gotvfile = viewfile(argv[++an], &ourview, 0, 0); | 
| 239 | > | gotvfile = viewfile(argv[++an], &ourview, NULL); | 
| 240 |  | if (gotvfile < 0) | 
| 241 |  | syserror(argv[an]); | 
| 242 |  | else if (gotvfile == 0) { | 
| 259 |  | fillo &= ~F_BACK; | 
| 260 |  | if (doavg < 0) | 
| 261 |  | doavg = (argc-an) > 2; | 
| 262 | < | if (expcomp != NULL) | 
| 263 | < | if (expcomp[0] == '+' | expcomp[0] == '-') { | 
| 262 | > | if (expcomp != NULL) { | 
| 263 | > | if ((expcomp[0] == '+') | (expcomp[0] == '-')) { | 
| 264 |  | expadj = atof(expcomp) + (expcomp[0]=='+' ? .5 : -.5); | 
| 265 |  | if (doavg | doblur) | 
| 266 |  | rexpadj = pow(2.0, atof(expcomp)); | 
| 274 |  | if (!(doavg | doblur)) | 
| 275 |  | rexpadj = pow(2.0, (double)expadj); | 
| 276 |  | } | 
| 277 | + | } | 
| 278 |  | /* set view */ | 
| 279 |  | if (nextview(doblur ? stdin : (FILE *)NULL) == EOF) { | 
| 280 |  | fprintf(stderr, "%s: no view on standard input!\n", | 
| 286 |  | if (doavg) { | 
| 287 |  | ourspict = (COLOR *)bmalloc(hresolu*vresolu*sizeof(COLOR)); | 
| 288 |  | ourweigh = (float *)bmalloc(hresolu*vresolu*sizeof(float)); | 
| 289 | < | if (ourspict == NULL | ourweigh == NULL) | 
| 289 | > | if ((ourspict == NULL) | (ourweigh == NULL)) | 
| 290 |  | syserror(progname); | 
| 291 |  | } else { | 
| 292 |  | ourpict = (COLR *)bmalloc(hresolu*vresolu*sizeof(COLR)); | 
| 303 |  | syserror(progname); | 
| 304 |  | /* new header */ | 
| 305 |  | newheader("RADIANCE", stdout); | 
| 306 | + | fputnow(stdout); | 
| 307 |  | /* run pictures */ | 
| 308 |  | do { | 
| 309 | < | bzero((char *)ourzbuf, hresolu*vresolu*sizeof(float)); | 
| 309 | > | memset((char *)ourzbuf, '\0', hresolu*vresolu*sizeof(float)); | 
| 310 |  | for (i = an; i < argc; i += 2) | 
| 311 |  | addpicture(argv[i], argv[i+1]); | 
| 312 |  | if (fillo&F_BACK)                       /* fill in spaces */ | 
| 326 |  | fprintview(&avgview, stdout); | 
| 327 |  | putc('\n', stdout); | 
| 328 |  | } | 
| 329 | < | if (pixaspect < .99 | pixaspect > 1.01) | 
| 329 | > | if ((pixaspect < .99) | (pixaspect > 1.01)) | 
| 330 |  | fputaspect(pixaspect, stdout); | 
| 331 |  | if (ourexp > 0) | 
| 332 |  | ourexp *= rexpadj; | 
| 333 |  | else | 
| 334 |  | ourexp = rexpadj; | 
| 335 | < | if (ourexp < .995 | ourexp > 1.005) | 
| 335 | > | if ((ourexp < .995) | (ourexp > 1.005)) | 
| 336 |  | fputexpos(ourexp, stdout); | 
| 337 |  | if (strcmp(ourfmt, PICFMT))             /* print format if known */ | 
| 338 |  | fputformat(ourfmt, stdout); | 
| 353 |  | } | 
| 354 |  |  | 
| 355 |  |  | 
| 356 | < | int | 
| 357 | < | headline(s)                             /* process header string */ | 
| 358 | < | char    *s; | 
| 356 | > | static int | 
| 357 | > | headline(                               /* process header string */ | 
| 358 | > | char    *s, | 
| 359 | > | void    *p | 
| 360 | > | ) | 
| 361 |  | { | 
| 362 | < | char    fmt[32]; | 
| 362 | > | char    fmt[MAXFMTLEN]; | 
| 363 |  |  | 
| 364 |  | if (isheadid(s)) | 
| 365 |  | return(0); | 
| 385 |  | } | 
| 386 |  |  | 
| 387 |  |  | 
| 388 | < | nextview(fp)                            /* get and set next view */ | 
| 389 | < | FILE    *fp; | 
| 388 | > | static int | 
| 389 | > | nextview(                               /* get and set next view */ | 
| 390 | > | FILE    *fp | 
| 391 | > | ) | 
| 392 |  | { | 
| 393 |  | char    linebuf[256]; | 
| 394 |  | char    *err; | 
| 395 | < | register int    i; | 
| 395 | > | int     i; | 
| 396 |  |  | 
| 397 |  | if (fp != NULL) { | 
| 398 |  | do                      /* get new view */ | 
| 406 |  | exit(1); | 
| 407 |  | } | 
| 408 |  | if (!nvavg) {                   /* first view */ | 
| 409 | < | copystruct(&avgview, &ourview); | 
| 409 | > | avgview = ourview; | 
| 410 |  | return(nvavg++); | 
| 411 |  | } | 
| 412 |  | /* add to average view */ | 
| 415 |  | avgview.vdir[i] += ourview.vdir[i]; | 
| 416 |  | avgview.vup[i] += ourview.vup[i]; | 
| 417 |  | } | 
| 418 | + | avgview.vdist += ourview.vdist; | 
| 419 |  | avgview.horiz += ourview.horiz; | 
| 420 |  | avgview.vert += ourview.vert; | 
| 421 |  | avgview.hoff += ourview.hoff; | 
| 426 |  | } | 
| 427 |  |  | 
| 428 |  |  | 
| 429 | < | compavgview()                           /* compute average view */ | 
| 429 | > | static void | 
| 430 | > | compavgview(void)                               /* compute average view */ | 
| 431 |  | { | 
| 432 | < | register int    i; | 
| 432 | > | int     i; | 
| 433 |  | double  f; | 
| 434 |  |  | 
| 435 |  | if (nvavg < 2) | 
| 440 |  | avgview.vdir[i] *= f; | 
| 441 |  | avgview.vup[i] *= f; | 
| 442 |  | } | 
| 443 | + | avgview.vdist *= f; | 
| 444 |  | avgview.horiz *= f; | 
| 445 |  | avgview.vert *= f; | 
| 446 |  | avgview.hoff *= f; | 
| 448 |  | avgview.vfore *= f; | 
| 449 |  | avgview.vaft *= f; | 
| 450 |  | if (setview(&avgview) != NULL)          /* in case of emergency... */ | 
| 451 | < | copystruct(&avgview, &ourview); | 
| 451 | > | avgview = ourview; | 
| 452 |  | pixaspect = viewaspect(&avgview) * hresolu / vresolu; | 
| 453 |  | } | 
| 454 |  |  | 
| 455 |  |  | 
| 456 | < | addpicture(pfile, zspec)                /* add picture to output */ | 
| 457 | < | char    *pfile, *zspec; | 
| 456 | > | static void | 
| 457 | > | addpicture(             /* add picture to output */ | 
| 458 | > | char    *pfile, | 
| 459 | > | char    *zspec | 
| 460 | > | ) | 
| 461 |  | { | 
| 462 |  | FILE    *pfp; | 
| 463 |  | int     zfd; | 
| 472 |  | syserror(pfile); | 
| 473 |  | /* get header with exposure and view */ | 
| 474 |  | theirexp = 1.0; | 
| 475 | < | copystruct(&theirview, &stdview); | 
| 475 | > | theirview = stdview; | 
| 476 |  | gotview = 0; | 
| 477 |  | if (nvavg < 2) | 
| 478 |  | printf("%s:\n", pfile); | 
| 485 |  | ourexp = theirexp; | 
| 486 |  | else if (ABS(theirexp-ourexp) > .01*ourexp) | 
| 487 |  | fprintf(stderr, "%s: different exposure (warning)\n", pfile); | 
| 488 | < | if (err = setview(&theirview)) { | 
| 488 | > | if ( (err = setview(&theirview)) ) { | 
| 489 |  | fprintf(stderr, "%s: %s\n", pfile, err); | 
| 490 |  | exit(1); | 
| 491 |  | } | 
| 495 |  | zin = (float *)malloc(scanlen(&tresolu)*sizeof(float)); | 
| 496 |  | if (zin == NULL) | 
| 497 |  | syserror(progname); | 
| 498 | < | if ((zfd = open(zspec, O_RDONLY)) == -1) { | 
| 499 | < | double  zvalue; | 
| 500 | < | register int    x; | 
| 501 | < | if (!isflt(zspec) || (zvalue = atof(zspec)) <= 0.0) | 
| 502 | < | syserror(zspec); | 
| 498 | > | if (isflt(zspec)) {             /* depth is a constant? */ | 
| 499 | > | double  zvalue = atof(zspec); | 
| 500 | > | int     x; | 
| 501 | > | if (zvalue <= 0.0) { | 
| 502 | > | fprintf(stderr, "%s: illegal Z-value %s\n", | 
| 503 | > | progname, zspec); | 
| 504 | > | exit(1); | 
| 505 | > | } | 
| 506 |  | for (x = scanlen(&tresolu); x-- > 0; ) | 
| 507 |  | zin[x] = zvalue; | 
| 508 | < | } | 
| 508 | > | zfd = -1; | 
| 509 | > | } else if ((zfd = open_float_depth(zspec, (long)tresolu.xr*tresolu.yr)) < 0) | 
| 510 | > | exit(1); | 
| 511 |  | /* compute transferrable perimeter */ | 
| 512 |  | xlim = (struct bound *)malloc(numscans(&tresolu)*sizeof(struct bound)); | 
| 513 |  | if (xlim == NULL) | 
| 514 |  | syserror(progname); | 
| 515 |  | if (!getperim(xlim, &ylim, zin, zfd)) { /* overlapping area? */ | 
| 516 | < | free((char *)zin); | 
| 517 | < | free((char *)xlim); | 
| 516 | > | free((void *)zin); | 
| 517 | > | free((void *)xlim); | 
| 518 |  | if (zfd != -1) | 
| 519 |  | close(zfd); | 
| 520 |  | fclose(pfp); | 
| 524 |  | scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR)); | 
| 525 |  | plast = (struct position *)calloc(scanlen(&tresolu), | 
| 526 |  | sizeof(struct position)); | 
| 527 | < | if (scanin == NULL | plast == NULL) | 
| 527 | > | if ((scanin == NULL) | (plast == NULL)) | 
| 528 |  | syserror(progname); | 
| 529 |  | /* skip to starting point */ | 
| 530 |  | for (y = 0; y < ylim.min; y++) | 
| 533 |  | exit(1); | 
| 534 |  | } | 
| 535 |  | if (zfd != -1 && lseek(zfd, | 
| 536 | < | (long)ylim.min*scanlen(&tresolu)*sizeof(float), 0) < 0) | 
| 536 | > | (off_t)ylim.min*scanlen(&tresolu)*sizeof(float), | 
| 537 | > | SEEK_SET) < 0) | 
| 538 |  | syserror(zspec); | 
| 539 |  | /* load image */ | 
| 540 |  | for (y = ylim.min; y <= ylim.max; y++) { | 
| 549 |  | addscanline(xlim+y, y, scanin, zin, plast); | 
| 550 |  | } | 
| 551 |  | /* clean up */ | 
| 552 | < | free((char *)xlim); | 
| 553 | < | free((char *)scanin); | 
| 554 | < | free((char *)zin); | 
| 555 | < | free((char *)plast); | 
| 552 | > | free((void *)xlim); | 
| 553 | > | free((void *)scanin); | 
| 554 | > | free((void *)zin); | 
| 555 | > | free((void *)plast); | 
| 556 |  | fclose(pfp); | 
| 557 |  | if (zfd != -1) | 
| 558 |  | close(zfd); | 
| 559 |  | } | 
| 560 |  |  | 
| 561 |  |  | 
| 562 | < | pixform(xfmat, vw1, vw2)                /* compute view1 to view2 matrix */ | 
| 563 | < | register MAT4   xfmat; | 
| 564 | < | register VIEW   *vw1, *vw2; | 
| 562 | > | static int | 
| 563 | > | pixform(                /* compute view1 to view2 matrix */ | 
| 564 | > | MAT4    xfmat, | 
| 565 | > | VIEW    *vw1, | 
| 566 | > | VIEW    *vw2 | 
| 567 | > | ) | 
| 568 |  | { | 
| 569 | < | double  m4t[4][4]; | 
| 569 | > | MAT4    m4t; | 
| 570 |  |  | 
| 571 | < | if (vw1->type != VT_PER & vw1->type != VT_PAR) | 
| 571 | > | if ((vw1->type != VT_PER) & (vw1->type != VT_PAR)) | 
| 572 |  | return(0); | 
| 573 | < | if (vw2->type != VT_PER & vw2->type != VT_PAR) | 
| 573 | > | if ((vw2->type != VT_PER) & (vw2->type != VT_PAR)) | 
| 574 |  | return(0); | 
| 575 |  | setident4(xfmat); | 
| 576 |  | xfmat[0][0] = vw1->hvec[0]; | 
| 603 |  | } | 
| 604 |  |  | 
| 605 |  |  | 
| 606 | < | addscanline(xl, y, pline, zline, lasty) /* add scanline to output */ | 
| 607 | < | struct bound    *xl; | 
| 608 | < | int     y; | 
| 609 | < | COLR    *pline; | 
| 610 | < | float   *zline; | 
| 611 | < | struct position *lasty;         /* input/output */ | 
| 606 | > | static void | 
| 607 | > | addscanline(    /* add scanline to output */ | 
| 608 | > | struct bound    *xl, | 
| 609 | > | int     y, | 
| 610 | > | COLR    *pline, | 
| 611 | > | float   *zline, | 
| 612 | > | struct position *lasty          /* input/output */ | 
| 613 | > | ) | 
| 614 |  | { | 
| 615 |  | FVECT   pos; | 
| 616 |  | struct position lastx, newpos; | 
| 617 |  | double  wt; | 
| 618 | < | register int    x; | 
| 618 | > | int     x; | 
| 619 |  |  | 
| 620 |  | lastx.z = 0; | 
| 621 |  | for (x = xl->max; x >= xl->min; x--) { | 
| 637 |  | } | 
| 638 |  |  | 
| 639 |  |  | 
| 640 | < | addpixel(p0, p1, p2, pix, w, z)         /* fill in pixel parallelogram */ | 
| 641 | < | struct position *p0, *p1, *p2; | 
| 642 | < | COLR    pix; | 
| 643 | < | double  w; | 
| 644 | < | double  z; | 
| 640 | > | static void | 
| 641 | > | addpixel(               /* fill in pixel parallelogram */ | 
| 642 | > | struct position *p0, | 
| 643 | > | struct position *p1, | 
| 644 | > | struct position *p2, | 
| 645 | > | COLR    pix, | 
| 646 | > | double  w, | 
| 647 | > | double  z | 
| 648 | > | ) | 
| 649 |  | { | 
| 650 |  | double  zt = 2.*zeps*p0->z;             /* threshold */ | 
| 651 |  | COLOR   pval;                           /* converted+weighted pixel */ | 
| 653 |  | int     l1, l2, c1, c2;                 /* side lengths and counters */ | 
| 654 |  | int     p1isy;                          /* p0p1 along y? */ | 
| 655 |  | int     x1, y1;                         /* p1 position */ | 
| 656 | < | register int    x, y;                   /* final position */ | 
| 656 | > | int     x, y;                   /* final position */ | 
| 657 |  |  | 
| 658 |  | /* compute vector p0p1 */ | 
| 659 |  | if (fillo&F_FORE && ABS(p1->z-p0->z) <= zt) { | 
| 660 |  | s1x = p1->x - p0->x; | 
| 661 |  | s1y = p1->y - p0->y; | 
| 662 |  | l1 = ABS(s1x); | 
| 663 | < | if (p1isy = (ABS(s1y) > l1)) | 
| 663 | > | if ( (p1isy = (ABS(s1y) > l1)) ) | 
| 664 |  | l1 = ABS(s1y); | 
| 665 |  | else if (l1 < 1) | 
| 666 |  | l1 = 1; | 
| 693 |  | y1 = p0->y + c1*s1y/l1; | 
| 694 |  | for (c2 = l2; c2-- > 0; ) { | 
| 695 |  | x = x1 + c2*s2x/l2; | 
| 696 | < | if (x < 0 | x >= hresolu) | 
| 696 | > | if ((x < 0) | (x >= hresolu)) | 
| 697 |  | continue; | 
| 698 |  | y = y1 + c2*s2y/l2; | 
| 699 | < | if (y < 0 | y >= vresolu) | 
| 699 | > | if ((y < 0) | (y >= vresolu)) | 
| 700 |  | continue; | 
| 701 |  | if (averaging) { | 
| 702 |  | if (zscan(y)[x] <= 0 || zscan(y)[x]-z | 
| 718 |  | } | 
| 719 |  |  | 
| 720 |  |  | 
| 721 | < | double | 
| 722 | < | movepixel(pos)                          /* reposition image point */ | 
| 723 | < | register FVECT  pos; | 
| 721 | > | static double | 
| 722 | > | movepixel(                              /* reposition image point */ | 
| 723 | > | FVECT   pos | 
| 724 | > | ) | 
| 725 |  | { | 
| 726 |  | FVECT   pt, tdir, odir; | 
| 727 |  | double  d; | 
| 731 |  | if (usematrix) { | 
| 732 |  | pos[0] += theirview.hoff - .5; | 
| 733 |  | pos[1] += theirview.voff - .5; | 
| 734 | < | if (normdist & theirview.type == VT_PER) | 
| 734 | > | if (normdist & (theirview.type == VT_PER)) | 
| 735 |  | d = sqrt(1. + pos[0]*pos[0]*theirview.hn2 | 
| 736 |  | + pos[1]*pos[1]*theirview.vn2); | 
| 737 |  | else | 
| 751 |  | } | 
| 752 |  | pos[0] += .5 - ourview.hoff; | 
| 753 |  | pos[1] += .5 - ourview.voff; | 
| 754 | + | if ((pos[0] < 0) | (pos[0] >= 1-FTINY) | | 
| 755 | + | (pos[1] < 0) | (pos[1] >= 1-FTINY)) | 
| 756 | + | return(0); | 
| 757 |  | pos[2] -= ourview.vfore; | 
| 758 |  | } else { | 
| 759 |  | if (viewray(pt, tdir, &theirview, pos[0], pos[1]) < -FTINY) | 
| 760 |  | return(0); | 
| 761 | < | if (!normdist & theirview.type == VT_PER)       /* adjust */ | 
| 762 | < | pos[2] *= sqrt(1. + pos[0]*pos[0]*theirview.hn2 | 
| 709 | < | + pos[1]*pos[1]*theirview.vn2); | 
| 761 | > | if (!normdist & (theirview.type == VT_PER))     /* adjust */ | 
| 762 | > | pos[2] /= DOT(theirview.vdir, tdir); | 
| 763 |  | pt[0] += tdir[0]*pos[2]; | 
| 764 |  | pt[1] += tdir[1]*pos[2]; | 
| 765 |  | pt[2] += tdir[2]*pos[2]; | 
| 766 | < | viewloc(pos, &ourview, pt); | 
| 714 | < | if (pos[2] <= 0) | 
| 766 | > | if (viewloc(pos, &ourview, pt) != VL_GOOD) | 
| 767 |  | return(0); | 
| 768 |  | } | 
| 717 | – | if (pos[0] < 0 | pos[0] >= 1-FTINY | pos[1] < 0 | pos[1] >= 1-FTINY) | 
| 718 | – | return(0); | 
| 769 |  | if (!averaging) | 
| 770 |  | return(1); | 
| 771 |  | /* compute pixel weight */ | 
| 783 |  | } | 
| 784 |  |  | 
| 785 |  |  | 
| 786 | < | getperim(xl, yl, zline, zfd)            /* compute overlapping image area */ | 
| 787 | < | register struct bound   *xl; | 
| 788 | < | struct bound    *yl; | 
| 789 | < | float   *zline; | 
| 790 | < | int     zfd; | 
| 786 | > | static int | 
| 787 | > | getperim(               /* compute overlapping image area */ | 
| 788 | > | struct bound    *xl, | 
| 789 | > | struct bound    *yl, | 
| 790 | > | float   *zline, | 
| 791 | > | int     zfd | 
| 792 | > | ) | 
| 793 |  | { | 
| 794 |  | int     step; | 
| 795 |  | FVECT   pos; | 
| 796 | < | register int    x, y; | 
| 796 | > | int     x, y; | 
| 797 |  | /* set up step size */ | 
| 798 |  | if (scanlen(&tresolu) < numscans(&tresolu)) | 
| 799 |  | step = scanlen(&tresolu)/NSTEPS; | 
| 812 |  | yl->min = 32000; yl->max = 0;           /* search for points on image */ | 
| 813 |  | for (y = step - 1; y < numscans(&tresolu); y += step) { | 
| 814 |  | if (zfd != -1) { | 
| 815 | < | if (lseek(zfd, (long)y*scanlen(&tresolu)*sizeof(float), | 
| 816 | < | 0) < 0) | 
| 815 | > | if (lseek(zfd, (off_t)y*scanlen(&tresolu)*sizeof(float), | 
| 816 | > | SEEK_SET) < 0) | 
| 817 |  | syserror("lseek"); | 
| 818 |  | if (read(zfd, (char *)zline, | 
| 819 |  | scanlen(&tresolu)*sizeof(float)) | 
| 858 |  | xl[y-1].max = xl[y-step].max; | 
| 859 |  | } | 
| 860 |  | for (x = 2; x < step; x++) | 
| 861 | < | copystruct(xl+y-x, xl+y-1); | 
| 861 | > | *(xl+y-x) = *(xl+y-1); | 
| 862 |  | } | 
| 863 |  | if (yl->max >= numscans(&tresolu)) | 
| 864 |  | yl->max = numscans(&tresolu) - 1; | 
| 865 |  | y -= step; | 
| 866 |  | for (x = numscans(&tresolu) - 1; x > y; x--)    /* fill bottom rows */ | 
| 867 | < | copystruct(xl+x, xl+y); | 
| 867 | > | *(xl+x) = *(xl+y); | 
| 868 |  | return(yl->max >= yl->min); | 
| 869 |  | } | 
| 870 |  |  | 
| 871 |  |  | 
| 872 | < | backpicture(fill, samp)                 /* background fill algorithm */ | 
| 873 | < | int     (*fill)(); | 
| 874 | < | int     samp; | 
| 872 | > | static void | 
| 873 | > | backpicture(                    /* background fill algorithm */ | 
| 874 | > | fillfunc_t *fill, | 
| 875 | > | int     samp | 
| 876 | > | ) | 
| 877 |  | { | 
| 878 |  | int     *yback, xback; | 
| 879 |  | int     y; | 
| 880 | < | register int    x, i; | 
| 880 | > | int     x, i; | 
| 881 |  | /* get back buffer */ | 
| 882 |  | yback = (int *)malloc(hresolu*sizeof(int)); | 
| 883 |  | if (yback == NULL) | 
| 975 |  | xback = -2; | 
| 976 |  | } | 
| 977 |  | } | 
| 978 | < | free((char *)yback); | 
| 978 | > | free((void *)yback); | 
| 979 |  | } | 
| 980 |  |  | 
| 981 |  |  | 
| 982 | < | fillpicture(fill)               /* paint in empty pixels using fill */ | 
| 983 | < | int     (*fill)(); | 
| 982 | > | static void | 
| 983 | > | fillpicture(            /* paint in empty pixels using fill */ | 
| 984 | > | fillfunc_t *fill | 
| 985 | > | ) | 
| 986 |  | { | 
| 987 | < | register int    x, y; | 
| 987 | > | int     x, y; | 
| 988 |  |  | 
| 989 |  | for (y = 0; y < vresolu; y++) | 
| 990 |  | for (x = 0; x < hresolu; x++) | 
| 995 |  | } | 
| 996 |  |  | 
| 997 |  |  | 
| 998 | < | clipaft()                       /* perform aft clipping as indicated */ | 
| 998 | > | static int | 
| 999 | > | clipaft(void)                   /* perform aft clipping as indicated */ | 
| 1000 |  | { | 
| 1001 | < | register int    x, y; | 
| 1002 | < | int     adjtest = ourview.type == VT_PER & zisnorm; | 
| 1001 | > | int     x, y; | 
| 1002 | > | int     adjtest = (ourview.type == VT_PER) & zisnorm; | 
| 1003 |  | double  tstdist; | 
| 1004 |  | double  yzn2, vx; | 
| 1005 |  |  | 
| 1022 |  | continue; | 
| 1023 |  | } | 
| 1024 |  | if (averaging) | 
| 1025 | < | bzero(sscan(y)[x], sizeof(COLOR)); | 
| 1025 | > | memset(sscan(y)[x], '\0', sizeof(COLOR)); | 
| 1026 |  | else | 
| 1027 | < | bzero(pscan(y)[x], sizeof(COLR)); | 
| 1027 | > | memset(pscan(y)[x], '\0', sizeof(COLR)); | 
| 1028 |  | zscan(y)[x] = 0.0; | 
| 1029 |  | } | 
| 1030 |  | } | 
| 1032 |  | } | 
| 1033 |  |  | 
| 1034 |  |  | 
| 1035 | < | addblur()                               /* add to blurred picture */ | 
| 1035 | > | static int | 
| 1036 | > | addblur(void)                           /* add to blurred picture */ | 
| 1037 |  | { | 
| 1038 |  | COLOR   cval; | 
| 1039 |  | double  d; | 
| 1040 | < | register int    i; | 
| 1040 | > | int     i; | 
| 1041 |  |  | 
| 1042 |  | if (!blurring) | 
| 1043 |  | return(0); | 
| 1073 |  | } | 
| 1074 |  |  | 
| 1075 |  |  | 
| 1076 | < | writepicture()                          /* write out picture (alters buffer) */ | 
| 1076 | > | static void | 
| 1077 | > | writepicture(void)                              /* write out picture (alters buffer) */ | 
| 1078 |  | { | 
| 1079 |  | int     y; | 
| 1080 | < | register int    x; | 
| 1080 | > | int     x; | 
| 1081 |  | double  d; | 
| 1082 |  |  | 
| 1083 |  | fprtresolu(hresolu, vresolu, stdout); | 
| 1105 |  | } | 
| 1106 |  |  | 
| 1107 |  |  | 
| 1108 | < | writedistance(fname)                    /* write out z file (alters buffer) */ | 
| 1109 | < | char    *fname; | 
| 1108 | > | static void | 
| 1109 | > | writedistance(                  /* write out z file (alters buffer) */ | 
| 1110 | > | char    *fname | 
| 1111 | > | ) | 
| 1112 |  | { | 
| 1113 |  | int     donorm = normdist & !zisnorm ? 1 : | 
| 1114 | < | ourview.type == VT_PER & !normdist & zisnorm ? -1 : 0; | 
| 1114 | > | (ourview.type == VT_PER) & !normdist & zisnorm ? -1 : 0; | 
| 1115 |  | int     fd; | 
| 1116 |  | int     y; | 
| 1117 |  |  | 
| 1120 |  | for (y = vresolu-1; y >= 0; y--) { | 
| 1121 |  | if (donorm) { | 
| 1122 |  | double  vx, yzn2, d; | 
| 1123 | < | register int    x; | 
| 1123 | > | int     x; | 
| 1124 |  | yzn2 = (y+.5)/vresolu + ourview.voff - .5; | 
| 1125 |  | yzn2 = 1. + yzn2*yzn2*ourview.vn2; | 
| 1126 |  | for (x = 0; x < hresolu; x++) { | 
| 1140 |  | } | 
| 1141 |  |  | 
| 1142 |  |  | 
| 1143 | < | backfill(x, y)                          /* fill pixel with background */ | 
| 1144 | < | int     x, y; | 
| 1143 | > | static void | 
| 1144 | > | backfill(                               /* fill pixel with background */ | 
| 1145 | > | int     x, | 
| 1146 | > | int     y | 
| 1147 | > | ) | 
| 1148 |  | { | 
| 1149 |  | if (averaging) { | 
| 1150 |  | copycolor(sscan(y)[x], backcolor); | 
| 1155 |  | } | 
| 1156 |  |  | 
| 1157 |  |  | 
| 1158 | < | calstart(prog, args)                    /* start fill calculation */ | 
| 1159 | < | char    *prog, *args; | 
| 1158 | > | static void | 
| 1159 | > | calstart(                    /* start fill calculation */ | 
| 1160 | > | char    *prog, | 
| 1161 | > | char    *args | 
| 1162 | > | ) | 
| 1163 |  | { | 
| 1164 |  | char    combuf[512]; | 
| 1165 |  | char    *argv[64]; | 
| 1166 |  | int     rval; | 
| 1167 | < | register char   **wp, *cp; | 
| 1167 | > | char    **wp, *cp; | 
| 1168 |  |  | 
| 1169 | < | if (childpid != -1) { | 
| 1169 | > | if (PDesc.flags & PF_RUNNING) { | 
| 1170 |  | fprintf(stderr, "%s: too many calculations\n", progname); | 
| 1171 |  | exit(1); | 
| 1172 |  | } | 
| 1185 |  | } | 
| 1186 |  | *wp = NULL; | 
| 1187 |  | /* start process */ | 
| 1188 | < | if ((rval = open_process(PDesc, argv)) < 0) | 
| 1188 | > | if ((rval = open_process(&PDesc, argv)) < 0) | 
| 1189 |  | syserror(progname); | 
| 1190 |  | if (rval == 0) { | 
| 1191 |  | fprintf(stderr, "%s: command not found\n", argv[0]); | 
| 1198 |  | } | 
| 1199 |  |  | 
| 1200 |  |  | 
| 1201 | < | caldone()                               /* done with calculation */ | 
| 1201 | > | static void | 
| 1202 | > | caldone(void)                               /* done with calculation */ | 
| 1203 |  | { | 
| 1204 | < | if (childpid == -1) | 
| 1204 | > | if (!(PDesc.flags & PF_RUNNING)) | 
| 1205 |  | return; | 
| 1206 |  | clearqueue(); | 
| 1207 | < | close_process(PDesc); | 
| 1140 | < | childpid = -1; | 
| 1207 | > | close_process(&PDesc); | 
| 1208 |  | } | 
| 1209 |  |  | 
| 1210 |  |  | 
| 1211 | < | rcalfill(x, y)                          /* fill with ray-calculated pixel */ | 
| 1212 | < | int     x, y; | 
| 1211 | > | static void | 
| 1212 | > | rcalfill(                               /* fill with ray-calculated pixel */ | 
| 1213 | > | int     x, | 
| 1214 | > | int     y | 
| 1215 | > | ) | 
| 1216 |  | { | 
| 1217 |  | if (queuesiz >= packsiz)        /* flush queue if needed */ | 
| 1218 |  | clearqueue(); | 
| 1223 |  | } | 
| 1224 |  |  | 
| 1225 |  |  | 
| 1226 | < | clearqueue()                            /* process queue */ | 
| 1226 | > | static void | 
| 1227 | > | clearqueue(void)                                /* process queue */ | 
| 1228 |  | { | 
| 1229 |  | FVECT   orig, dir; | 
| 1230 |  | float   fbuf[6*(PACKSIZ+1)]; | 
| 1231 | < | register float  *fbp; | 
| 1232 | < | register int    i; | 
| 1231 | > | float   *fbp; | 
| 1232 | > | int     i; | 
| 1233 |  | double  vx, vy; | 
| 1234 |  |  | 
| 1235 |  | if (queuesiz == 0) | 
| 1243 |  | *fbp++ = dir[0]; *fbp++ = dir[1]; *fbp++ = dir[2]; | 
| 1244 |  | } | 
| 1245 |  | /* mark end and get results */ | 
| 1246 | < | bzero((char *)fbp, 6*sizeof(float)); | 
| 1247 | < | if (process(PDesc, fbuf, fbuf, 4*sizeof(float)*(queuesiz+1), | 
| 1246 | > | memset((char *)fbp, '\0', 6*sizeof(float)); | 
| 1247 | > | if (process(&PDesc, fbuf, fbuf, | 
| 1248 | > | 4*sizeof(float)*(queuesiz+1), | 
| 1249 |  | 6*sizeof(float)*(queuesiz+1)) != | 
| 1250 |  | 4*sizeof(float)*(queuesiz+1)) { | 
| 1251 |  | fprintf(stderr, "%s: error reading from rtrace process\n", | 
| 1280 |  | } | 
| 1281 |  |  | 
| 1282 |  |  | 
| 1283 | < | syserror(s)                     /* report error and exit */ | 
| 1284 | < | char    *s; | 
| 1283 | > | static void | 
| 1284 | > | syserror(                       /* report error and exit */ | 
| 1285 | > | char    *s | 
| 1286 | > | ) | 
| 1287 |  | { | 
| 1288 |  | perror(s); | 
| 1289 |  | exit(1); |