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

Comparing ray/src/px/pfilt.c (file contents):
Revision 2.4 by greg, Mon Sep 21 12:14:17 1992 UTC vs.
Revision 2.17 by greg, Mon Apr 1 17:24:44 1996 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1992 Regents of the University of California */
1 > /* Copyright (c) 1996 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 8 | Line 8 | static char SCCSid[] = "$SunId$ LBL";
8   *  pfilt.c - program to post-process picture file.
9   *
10   *     9/26/85
11 + *     6/23/93  Added additional buffers for value spreading
12   */
13  
14 < #include  <stdio.h>
14 > #include  "standard.h"
15  
15 #ifdef MSDOS
16 #include  <fcntl.h>
17 #endif
18
16   #include  <signal.h>
17  
18   #include  "color.h"
19  
20 + #include  "view.h"
21 +
22   #include  "resolu.h"
23  
24   #include  "paths.h"
25  
27 extern char  *malloc();
26   extern float  *matchlamp();
27  
28   #define  FEQ(a,b)       ((a) >= .98*(b) && (a) <= 1.02*(b))
29  
30 < #define  CHECKRAD       1.5     /* radius to check for filtering */
30 > double   CHECKRAD = 1.5;        /* radius to check for filtering */
31  
32 + #define  THRESHRAD      5.0     /* maximum sample spread in output */
33 +
34   COLOR  exposure = WHTCOLOR;     /* exposure for the frame */
35  
36   double  rad = 0.0;              /* output pixel radius for filtering */
37  
38 + double  thresh = 0.0;           /* maximum contribution for subpixel */
39 +
40   int  nrows = 0;                 /* number of rows for output */
41   int  ncols = 0;                 /* number of columns for output */
42  
# Line 45 | Line 47 | int  singlepass = 0;           /* true means skip first pass */
47  
48   int  avghot = 0;                /* true means average in bright spots */
49  
50 < double  hotlvl = 1000.0;        /* level considered "hot" */
50 > double  hotlvl = 100.0;         /* level considered "hot" */
51  
52   int  npts = 0;                  /* (half) number of points for stars */
53  
# Line 53 | Line 55 | double spread = 1e-4;          /* spread for star points */
55  
56   char  *tfname = NULL;
57  
58 + char  template[] = TEMPLATE;
59 +
60   char  *lampdat = "lamp.tab";    /* lamp data file */
61  
62   int  order;                     /* scanline ordering of input */
# Line 62 | Line 66 | int  correctaspect = 0;                /* aspect ratio correction? *
66  
67   int  wrongformat = 0;
68  
69 < int  xrad;                      /* x window size */
70 < int  yrad;                      /* y window size */
69 > VIEW  ourview = STDVIEW;
70 > int  gotview = 0;
71 > int  wrapfilt = 0;              /* wrap filter horizontally? */
72  
73 + int  xrad;                      /* x search radius */
74 + int  yrad;                      /* y search radius */
75 + int  xbrad;                     /* x box size */
76 + int  ybrad;                     /* y box size */
77 +
78   int  barsize;                   /* size of input scan bar */
79   COLOR  **scanin;                /* input scan bar */
80   COLOR  *scanout;                /* output scan line */
81 + COLOR  **scoutbar;              /* output scan bar (if thresh > 0) */
82 + float  **greybar;               /* grey-averaged input values */
83 + int  obarsize = 0;              /* size of output scan bar */
84 + int  orad = 0;                  /* output window radius */
85  
86   char  *progname;
87  
# Line 76 | Line 90 | main(argc, argv)
90   int  argc;
91   char  **argv;
92   {
79        extern double  pow();
93          extern long  ftell();
94          extern int  quit(), headline();
95          FILE  *fin;
# Line 95 | Line 108 | char  **argv;
108          if (signal(SIGINT, quit) == SIG_IGN)
109                  signal(SIGINT, SIG_IGN);
110          if (signal(SIGHUP, quit) == SIG_IGN)
111 <                signal(SIGINT, SIG_IGN);
111 >                signal(SIGHUP, SIG_IGN);
112          signal(SIGTERM, quit);
113          signal(SIGPIPE, quit);
114   #ifdef  SIGXCPU
# Line 103 | Line 116 | char  **argv;
116          signal(SIGXFSZ, quit);
117   #endif
118  
119 <        progname = argv[0];
119 >        progname = argv[0] = fixargv0(argv[0]);
120  
121          for (i = 1; i < argc; i++)
122                  if (argv[i][0] == '-')
# Line 187 | Line 200 | char  **argv;
200                          case 'r':
201                                  rad = atof(argv[++i]);
202                                  break;
203 +                        case 'm':
204 +                                thresh = atof(argv[++i]);
205 +                                if (rad <= FTINY)
206 +                                        rad = 1.0;
207 +                                break;
208                          case 'b':
209 <                                rad = 0.0;
209 >                                rad = thresh = 0.0;
210                                  break;
211                          default:;
212                          badopt:
# Line 207 | Line 225 | char  **argv;
225                          fprintf(stderr, "%s: unknown lamp type\n", lamptype);
226                          quit(1);
227                  }
228 <                for (i = 0; i < 3; i++)
229 <                        if (lampcolor[i] > 1e-4)
230 <                                colval(exposure,i) /= lampcolor[i];
228 >                for (j = 0; j < 3; j++)
229 >                        if (lampcolor[j] > 1e-4)
230 >                                colval(exposure,j) /= lampcolor[j];
231                  freelamps();
232          }
233                                          /* open input file */
# Line 217 | Line 235 | char  **argv;
235                  if (singlepass)
236                          fin = stdin;
237                  else {
238 <                        tfname = mktemp(TEMPLATE);
238 >                        tfname = mktemp(template);
239                          if ((fin = fopen(tfname, "w+")) == NULL) {
240                                  fprintf(stderr, "%s: can't create ", progname);
241                                  fprintf(stderr, "temp file \"%s\"\n", tfname);
# Line 255 | Line 273 | char  **argv;
273          }
274          if (!(order & YMAJOR))
275                  inpaspect = 1.0/inpaspect;
276 +                                        /* wrap around for cylindrical view? */
277 +        wrapfilt = gotview && ourview.type == VT_CYL &&
278 +                        ourview.horiz >= 360.-FTINY && order & YMAJOR;
279                                          /* compute output resolution */
280          if (ncols <= 0)
281                  ncols = x_c*xres + .5;
# Line 290 | Line 311 | char  **argv;
311   }
312  
313  
314 + double
315 + rgb_bright(clr)
316 + COLOR  clr;
317 + {
318 +        return(bright(clr));
319 + }
320 +
321 +
322 + double
323 + xyz_bright(clr)
324 + COLOR  clr;
325 + {
326 +        return(clr[CIEY]);
327 + }
328 +
329 +
330 + double  (*ourbright)() = rgb_bright;
331 +
332 +
333   headline(s)                             /* process line from header */
334   char  *s;
335   {
# Line 298 | Line 338 | char  *s;
338          fputs(s, stdout);               /* copy to output */
339          if (isaspect(s))                /* get aspect ratio */
340                  inpaspect *= aspectval(s);
341 <        else if (isformat(s)) {
342 <                formatval(fmt, s);
343 <                wrongformat = strcmp(fmt, COLRFMT);
344 <        }
341 >        else if (isexpos(s))            /* get exposure */
342 >                hotlvl *= exposval(s);
343 >        else if (formatval(fmt, s)) {   /* get format */
344 >                wrongformat = 0;
345 >                if (!strcmp(COLRFMT, fmt))
346 >                        ourbright = rgb_bright;
347 >                else if (!strcmp(CIEFMT, fmt))
348 >                        ourbright = xyz_bright;
349 >                else
350 >                        wrongformat = !globmatch(PICFMT, fmt);
351 >        } else if (isview(s) && sscanview(&ourview, s) > 0)
352 >                gotview++;
353   }
354  
355  
# Line 335 | Line 383 | FILE  *in;
383          }
384          for (i = 0; i < yres; i++) {
385                  if (freadscan(scan, xres, in) < 0) {
386 <                        nrows = nrows * i / yres;       /* adjust frame */
386 >                        nrows = (long)nrows * i / yres; /* adjust frame */
387                          if (nrows <= 0) {
388                                  fprintf(stderr, "%s: empty frame\n", progname);
389                                  quit(1);
390                          }
391                          fprintf(stderr, "%s: warning - partial frame (%d%%)\n",
392 <                                        progname, 100*i/yres);
392 >                                        progname, (int)(100L*i/yres));
393                          yres = i;
394                          y_r = (double)nrows/yres;
395                          break;
# Line 369 | Line 417 | FILE  *in;
417                                  if (freadscan(scanin[yread%barsize],
418                                                  xres, in) < 0) {
419                                          fprintf(stderr,
420 <                                                "%s: bad read (y=%d)\n",
420 >                                                "%s: truncated input (y=%d)\n",
421                                                  progname, yres-1-yread);
422                                          quit(1);
423                                  }
# Line 377 | Line 425 | FILE  *in;
425                          }
426                          yread++;
427                  }
428 +                if (obarsize > 0)
429 +                        scan2sync(r);
430                  for (c = 0; c < ncols; c++) {
431                          xcent = (long)c*xres/ncols;
432 <                        if (rad <= 0.0)
433 <                                dobox(scanout[c], xcent, ycent, c, r);
434 <                        else
432 >                        if (thresh > FTINY)
433 >                                dothresh(xcent, ycent, c, r);
434 >                        else if (rad > FTINY)
435                                  dogauss(scanout[c], xcent, ycent, c, r);
436 +                        else
437 +                                dobox(scanout[c], xcent, ycent, c, r);
438                  }
439 <                if (fwritescan(scanout, ncols, stdout) < 0) {
439 >                if (scanout != NULL && fwritescan(scanout, ncols, stdout) < 0) {
440                          fprintf(stderr, "%s: write error in pass2\n", progname);
441                          quit(1);
442                  }
443          }
444 <                                        /* skip leftovers */
444 >                                        /* skip leftover input */
445          while (yread < yres) {
446                  if (freadscan(scanin[0], xres, in) < 0)
447                          break;
448                  yread++;
449          }
450 +        scan2flush();                   /* flush output */
451   }
452  
453  
# Line 404 | Line 457 | scan2init()                    /* prepare scanline arrays */
457          double  d;
458          register int  i;
459  
460 <        if (rad <= 0.0) {
461 <                xrad = xres/ncols/2 + 1;
462 <                yrad = yres/nrows/2 + 1;
410 <        } else {
460 >        xbrad = xres/ncols/2 + 1;
461 >        ybrad = yres/nrows/2 + 1;
462 >        if (rad > FTINY) {
463                  if (nrows >= yres && ncols >= xres)
464                          rad *= (y_r + x_c)/2.0;
465  
466 <                xrad = CHECKRAD*rad/x_c + 1;
467 <                yrad = CHECKRAD*rad/y_r + 1;
468 <
466 >                if (thresh > FTINY) {
467 >                        orad = CHECKRAD*THRESHRAD*rad + 1;
468 >                        xrad = orad/x_c + xbrad;
469 >                        yrad = orad/y_r + ybrad;
470 >                        obarsize = 2*orad + 1;
471 >                } else {
472 >                        xrad = CHECKRAD*rad/x_c + 1;
473 >                        yrad = CHECKRAD*rad/y_r + 1;
474 >                }
475                  initmask();             /* initialize filter table */
476 +        } else {
477 +                xrad = xbrad;
478 +                yrad = ybrad;
479          }
480          barsize = 2*yrad + 1;
481          scanin = (COLOR **)malloc(barsize*sizeof(COLOR *));
482 +        if (scanin == NULL)
483 +                goto memerr;
484          for (i = 0; i < barsize; i++) {
485                  scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR));
486 <                if (scanin[i] == NULL) {
487 <                        fprintf(stderr, "%s: out of memory\n", progname);
488 <                        quit(1);
486 >                if (scanin[i] == NULL)
487 >                        goto memerr;
488 >        }
489 >        if (obarsize > 0) {
490 >                scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *));
491 >                greybar = (float **)malloc(obarsize*sizeof(float *));
492 >                if (scoutbar == NULL | greybar == NULL)
493 >                        goto memerr;
494 >                for (i = 0; i < obarsize; i++) {
495 >                        scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR));
496 >                        greybar[i] = (float *)malloc(ncols*sizeof(float));
497 >                        if (scoutbar[i] == NULL | greybar[i] == NULL)
498 >                                goto memerr;
499                  }
500 +        } else {
501 +                scanout = (COLOR *)malloc(ncols*sizeof(COLOR));
502 +                if (scanout == NULL)
503 +                        goto memerr;
504          }
428        scanout = (COLOR *)malloc(ncols*sizeof(COLOR));
429        if (scanout == NULL) {
430                fprintf(stderr, "%s: out of memory\n", progname);
431                quit(1);
432        }
505                                          /* record pixel aspect ratio */
506          if (!correctaspect) {
507                  d = order & YMAJOR ? x_c/y_r : y_r/x_c ;
# Line 437 | Line 509 | scan2init()                    /* prepare scanline arrays */
509                          fputaspect(d, stdout);
510          }
511                                          /* record exposure */
512 <        d = bright(exposure);
512 >        d = (*ourbright)(exposure);
513          if (!FEQ(d,1.0))
514                  fputexpos(d, stdout);
515                                          /* record color correction */
# Line 449 | Line 521 | scan2init()                    /* prepare scanline arrays */
521          printf("\n");
522                                          /* write out resolution */
523          fputresolu(order, ncols, nrows, stdout);
524 +        return;
525 + memerr:
526 +        fprintf(stderr, "%s: out of memory\n", progname);
527 +        quit(1);
528 + }
529 +
530 +
531 + scan2sync(r)                    /* synchronize grey averages and output scan */
532 + int  r;
533 + {
534 +        static int  nextrow = 0;
535 +        COLOR  ctmp;
536 +        int  ybot;
537 +        register int  c;
538 +                                        /* average input scanlines */
539 +        while (nextrow <= r+orad && nextrow < nrows) {
540 +                ybot = (long)nextrow*yres/nrows;
541 +                for (c = 0; c < ncols; c++) {
542 +                        dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow);
543 +                        greybar[nextrow%obarsize][c] = (*ourbright)(ctmp);
544 +                }
545 +                                        /* and zero output scanline */
546 +                bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR));
547 +                nextrow++;
548 +        }
549 +                                        /* point to top scanline for output */
550 +        if (r-orad >= 0)
551 +                scanout = scoutbar[(r-orad)%obarsize];
552 +        else
553 +                scanout = NULL;
554 + }
555 +
556 +
557 + scan2flush()                    /* flush output buffer */
558 + {
559 +        register int  r;
560 +
561 +        for (r = nrows-orad; r < nrows; r++)
562 +                if (fwritescan(scoutbar[r%obarsize], ncols, stdout) < 0)
563 +                        break;
564 +        if (fflush(stdout) < 0) {
565 +                fprintf(stderr, "%s: write error at end of pass2\n", progname);
566 +                exit(1);
567 +        }
568   }
569  
570  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines