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.2 by greg, Wed Oct 25 15:13:38 1995 UTC vs.
Revision 2.7 by schorsch, Thu Jun 5 19:29:34 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1995 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ LBL";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   *  Program to convert between RADIANCE RGBE and XYZE formats
6 + *  Added white-balance adjustment 10/01 (GW).
7   */
8  
9   #include  <stdio.h>
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
20 extern char  *malloc(), *strcpy();
21
18   int  rgbinp = -1;                       /* input is RGBE? */
19  
20   int  rgbout = 0;                        /* output should be RGBE? */
# Line 34 | Line 30 | int  doflat = -1;                      /* produce flat file? */
30   char  *progname;
31  
32  
33 + int
34   headline(s)                             /* process header line */
35   char    *s;
36   {
# Line 46 | Line 43 | char   *s;
43                          rgbinp = 0;
44                  else
45                          rgbinp = -2;
46 <                return;                 /* don't echo */
46 >                return(0);              /* don't echo */
47          }
48          if (isprims(s)) {               /* get input primaries */
49                  primsval(inprims, s);
50 <                return;                 /* don't echo */
50 >                return(0);              /* don't echo */
51          }
52                                          /* should I grok colcorr also? */
53 <        fputs(s, stdout);
53 >        return(fputs(s, stdout));
54   }
55  
56  
# Line 62 | Line 59 | int  argc;
59   char  *argv[];
60   {
61          int  i;
62 < #ifdef MSDOS
63 <        extern int  _fmode;
64 <        _fmode = O_BINARY;
68 <        setmode(fileno(stdin), O_BINARY);
69 <        setmode(fileno(stdout), O_BINARY);
70 < #endif
62 >        SET_DEFAULT_BINARY();
63 >        SET_FILE_BINARY(stdin);
64 >        SET_FILE_BINARY(stdout);
65          progname = argv[0];
66  
67          for (i = 1; i < argc; i++)
# Line 125 | Line 119 | char  *argv[];
119          if (rgbinp == -1)
120                  rgbinp = !rgbout;
121          printargs(argc, argv, stdout);          /* add to header */
128        if (expcomp < 0.99 || expcomp > 1.01)
129                fputexpos(expcomp, stdout);
122          convert();                              /* convert picture */
123          exit(0);
124   userr:
# Line 154 | Line 146 | convert()                              /* convert to XYZE or RGBE picture */
146          COLORMAT        xfm;
147          register COLOR  *scanin;
148          register COLR   *scanout;
149 +        double  ourexp = expcomp;
150          int     y;
151          register int    x;
152                                                  /* compute transform */
153          if (rgbout) {
161                double  mult;
154                  if (rgbinp) {                   /* RGBE -> RGBE */
155 <                        comprgb2rgbmat(xfm, inprims, outprims);
164 <                        mult = expcomp;
155 >                        comprgb2rgbWBmat(xfm, inprims, outprims);
156                  } else {                        /* XYZE -> RGBE */
157 <                        compxyz2rgbmat(xfm, outprims);
158 <                        mult = expcomp/WHTEFFICACY;
157 >                        compxyz2rgbWBmat(xfm, outprims);
158 >                        ourexp *= WHTEFFICACY;
159                  }
169                for (y = 0; y < 3; y++)
170                        for (x = 0; x < 3; x++)
171                                xfm[y][x] *= mult;
160          } else {
161                  if (rgbinp) {                   /* RGBE -> XYZE */
162 <                        comprgb2xyzmat(xfm, inprims);
163 <                        for (y = 0; y < 3; y++)
176 <                                for (x = 0; x < 3; x++)
177 <                                        xfm[y][x] *= WHTEFFICACY*expcomp;
162 >                        comprgb2xyzWBmat(xfm, inprims);
163 >                        ourexp /= WHTEFFICACY;
164                  } else {                        /* XYZE -> XYZE */
165                          for (y = 0; y < 3; y++)
166                                  for (x = 0; x < 3; x++)
167 <                                        xfm[y][x] = x==y ? expcomp : 0.;
167 >                                        xfm[y][x] = x==y ? 1. : 0.;
168                  }
169          }
170 +        for (y = 0; y < 3; y++)
171 +                for (x = 0; x < 3; x++)
172 +                        xfm[y][x] *= expcomp;
173                                                  /* get input resolution */
174          if ((order = fgetresolu(&xmax, &ymax, stdin)) < 0)
175                  quiterr("bad picture format");
176                                                  /* complete output header */
177 +        if (ourexp < 0.99 || ourexp > 1.01)
178 +                fputexpos(ourexp, stdout);
179          if (rgbout) {
180                  fputprims(outprims, stdout);
181                  fputformat(COLRFMT, stdout);
# Line 201 | Line 192 | convert()                              /* convert to XYZE or RGBE picture */
192          for (y = 0; y < ymax; y++) {
193                  if (freadscan(scanin, xmax, stdin) < 0)
194                          quiterr("error reading input picture");
195 <                for (x = 0; x < xmax; x++)
195 >                for (x = 0; x < xmax; x++) {
196                          colortrans(scanin[x], xfm, scanin[x]);
197 +                        if (rgbout)
198 +                                clipgamut(scanin[x], bright(scanin[x]),
199 +                                                CGAMUT_LOWER, cblack, cwhite);
200 +                }
201                  if (scanout != NULL) {
202                          for (x = 0; x < xmax; x++)
203                                  setcolr(scanout[x], colval(scanin[x],RED),
# Line 215 | Line 210 | convert()                              /* convert to XYZE or RGBE picture */
210                          quiterr("error writing output picture");
211          }
212                                                  /* free scanline */
213 <        free((char *)scanin);
213 >        free((void *)scanin);
214          if (scanout != NULL)
215 <                free((char *)scanout);
215 >                free((void *)scanout);
216   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines