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.36 by greg, Fri Dec 8 17:56:26 2023 UTC vs.
Revision 2.41 by greg, Sat Jun 7 05:09:46 2025 UTC

# Line 13 | Line 13 | static const char RCSid[] = "$Id$";
13   #include  <signal.h>
14   #include  "pfilt.h"
15   #include  "platform.h"
16 #include  "paths.h"
16   #include  "view.h"
17  
18   #define  FEQ(a,b)       ((a) >= .98*(b) && (a) <= 1.02*(b))
# Line 76 | Line 75 | 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 <
80 < static gethfunc headline;
82 < static void copyfile(FILE  *in, FILE  *out);
83 < static void pass1(FILE  *in);
84 < static void pass2(FILE  *in);
78 > static void copyfile(FILE  *infp, FILE  *out);
79 > static void pass1(FILE  *infp);
80 > static void pass2(FILE  *infp);
81   static void scan2init(void);
82   static void scan2sync(int  r);
83   static void scan2flush(void);
84  
85  
86 + static double
87 + rgb_bright(
88 +        SCOLOR  clr
89 + )
90 + {
91 +        return(bright(clr));
92 + }
93 +
94 +
95 + static double
96 + xyz_bright(
97 +        SCOLOR  clr
98 + )
99 + {
100 +        return(colval(clr,CIEY));
101 + }
102 +
103 +
104 + static double
105 + spec_bright(
106 +        SCOLOR  clr
107 + )
108 + {
109 +        return(pbright(clr));
110 + }
111 +
112 +
113 + brightfunc_t    *ourbright = rgb_bright;
114 +
115 +
116 + static int
117 + headline(                               /* process line from header */
118 +        char    *s,
119 +        void    *p
120 + )
121 + {
122 +        char  fmt[MAXFMTLEN];
123 +
124 +        fputs(s, stdout);               /* copy to output */
125 +        if (isaspect(s))                /* get aspect ratio */
126 +                inpaspect *= aspectval(s);
127 +        else if (isexpos(s))            /* get exposure */
128 +                hotlvl *= exposval(s);
129 +        else if (isncomp(s))            /* get #components (spectral) */
130 +                NCSAMP = ncompval(s);
131 +        else if (iswlsplit(s))          /* get wavelength partitions */
132 +                wlsplitval(WLPART, s);
133 +        else if (formatval(fmt, s)) {   /* get format */
134 +                wrongformat = 0;
135 +                if (!strcmp(COLRFMT, fmt))
136 +                        ourbright = rgb_bright;
137 +                else if (!strcmp(CIEFMT, fmt))
138 +                        ourbright = xyz_bright;
139 +                else if (!strcmp(SPECFMT, fmt))
140 +                        ourbright = spec_bright;
141 +                else
142 +                        wrongformat = !globmatch(PICFMT, fmt);
143 +        } else if (isview(s) && sscanview(&ourview, s) > 0)
144 +                gotview++;
145 +        return(0);
146 + }
147 +
148 +
149   int
150   main(
151          int  argc,
# Line 100 | Line 159 | main(
159          double  outaspect = 0.0;
160          double  d;
161          int  i, j;
162 +
163 +        fixargv0(argv[0]);              /* sets global progname */
164          SET_DEFAULT_BINARY();
165          SET_FILE_BINARY(stdin);
166          SET_FILE_BINARY(stdout);
# Line 117 | Line 178 | main(
178          signal(SIGXCPU, quit);
179          signal(SIGXFSZ, quit);
180   #endif
120
121        progname = argv[0] = fixargv0(argv[0]);
122
181          for (i = 1; i < argc; i++)
182                  if (argv[i][0] == '-')
183                          switch (argv[i][1]) {
# Line 154 | Line 212 | main(
212                                  if (d < 1e-20 || d > 1e20) {
213                                          fprintf(stderr,
214                                                  "%s: exposure out of range\n",
215 <                                                        argv[0]);
215 >                                                        progname);
216                                          quit(1);
217                                  }
218                                  switch (argv[i][2]) {
# Line 238 | Line 296 | main(
296                          fin = stdin;
297                  else {
298                          tfname = mktemp(template);
299 <                        if ((fin = fopen(tfname, "w+")) == NULL) {
299 >                        if ((fin = fopen(tfname, "w+b")) == NULL) {
300                                  fprintf(stderr, "%s: can't create ", progname);
301                                  fprintf(stderr, "temp file \"%s\"\n", tfname);
302                                  quit(1);
# Line 250 | Line 308 | main(
308                          }
309                  }
310          } else if (i == argc-1) {
311 <                if ((fin = fopen(argv[i], "r")) == NULL) {
311 >                if ((fin = fopen(argv[i], "rb")) == NULL) {
312                          fprintf(stderr, "%s: can't open file \"%s\"\n",
313                                                  progname, argv[i]);
314                          quit(1);
# Line 266 | Line 324 | main(
324                                  progname);
325                  quit(1);
326          }
327 <        if (NCSAMP < 3) {
327 >        if ((ourbright == spec_bright) ^ (NCSAMP > 3) ||
328 >                        setspectrsamp(CNDX, WLPART) < 0) {
329                  fprintf(stderr, "%s: bad number of components\n", progname);
330                  quit(1);
331          }
# Line 318 | Line 377 | main(
377   }
378  
379  
321 static double
322 rgb_bright(
323        SCOLOR  clr
324 )
325 {
326        return(bright(clr));
327 }
328
329
330 static double
331 xyz_bright(
332        SCOLOR  clr
333 )
334 {
335        return(colval(clr,CIEY));
336 }
337
338
339 static double
340 spec_bright(
341        SCOLOR  clr
342 )
343 {
344        return(pbright(clr));
345 }
346
347
348 brightfunc_t *ourbright = rgb_bright;
349
350 static int
351 headline(                               /* process line from header */
352        char    *s,
353        void    *p
354 )
355 {
356        char  fmt[MAXFMTLEN];
357
358        fputs(s, stdout);               /* copy to output */
359        if (isaspect(s))                /* get aspect ratio */
360                inpaspect *= aspectval(s);
361        else if (isexpos(s))            /* get exposure */
362                hotlvl *= exposval(s);
363        else if (isncomp(s))            /* get #components (spectral) */
364                NCSAMP = ncompval(s);
365        else if (iswlsplit(s))          /* get wavelength partitions */
366                wlsplitval(WLPART, s);
367        else if (formatval(fmt, s)) {   /* get format */
368                wrongformat = 0;
369                if (!strcmp(COLRFMT, fmt))
370                        ourbright = rgb_bright;
371                else if (!strcmp(CIEFMT, fmt))
372                        ourbright = xyz_bright;
373                else if (!strcmp(SPECFMT, fmt))
374                        ourbright = spec_bright;
375                else
376                        wrongformat = !globmatch(PICFMT, fmt);
377        } else if (isview(s) && sscanview(&ourview, s) > 0)
378                gotview++;
379        return(0);
380 }
381
382
380   static void
381   copyfile(                       /* copy a file */
382 <        FILE  *in,
382 >        FILE  *infp,
383          FILE  *out
384   )
385   {
386          int  c;
387  
388 <        while ((c = getc(in)) != EOF)
388 >        while ((c = getc(infp)) != EOF)
389                  putc(c, out);
390  
391          if (ferror(out)) {
# Line 400 | Line 397 | copyfile(                      /* copy a file */
397  
398   static void
399   pass1(                          /* first pass of picture file */
400 <        FILE  *in
400 >        FILE  *infp
401   )
402   {
403          int  i;
# Line 414 | Line 411 | pass1(                         /* first pass of picture file */
411                  quit(1);
412          }
413          for (i = 0; i < yres; i++) {
414 <                if (freadsscan(scan, NCSAMP, xres, in) < 0) {
414 >                if (freadsscan(scan, NCSAMP, xres, infp) < 0) {
415                          nrows = (long)nrows * i / yres; /* adjust frame */
416                          if (nrows <= 0) {
417                                  fprintf(stderr, "%s: empty frame\n", progname);
# Line 435 | Line 432 | pass1(                         /* first pass of picture file */
432  
433   static void
434   pass2(                  /* last pass on file, write to stdout */
435 <        FILE  *in
435 >        FILE  *infp
436   )
437   {
438          int  yread;
# Line 450 | Line 447 | pass2(                 /* last pass on file, write to stdout */
447                  while (yread <= ycent+yrad) {
448                          if (yread < yres) {
449                                  if (freadsscan(scanin[yread%barsize],
450 <                                                NCSAMP, xres, in) < 0) {
450 >                                                NCSAMP, xres, infp) < 0) {
451                                          fprintf(stderr,
452                                                  "%s: truncated input (y=%d)\n",
453                                                  progname, yres-1-yread);
# Line 460 | Line 457 | pass2(                 /* last pass on file, write to stdout */
457                          }
458                          yread++;
459                  }
460 <                if (obarsize > 0)
460 >                if (obarsize > 0)       /* => thresh > FTINY */
461                          scan2sync(r);
462                  for (c = 0; c < ncols; c++) {
463                          xcent = (c+.5)*xres/ncols;
# Line 478 | Line 475 | pass2(                 /* last pass on file, write to stdout */
475          }
476                                          /* skip leftover input */
477          while (yread < yres) {
478 <                if (freadsscan(scanin[0], NCSAMP, xres, in) < 0)
478 >                if (freadscolrs((uby8 *)tempbuffer(xres*(NCSAMP+1)),
479 >                                        NCSAMP, xres, infp) < 0)
480                          break;
481                  yread++;
482          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines