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.11 by greg, Tue Sep 21 10:55:54 1993 UTC

# 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"
# Line 24 | Line 21 | static char SCCSid[] = "$SunId$ LBL";
21  
22   #include  "paths.h"
23  
27 extern char  *malloc();
24   extern float  *matchlamp();
25  
26   #define  FEQ(a,b)       ((a) >= .98*(b) && (a) <= 1.02*(b))
27  
28 < #define  CHECKRAD       1.5     /* radius to check for filtering */
28 > double   CHECKRAD = 1.5;        /* radius to check for filtering */
29  
30 + #define  THRESHRAD      5.0     /* maximum sample spread in output */
31 +
32   COLOR  exposure = WHTCOLOR;     /* exposure for the frame */
33  
34   double  rad = 0.0;              /* output pixel radius for filtering */
35  
36 + double  thresh = 0.0;           /* maximum contribution for subpixel */
37 +
38   int  nrows = 0;                 /* number of rows for output */
39   int  ncols = 0;                 /* number of columns for output */
40  
# Line 45 | Line 45 | int  singlepass = 0;           /* true means skip first pass */
45  
46   int  avghot = 0;                /* true means average in bright spots */
47  
48 < double  hotlvl = 1000.0;        /* level considered "hot" */
48 > double  hotlvl = 100.0;         /* level considered "hot" */
49  
50   int  npts = 0;                  /* (half) number of points for stars */
51  
# Line 53 | Line 53 | double spread = 1e-4;          /* spread for star points */
53  
54   char  *tfname = NULL;
55  
56 + char  template[] = TEMPLATE;
57 +
58   char  *lampdat = "lamp.tab";    /* lamp data file */
59  
60   int  order;                     /* scanline ordering of input */
# Line 62 | Line 64 | int  correctaspect = 0;                /* aspect ratio correction? *
64  
65   int  wrongformat = 0;
66  
67 < int  xrad;                      /* x window size */
68 < int  yrad;                      /* y window size */
67 > int  xrad;                      /* x search radius */
68 > int  yrad;                      /* y search radius */
69 > int  xbrad;                     /* x box size */
70 > int  ybrad;                     /* y box size */
71  
72   int  barsize;                   /* size of input scan bar */
73   COLOR  **scanin;                /* input scan bar */
74   COLOR  *scanout;                /* output scan line */
75 + COLOR  **scoutbar;              /* output scan bar (if thresh > 0) */
76 + float  **greybar;               /* grey-averaged input values */
77 + int  obarsize = 0;              /* size of output scan bar */
78 + int  orad = 0;                  /* output window radius */
79  
80   char  *progname;
81  
# Line 76 | Line 84 | main(argc, argv)
84   int  argc;
85   char  **argv;
86   {
79        extern double  pow();
87          extern long  ftell();
88          extern int  quit(), headline();
89          FILE  *fin;
# Line 95 | Line 102 | char  **argv;
102          if (signal(SIGINT, quit) == SIG_IGN)
103                  signal(SIGINT, SIG_IGN);
104          if (signal(SIGHUP, quit) == SIG_IGN)
105 <                signal(SIGINT, SIG_IGN);
105 >                signal(SIGHUP, SIG_IGN);
106          signal(SIGTERM, quit);
107          signal(SIGPIPE, quit);
108   #ifdef  SIGXCPU
# Line 103 | Line 110 | char  **argv;
110          signal(SIGXFSZ, quit);
111   #endif
112  
113 <        progname = argv[0];
113 >        progname = argv[0] = fixargv0(argv[0]);
114  
115          for (i = 1; i < argc; i++)
116                  if (argv[i][0] == '-')
# Line 187 | Line 194 | char  **argv;
194                          case 'r':
195                                  rad = atof(argv[++i]);
196                                  break;
197 +                        case 'm':
198 +                                thresh = atof(argv[++i]);
199 +                                if (rad <= FTINY)
200 +                                        rad = 1.0;
201 +                                break;
202                          case 'b':
203 <                                rad = 0.0;
203 >                                rad = thresh = 0.0;
204                                  break;
205                          default:;
206                          badopt:
# Line 217 | Line 229 | char  **argv;
229                  if (singlepass)
230                          fin = stdin;
231                  else {
232 <                        tfname = mktemp(TEMPLATE);
232 >                        tfname = mktemp(template);
233                          if ((fin = fopen(tfname, "w+")) == NULL) {
234                                  fprintf(stderr, "%s: can't create ", progname);
235                                  fprintf(stderr, "temp file \"%s\"\n", tfname);
# Line 298 | Line 310 | char  *s;
310          fputs(s, stdout);               /* copy to output */
311          if (isaspect(s))                /* get aspect ratio */
312                  inpaspect *= aspectval(s);
313 +        else if (isexpos(s))
314 +                hotlvl *= exposval(s);
315          else if (isformat(s)) {
316                  formatval(fmt, s);
317                  wrongformat = strcmp(fmt, COLRFMT);
# Line 335 | Line 349 | FILE  *in;
349          }
350          for (i = 0; i < yres; i++) {
351                  if (freadscan(scan, xres, in) < 0) {
352 <                        nrows = nrows * i / yres;       /* adjust frame */
352 >                        nrows = (long)nrows * i / yres; /* adjust frame */
353                          if (nrows <= 0) {
354                                  fprintf(stderr, "%s: empty frame\n", progname);
355                                  quit(1);
356                          }
357                          fprintf(stderr, "%s: warning - partial frame (%d%%)\n",
358 <                                        progname, 100*i/yres);
358 >                                        progname, (int)(100L*i/yres));
359                          yres = i;
360                          y_r = (double)nrows/yres;
361                          break;
# Line 377 | Line 391 | FILE  *in;
391                          }
392                          yread++;
393                  }
394 +                if (obarsize > 0)
395 +                        scan2sync(r);
396                  for (c = 0; c < ncols; c++) {
397                          xcent = (long)c*xres/ncols;
398 <                        if (rad <= 0.0)
399 <                                dobox(scanout[c], xcent, ycent, c, r);
400 <                        else
398 >                        if (thresh > FTINY)
399 >                                dothresh(xcent, ycent, c, r);
400 >                        else if (rad > FTINY)
401                                  dogauss(scanout[c], xcent, ycent, c, r);
402 +                        else
403 +                                dobox(scanout[c], xcent, ycent, c, r);
404                  }
405 <                if (fwritescan(scanout, ncols, stdout) < 0) {
405 >                if (scanout != NULL && fwritescan(scanout, ncols, stdout) < 0) {
406                          fprintf(stderr, "%s: write error in pass2\n", progname);
407                          quit(1);
408                  }
409          }
410 <                                        /* skip leftovers */
410 >                                        /* skip leftover input */
411          while (yread < yres) {
412                  if (freadscan(scanin[0], xres, in) < 0)
413                          break;
414                  yread++;
415          }
416 +        scan2flush();                   /* flush output */
417   }
418  
419  
# Line 404 | Line 423 | scan2init()                    /* prepare scanline arrays */
423          double  d;
424          register int  i;
425  
426 <        if (rad <= 0.0) {
427 <                xrad = xres/ncols/2 + 1;
428 <                yrad = yres/nrows/2 + 1;
410 <        } else {
426 >        xbrad = xres/ncols/2 + 1;
427 >        ybrad = yres/nrows/2 + 1;
428 >        if (rad > FTINY) {
429                  if (nrows >= yres && ncols >= xres)
430                          rad *= (y_r + x_c)/2.0;
431  
432 <                xrad = CHECKRAD*rad/x_c + 1;
433 <                yrad = CHECKRAD*rad/y_r + 1;
434 <
432 >                if (thresh > FTINY) {
433 >                        xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad;
434 >                        yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad;
435 >                        orad = CHECKRAD*THRESHRAD*rad + 1;
436 >                        obarsize = 2*orad + 1;
437 >                } else {
438 >                        xrad = CHECKRAD*rad/x_c + 1;
439 >                        yrad = CHECKRAD*rad/y_r + 1;
440 >                }
441                  initmask();             /* initialize filter table */
442 +        } else {
443 +                xrad = xbrad;
444 +                yrad = ybrad;
445          }
446          barsize = 2*yrad + 1;
447          scanin = (COLOR **)malloc(barsize*sizeof(COLOR *));
448 +        if (scanin == NULL)
449 +                goto memerr;
450          for (i = 0; i < barsize; i++) {
451                  scanin[i] = (COLOR *)malloc(xres*sizeof(COLOR));
452 <                if (scanin[i] == NULL) {
453 <                        fprintf(stderr, "%s: out of memory\n", progname);
454 <                        quit(1);
452 >                if (scanin[i] == NULL)
453 >                        goto memerr;
454 >        }
455 >        if (obarsize > 0) {
456 >                scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *));
457 >                greybar = (float **)malloc(obarsize*sizeof(float *));
458 >                if (scoutbar == NULL | greybar == NULL)
459 >                        goto memerr;
460 >                for (i = 0; i < obarsize; i++) {
461 >                        scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR));
462 >                        greybar[i] = (float *)malloc(ncols*sizeof(float));
463 >                        if (scoutbar[i] == NULL | greybar[i] == NULL)
464 >                                goto memerr;
465                  }
466 +        } else {
467 +                scanout = (COLOR *)malloc(ncols*sizeof(COLOR));
468 +                if (scanout == NULL)
469 +                        goto memerr;
470          }
428        scanout = (COLOR *)malloc(ncols*sizeof(COLOR));
429        if (scanout == NULL) {
430                fprintf(stderr, "%s: out of memory\n", progname);
431                quit(1);
432        }
471                                          /* record pixel aspect ratio */
472          if (!correctaspect) {
473                  d = order & YMAJOR ? x_c/y_r : y_r/x_c ;
# Line 449 | Line 487 | scan2init()                    /* prepare scanline arrays */
487          printf("\n");
488                                          /* write out resolution */
489          fputresolu(order, ncols, nrows, stdout);
490 +        return;
491 + memerr:
492 +        fprintf(stderr, "%s: out of memory\n", progname);
493 +        quit(1);
494 + }
495 +
496 +
497 + scan2sync(r)                    /* synchronize grey averages and output scan */
498 + int  r;
499 + {
500 +        static int  nextrow = 0;
501 +        COLOR  ctmp;
502 +        int  ybot;
503 +        register int  c;
504 +                                        /* average input scanlines */
505 +        while (nextrow < r+orad && nextrow < nrows) {
506 +                ybot = (long)nextrow*yres/nrows;
507 +                for (c = 0; c < ncols; c++) {
508 +                        dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow);
509 +                        greybar[nextrow%obarsize][c] = bright(ctmp);
510 +                }
511 +                                        /* and zero output scanline */
512 +                bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR));
513 +                nextrow++;
514 +        }
515 +                                        /* point to top scanline for output */
516 +        if (r-orad >= 0)
517 +                scanout = scoutbar[(r-orad)%obarsize];
518 +        else
519 +                scanout = NULL;
520 + }
521 +
522 +
523 + scan2flush()                    /* flush output buffer */
524 + {
525 +        register int  r;
526 +
527 +        for (r = nrows-orad; r < nrows; r++)
528 +                if (fwritescan(scoutbar[r%obarsize], ncols, stdout) < 0)
529 +                        break;
530 +        if (fflush(stdout) < 0) {
531 +                fprintf(stderr, "%s: write error at end of pass2\n", progname);
532 +                exit(1);
533 +        }
534   }
535  
536  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines