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.11 by greg, Tue Sep 21 10:55:54 1993 UTC vs.
Revision 2.24 by schorsch, Sun Jun 8 12:03:10 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  "platform.h"
15   #include  "color.h"
16 <
20 < #include  "resolu.h"
21 <
16 > #include  "view.h"
17   #include  "paths.h"
18  
19   extern float  *matchlamp();
20  
21   #define  FEQ(a,b)       ((a) >= .98*(b) && (a) <= 1.02*(b))
22  
23 < double   CHECKRAD = 1.5;        /* radius to check for filtering */
23 > double   CHECKRAD = 2.0;        /* radius to check for filtering */
24  
25   #define  THRESHRAD      5.0     /* maximum sample spread in output */
26  
# Line 64 | Line 59 | int  correctaspect = 0;                /* aspect ratio correction? *
59  
60   int  wrongformat = 0;
61  
62 + VIEW  ourview = STDVIEW;
63 + int  gotview = 0;
64 + int  wrapfilt = 0;              /* wrap filter horizontally? */
65 +
66 + int  estatus = 0;               /* exit status (for non-fatal errors) */
67 +
68   int  xrad;                      /* x search radius */
69   int  yrad;                      /* y search radius */
70   int  xbrad;                     /* x box size */
# Line 84 | Line 85 | main(argc, argv)
85   int  argc;
86   char  **argv;
87   {
88 <        extern long  ftell();
88 <        extern int  quit(), headline();
88 >        extern int  headline();
89          FILE  *fin;
90          float  *lampcolor;
91          char  *lamptype = NULL;
# Line 93 | Line 93 | char  **argv;
93          double  outaspect = 0.0;
94          double  d;
95          int  i, j;
96 < #ifdef MSDOS
97 <        extern int  _fmode;
98 <        _fmode = O_BINARY;
99 <        setmode(fileno(stdin), O_BINARY);
100 <        setmode(fileno(stdout), O_BINARY);
101 < #endif
96 >        SET_DEFAULT_BINARY();
97 >        SET_FILE_BINARY(stdin);
98 >        SET_FILE_BINARY(stdout);
99          if (signal(SIGINT, quit) == SIG_IGN)
100                  signal(SIGINT, SIG_IGN);
101 + #ifdef SIGHUP
102          if (signal(SIGHUP, quit) == SIG_IGN)
103                  signal(SIGHUP, SIG_IGN);
104 + #endif
105          signal(SIGTERM, quit);
106 + #ifdef SIGPIPE
107          signal(SIGPIPE, quit);
108 + #endif
109   #ifdef  SIGXCPU
110          signal(SIGXCPU, quit);
111          signal(SIGXFSZ, quit);
# Line 147 | Line 148 | char  **argv;
148                                          fprintf(stderr,
149                                                  "%s: exposure out of range\n",
150                                                          argv[0]);
151 <                                        exit(1);
151 >                                        quit(1);
152                                  }
153                                  switch (argv[i][2]) {
154                                  case '\0':
# Line 197 | Line 198 | char  **argv;
198                          case 'm':
199                                  thresh = atof(argv[++i]);
200                                  if (rad <= FTINY)
201 <                                        rad = 1.0;
201 >                                        rad = 0.6;
202                                  break;
203                          case 'b':
204                                  rad = thresh = 0.0;
# Line 219 | Line 220 | char  **argv;
220                          fprintf(stderr, "%s: unknown lamp type\n", lamptype);
221                          quit(1);
222                  }
223 <                for (i = 0; i < 3; i++)
224 <                        if (lampcolor[i] > 1e-4)
225 <                                colval(exposure,i) /= lampcolor[i];
223 >                for (j = 0; j < 3; j++)
224 >                        if (lampcolor[j] > 1e-4)
225 >                                colval(exposure,j) /= lampcolor[j];
226                  freelamps();
227          }
228                                          /* open input file */
# Line 267 | Line 268 | char  **argv;
268          }
269          if (!(order & YMAJOR))
270                  inpaspect = 1.0/inpaspect;
271 +                                        /* wrap around for cylindrical view? */
272 +        wrapfilt = gotview && ourview.type == VT_CYL &&
273 +                        ourview.horiz >= 360.-FTINY && order & YMAJOR;
274                                          /* compute output resolution */
275          if (ncols <= 0)
276                  ncols = x_c*xres + .5;
# Line 298 | Line 302 | char  **argv;
302          }
303          pass2(fin);
304  
305 <        quit(0);
305 >        quit(estatus);
306   }
307  
308  
309 + double
310 + rgb_bright(clr)
311 + COLOR  clr;
312 + {
313 +        return(bright(clr));
314 + }
315 +
316 +
317 + double
318 + xyz_bright(clr)
319 + COLOR  clr;
320 + {
321 +        return(clr[CIEY]);
322 + }
323 +
324 +
325 + double  (*ourbright)() = rgb_bright;
326 +
327 +
328 + int
329   headline(s)                             /* process line from header */
330   char  *s;
331   {
# Line 310 | Line 334 | char  *s;
334          fputs(s, stdout);               /* copy to output */
335          if (isaspect(s))                /* get aspect ratio */
336                  inpaspect *= aspectval(s);
337 <        else if (isexpos(s))
337 >        else if (isexpos(s))            /* get exposure */
338                  hotlvl *= exposval(s);
339 <        else if (isformat(s)) {
340 <                formatval(fmt, s);
341 <                wrongformat = strcmp(fmt, COLRFMT);
342 <        }
339 >        else if (formatval(fmt, s)) {   /* get format */
340 >                wrongformat = 0;
341 >                if (!strcmp(COLRFMT, fmt))
342 >                        ourbright = rgb_bright;
343 >                else if (!strcmp(CIEFMT, fmt))
344 >                        ourbright = xyz_bright;
345 >                else
346 >                        wrongformat = !globmatch(PICFMT, fmt);
347 >        } else if (isview(s) && sscanview(&ourview, s) > 0)
348 >                gotview++;
349 >        return(0);
350   }
351  
352  
# Line 358 | Line 389 | FILE  *in;
389                                          progname, (int)(100L*i/yres));
390                          yres = i;
391                          y_r = (double)nrows/yres;
392 +                        estatus++;
393                          break;
394                  }
395                  pass1scan(scan, i);
396          }
397 <        free((char *)scan);
397 >        free((void *)scan);
398   }
399  
400  
# Line 377 | Line 409 | FILE  *in;
409          scan2init();
410          yread = 0;
411          for (r = 0; r < nrows; r++) {
412 <                ycent = (long)r*yres/nrows;
412 >                ycent = (r+.5)*yres/nrows;
413                  while (yread <= ycent+yrad) {
414                          if (yread < yres) {
415                                  if (freadscan(scanin[yread%barsize],
416                                                  xres, in) < 0) {
417                                          fprintf(stderr,
418 <                                                "%s: bad read (y=%d)\n",
418 >                                                "%s: truncated input (y=%d)\n",
419                                                  progname, yres-1-yread);
420                                          quit(1);
421                                  }
# Line 394 | Line 426 | FILE  *in;
426                  if (obarsize > 0)
427                          scan2sync(r);
428                  for (c = 0; c < ncols; c++) {
429 <                        xcent = (long)c*xres/ncols;
429 >                        xcent = (c+.5)*xres/ncols;
430                          if (thresh > FTINY)
431                                  dothresh(xcent, ycent, c, r);
432                          else if (rad > FTINY)
# Line 430 | Line 462 | scan2init()                    /* prepare scanline arrays */
462                          rad *= (y_r + x_c)/2.0;
463  
464                  if (thresh > FTINY) {
433                        xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad;
434                        yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad;
465                          orad = CHECKRAD*THRESHRAD*rad + 1;
466 +                        xrad = orad/x_c + xbrad;
467 +                        yrad = orad/y_r + ybrad;
468                          obarsize = 2*orad + 1;
469                  } else {
470                          xrad = CHECKRAD*rad/x_c + 1;
# Line 475 | Line 507 | scan2init()                    /* prepare scanline arrays */
507                          fputaspect(d, stdout);
508          }
509                                          /* record exposure */
510 <        d = bright(exposure);
510 >        d = (*ourbright)(exposure);
511          if (!FEQ(d,1.0))
512                  fputexpos(d, stdout);
513                                          /* record color correction */
# Line 502 | Line 534 | int  r;
534          int  ybot;
535          register int  c;
536                                          /* average input scanlines */
537 <        while (nextrow < r+orad && nextrow < nrows) {
538 <                ybot = (long)nextrow*yres/nrows;
537 >        while (nextrow <= r+orad && nextrow < nrows) {
538 >                ybot = (nextrow+.5)*yres/nrows;
539                  for (c = 0; c < ncols; c++) {
540 <                        dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow);
541 <                        greybar[nextrow%obarsize][c] = bright(ctmp);
540 >                        dobox(ctmp, (int)((c+.5)*xres/ncols),ybot, c,nextrow);
541 >                        greybar[nextrow%obarsize][c] = (*ourbright)(ctmp);
542                  }
543                                          /* and zero output scanline */
544                  bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR));
# Line 529 | Line 561 | scan2flush()                   /* flush output buffer */
561                          break;
562          if (fflush(stdout) < 0) {
563                  fprintf(stderr, "%s: write error at end of pass2\n", progname);
564 <                exit(1);
564 >                quit(1);
565          }
566   }
567  
568  
569 + void
570   quit(code)              /* remove temporary file and exit */
571   int  code;
572   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines