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.8 by greg, Fri Jun 18 16:20:16 1993 UTC vs.
Revision 2.9 by greg, Fri Jun 25 15:01:17 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  "standard.h"
# Line 24 | Line 25 | 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 57 | Line 62 | int  correctaspect = 0;                /* aspect ratio correction? *
62  
63   int  wrongformat = 0;
64  
65 < int  xrad;                      /* x window size */
66 < int  yrad;                      /* y window size */
65 > int  xrad;                      /* x search radius */
66 > int  yrad;                      /* y search radius */
67 > int  xbrad;                     /* x box size */
68 > int  ybrad;                     /* y box size */
69  
70   int  barsize;                   /* size of input scan bar */
71   COLOR  **scanin;                /* input scan bar */
72   COLOR  *scanout;                /* output scan line */
73 + COLOR  **scoutbar;              /* output scan bar (if thresh > 0) */
74 + float  **greybar;               /* grey-averaged input values */
75 + int  obarsize = 0;              /* size of output scan bar */
76 + int  orad = 0;                  /* output window radius */
77  
78   char  *progname;
79  
# Line 181 | Line 192 | char  **argv;
192                          case 'r':
193                                  rad = atof(argv[++i]);
194                                  break;
195 +                        case 'm':
196 +                                thresh = atof(argv[++i]);
197 +                                if (rad <= FTINY)
198 +                                        rad = 1.0;
199 +                                break;
200                          case 'b':
201 <                                rad = 0.0;
201 >                                rad = thresh = 0.0;
202                                  break;
203                          default:;
204                          badopt:
# Line 373 | Line 389 | FILE  *in;
389                          }
390                          yread++;
391                  }
392 +                if (obarsize > 0)
393 +                        scan2sync(r);
394                  for (c = 0; c < ncols; c++) {
395                          xcent = (long)c*xres/ncols;
396 <                        if (rad <= 0.0)
397 <                                dobox(scanout[c], xcent, ycent, c, r);
398 <                        else
396 >                        if (thresh > FTINY)
397 >                                dothresh(xcent, ycent, c, r);
398 >                        else if (rad > FTINY)
399                                  dogauss(scanout[c], xcent, ycent, c, r);
400 +                        else
401 +                                dobox(scanout[c], xcent, ycent, c, r);
402                  }
403 <                if (fwritescan(scanout, ncols, stdout) < 0) {
403 >                if (scanout != NULL && fwritescan(scanout, ncols, stdout) < 0) {
404                          fprintf(stderr, "%s: write error in pass2\n", progname);
405                          quit(1);
406                  }
407          }
408 <                                        /* skip leftovers */
408 >                                        /* skip leftover input */
409          while (yread < yres) {
410                  if (freadscan(scanin[0], xres, in) < 0)
411                          break;
412                  yread++;
413          }
414 +        scan2flush();                   /* flush output */
415   }
416  
417  
# Line 400 | Line 421 | scan2init()                    /* prepare scanline arrays */
421          double  d;
422          register int  i;
423  
424 <        if (rad <= 0.0) {
425 <                xrad = xres/ncols/2 + 1;
426 <                yrad = yres/nrows/2 + 1;
406 <        } else {
424 >        xbrad = xres/ncols/2 + 1;
425 >        ybrad = yres/nrows/2 + 1;
426 >        if (rad > FTINY) {
427                  if (nrows >= yres && ncols >= xres)
428                          rad *= (y_r + x_c)/2.0;
429  
430 <                xrad = CHECKRAD*rad/x_c + 1;
431 <                yrad = CHECKRAD*rad/y_r + 1;
432 <
430 >                if (thresh > FTINY) {
431 >                        xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad;
432 >                        yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad;
433 >                        orad = CHECKRAD*THRESHRAD*rad + 1;
434 >                        obarsize = 2*orad + 1;
435 >                } else {
436 >                        xrad = CHECKRAD*rad/x_c + 1;
437 >                        yrad = CHECKRAD*rad/y_r + 1;
438 >                }
439                  initmask();             /* initialize filter table */
440 +        } else {
441 +                xrad = xbrad;
442 +                yrad = ybrad;
443          }
444          barsize = 2*yrad + 1;
445          scanin = (COLOR **)malloc(barsize*sizeof(COLOR *));
# Line 421 | Line 450 | scan2init()                    /* prepare scanline arrays */
450                          quit(1);
451                  }
452          }
453 <        scanout = (COLOR *)malloc(ncols*sizeof(COLOR));
454 <        if (scanout == NULL) {
455 <                fprintf(stderr, "%s: out of memory\n", progname);
456 <                quit(1);
453 >        if (obarsize > 0) {
454 >                scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *));
455 >                greybar = (float **)malloc(obarsize*sizeof(float *));
456 >                for (i = 0; i < obarsize; i++) {
457 >                        scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR));
458 >                        greybar[i] = (float *)malloc(ncols*sizeof(float));
459 >                        if (scoutbar[i] == NULL | greybar[i] == NULL) {
460 >                                fprintf(stderr, "%s: out of memory\n",
461 >                                                progname);
462 >                                quit(1);
463 >                        }
464 >                }
465 >        } else {
466 >                scanout = (COLOR *)malloc(ncols*sizeof(COLOR));
467 >                if (scanout == NULL) {
468 >                        fprintf(stderr, "%s: out of memory\n", progname);
469 >                        quit(1);
470 >                }
471          }
472                                          /* record pixel aspect ratio */
473          if (!correctaspect) {
# Line 445 | Line 488 | scan2init()                    /* prepare scanline arrays */
488          printf("\n");
489                                          /* write out resolution */
490          fputresolu(order, ncols, nrows, stdout);
491 + }
492 +
493 +
494 + scan2sync(r)                    /* synchronize grey averages and output scan */
495 + int  r;
496 + {
497 +        static int  nextrow = 0;
498 +        COLOR  ctmp;
499 +        int  ybot;
500 +        register int  c;
501 +                                        /* average input scanlines */
502 +        while (nextrow < r+orad && nextrow < nrows) {
503 +                ybot = (long)nextrow*yres/nrows;
504 +                for (c = 0; c < ncols; c++) {
505 +                        dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow);
506 +                        greybar[nextrow%obarsize][c] = bright(ctmp);
507 +                }
508 +                                        /* and zero output scanline */
509 +                bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR));
510 +                nextrow++;
511 +        }
512 +                                        /* point to top scanline for output */
513 +        if (r-orad >= 0)
514 +                scanout = scoutbar[(r-orad)%obarsize];
515 +        else
516 +                scanout = NULL;
517 + }
518 +
519 +
520 + scan2flush()                    /* flush output buffer */
521 + {
522 +        register int  r;
523 +
524 +        for (r = nrows-orad; r < nrows; r++)
525 +                if (fwritescan(scoutbar[r%obarsize], ncols, stdout) < 0)
526 +                        break;
527 +        if (fflush(stdout) < 0) {
528 +                fprintf(stderr, "%s: write error at end of pass2\n", progname);
529 +                exit(1);
530 +        }
531   }
532  
533  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines