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.40 by greg, Tue Jun 3 21:31:51 2025 UTC

# Line 76 | Line 76 | float  **greybar;              /* grey-averaged input values */
76   int  obarsize = 0;              /* size of output scan bar */
77   int  orad = 0;                  /* output window radius */
78  
79 < char  *progname;
80 <
81 < static gethfunc headline;
82 < static void copyfile(FILE  *in, FILE  *out);
83 < static void pass1(FILE  *in);
84 < static void pass2(FILE  *in);
79 > static void copyfile(FILE  *infp, FILE  *out);
80 > static void pass1(FILE  *infp);
81 > static void pass2(FILE  *infp);
82   static void scan2init(void);
83   static void scan2sync(int  r);
84   static void scan2flush(void);
85  
86  
87 + static double
88 + rgb_bright(
89 +        SCOLOR  clr
90 + )
91 + {
92 +        return(bright(clr));
93 + }
94 +
95 +
96 + static double
97 + xyz_bright(
98 +        SCOLOR  clr
99 + )
100 + {
101 +        return(colval(clr,CIEY));
102 + }
103 +
104 +
105 + static double
106 + spec_bright(
107 +        SCOLOR  clr
108 + )
109 + {
110 +        return(pbright(clr));
111 + }
112 +
113 +
114 + brightfunc_t    *ourbright = rgb_bright;
115 +
116 +
117 + static int
118 + headline(                               /* process line from header */
119 +        char    *s,
120 +        void    *p
121 + )
122 + {
123 +        char  fmt[MAXFMTLEN];
124 +
125 +        fputs(s, stdout);               /* copy to output */
126 +        if (isaspect(s))                /* get aspect ratio */
127 +                inpaspect *= aspectval(s);
128 +        else if (isexpos(s))            /* get exposure */
129 +                hotlvl *= exposval(s);
130 +        else if (isncomp(s))            /* get #components (spectral) */
131 +                NCSAMP = ncompval(s);
132 +        else if (iswlsplit(s))          /* get wavelength partitions */
133 +                wlsplitval(WLPART, s);
134 +        else if (formatval(fmt, s)) {   /* get format */
135 +                wrongformat = 0;
136 +                if (!strcmp(COLRFMT, fmt))
137 +                        ourbright = rgb_bright;
138 +                else if (!strcmp(CIEFMT, fmt))
139 +                        ourbright = xyz_bright;
140 +                else if (!strcmp(SPECFMT, fmt))
141 +                        ourbright = spec_bright;
142 +                else
143 +                        wrongformat = !globmatch(PICFMT, fmt);
144 +        } else if (isview(s) && sscanview(&ourview, s) > 0)
145 +                gotview++;
146 +        return(0);
147 + }
148 +
149 +
150   int
151   main(
152          int  argc,
# Line 100 | Line 160 | main(
160          double  outaspect = 0.0;
161          double  d;
162          int  i, j;
163 +
164 +        fixargv0(argv[0]);              /* sets global progname */
165          SET_DEFAULT_BINARY();
166          SET_FILE_BINARY(stdin);
167          SET_FILE_BINARY(stdout);
# Line 117 | Line 179 | main(
179          signal(SIGXCPU, quit);
180          signal(SIGXFSZ, quit);
181   #endif
120
121        progname = argv[0] = fixargv0(argv[0]);
122
182          for (i = 1; i < argc; i++)
183                  if (argv[i][0] == '-')
184                          switch (argv[i][1]) {
# Line 154 | Line 213 | main(
213                                  if (d < 1e-20 || d > 1e20) {
214                                          fprintf(stderr,
215                                                  "%s: exposure out of range\n",
216 <                                                        argv[0]);
216 >                                                        progname);
217                                          quit(1);
218                                  }
219                                  switch (argv[i][2]) {
# Line 238 | Line 297 | main(
297                          fin = stdin;
298                  else {
299                          tfname = mktemp(template);
300 <                        if ((fin = fopen(tfname, "w+")) == NULL) {
300 >                        if ((fin = fopen(tfname, "w+b")) == NULL) {
301                                  fprintf(stderr, "%s: can't create ", progname);
302                                  fprintf(stderr, "temp file \"%s\"\n", tfname);
303                                  quit(1);
# Line 250 | Line 309 | main(
309                          }
310                  }
311          } else if (i == argc-1) {
312 <                if ((fin = fopen(argv[i], "r")) == NULL) {
312 >                if ((fin = fopen(argv[i], "rb")) == NULL) {
313                          fprintf(stderr, "%s: can't open file \"%s\"\n",
314                                                  progname, argv[i]);
315                          quit(1);
# Line 266 | Line 325 | main(
325                                  progname);
326                  quit(1);
327          }
328 <        if (NCSAMP < 3) {
328 >        if ((ourbright == spec_bright) ^ (NCSAMP > 3) ||
329 >                        setspectrsamp(CNDX, WLPART) < 0) {
330                  fprintf(stderr, "%s: bad number of components\n", progname);
331                  quit(1);
332          }
# Line 318 | Line 378 | main(
378   }
379  
380  
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
381   static void
382   copyfile(                       /* copy a file */
383 <        FILE  *in,
383 >        FILE  *infp,
384          FILE  *out
385   )
386   {
387          int  c;
388  
389 <        while ((c = getc(in)) != EOF)
389 >        while ((c = getc(infp)) != EOF)
390                  putc(c, out);
391  
392          if (ferror(out)) {
# Line 400 | Line 398 | copyfile(                      /* copy a file */
398  
399   static void
400   pass1(                          /* first pass of picture file */
401 <        FILE  *in
401 >        FILE  *infp
402   )
403   {
404          int  i;
# Line 414 | Line 412 | pass1(                         /* first pass of picture file */
412                  quit(1);
413          }
414          for (i = 0; i < yres; i++) {
415 <                if (freadsscan(scan, NCSAMP, xres, in) < 0) {
415 >                if (freadsscan(scan, NCSAMP, xres, infp) < 0) {
416                          nrows = (long)nrows * i / yres; /* adjust frame */
417                          if (nrows <= 0) {
418                                  fprintf(stderr, "%s: empty frame\n", progname);
# Line 435 | Line 433 | pass1(                         /* first pass of picture file */
433  
434   static void
435   pass2(                  /* last pass on file, write to stdout */
436 <        FILE  *in
436 >        FILE  *infp
437   )
438   {
439          int  yread;
# Line 450 | Line 448 | pass2(                 /* last pass on file, write to stdout */
448                  while (yread <= ycent+yrad) {
449                          if (yread < yres) {
450                                  if (freadsscan(scanin[yread%barsize],
451 <                                                NCSAMP, xres, in) < 0) {
451 >                                                NCSAMP, xres, infp) < 0) {
452                                          fprintf(stderr,
453                                                  "%s: truncated input (y=%d)\n",
454                                                  progname, yres-1-yread);
# Line 460 | Line 458 | pass2(                 /* last pass on file, write to stdout */
458                          }
459                          yread++;
460                  }
461 <                if (obarsize > 0)
461 >                if (obarsize > 0)       /* => thresh > FTINY */
462                          scan2sync(r);
463                  for (c = 0; c < ncols; c++) {
464                          xcent = (c+.5)*xres/ncols;
# Line 478 | Line 476 | pass2(                 /* last pass on file, write to stdout */
476          }
477                                          /* skip leftover input */
478          while (yread < yres) {
479 <                if (freadsscan(scanin[0], NCSAMP, xres, in) < 0)
479 >                if (freadscolrs((uby8 *)tempbuffer(xres*(NCSAMP+1)),
480 >                                        NCSAMP, xres, infp) < 0)
481                          break;
482                  yread++;
483          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines