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.39 by greg, Fri Dec 15 01:57:45 2023 UTC

# Line 78 | Line 78 | 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);
81 > static void copyfile(FILE  *infp, FILE  *out);
82 > static void pass1(FILE  *infp);
83 > static void pass2(FILE  *infp);
84   static void scan2init(void);
85   static void scan2sync(int  r);
86   static void scan2flush(void);
87  
88  
89 + static double
90 + rgb_bright(
91 +        SCOLOR  clr
92 + )
93 + {
94 +        return(bright(clr));
95 + }
96 +
97 +
98 + static double
99 + xyz_bright(
100 +        SCOLOR  clr
101 + )
102 + {
103 +        return(colval(clr,CIEY));
104 + }
105 +
106 +
107 + static double
108 + spec_bright(
109 +        SCOLOR  clr
110 + )
111 + {
112 +        return(pbright(clr));
113 + }
114 +
115 +
116 + brightfunc_t    *ourbright = rgb_bright;
117 +
118 +
119 + static int
120 + headline(                               /* process line from header */
121 +        char    *s,
122 +        void    *p
123 + )
124 + {
125 +        char  fmt[MAXFMTLEN];
126 +
127 +        fputs(s, stdout);               /* copy to output */
128 +        if (isaspect(s))                /* get aspect ratio */
129 +                inpaspect *= aspectval(s);
130 +        else if (isexpos(s))            /* get exposure */
131 +                hotlvl *= exposval(s);
132 +        else if (isncomp(s))            /* get #components (spectral) */
133 +                NCSAMP = ncompval(s);
134 +        else if (iswlsplit(s))          /* get wavelength partitions */
135 +                wlsplitval(WLPART, s);
136 +        else if (formatval(fmt, s)) {   /* get format */
137 +                wrongformat = 0;
138 +                if (!strcmp(COLRFMT, fmt))
139 +                        ourbright = rgb_bright;
140 +                else if (!strcmp(CIEFMT, fmt))
141 +                        ourbright = xyz_bright;
142 +                else if (!strcmp(SPECFMT, fmt))
143 +                        ourbright = spec_bright;
144 +                else
145 +                        wrongformat = !globmatch(PICFMT, fmt);
146 +        } else if (isview(s) && sscanview(&ourview, s) > 0)
147 +                gotview++;
148 +        return(0);
149 + }
150 +
151 +
152   int
153   main(
154          int  argc,
# Line 238 | Line 300 | main(
300                          fin = stdin;
301                  else {
302                          tfname = mktemp(template);
303 <                        if ((fin = fopen(tfname, "w+")) == NULL) {
303 >                        if ((fin = fopen(tfname, "w+b")) == NULL) {
304                                  fprintf(stderr, "%s: can't create ", progname);
305                                  fprintf(stderr, "temp file \"%s\"\n", tfname);
306                                  quit(1);
# Line 250 | Line 312 | main(
312                          }
313                  }
314          } else if (i == argc-1) {
315 <                if ((fin = fopen(argv[i], "r")) == NULL) {
315 >                if ((fin = fopen(argv[i], "rb")) == NULL) {
316                          fprintf(stderr, "%s: can't open file \"%s\"\n",
317                                                  progname, argv[i]);
318                          quit(1);
# Line 266 | Line 328 | main(
328                                  progname);
329                  quit(1);
330          }
331 <        if (NCSAMP < 3) {
331 >        if ((ourbright == spec_bright) ^ (NCSAMP > 3) ||
332 >                        setspectrsamp(CNDX, WLPART) < 0) {
333                  fprintf(stderr, "%s: bad number of components\n", progname);
334                  quit(1);
335          }
# Line 318 | Line 381 | main(
381   }
382  
383  
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
384   static void
385   copyfile(                       /* copy a file */
386 <        FILE  *in,
386 >        FILE  *infp,
387          FILE  *out
388   )
389   {
390          int  c;
391  
392 <        while ((c = getc(in)) != EOF)
392 >        while ((c = getc(infp)) != EOF)
393                  putc(c, out);
394  
395          if (ferror(out)) {
# Line 400 | Line 401 | copyfile(                      /* copy a file */
401  
402   static void
403   pass1(                          /* first pass of picture file */
404 <        FILE  *in
404 >        FILE  *infp
405   )
406   {
407          int  i;
# Line 414 | Line 415 | pass1(                         /* first pass of picture file */
415                  quit(1);
416          }
417          for (i = 0; i < yres; i++) {
418 <                if (freadsscan(scan, NCSAMP, xres, in) < 0) {
418 >                if (freadsscan(scan, NCSAMP, xres, infp) < 0) {
419                          nrows = (long)nrows * i / yres; /* adjust frame */
420                          if (nrows <= 0) {
421                                  fprintf(stderr, "%s: empty frame\n", progname);
# Line 435 | Line 436 | pass1(                         /* first pass of picture file */
436  
437   static void
438   pass2(                  /* last pass on file, write to stdout */
439 <        FILE  *in
439 >        FILE  *infp
440   )
441   {
442          int  yread;
# Line 450 | Line 451 | pass2(                 /* last pass on file, write to stdout */
451                  while (yread <= ycent+yrad) {
452                          if (yread < yres) {
453                                  if (freadsscan(scanin[yread%barsize],
454 <                                                NCSAMP, xres, in) < 0) {
454 >                                                NCSAMP, xres, infp) < 0) {
455                                          fprintf(stderr,
456                                                  "%s: truncated input (y=%d)\n",
457                                                  progname, yres-1-yread);
# Line 460 | Line 461 | pass2(                 /* last pass on file, write to stdout */
461                          }
462                          yread++;
463                  }
464 <                if (obarsize > 0)
464 >                if (obarsize > 0)       /* => thresh > FTINY */
465                          scan2sync(r);
466                  for (c = 0; c < ncols; c++) {
467                          xcent = (c+.5)*xres/ncols;
# Line 478 | Line 479 | pass2(                 /* last pass on file, write to stdout */
479          }
480                                          /* skip leftover input */
481          while (yread < yres) {
482 <                if (freadsscan(scanin[0], NCSAMP, xres, in) < 0)
482 >                if (freadscolrs((uby8 *)tempbuffer(xres*(NCSAMP+1)),
483 >                                        NCSAMP, xres, infp) < 0)
484                          break;
485                  yread++;
486          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines