ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pinterp.c
(Generate patch)

Comparing ray/src/px/pinterp.c (file contents):
Revision 1.26 by greg, Tue Mar 6 12:04:56 1990 UTC vs.
Revision 1.34 by greg, Mon Nov 11 14:01:57 1991 UTC

# Line 1 | Line 1
1 + /* Copyright (c) 1991 Regents of the University of California */
2 +
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
5   #endif
# Line 16 | Line 18 | static char SCCSid[] = "$SunId$ LBL";
18  
19   #include "color.h"
20  
21 + #include "resolu.h"
22 +
23   #ifndef BSD
24   #define vfork           fork
25   #endif
# Line 57 | Line 61 | double ourexp = -1;                    /* output picture exposure */
61  
62   VIEW    theirview = STDVIEW;            /* input view */
63   int     gotview;                        /* got input view? */
64 < int     thresolu, tvresolu;             /* input resolution */
64 > int     wrongformat = 0;                /* input in another format? */
65 > RESOLU  tresolu;                        /* input resolution */
66   double  theirexp;                       /* input picture exposure */
67   double  theirs2ours[4][4];              /* transformation matrix */
68 + int     hasmatrix = 0;                  /* has transformation matrix */
69  
70   int     childpid = -1;                  /* id of fill process */
71   FILE    *psend, *precv;                 /* pipes to/from fill calculation */
# Line 210 | Line 216 | char   *argv[];
216                  fputaspect(pixaspect, stdout);
217          if (ourexp > 0 && (ourexp < .995 || ourexp > 1.005))
218                  fputexpos(ourexp, stdout);
219 +        fputformat(COLRFMT, stdout);
220          putc('\n', stdout);
221                                                          /* write picture */
222          writepicture();
# Line 232 | Line 239 | char   *s;
239   {
240          static char     *altname[] = {VIEWSTR,"rpict","rview","pinterp",NULL};
241          register char   **an;
242 +        char    fmt[32];
243  
244 +        if (isformat(s)) {
245 +                formatval(fmt, s);
246 +                wrongformat = strcmp(fmt, COLRFMT);
247 +                return;
248 +        }
249          putc('\t', stdout);
250          fputs(s, stdout);
251  
# Line 269 | Line 282 | char   *pfile, *zspec;
282          theirexp = 1.0;
283          gotview = 0;
284          printf("%s:\n", pfile);
285 <        getheader(pfp, headline);
286 <        if (!gotview || fgetresolu(&thresolu, &tvresolu, pfp)
287 <                        != (YMAJOR|YDECR)) {
275 <                fprintf(stderr, "%s: picture view error\n", pfile);
285 >        getheader(pfp, headline, NULL);
286 >        if (wrongformat || !gotview || !fgetsresolu(&tresolu, pfp)) {
287 >                fprintf(stderr, "%s: picture format error\n", pfile);
288                  exit(1);
289          }
290          if (ourexp <= 0)
# Line 284 | Line 296 | char   *pfile, *zspec;
296                  exit(1);
297          }
298                                          /* compute transformation */
299 <        pixform(theirs2ours, &theirview, &ourview);
299 >        hasmatrix = pixform(theirs2ours, &theirview, &ourview);
300                                          /* allocate scanlines */
301 <        scanin = (COLR *)malloc(thresolu*sizeof(COLR));
302 <        zin = (float *)malloc(thresolu*sizeof(float));
303 <        plast = (struct position *)calloc(thresolu, sizeof(struct position));
301 >        scanin = (COLR *)malloc(scanlen(&tresolu)*sizeof(COLR));
302 >        zin = (float *)malloc(scanlen(&tresolu)*sizeof(float));
303 >        plast = (struct position *)calloc(scanlen(&tresolu),
304 >                        sizeof(struct position));
305          if (scanin == NULL || zin == NULL || plast == NULL)
306                  syserror();
307                                          /* get z specification or file */
# Line 299 | Line 312 | char   *pfile, *zspec;
312                          perror(zspec);
313                          exit(1);
314                  }
315 <                for (x = 0; x < thresolu; x++)
315 >                for (x = scanlen(&tresolu); x-- > 0; )
316                          zin[x] = zvalue;
317          }
318                                          /* load image */
319 <        for (y = tvresolu-1; y >= 0; y--) {
320 <                if (freadcolrs(scanin, thresolu, pfp) < 0) {
319 >        for (y = 0; y < numscans(&tresolu); y++) {
320 >                if (freadcolrs(scanin, scanlen(&tresolu), pfp) < 0) {
321                          fprintf(stderr, "%s: read error\n", pfile);
322                          exit(1);
323                  }
324 <                if (zfd != -1 && read(zfd,(char *)zin,thresolu*sizeof(float))
325 <                                < thresolu*sizeof(float)) {
324 >                if (zfd != -1 && read(zfd,(char *)zin,
325 >                                scanlen(&tresolu)*sizeof(float))
326 >                                < scanlen(&tresolu)*sizeof(float)) {
327                          fprintf(stderr, "%s: read error\n", zspec);
328                          exit(1);
329                  }
# Line 331 | Line 345 | register VIEW  *vw1, *vw2;
345   {
346          double  m4t[4][4];
347  
348 +        if (vw1->type != VT_PER && vw1->type != VT_PAR)
349 +                return(0);
350 +        if (vw2->type != VT_PER && vw2->type != VT_PAR)
351 +                return(0);
352          setident4(xfmat);
353          xfmat[0][0] = vw1->hvec[0];
354          xfmat[0][1] = vw1->hvec[1];
# Line 358 | Line 376 | register VIEW  *vw1, *vw2;
376          m4t[2][2] = vw2->vdir[2];
377          m4t[3][2] = -DOT(vw2->vp,vw2->vdir);
378          multmat4(xfmat, xfmat, m4t);
379 +        return(1);
380   }
381  
382  
# Line 368 | Line 387 | float  *zline;
387   struct position *lasty;         /* input/output */
388   {
389          extern double   sqrt();
390 <        double  pos[3];
390 >        FVECT   pos;
391          struct position lastx, newpos;
392          register int    x;
393  
394          lastx.z = 0;
395 <        for (x = thresolu-1; x >= 0; x--) {
396 <                pos[0] = (x+.5)/thresolu + theirview.hoff - .5;
378 <                pos[1] = (y+.5)/tvresolu + theirview.voff - .5;
395 >        for (x = scanlen(&tresolu); x-- > 0; ) {
396 >                pix2loc(pos, &tresolu, x, y);
397                  pos[2] = zline[x];
398 <                if (theirview.type == VT_PER) {
381 <                        if (normdist)   /* adjust for eye-ray distance */
382 <                                pos[2] /= sqrt( 1.
383 <                                        + pos[0]*pos[0]*theirview.hn2
384 <                                        + pos[1]*pos[1]*theirview.vn2 );
385 <                        pos[0] *= pos[2];
386 <                        pos[1] *= pos[2];
387 <                }
388 <                multp3(pos, pos, theirs2ours);
389 <                if (pos[2] <= 0) {
398 >                if (movepixel(pos) < 0) {
399                          lasty[x].z = lastx.z = 0;       /* mark invalid */
400                          continue;
401                  }
393                if (ourview.type == VT_PER) {
394                        pos[0] /= pos[2];
395                        pos[1] /= pos[2];
396                }
397                pos[0] += .5 - ourview.hoff;
398                pos[1] += .5 - ourview.voff;
402                  newpos.x = pos[0] * hresolu;
403                  newpos.y = pos[1] * vresolu;
404                  newpos.z = zline[x];
# Line 454 | Line 457 | double z;
457                  y1 = p0->y + c1*s1y/l1;
458                  for (c2 = l2; c2-- > 0; ) {
459                          x = x1 + c2*s2x/l2;
460 +                        if (x < 0 || x >= hresolu)
461 +                                continue;
462                          y = y1 + c2*s2y/l2;
463 +                        if (y < 0 || y >= vresolu)
464 +                                continue;
465                          if (zscan(y)[x] <= 0 || zscan(y)[x]-z
466                                                  > zeps*zscan(y)[x]) {
467                                  zscan(y)[x] = z;
# Line 465 | Line 472 | double z;
472   }
473  
474  
475 + movepixel(pos)                          /* reposition image point */
476 + FVECT   pos;
477 + {
478 +        FVECT   pt, direc;
479 +        
480 +        if (pos[2] <= 0)                /* empty pixel */
481 +                return(-1);
482 +        if (hasmatrix) {
483 +                pos[0] += theirview.hoff - .5;
484 +                pos[1] += theirview.voff - .5;
485 +                if (theirview.type == VT_PER) {
486 +                        if (normdist)   /* adjust for eye-ray distance */
487 +                                pos[2] /= sqrt( 1.
488 +                                        + pos[0]*pos[0]*theirview.hn2
489 +                                        + pos[1]*pos[1]*theirview.vn2 );
490 +                        pos[0] *= pos[2];
491 +                        pos[1] *= pos[2];
492 +                }
493 +                multp3(pos, pos, theirs2ours);
494 +                if (pos[2] <= 0)
495 +                        return(-1);
496 +                if (ourview.type == VT_PER) {
497 +                        pos[0] /= pos[2];
498 +                        pos[1] /= pos[2];
499 +                }
500 +                pos[0] += .5 - ourview.hoff;
501 +                pos[1] += .5 - ourview.voff;
502 +                return(0);
503 +        }
504 +        if (viewray(pt, direc, &theirview, pos[0], pos[1]) < 0)
505 +                return(-1);
506 +        pt[0] += direc[0]*pos[2];
507 +        pt[1] += direc[1]*pos[2];
508 +        pt[2] += direc[2]*pos[2];
509 +        viewloc(pos, &ourview, pt);
510 +        if (pos[2] <= 0)
511 +                return(-1);
512 +        return(0);
513 + }
514 +
515 +
516   backpicture(fill, samp)                 /* background fill algorithm */
517   int     (*fill)();
518   int     samp;
519   {
520          int     *yback, xback;
521          int     y;
474        COLR    pfill;
522          register int    x, i;
523                                                          /* get back buffer */
524          yback = (int *)malloc(hresolu*sizeof(int));
# Line 519 | Line 566 | int    samp;
566                                  }
567                                  /*
568                                   * If we have no background for this pixel,
522                                 * or if the background is too distant,
569                                   * use the given fill function.
570                                   */
571 <                                if ((xback < 0 && yback[x] < 0)
572 <                                        || (samp > 0
527 <                                                && ABS(x-xback) >= samp
528 <                                                && ABS(y-yback[y]) >= samp)) {
529 <                                        (*fill)(x,y);
530 <                                        if (fill != backfill) { /* reuse */
531 <                                                yback[x] = -2;
532 <                                                xback = -2;
533 <                                        }
534 <                                        continue;
535 <                                }
571 >                                if (xback < 0 && yback[x] < 0)
572 >                                        goto fillit;
573                                  /*
574                                   * Compare, and use the background that is
575                                   * farther, unless one of them is next to us.
576 +                                 * If the background is too distant, call
577 +                                 * the fill function.
578                                   */
579                                  if ( yback[x] < 0
580                                          || (xback >= 0 && ABS(x-xback) <= 1)
581                                          || ( ABS(y-yback[x]) > 1
582                                                  && zscan(yback[x])[x]
583                                                  < zscan(y)[xback] ) ) {
584 +                                        if (samp > 0 && ABS(x-xback) >= samp)
585 +                                                goto fillit;
586                                          copycolr(pscan(y)[x],pscan(y)[xback]);
587                                          zscan(y)[x] = zscan(y)[xback];
588                                  } else {
589 +                                        if (samp > 0 && ABS(y-yback[x]) > samp)
590 +                                                goto fillit;
591                                          copycolr(pscan(y)[x],pscan(yback[x])[x]);
592                                          zscan(y)[x] = zscan(yback[x])[x];
593                                  }
594 +                                continue;
595 +                        fillit:
596 +                                (*fill)(x,y);
597 +                                if (fill == rcalfill) {         /* use it */
598 +                                        clearqueue();
599 +                                        xback = x;
600 +                                        yback[x] = y;
601 +                                }
602                          } else {                                /* full pixel */
603                                  yback[x] = -2;
604                                  xback = -2;
# Line 573 | Line 624 | writepicture()                         /* write out picture */
624   {
625          int     y;
626  
627 <        fputresolu(YMAJOR|YDECR, hresolu, vresolu, stdout);
627 >        fprtresolu(hresolu, vresolu, stdout);
628          for (y = vresolu-1; y >= 0; y--)
629                  if (fwritecolrs(pscan(y), hresolu, stdout) < 0)
630                          syserror();
# Line 600 | Line 651 | char   *fname;
651                  if (donorm) {
652                          double  vx, yzn2;
653                          register int    x;
654 <                        yzn2 = y - .5*(vresolu-1);
654 >                        yzn2 = (y+.5)/vresolu + ourview.voff - .5;
655                          yzn2 = 1. + yzn2*yzn2*ourview.vn2;
656                          for (x = 0; x < hresolu; x++) {
657 <                                vx = x - .5*(hresolu-1);
657 >                                vx = (x+.5)/hresolu + ourview.hoff - .5;
658                                  zout[x] = zscan(y)[x]
659                                          * sqrt(vx*vx*ourview.hn2 + yzn2);
660                          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines