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

Comparing ray/src/px/ra_xyze.c (file contents):
Revision 2.6 by greg, Sat Feb 22 02:07:28 2003 UTC vs.
Revision 2.13 by greg, Sat Dec 28 18:05:14 2019 UTC

# Line 6 | Line 6 | static const char      RCSid[] = "$Id$";
6   *  Added white-balance adjustment 10/01 (GW).
7   */
8  
9 #include  <stdio.h>
10 #include  <string.h>
9   #include  <math.h>
10 < #include  <time.h>
10 >
11 > #include  "platform.h"
12   #include  "color.h"
13   #include  "resolu.h"
14 + #include  "rtio.h"
15  
16 #ifdef MSDOS
17 #include  <fcntl.h>
18 #endif
19
16   int  rgbinp = -1;                       /* input is RGBE? */
21
17   int  rgbout = 0;                        /* output should be RGBE? */
23
18   RGBPRIMS  inprims = STDPRIMS;           /* input primaries */
25
19   RGBPRIMS  outprims = STDPRIMS;          /* output primaries */
27
20   double  expcomp = 1.0;                  /* exposure compensation */
29
21   int  doflat = -1;                       /* produce flat file? */
22 <
22 > double  origexp = -1.0;                 /* original exposure */
23   char  *progname;
24  
25 + static gethfunc headline;
26 + static void quiterr(char *err);
27 + static void convert(void);
28  
29 < int
30 < headline(s)                             /* process header line */
31 < char    *s;
29 >
30 >
31 > static int
32 > headline(                               /* process header line */
33 >        char    *s,
34 >        void    *p
35 > )
36   {
37 <        char    fmt[32];
37 >        char    fmt[MAXFMTLEN];
38  
39          if (formatval(fmt, s)) {        /* check if format string */
40                  if (!strcmp(fmt,COLRFMT))
# Line 47 | Line 45 | char   *s;
45                          rgbinp = -2;
46                  return(0);              /* don't echo */
47          }
48 +        if (origexp > 0.0 && isexpos(s)) {
49 +                origexp *= exposval(s);
50 +                return(0);              /* don't echo */
51 +        }
52          if (isprims(s)) {               /* get input primaries */
53                  primsval(inprims, s);
54                  return(0);              /* don't echo */
# Line 56 | Line 58 | char   *s;
58   }
59  
60  
61 < main(argc, argv)
62 < int  argc;
61 < char  *argv[];
61 > int
62 > main(int  argc, char  *argv[])
63   {
64          int  i;
65 < #ifdef MSDOS
66 <        extern int  _fmode;
67 <        _fmode = O_BINARY;
67 <        setmode(fileno(stdin), O_BINARY);
68 <        setmode(fileno(stdout), O_BINARY);
69 < #endif
65 >        SET_DEFAULT_BINARY();
66 >        SET_FILE_BINARY(stdin);
67 >        SET_FILE_BINARY(stdout);
68          progname = argv[0];
69  
70          for (i = 1; i < argc; i++)
# Line 93 | Line 91 | char  *argv[];
91                                  outprims[WHT][CIEX] = atof(argv[++i]);
92                                  outprims[WHT][CIEY] = atof(argv[++i]);
93                                  break;
94 +                        case 'o':               /* original exposure */
95 +                                origexp = 1.0;
96 +                                break;
97                          case 'e':               /* exposure compensation */
98                                  expcomp = atof(argv[++i]);
99                                  if (argv[i][0] == '+' || argv[i][0] == '-')
# Line 127 | Line 128 | char  *argv[];
128          convert();                              /* convert picture */
129          exit(0);
130   userr:
131 <        fprintf(stderr, "Usage: %s [-r][-e exp][-c|-u]", progname);
131 >        fprintf(stderr, "Usage: %s [-r][-o][-e exp][-c|-u]", progname);
132          fprintf(stderr, "[-p rx ry gx gy bx by wx wy] [input [output]]\n");
133          exit(1);
134   }
135  
136  
137 < quiterr(err)            /* print message and exit */
138 < char  *err;
137 > static void
138 > quiterr(                /* print message and exit */
139 >        char  *err
140 > )
141   {
142          if (err != NULL) {
143                  fprintf(stderr, "%s: %s\n", progname, err);
# Line 144 | Line 147 | char  *err;
147   }
148  
149  
150 < convert()                               /* convert to XYZE or RGBE picture */
150 > static void
151 > convert(void)                           /* convert to XYZE or RGBE picture */
152   {
153          int     order;
154          int     xmax, ymax;
155          COLORMAT        xfm;
156          register COLOR  *scanin;
157          register COLR   *scanout;
158 <        double  ourexp = expcomp;
158 >        double  exp2do = expcomp;
159 >        double  exp2report = expcomp;
160          int     y;
161          register int    x;
162 +                                                /* recover original? */
163 +        if (origexp > 0.0)
164 +                exp2do /= origexp;
165                                                  /* compute transform */
166          if (rgbout) {
167                  if (rgbinp) {                   /* RGBE -> RGBE */
168                          comprgb2rgbWBmat(xfm, inprims, outprims);
169                  } else {                        /* XYZE -> RGBE */
170                          compxyz2rgbWBmat(xfm, outprims);
171 <                        ourexp *= WHTEFFICACY;
171 >                        if (origexp > 0.0)
172 >                                exp2do /= WHTEFFICACY;
173 >                        else
174 >                                exp2report *= WHTEFFICACY;
175                  }
176          } else {
177                  if (rgbinp) {                   /* RGBE -> XYZE */
178                          comprgb2xyzWBmat(xfm, inprims);
179 <                        ourexp /= WHTEFFICACY;
179 >                        if (origexp > 0.0)
180 >                                exp2do *= WHTEFFICACY;
181 >                        else
182 >                                exp2report /= WHTEFFICACY;
183                  } else {                        /* XYZE -> XYZE */
184                          for (y = 0; y < 3; y++)
185                                  for (x = 0; x < 3; x++)
# Line 174 | Line 188 | convert()                              /* convert to XYZE or RGBE picture */
188          }
189          for (y = 0; y < 3; y++)
190                  for (x = 0; x < 3; x++)
191 <                        xfm[y][x] *= expcomp;
191 >                        xfm[y][x] *= exp2do;
192                                                  /* get input resolution */
193          if ((order = fgetresolu(&xmax, &ymax, stdin)) < 0)
194                  quiterr("bad picture format");
195                                                  /* complete output header */
196 <        if (ourexp < 0.99 || ourexp > 1.01)
197 <                fputexpos(ourexp, stdout);
196 >        if ((exp2report < 0.99) | (exp2report > 1.01))
197 >                fputexpos(exp2report, stdout);
198          if (rgbout) {
199                  fputprims(outprims, stdout);
200                  fputformat(COLRFMT, stdout);
# Line 208 | Line 222 | convert()                              /* convert to XYZE or RGBE picture */
222                                  setcolr(scanout[x], colval(scanin[x],RED),
223                                                  colval(scanin[x],GRN),
224                                                  colval(scanin[x],BLU));
225 <                        fwrite((char *)scanout, sizeof(COLR), xmax, stdout);
225 >                        putbinary((char *)scanout, sizeof(COLR), xmax, stdout);
226                  } else
227                          fwritescan(scanin, xmax, stdout);
228                  if (ferror(stdout))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines