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.13 by greg, Mon Feb 7 16:27:50 1994 UTC vs.
Revision 2.25 by schorsch, Mon Jun 30 14:59:12 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  
11 < #include  "standard.h"
11 > #include  "copyright.h"
12  
13   #include  <signal.h>
14 + #include  <string.h>
15  
16 + #include  "standard.h"
17 + #include  "platform.h"
18   #include  "color.h"
19 <
20 < #include  "resolu.h"
21 <
19 > #include  "view.h"
20   #include  "paths.h"
21  
22   extern float  *matchlamp();
23  
24   #define  FEQ(a,b)       ((a) >= .98*(b) && (a) <= 1.02*(b))
25  
26 < double   CHECKRAD = 1.5;        /* radius to check for filtering */
26 > double   CHECKRAD = 2.0;        /* radius to check for filtering */
27  
28   #define  THRESHRAD      5.0     /* maximum sample spread in output */
29  
# Line 64 | Line 62 | int  correctaspect = 0;                /* aspect ratio correction? *
62  
63   int  wrongformat = 0;
64  
65 + VIEW  ourview = STDVIEW;
66 + int  gotview = 0;
67 + int  wrapfilt = 0;              /* wrap filter horizontally? */
68 +
69 + int  estatus = 0;               /* exit status (for non-fatal errors) */
70 +
71   int  xrad;                      /* x search radius */
72   int  yrad;                      /* y search radius */
73   int  xbrad;                     /* x box size */
# Line 84 | Line 88 | main(argc, argv)
88   int  argc;
89   char  **argv;
90   {
91 <        extern long  ftell();
88 <        extern int  quit(), headline();
91 >        extern int  headline();
92          FILE  *fin;
93          float  *lampcolor;
94          char  *lamptype = NULL;
# Line 93 | Line 96 | char  **argv;
96          double  outaspect = 0.0;
97          double  d;
98          int  i, j;
99 < #ifdef MSDOS
100 <        extern int  _fmode;
101 <        _fmode = O_BINARY;
99 <        setmode(fileno(stdin), O_BINARY);
100 <        setmode(fileno(stdout), O_BINARY);
101 < #endif
99 >        SET_DEFAULT_BINARY();
100 >        SET_FILE_BINARY(stdin);
101 >        SET_FILE_BINARY(stdout);
102          if (signal(SIGINT, quit) == SIG_IGN)
103                  signal(SIGINT, SIG_IGN);
104 + #ifdef SIGHUP
105          if (signal(SIGHUP, quit) == SIG_IGN)
106                  signal(SIGHUP, SIG_IGN);
107 + #endif
108          signal(SIGTERM, quit);
109 + #ifdef SIGPIPE
110          signal(SIGPIPE, quit);
111 + #endif
112   #ifdef  SIGXCPU
113          signal(SIGXCPU, quit);
114          signal(SIGXFSZ, quit);
# Line 147 | Line 151 | char  **argv;
151                                          fprintf(stderr,
152                                                  "%s: exposure out of range\n",
153                                                          argv[0]);
154 <                                        exit(1);
154 >                                        quit(1);
155                                  }
156                                  switch (argv[i][2]) {
157                                  case '\0':
# Line 197 | Line 201 | char  **argv;
201                          case 'm':
202                                  thresh = atof(argv[++i]);
203                                  if (rad <= FTINY)
204 <                                        rad = 1.0;
204 >                                        rad = 0.6;
205                                  break;
206                          case 'b':
207                                  rad = thresh = 0.0;
# Line 267 | Line 271 | char  **argv;
271          }
272          if (!(order & YMAJOR))
273                  inpaspect = 1.0/inpaspect;
274 +                                        /* wrap around for cylindrical view? */
275 +        wrapfilt = gotview && ourview.type == VT_CYL &&
276 +                        ourview.horiz >= 360.-FTINY && order & YMAJOR;
277                                          /* compute output resolution */
278          if (ncols <= 0)
279                  ncols = x_c*xres + .5;
# Line 298 | Line 305 | char  **argv;
305          }
306          pass2(fin);
307  
308 <        quit(0);
308 >        quit(estatus);
309   }
310  
311  
312 + double
313 + rgb_bright(clr)
314 + COLOR  clr;
315 + {
316 +        return(bright(clr));
317 + }
318 +
319 +
320 + double
321 + xyz_bright(clr)
322 + COLOR  clr;
323 + {
324 +        return(clr[CIEY]);
325 + }
326 +
327 +
328 + double  (*ourbright)() = rgb_bright;
329 +
330 +
331 + int
332   headline(s)                             /* process line from header */
333   char  *s;
334   {
# Line 310 | Line 337 | char  *s;
337          fputs(s, stdout);               /* copy to output */
338          if (isaspect(s))                /* get aspect ratio */
339                  inpaspect *= aspectval(s);
340 <        else if (isexpos(s))
340 >        else if (isexpos(s))            /* get exposure */
341                  hotlvl *= exposval(s);
342 <        else if (isformat(s)) {
343 <                formatval(fmt, s);
344 <                wrongformat = strcmp(fmt, COLRFMT);
345 <        }
342 >        else if (formatval(fmt, s)) {   /* get format */
343 >                wrongformat = 0;
344 >                if (!strcmp(COLRFMT, fmt))
345 >                        ourbright = rgb_bright;
346 >                else if (!strcmp(CIEFMT, fmt))
347 >                        ourbright = xyz_bright;
348 >                else
349 >                        wrongformat = !globmatch(PICFMT, fmt);
350 >        } else if (isview(s) && sscanview(&ourview, s) > 0)
351 >                gotview++;
352 >        return(0);
353   }
354  
355  
# Line 358 | Line 392 | FILE  *in;
392                                          progname, (int)(100L*i/yres));
393                          yres = i;
394                          y_r = (double)nrows/yres;
395 +                        estatus++;
396                          break;
397                  }
398                  pass1scan(scan, i);
399          }
400 <        free((char *)scan);
400 >        free((void *)scan);
401   }
402  
403  
# Line 377 | Line 412 | FILE  *in;
412          scan2init();
413          yread = 0;
414          for (r = 0; r < nrows; r++) {
415 <                ycent = (long)r*yres/nrows;
415 >                ycent = (r+.5)*yres/nrows;
416                  while (yread <= ycent+yrad) {
417                          if (yread < yres) {
418                                  if (freadscan(scanin[yread%barsize],
419                                                  xres, in) < 0) {
420                                          fprintf(stderr,
421 <                                                "%s: bad read (y=%d)\n",
421 >                                                "%s: truncated input (y=%d)\n",
422                                                  progname, yres-1-yread);
423                                          quit(1);
424                                  }
# Line 394 | Line 429 | FILE  *in;
429                  if (obarsize > 0)
430                          scan2sync(r);
431                  for (c = 0; c < ncols; c++) {
432 <                        xcent = (long)c*xres/ncols;
432 >                        xcent = (c+.5)*xres/ncols;
433                          if (thresh > FTINY)
434                                  dothresh(xcent, ycent, c, r);
435                          else if (rad > FTINY)
# Line 430 | Line 465 | scan2init()                    /* prepare scanline arrays */
465                          rad *= (y_r + x_c)/2.0;
466  
467                  if (thresh > FTINY) {
433                        xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad;
434                        yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad;
468                          orad = CHECKRAD*THRESHRAD*rad + 1;
469 +                        xrad = orad/x_c + xbrad;
470 +                        yrad = orad/y_r + ybrad;
471                          obarsize = 2*orad + 1;
472                  } else {
473                          xrad = CHECKRAD*rad/x_c + 1;
# Line 475 | Line 510 | scan2init()                    /* prepare scanline arrays */
510                          fputaspect(d, stdout);
511          }
512                                          /* record exposure */
513 <        d = bright(exposure);
513 >        d = (*ourbright)(exposure);
514          if (!FEQ(d,1.0))
515                  fputexpos(d, stdout);
516                                          /* record color correction */
# Line 502 | Line 537 | int  r;
537          int  ybot;
538          register int  c;
539                                          /* average input scanlines */
540 <        while (nextrow < r+orad && nextrow < nrows) {
541 <                ybot = (long)nextrow*yres/nrows;
540 >        while (nextrow <= r+orad && nextrow < nrows) {
541 >                ybot = (nextrow+.5)*yres/nrows;
542                  for (c = 0; c < ncols; c++) {
543 <                        dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow);
544 <                        greybar[nextrow%obarsize][c] = bright(ctmp);
543 >                        dobox(ctmp, (int)((c+.5)*xres/ncols),ybot, c,nextrow);
544 >                        greybar[nextrow%obarsize][c] = (*ourbright)(ctmp);
545                  }
546                                          /* and zero output scanline */
547 <                bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR));
547 >                memset((char *)scoutbar[nextrow%obarsize], '\0', ncols*sizeof(COLOR));
548                  nextrow++;
549          }
550                                          /* point to top scanline for output */
# Line 529 | Line 564 | scan2flush()                   /* flush output buffer */
564                          break;
565          if (fflush(stdout) < 0) {
566                  fprintf(stderr, "%s: write error at end of pass2\n", progname);
567 <                exit(1);
567 >                quit(1);
568          }
569   }
570  
571  
572 + void
573   quit(code)              /* remove temporary file and exit */
574   int  code;
575   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines