ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/pextrem.c
(Generate patch)

Comparing ray/src/px/pextrem.c (file contents):
Revision 2.5 by greg, Sat Feb 22 02:07:27 2003 UTC vs.
Revision 2.16 by greg, Fri Sep 20 17:39:12 2024 UTC

# Line 2 | Line 2
2   static const char       RCSid[] = "$Id$";
3   #endif
4   /*
5 < * Find extrema points in a Radiance picture.
5 > * Find extrema points in a Radiance picture (RGBE, XYZE, or HyperSpectral)
6   */
7  
8 #include  <stdio.h>
8   #include  <math.h>
9 < #ifdef MSDOS
10 < #include  <fcntl.h>
11 < #endif
9 >
10 > #include  "rtio.h"
11 > #include  "platform.h"
12   #include  "color.h"
13 + #include  "resolu.h"
14  
15  
16   int  orig = 0;
17  
18 int  wrongformat = 0;
19
18   COLOR  expos = WHTCOLOR;
19  
20 + char    fmt[MAXFMTLEN];
21  
22 < headline(s)                     /* check header line */
23 < char  *s;
22 > static gethfunc headline;
23 >
24 >
25 > static int
26 > headline(                       /* check header line */
27 >        char  *s,
28 >        void    *p
29 > )
30   {
26        char    fmt[32];
31          double  d;
32          COLOR   ctmp;
33  
34 <        if (isformat(s)) {                      /* format */
35 <                formatval(fmt, s);
36 <                wrongformat = !globmatch(PICFMT, fmt);
34 >        if (formatval(fmt, s))                  /* format */
35 >                return(0);
36 >        if (iswlsplit(s)) {                     /* wavelength splits */
37 >                wlsplitval(WLPART, s);
38 >                return(0);
39          }
40 <        if (!orig)
40 >        if (isncomp(s)) {                       /* # spectral components */
41 >                NCSAMP = ncompval(s);
42                  return(0);
43 +        }
44 +        if (!orig)                              /* don't undo exposure? */
45 +                return(0);
46          if (isexpos(s)) {                       /* exposure */
47                  d = exposval(s);
48                  scalecolor(expos, d);
# Line 44 | Line 54 | char  *s;
54   }
55  
56  
57 < main(argc, argv)
58 < int  argc;
59 < char  *argv[];
57 > int
58 > main(
59 >        int  argc,
60 >        char  *argv[]
61 > )
62   {
63          int  i;
64          int  xres, yres;
65          int  y;
66 <        register int  x;
67 <        COLR  *scan;
68 <        COLR  cmin, cmax;
66 >        int  x;
67 >        COLRV  *scan;
68 >        SCOLR  cmin, cmax;
69 >        COLOR  tcol;
70          int  xmin, ymin, xmax, ymax;
71 < #ifdef MSDOS
72 <        extern int  _fmode;
73 <        _fmode = O_BINARY;
61 <        setmode(fileno(stdin), O_BINARY);
62 < #endif
71 >
72 >        SET_DEFAULT_BINARY();
73 >        SET_FILE_BINARY(stdin);
74          for (i = 1; i < argc; i++)      /* get options */
75                  if (!strcmp(argv[i], "-o"))
76 <                        orig++;
76 >                        orig = 1;
77 >                else if (!strcmp(argv[i], "-O"))
78 >                        orig = -1;
79                  else
80                          break;
81  
82          if (i == argc-1 && freopen(argv[i], "r", stdin) == NULL) {
83                  fprintf(stderr, "%s: can't open input \"%s\"\n",
84                                  argv[0], argv[i]);
85 <                exit(1);
85 >                return(1);
86          }
87                                          /* get our header */
88 <        if (getheader(stdin, headline, NULL) < 0 || wrongformat ||
88 >        if (getheader(stdin, headline, NULL) < 0 ||
89 >                        (!globmatch(PICFMT, fmt) && strcmp(fmt, SPECFMT)) ||
90                          fgetresolu(&xres, &yres, stdin) < 0) {
91                  fprintf(stderr, "%s: bad picture format\n", argv[0]);
92 <                exit(1);
92 >                return(1);
93          }
94 <        if ((scan = (COLR *)malloc(xres*sizeof(COLR))) == NULL) {
94 >        if (setspectrsamp(CNDX, WLPART) < 0) {
95 >                fprintf(stderr, "%s: bad wavelength split or component count",
96 >                                argv[0]);
97 >                return(1);
98 >        }
99 >        if (orig < 0 && !strcmp(CIEFMT, fmt))
100 >                scalecolor(expos, 1./WHTEFFICACY);
101 >        if ((scan = (COLRV *)malloc(xres*sizeof(COLRV)*(NCSAMP+1))) == NULL) {
102                  fprintf(stderr, "%s: out of memory\n", argv[0]);
103 <                exit(1);
103 >                return(1);
104          }
105 <        setcolr(cmin, 1e10, 1e10, 1e10);
106 <        setcolr(cmax, 0., 0., 0.);
105 >        setscolr(cmin, 1e30, 1e30, 1e30); xmin=ymin=0;
106 >        scolrblack(cmax); xmax=ymax=0;
107                                          /* find extrema */
108          for (y = yres-1; y >= 0; y--) {
109 <                if (freadcolrs(scan, xres, stdin) < 0) {
109 >                if (freadscolrs(scan, NCSAMP, xres, stdin) < 0) {
110                          fprintf(stderr, "%s: read error on input\n", argv[0]);
111 <                        exit(1);
111 >                        return(1);
112                  }
113                  for (x = xres; x-- > 0; ) {
114 <                        if (scan[x][EXP] > cmax[EXP] ||
115 <                                        (scan[x][EXP] == cmax[EXP] &&
116 <                                         normbright(scan[x]) >
117 <                                                normbright(cmax))) {
118 <                                copycolr(cmax, scan[x]);
114 >                        const COLRV *   sclr = scan + x*(NCSAMP+1);
115 >                        if (sclr[CNDX[EXP]] > cmax[CNDX[EXP]] ||
116 >                                        (sclr[CNDX[EXP]] == cmax[CNDX[EXP]] &&
117 >                                         normpbright(sclr) > normpbright(cmax))) {
118 >                                copyscolr(cmax, sclr);
119                                  xmax = x; ymax = y;
120                          }
121 <                        if (scan[x][EXP] < cmin[EXP] ||
122 <                                        (scan[x][EXP] == cmin[EXP] &&
123 <                                         normbright(scan[x]) <
124 <                                                normbright(cmin))) {
104 <                                copycolr(cmin, scan[x]);
121 >                        if (sclr[CNDX[EXP]] < cmin[CNDX[EXP]] ||
122 >                                (sclr[CNDX[EXP]] == cmin[CNDX[EXP]] &&
123 >                                         normpbright(sclr) < normpbright(cmin))) {
124 >                                copyscolr(cmin, sclr);
125                                  xmin = x; ymin = y;
126                          }
127                  }
128          }
129 <        free((void *)scan);
130 <        printf("%d %d\t%e %e %e\n", xmin, ymin,
131 <                        colrval(cmin,RED)/colval(expos,RED),
132 <                        colrval(cmin,GRN)/colval(expos,GRN),
133 <                        colrval(cmin,BLU)/colval(expos,BLU));
134 <        printf("%d %d\t%e %e %e\n", xmax, ymax,
135 <                        colrval(cmax,RED)/colval(expos,RED),
136 <                        colrval(cmax,GRN)/colval(expos,GRN),
137 <                        colrval(cmax,BLU)/colval(expos,BLU));
138 <        exit(0);
129 >        free(scan);
130 >        scolr_color(tcol, cmin);
131 >        printf("%d %d\t%.2e %.2e %.2e\n", xmin, ymin,
132 >                        colval(tcol,RED)/colval(expos,RED),
133 >                        colval(tcol,GRN)/colval(expos,GRN),
134 >                        colval(tcol,BLU)/colval(expos,BLU));
135 >        scolr_color(tcol, cmax);
136 >        printf("%d %d\t%.2e %.2e %.2e\n", xmax, ymax,
137 >                        colval(tcol,RED)/colval(expos,RED),
138 >                        colval(tcol,GRN)/colval(expos,GRN),
139 >                        colval(tcol,BLU)/colval(expos,BLU));
140 >        return(0);
141   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines