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.10 by greg, Fri Jun 25 17:07:03 1993 UTC vs.
Revision 2.35 by greg, Thu Dec 7 21:15:54 2023 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 <
15 < #include  "color.h"
19 <
20 < #include  "resolu.h"
21 <
14 > #include  "pfilt.h"
15 > #include  "platform.h"
16   #include  "paths.h"
17 + #include  "view.h"
18  
24 extern float  *matchlamp();
25
19   #define  FEQ(a,b)       ((a) >= .98*(b) && (a) <= 1.02*(b))
20  
21 < double   CHECKRAD = 1.5;        /* radius to check for filtering */
21 > double   CHECKRAD = 2.0;        /* radius to check for filtering */
22  
23   #define  THRESHRAD      5.0     /* maximum sample spread in output */
24  
# Line 53 | Line 46 | double spread = 1e-4;          /* spread for star points */
46  
47   char  *tfname = NULL;
48  
49 + char  template[] = TEMPLATE;
50 +
51   char  *lampdat = "lamp.tab";    /* lamp data file */
52  
53   int  order;                     /* scanline ordering of input */
# Line 62 | Line 57 | int  correctaspect = 0;                /* aspect ratio correction? *
57  
58   int  wrongformat = 0;
59  
60 + VIEW  ourview = STDVIEW;
61 + int  gotview = 0;
62 + int  wrapfilt = 0;              /* wrap filter horizontally? */
63 +
64 + int  estatus = 0;               /* exit status (for non-fatal errors) */
65 +
66   int  xrad;                      /* x search radius */
67   int  yrad;                      /* y search radius */
68   int  xbrad;                     /* x box size */
# Line 77 | Line 78 | int  orad = 0;                 /* output window radius */
78  
79   char  *progname;
80  
81 + static gethfunc headline;
82 + static brightfunc_t rgb_bright;
83 + static brightfunc_t xyz_bright;
84 + static void copyfile(FILE  *in, FILE  *out);
85 + static void pass1(FILE  *in);
86 + static void pass2(FILE  *in);
87 + static void scan2init(void);
88 + static void scan2sync(int  r);
89 + static void scan2flush(void);
90  
91 < main(argc, argv)
92 < int  argc;
93 < char  **argv;
91 >
92 > int
93 > main(
94 >        int  argc,
95 >        char  **argv
96 > )
97   {
85        extern long  ftell();
86        extern int  quit(), headline();
98          FILE  *fin;
99          float  *lampcolor;
100          char  *lamptype = NULL;
# Line 91 | Line 102 | char  **argv;
102          double  outaspect = 0.0;
103          double  d;
104          int  i, j;
105 < #ifdef MSDOS
106 <        extern int  _fmode;
107 <        _fmode = O_BINARY;
97 <        setmode(fileno(stdin), O_BINARY);
98 <        setmode(fileno(stdout), O_BINARY);
99 < #endif
105 >        SET_DEFAULT_BINARY();
106 >        SET_FILE_BINARY(stdin);
107 >        SET_FILE_BINARY(stdout);
108          if (signal(SIGINT, quit) == SIG_IGN)
109                  signal(SIGINT, SIG_IGN);
110 + #ifdef SIGHUP
111          if (signal(SIGHUP, quit) == SIG_IGN)
112 <                signal(SIGINT, SIG_IGN);
112 >                signal(SIGHUP, SIG_IGN);
113 > #endif
114          signal(SIGTERM, quit);
115 + #ifdef SIGPIPE
116          signal(SIGPIPE, quit);
117 + #endif
118   #ifdef  SIGXCPU
119          signal(SIGXCPU, quit);
120          signal(SIGXFSZ, quit);
# Line 145 | Line 157 | char  **argv;
157                                          fprintf(stderr,
158                                                  "%s: exposure out of range\n",
159                                                          argv[0]);
160 <                                        exit(1);
160 >                                        quit(1);
161                                  }
162                                  switch (argv[i][2]) {
163                                  case '\0':
# Line 195 | Line 207 | char  **argv;
207                          case 'm':
208                                  thresh = atof(argv[++i]);
209                                  if (rad <= FTINY)
210 <                                        rad = 1.0;
210 >                                        rad = 0.6;
211                                  break;
212                          case 'b':
213                                  rad = thresh = 0.0;
# Line 217 | Line 229 | char  **argv;
229                          fprintf(stderr, "%s: unknown lamp type\n", lamptype);
230                          quit(1);
231                  }
232 <                for (i = 0; i < 3; i++)
233 <                        if (lampcolor[i] > 1e-4)
234 <                                colval(exposure,i) /= lampcolor[i];
232 >                for (j = 0; j < 3; j++)
233 >                        if (lampcolor[j] > 1e-4)
234 >                                colval(exposure,j) /= lampcolor[j];
235                  freelamps();
236          }
237                                          /* open input file */
# Line 227 | Line 239 | char  **argv;
239                  if (singlepass)
240                          fin = stdin;
241                  else {
242 <                        tfname = mktemp(TEMPLATE);
242 >                        tfname = mktemp(template);
243                          if ((fin = fopen(tfname, "w+")) == NULL) {
244                                  fprintf(stderr, "%s: can't create ", progname);
245                                  fprintf(stderr, "temp file \"%s\"\n", tfname);
# Line 265 | Line 277 | char  **argv;
277          }
278          if (!(order & YMAJOR))
279                  inpaspect = 1.0/inpaspect;
280 +                                        /* wrap around for cylindrical view? */
281 +        wrapfilt = gotview && ourview.type == VT_CYL &&
282 +                        ourview.horiz >= 360.-FTINY && order & YMAJOR;
283                                          /* compute output resolution */
284          if (ncols <= 0)
285                  ncols = x_c*xres + .5;
# Line 296 | Line 311 | char  **argv;
311          }
312          pass2(fin);
313  
314 <        quit(0);
314 >        quit(estatus);
315 >        return estatus; /* pro forma return */
316   }
317  
318  
319 < headline(s)                             /* process line from header */
320 < char  *s;
319 > static double
320 > rgb_bright(
321 >        COLOR  clr
322 > )
323   {
324 <        char  fmt[32];
324 >        return(bright(clr));
325 > }
326  
327 +
328 + static double
329 + xyz_bright(
330 +        COLOR  clr
331 + )
332 + {
333 +        return(clr[CIEY]);
334 + }
335 +
336 +
337 + brightfunc_t *ourbright = rgb_bright;
338 +
339 + static int
340 + headline(                               /* process line from header */
341 +        char    *s,
342 +        void    *p
343 + )
344 + {
345 +        char  fmt[MAXFMTLEN];
346 +
347          fputs(s, stdout);               /* copy to output */
348          if (isaspect(s))                /* get aspect ratio */
349                  inpaspect *= aspectval(s);
350 <        else if (isexpos(s))
350 >        else if (isexpos(s))            /* get exposure */
351                  hotlvl *= exposval(s);
352 <        else if (isformat(s)) {
353 <                formatval(fmt, s);
354 <                wrongformat = strcmp(fmt, COLRFMT);
355 <        }
352 >        else if (formatval(fmt, s)) {   /* get format */
353 >                wrongformat = 0;
354 >                if (!strcmp(COLRFMT, fmt))
355 >                        ourbright = rgb_bright;
356 >                else if (!strcmp(CIEFMT, fmt))
357 >                        ourbright = xyz_bright;
358 >                else
359 >                        wrongformat = !globmatch(PICFMT, fmt);
360 >        } else if (isview(s) && sscanview(&ourview, s) > 0)
361 >                gotview++;
362 >        return(0);
363   }
364  
365  
366 < copyfile(in, out)                       /* copy a file */
367 < register FILE  *in, *out;
366 > static void
367 > copyfile(                       /* copy a file */
368 >        FILE  *in,
369 >        FILE  *out
370 > )
371   {
372 <        register int  c;
372 >        int  c;
373  
374          while ((c = getc(in)) != EOF)
375                  putc(c, out);
# Line 332 | Line 381 | register FILE  *in, *out;
381   }
382  
383  
384 < pass1(in)                               /* first pass of picture file */
385 < FILE  *in;
384 > static void
385 > pass1(                          /* first pass of picture file */
386 >        FILE  *in
387 > )
388   {
389          int  i;
390          COLOR  *scan;
# Line 356 | Line 407 | FILE  *in;
407                                          progname, (int)(100L*i/yres));
408                          yres = i;
409                          y_r = (double)nrows/yres;
410 +                        estatus++;
411                          break;
412                  }
413                  pass1scan(scan, i);
414          }
415 <        free((char *)scan);
415 >        free((void *)scan);
416   }
417  
418  
419 < pass2(in)                       /* last pass on file, write to stdout */
420 < FILE  *in;
419 > static void
420 > pass2(                  /* last pass on file, write to stdout */
421 >        FILE  *in
422 > )
423   {
424          int  yread;
425          int  ycent, xcent;
# Line 375 | Line 429 | FILE  *in;
429          scan2init();
430          yread = 0;
431          for (r = 0; r < nrows; r++) {
432 <                ycent = (long)r*yres/nrows;
432 >                ycent = (r+.5)*yres/nrows;
433                  while (yread <= ycent+yrad) {
434                          if (yread < yres) {
435                                  if (freadscan(scanin[yread%barsize],
436                                                  xres, in) < 0) {
437                                          fprintf(stderr,
438 <                                                "%s: bad read (y=%d)\n",
438 >                                                "%s: truncated input (y=%d)\n",
439                                                  progname, yres-1-yread);
440                                          quit(1);
441                                  }
# Line 392 | Line 446 | FILE  *in;
446                  if (obarsize > 0)
447                          scan2sync(r);
448                  for (c = 0; c < ncols; c++) {
449 <                        xcent = (long)c*xres/ncols;
449 >                        xcent = (c+.5)*xres/ncols;
450                          if (thresh > FTINY)
451                                  dothresh(xcent, ycent, c, r);
452                          else if (rad > FTINY)
# Line 415 | Line 469 | FILE  *in;
469   }
470  
471  
472 < scan2init()                     /* prepare scanline arrays */
472 > static void
473 > scan2init(void)                 /* prepare scanline arrays */
474   {
475          COLOR   ctmp;
476          double  d;
477 <        register int  i;
477 >        int  i;
478  
479          xbrad = xres/ncols/2 + 1;
480          ybrad = yres/nrows/2 + 1;
# Line 428 | Line 483 | scan2init()                    /* prepare scanline arrays */
483                          rad *= (y_r + x_c)/2.0;
484  
485                  if (thresh > FTINY) {
431                        xrad = CHECKRAD*THRESHRAD*rad/x_c + xbrad;
432                        yrad = CHECKRAD*THRESHRAD*rad/y_r + ybrad;
486                          orad = CHECKRAD*THRESHRAD*rad + 1;
487 +                        xrad = orad/x_c + xbrad;
488 +                        yrad = orad/y_r + ybrad;
489                          obarsize = 2*orad + 1;
490                  } else {
491                          xrad = CHECKRAD*rad/x_c + 1;
# Line 453 | Line 508 | scan2init()                    /* prepare scanline arrays */
508          if (obarsize > 0) {
509                  scoutbar = (COLOR **)malloc(obarsize*sizeof(COLOR *));
510                  greybar = (float **)malloc(obarsize*sizeof(float *));
511 <                if (scoutbar == NULL | greybar == NULL)
511 >                if ((scoutbar == NULL) | (greybar == NULL))
512                          goto memerr;
513                  for (i = 0; i < obarsize; i++) {
514                          scoutbar[i] = (COLOR *)malloc(ncols*sizeof(COLOR));
515                          greybar[i] = (float *)malloc(ncols*sizeof(float));
516 <                        if (scoutbar[i] == NULL | greybar[i] == NULL)
516 >                        if ((scoutbar[i] == NULL) | (greybar[i] == NULL))
517                                  goto memerr;
518                  }
519          } else {
# Line 473 | Line 528 | scan2init()                    /* prepare scanline arrays */
528                          fputaspect(d, stdout);
529          }
530                                          /* record exposure */
531 <        d = bright(exposure);
531 >        d = (*ourbright)(exposure);
532          if (!FEQ(d,1.0))
533                  fputexpos(d, stdout);
534                                          /* record color correction */
# Line 492 | Line 547 | memerr:
547   }
548  
549  
550 < scan2sync(r)                    /* synchronize grey averages and output scan */
551 < int  r;
550 > static void
551 > scan2sync(                      /* synchronize grey averages and output scan */
552 >        int  r
553 > )
554   {
555          static int  nextrow = 0;
556          COLOR  ctmp;
557          int  ybot;
558 <        register int  c;
558 >        int  c;
559                                          /* average input scanlines */
560 <        while (nextrow < r+orad && nextrow < nrows) {
561 <                ybot = (long)nextrow*yres/nrows;
560 >        while (nextrow <= r+orad && nextrow < nrows) {
561 >                ybot = (nextrow+.5)*yres/nrows;
562                  for (c = 0; c < ncols; c++) {
563 <                        dobox(ctmp, (int)((long)c*xres/ncols),ybot, c,nextrow);
564 <                        greybar[nextrow%obarsize][c] = bright(ctmp);
563 >                        dobox(ctmp, (int)((c+.5)*xres/ncols),ybot, c,nextrow);
564 >                        greybar[nextrow%obarsize][c] = (*ourbright)(ctmp);
565                  }
566                                          /* and zero output scanline */
567 <                bzero((char *)scoutbar[nextrow%obarsize], ncols*sizeof(COLOR));
567 >                memset((char *)scoutbar[nextrow%obarsize], '\0', ncols*sizeof(COLOR));
568                  nextrow++;
569          }
570                                          /* point to top scanline for output */
# Line 518 | Line 575 | int  r;
575   }
576  
577  
578 < scan2flush()                    /* flush output buffer */
578 > static void
579 > scan2flush(void)                        /* flush output buffer */
580   {
581 <        register int  r;
581 >        int  r;
582  
583          for (r = nrows-orad; r < nrows; r++)
584                  if (fwritescan(scoutbar[r%obarsize], ncols, stdout) < 0)
585                          break;
586          if (fflush(stdout) < 0) {
587                  fprintf(stderr, "%s: write error at end of pass2\n", progname);
588 <                exit(1);
588 >                quit(1);
589          }
590   }
591  
592  
593 + void
594   quit(code)              /* remove temporary file and exit */
595   int  code;
596   {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines