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.10 by greg, Tue Aug 22 21:38:22 2006 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines