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.14 by greg, Wed May 31 08:50:27 1995 UTC vs.
Revision 2.23 by schorsch, Thu Jun 5 19:29:34 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1992 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  pfilt.c - program to post-process picture file.
6   *
# Line 11 | Line 8 | static char SCCSid[] = "$SunId$ LBL";
8   *     6/23/93  Added additional buffers for value spreading
9   */
10  
14 #include  "standard.h"
15
11   #include  <signal.h>
12  
13 + #include  "standard.h"
14   #include  "color.h"
15 <
20 < #include  "resolu.h"
21 <
15 > #include  "view.h"
16   #include  "paths.h"
17  
18   extern float  *matchlamp();
19  
20   #define  FEQ(a,b)       ((a) >= .98*(b) && (a) <= 1.02*(b))
21  
22 < double   CHECKRAD = 1.5;        /* radius to check for filtering */
22 > double   CHECKRAD = 2.0;        /* radius to check for filtering */
23  
24   #define  THRESHRAD      5.0     /* maximum sample spread in output */
25  
# Line 64 | Line 58 | int  correctaspect = 0;                /* aspect ratio correction? *
58  
59   int  wrongformat = 0;
60  
61 + VIEW  ourview = STDVIEW;
62 + int  gotview = 0;
63 + int  wrapfilt = 0;              /* wrap filter horizontally? */
64 +
65 + int  estatus = 0;               /* exit status (for non-fatal errors) */
66 +
67   int  xrad;                      /* x search radius */
68   int  yrad;                      /* y search radius */
69   int  xbrad;                     /* x box size */
# Line 84 | Line 84 | main(argc, argv)
84   int  argc;
85   char  **argv;
86   {
87 <        extern long  ftell();
88 <        extern int  quit(), headline();
87 >        extern int  headline();
88          FILE  *fin;
89          float  *lampcolor;
90          char  *lamptype = NULL;
# Line 93 | Line 92 | char  **argv;
92          double  outaspect = 0.0;
93          double  d;
94          int  i, j;
95 < #ifdef MSDOS
96 <        extern int  _fmode;
97 <        _fmode = O_BINARY;
99 <        setmode(fileno(stdin), O_BINARY);
100 <        setmode(fileno(stdout), O_BINARY);
101 < #endif
95 >        SET_DEFAULT_BINARY();
96 >        SET_FILE_BINARY(stdin);
97 >        SET_FILE_BINARY(stdout);
98          if (signal(SIGINT, quit) == SIG_IGN)
99                  signal(SIGINT, SIG_IGN);
100          if (signal(SIGHUP, quit) == SIG_IGN)
# Line 147 | Line 143 | char  **argv;
143                                          fprintf(stderr,
144                                                  "%s: exposure out of range\n",
145                                                          argv[0]);
146 <                                        exit(1);
146 >                                        quit(1);
147                                  }
148                                  switch (argv[i][2]) {
149                                  case '\0':
# Line 197 | Line 193 | char  **argv;
193                          case 'm':
194                                  thresh = atof(argv[++i]);
195                                  if (rad <= FTINY)
196 <                                        rad = 1.0;
196 >                                        rad = 0.6;
197                                  break;
198                          case 'b':
199                                  rad = thresh = 0.0;
# Line 267 | Line 263 | char  **argv;
263          }
264          if (!(order & YMAJOR))
265                  inpaspect = 1.0/inpaspect;
266 +                                        /* wrap around for cylindrical view? */
267 +        wrapfilt = gotview && ourview.type == VT_CYL &&
268 +                        ourview.horiz >= 360.-FTINY && order & YMAJOR;
269                                          /* compute output resolution */
270          if (ncols <= 0)
271                  ncols = x_c*xres + .5;
# Line 298 | Line 297 | char  **argv;
297          }
298          pass2(fin);
299  
300 <        quit(0);
300 >        quit(estatus);
301   }
302  
303  
304 + double
305 + rgb_bright(clr)
306 + COLOR  clr;
307 + {
308 +        return(bright(clr));
309 + }
310 +
311 +
312 + double
313 + xyz_bright(clr)
314 + COLOR  clr;
315 + {
316 +        return(clr[CIEY]);
317 + }
318 +
319 +
320 + double  (*ourbright)() = rgb_bright;
321 +
322 +
323 + int
324   headline(s)                             /* process line from header */
325   char  *s;
326   {
# Line 310 | Line 329 | char  *s;
329          fputs(s, stdout);               /* copy to output */
330          if (isaspect(s))                /* get aspect ratio */
331                  inpaspect *= aspectval(s);
332 <        else if (isexpos(s))
332 >        else if (isexpos(s))            /* get exposure */
333                  hotlvl *= exposval(s);
334 <        else if (isformat(s)) {
335 <                formatval(fmt, s);
336 <                wrongformat = strcmp(fmt, COLRFMT);
337 <        }
334 >        else if (formatval(fmt, s)) {   /* get format */
335 >                wrongformat = 0;
336 >                if (!strcmp(COLRFMT, fmt))
337 >                        ourbright = rgb_bright;
338 >                else if (!strcmp(CIEFMT, fmt))
339 >                        ourbright = xyz_bright;
340 >                else
341 >                        wrongformat = !globmatch(PICFMT, fmt);
342 >        } else if (isview(s) && sscanview(&ourview, s) > 0)
343 >                gotview++;
344 >        return(0);
345   }
346  
347  
# Line 358 | Line 384 | FILE  *in;
384                                          progname, (int)(100L*i/yres));
385                          yres = i;
386                          y_r = (double)nrows/yres;
387 +                        estatus++;
388                          break;
389                  }
390                  pass1scan(scan, i);
391          }
392 <        free((char *)scan);
392 >        free((void *)scan);
393   }
394  
395  
# Line 377 | Line 404 | FILE  *in;
404          scan2init();
405          yread = 0;
406          for (r = 0; r < nrows; r++) {
407 <                ycent = (long)r*yres/nrows;
407 >                ycent = (r+.5)*yres/nrows;
408                  while (yread <= ycent+yrad) {
409                          if (yread < yres) {
410                                  if (freadscan(scanin[yread%barsize],
# Line 394 | Line 421 | FILE  *in;
421                  if (obarsize > 0)
422                          scan2sync(r);
423                  for (c = 0; c < ncols; c++) {
424 <                        xcent = (long)c*xres/ncols;
424 >                        xcent = (c+.5)*xres/ncols;
425                          if (thresh > FTINY)
426                                  dothresh(xcent, ycent, c, r);
427                          else if (rad > FTINY)
# Line 430 | Line 457 | scan2init()                    /* prepare scanline arrays */
457                          rad *= (y_r + x_c)/2.0;
458  
459                  if (thresh > FTINY) {
433                        xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad;
434                        yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad;
460                          orad = CHECKRAD*THRESHRAD*rad + 1;
461 +                        xrad = orad/x_c + xbrad;
462 +                        yrad = orad/y_r + ybrad;
463                          obarsize = 2*orad + 1;
464                  } else {
465                          xrad = CHECKRAD*rad/x_c + 1;
# Line 475 | Line 502 | scan2init()                    /* prepare scanline arrays */
502                          fputaspect(d, stdout);
503          }
504                                          /* record exposure */
505 <        d = bright(exposure);
505 >        d = (*ourbright)(exposure);
506          if (!FEQ(d,1.0))
507                  fputexpos(d, stdout);
508                                          /* record color correction */
# Line 502 | Line 529 | int  r;
529          int  ybot;
530          register int  c;
531                                          /* average input scanlines */
532 <        while (nextrow < r+orad && nextrow < nrows) {
533 <                ybot = (long)nextrow*yres/nrows;
532 >        while (nextrow <= r+orad && nextrow < nrows) {
533 >                ybot = (nextrow+.5)*yres/nrows;
534                  for (c = 0; c < ncols; c++) {
535 <                        dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow);
536 <                        greybar[nextrow%obarsize][c] = bright(ctmp);
535 >                        dobox(ctmp, (int)((c+.5)*xres/ncols),ybot, c,nextrow);
536 >                        greybar[nextrow%obarsize][c] = (*ourbright)(ctmp);
537                  }
538                                          /* and zero output scanline */
539                  bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR));
# Line 529 | Line 556 | scan2flush()                   /* flush output buffer */
556                          break;
557          if (fflush(stdout) < 0) {
558                  fprintf(stderr, "%s: write error at end of pass2\n", progname);
559 <                exit(1);
559 >                quit(1);
560          }
561   }
562  
563  
564 + void
565   quit(code)              /* remove temporary file and exit */
566   int  code;
567   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines