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.14 by greg, Thu Jan 4 17:47:37 1990 UTC vs.
Revision 1.16 by greg, Sat Jan 6 22:27:10 1990 UTC

# Line 26 | Line 26 | static char SCCSid[] = "$SunId$ LBL";
26  
27   #define ABS(x)          ((x)>0?(x):-(x))
28  
29 + struct position {int x,y; float z;};
30 +
31   VIEW    ourview = STDVIEW(512);         /* desired view */
32  
33   double  zeps = .02;                     /* allowed z epsilon */
# Line 35 | Line 37 | float  *ourzbuf;                       /* corresponding z-buffer */
37  
38   char    *progname;
39  
38 VIEW    theirview = STDVIEW(512);       /* input view */
39 int     gotview;                        /* got input view? */
40
40   int     fill = F_FORE|F_BACK;           /* selected fill algorithm */
41   extern int      backfill(), rcalfill(); /* fill functions */
42   int     (*deffill)() = backfill;        /* selected fill function */
43   COLR    backcolr = BLKCOLR;             /* background color */
44   double  backz = 0.0;                    /* background z value */
45 + int     normdist = 1;                   /* normalized distance? */
46 + double  ourexp = -1;                    /* output picture exposure */
47  
48 + VIEW    theirview = STDVIEW(512);       /* input view */
49 + int     gotview;                        /* got input view? */
50   double  theirs2ours[4][4];              /* transformation matrix */
51 < int     normdist = 1;                   /* normalized distance? */
51 > double  theirexp;                       /* input picture exposure */
52  
53   int     childpid = -1;                  /* id of fill process */
54   FILE    *psend, *precv;                 /* pipes to/from fill calculation */
# Line 192 | Line 195 | char   *argv[];
195                                                  /* allocate frame */
196          ourpict = (COLR *)malloc(ourview.hresolu*ourview.vresolu*sizeof(COLR));
197          ourzbuf = (float *)calloc(ourview.hresolu*ourview.vresolu,sizeof(float));
198 <        if (ourpict == NULL || ourzbuf == NULL) {
199 <                perror(progname);
197 <                exit(1);
198 <        }
198 >        if (ourpict == NULL || ourzbuf == NULL)
199 >                syserror();
200                                                          /* get input */
201          for ( ; i < argc; i += 2)
202                  addpicture(argv[i], argv[i+1]);
# Line 213 | Line 214 | char   *argv[];
214                  fprintview(&ourview, stdout);
215                  printf("\n");
216          }
217 +        if (ourexp > 0 && ourexp != 1.0)
218 +                fputexpos(ourexp, stdout);
219          printf("\n");
220                                                          /* write picture */
221          writepicture();
# Line 238 | Line 241 | char   *s;
241  
242          printf("\t%s", s);
243  
244 +        if (isexpos(s)) {
245 +                theirexp *= exposval(s);
246 +                return;
247 +        }
248          for (an = altname; *an != NULL; an++)
249                  if (!strncmp(*an, s, strlen(*an))) {
250                          if (sscanview(&theirview, s+strlen(*an)) == 0)
# Line 254 | Line 261 | char   *pfile, *zspec;
261          FILE    *pfp, *zfp;
262          char    *err;
263          COLR    *scanin;
264 <        float   *zin, *zlast;
265 <        int     *plast;
264 >        float   *zin;
265 >        struct position *plast;
266          int     y;
267                                          /* open picture file */
268          if ((pfp = fopen(pfile, "r")) == NULL) {
269                  perror(pfile);
270                  exit(1);
271          }
272 <                                        /* get header and view */
273 <        printf("%s:\n", pfile);
272 >                                        /* get header with exposure and view */
273 >        theirexp = 1.0;
274          gotview = 0;
275 +        printf("%s:\n", pfile);
276          getheader(pfp, headline);
277          if (!gotview || fgetresolu(&theirview.hresolu, &theirview.vresolu, pfp)
278                          != (YMAJOR|YDECR)) {
279                  fprintf(stderr, "%s: picture view error\n", pfile);
280                  exit(1);
281          }
282 +        if (ourexp <= 0)
283 +                ourexp = theirexp;
284 +        else if (ABS(theirexp-ourexp) > .01*ourexp)
285 +                fprintf(stderr, "%s: different exposure (warning)\n", pfile);
286          if (err = setview(&theirview)) {
287                  fprintf(stderr, "%s: %s\n", pfile, err);
288                  exit(1);
# Line 280 | Line 292 | char   *pfile, *zspec;
292                                          /* allocate scanlines */
293          scanin = (COLR *)malloc(theirview.hresolu*sizeof(COLR));
294          zin = (float *)malloc(theirview.hresolu*sizeof(float));
295 <        plast = (int *)calloc(theirview.hresolu, sizeof(int));
296 <        zlast = (float *)calloc(theirview.hresolu, sizeof(float));
297 <        if (scanin == NULL || zin == NULL || plast == NULL || zlast == NULL) {
298 <                perror(progname);
287 <                exit(1);
288 <        }
295 >        plast = (struct position *)calloc(theirview.hresolu,
296 >                                                sizeof(struct position));
297 >        if (scanin == NULL || zin == NULL || plast == NULL)
298 >                syserror();
299                                          /* get z specification or file */
300          if ((zfp = fopen(zspec, "r")) == NULL) {
301                  double  zvalue;
# Line 309 | Line 319 | char   *pfile, *zspec;
319                          fprintf(stderr, "%s: read error\n", zspec);
320                          exit(1);
321                  }
322 <                addscanline(y, scanin, zin, plast, zlast);
322 >                addscanline(y, scanin, zin, plast);
323          }
324                                          /* clean up */
325          free((char *)scanin);
326          free((char *)zin);
327          free((char *)plast);
318        free((char *)zlast);
328          fclose(pfp);
329          if (zfp != NULL)
330                  fclose(zfp);
# Line 358 | Line 367 | register VIEW  *vw1, *vw2;
367   }
368  
369  
370 < addscanline(y, pline, zline, lasty, lastyz)     /* add scanline to output */
370 > addscanline(y, pline, zline, lasty)     /* add scanline to output */
371   int     y;
372   COLR    *pline;
373   float   *zline;
374 < int     *lasty;                 /* input/output */
366 < float   *lastyz;                /* input/output */
374 > struct position *lasty;         /* input/output */
375   {
376          extern double   sqrt();
377          double  pos[3];
378 <        int     lastx = 0;
371 <        double  lastxz = 0;
372 <        double  zt;
373 <        int     xpos, ypos;
378 >        struct position lastx, newpos;
379          register int    x;
380  
381          for (x = theirview.hresolu-1; x >= 0; x--) {
# Line 386 | Line 391 | float  *lastyz;                /* input/output */
391                          pos[1] *= pos[2];
392                  }
393                  multp3(pos, pos, theirs2ours);
394 <                if (pos[2] <= 0)
394 >                if (pos[2] <= 0) {
395 >                        lasty[x].z = lastx.z = 0;       /* mark invalid */
396                          continue;
397 +                }
398                  if (ourview.type == VT_PER) {
399                          pos[0] /= pos[2];
400                          pos[1] /= pos[2];
401                  }
402                  pos[0] += .5*ourview.hresolu;
403                  pos[1] += .5*ourview.vresolu;
404 <                if (pos[0] < 0 || (xpos = pos[0]) >= ourview.hresolu
405 <                        || pos[1] < 0 || (ypos = pos[1]) >= ourview.vresolu)
406 <                        continue;
404 >                newpos.x = pos[0];
405 >                newpos.y = pos[1];
406 >                newpos.z = zline[x];
407                                          /* add pixel to our image */
408 <                zt = 2.*zeps*zline[x];
409 <                addpixel(xpos, ypos,
410 <                        (fill&F_FORE && ABS(zline[x]-lastxz) <= zt)
411 <                                ? lastx - xpos : 1,
412 <                        (fill&F_FORE && ABS(zline[x]-lastyz[x]) <= zt)
413 <                                ? lasty[x] - ypos : 1,
414 <                        pline[x], pos[2]);
415 <                lastx = xpos;
409 <                lasty[x] = ypos;
410 <                lastxz = lastyz[x] = zline[x];
408 >                if (pos[0] >= 0 && newpos.x < ourview.hresolu
409 >                                && pos[1] >= 0 && newpos.y < ourview.vresolu) {
410 >                        addpixel(&newpos, &lastx, &lasty[x], pline[x], pos[2]);
411 >                        lasty[x].x = lastx.x = newpos.x;
412 >                        lasty[x].y = lastx.y = newpos.y;
413 >                        lasty[x].z = lastx.z = newpos.z;
414 >                } else
415 >                        lasty[x].z = lastx.z = 0;       /* mark invalid */
416          }
417   }
418  
419  
420 < addpixel(xstart, ystart, width, height, pix, z) /* fill in area for pixel */
421 < int     xstart, ystart;
417 < int     width, height;
420 > addpixel(p0, p1, p2, pix, z)            /* fill in pixel parallelogram */
421 > struct position *p0, *p1, *p2;
422   COLR    pix;
423   double  z;
424   {
425 <        register int    x, y;
426 <                                        /* make width and height positive */
427 <        if (width < 0) {
428 <                width = -width;
429 <                xstart = xstart-width+1;
430 <        } else if (width == 0)
431 <                width = 1;
432 <        if (height < 0) {
433 <                height = -height;
434 <                ystart = ystart-height+1;
435 <        } else if (height == 0)
436 <                height = 1;
437 <                                        /* fill pixel(s) within rectangle */
438 <        for (y = ystart; y < ystart+height; y++)
439 <                for (x = xstart; x < xstart+width; x++)
440 <                        if (zscan(y)[x] <= 0
441 <                                        || zscan(y)[x]-z > zeps*zscan(y)[x]) {
425 >        double  zt = 2.*zeps*p0->z;             /* threshold */
426 >        int     s1x, s1y, s2x, s2y;             /* step sizes */
427 >        int     l1, l2, c1, c2;                 /* side lengths and counters */
428 >        int     p1isy;                          /* p0p1 along y? */
429 >        int     x1, y1;                         /* p1 position */
430 >        register int    x, y;                   /* final position */
431 >
432 >                                        /* compute vector p0p1 */
433 >        if (fill&F_FORE && ABS(p1->z-p0->z) <= zt) {
434 >                s1x = p1->x - p0->x;
435 >                s1y = p1->y - p0->y;
436 >                l1 = ABS(s1x);
437 >                if (p1isy = (ABS(s1y) > l1))
438 >                        l1 = ABS(s1y);
439 >        } else {
440 >                l1 = s1x = s1y = 1;
441 >                p1isy = -1;
442 >        }
443 >                                        /* compute vector p0p2 */
444 >        if (fill&F_FORE && ABS(p2->z-p0->z) <= zt) {
445 >                s2x = p2->x - p0->x;
446 >                s2y = p2->y - p0->y;
447 >                if (p1isy == 1)
448 >                        l2 = ABS(s2x);
449 >                else {
450 >                        l2 = ABS(s2y);
451 >                        if (p1isy != 0 && ABS(s2x) > l2)
452 >                                l2 = ABS(s2x);
453 >                }
454 >        } else
455 >                l2 = s2x = s2y = 1;
456 >                                        /* fill the parallelogram */
457 >        for (c1 = l1; c1-- > 0; ) {
458 >                x1 = p0->x + c1*s1x/l1;
459 >                y1 = p0->y + c1*s1y/l1;
460 >                for (c2 = l2; c2-- > 0; ) {
461 >                        x = x1 + c2*s2x/l2;
462 >                        y = y1 + c2*s2y/l2;
463 >                        if (zscan(y)[x] <= 0 || zscan(y)[x]-z
464 >                                                > zeps*zscan(y)[x]) {
465                                  zscan(y)[x] = z;
466                                  copycolr(pscan(y)[x], pix);
467                          }
468 +                }
469 +        }
470   }
471  
472  
# Line 449 | Line 478 | backpicture()                          /* background fill algorithm */
478          register int    x, i;
479                                                          /* get back buffer */
480          yback = (int *)malloc(ourview.hresolu*sizeof(int));
481 <        if (yback == NULL) {
482 <                perror(progname);
454 <                return;
455 <        }
481 >        if (yback == NULL)
482 >                syserror();
483          for (x = 0; x < ourview.hresolu; x++)
484                  yback[x] = -2;
485          /*
# Line 542 | Line 569 | writepicture()                         /* write out picture */
569  
570          fputresolu(YMAJOR|YDECR, ourview.hresolu, ourview.vresolu, stdout);
571          for (y = ourview.vresolu-1; y >= 0; y--)
572 <                if (fwritecolrs(pscan(y), ourview.hresolu, stdout) < 0) {
573 <                        perror(progname);
547 <                        exit(1);
548 <                }
572 >                if (fwritecolrs(pscan(y), ourview.hresolu, stdout) < 0)
573 >                        syserror();
574   }
575  
576  
# Line 563 | Line 588 | char   *fname;
588                  exit(1);
589          }
590          if (donorm
591 <        && (zout = (float *)malloc(ourview.hresolu*sizeof(float))) == NULL) {
592 <                perror(progname);
568 <                exit(1);
569 <        }
591 >        && (zout = (float *)malloc(ourview.hresolu*sizeof(float))) == NULL)
592 >                syserror();
593          for (y = ourview.vresolu-1; y >= 0; y--) {
594                  if (donorm) {
595                          double  vx, yzn2;
# Line 703 | Line 726 | clearqueue()                           /* get results from queue */
726                          fprintf(stderr, "%s: read error in clearqueue\n",
727                                          progname);
728                          exit(1);
729 +                }
730 +                if (ourexp > 0 && ourexp != 1.0) {
731 +                        inbuf[0] *= ourexp;
732 +                        inbuf[1] *= ourexp;
733 +                        inbuf[2] *= ourexp;
734                  }
735                  setcolr(pscan(queue[i][1])[queue[i][0]],
736                                  inbuf[0], inbuf[1], inbuf[2]);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines