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

Comparing ray/src/px/pcond2.c (file contents):
Revision 3.3 by greg, Fri Oct 4 18:34:57 1996 UTC vs.
Revision 3.12 by schorsch, Sun Mar 28 20:33:14 2004 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1996 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   * Input and output conditioning routines for pcond.
6 + *  Added white-balance adjustment 10/01 (GW).
7   */
8  
9   #include "pcond.h"
10 + #include "warp3d.h"
11  
12  
13   RGBPRIMP        inprims = stdprims;     /* input primaries */
# Line 19 | Line 18 | double (*lumf)() = rgblum;             /* input luminance functio
18   double  inpexp = 1.0;                   /* input exposure value */
19  
20   char    *mbcalfile = NULL;              /* macbethcal mapping file */
21 + char    *cwarpfile = NULL;              /* color space warping file */
22  
23   static struct mbc {
24        float   xa[3][6], ya[3][6];
24          COLORMAT        cmat;
25 +        float   xa[3][6], ya[3][6];
26 +        COLOR   cmin, cmax;
27   }       mbcond;                         /* macbethcal conditioning struct */
28  
29 + static WARP3D   *cwarp;                 /* color warping structure */
30 +
31   static COLOR    *scanbuf;               /* scanline processing buffer */
32   static int      nread;                  /* number of scanlines processed */
33  
34 + static void sfscan(COLOR *sl, int len, double sf);
35 + static void matscan(COLOR *sl, int len, COLORMAT mat);
36 + static void mbscan(COLOR *sl, int len, struct mbc *mb);
37 + static void cwscan(COLOR *sl, int len, WARP3D *wp);
38 + static void getmbcalfile(char *fn, struct mbc *mb);
39  
40 < double
41 < rgblum(clr, scotopic)           /* compute (scotopic) luminance of RGB color */
42 < COLOR   clr;
43 < int     scotopic;
40 >
41 > extern double
42 > rgblum(         /* compute (scotopic) luminance of RGB color */
43 >        COLOR   clr,
44 >        int     scotopic
45 > )
46   {
47          if (scotopic)           /* approximate */
48                  return( WHTSEFFICACY * (colval(clr,RED)*.062 +
# Line 43 | Line 53 | int    scotopic;
53   }
54  
55  
56 < double
57 < cielum(xyz, scotopic)           /* compute (scotopic) luminance of CIE color */
58 < COLOR   xyz;
59 < int     scotopic;
56 > extern double
57 > cielum(         /* compute (scotopic) luminance of CIE color */
58 >        COLOR   xyz,
59 >        int     scotopic
60 > )
61   {
62          if (scotopic)           /* approximate */
63                  return(colval(xyz,CIEY) *
# Line 56 | Line 67 | int    scotopic;
67   }
68  
69  
70 < COLOR *
71 < nextscan()                              /* read and condition next scanline */
70 > extern COLOR *
71 > nextscan(void)                          /* read and condition next scanline */
72   {
73          if (nread >= numscans(&inpres)) {
74 < #ifdef DEBUG
75 <                fputs("done\n", stderr);
76 < #endif
77 <                return(NULL);
74 >                if (cwarpfile != NULL)
75 >                        free3dw(cwarp);
76 >                free((void *)scanbuf);
77 >                return(scanbuf = NULL);
78          }
79          if (what2do&DO_ACUITY)
80                  acuscan(scanbuf, nread);
# Line 82 | Line 93 | nextscan()                             /* read and condition next scanline */
93                  mapscan(scanbuf, scanlen(&inpres));
94          if (mbcalfile != NULL)                  /* device color correction */
95                  mbscan(scanbuf, scanlen(&inpres), &mbcond);
96 <        else if (lumf == cielum | inprims != outprims)
96 >        else if (cwarpfile != NULL)             /* device color space warp */
97 >                cwscan(scanbuf, scanlen(&inpres), cwarp);
98 >        else if ((lumf == cielum) | (inprims != outprims))
99                  matscan(scanbuf, scanlen(&inpres), mbcond.cmat);
100          nread++;
101          return(scanbuf);
102   }
103  
104  
105 < COLOR *
106 < firstscan()                             /* return first processed scanline */
105 > extern COLOR *
106 > firstscan(void)                         /* return first processed scanline */
107   {
108          if (mbcalfile != NULL)          /* load macbethcal file */
109                  getmbcalfile(mbcalfile, &mbcond);
110 <        else
110 >        else if (cwarpfile != NULL) {
111 >                if ((cwarp = load3dw(cwarpfile, NULL)) == NULL)
112 >                        syserror(cwarpfile);
113 >        } else
114                  if (lumf == rgblum)
115 <                        comprgb2rgbmat(mbcond.cmat, inprims, outprims);
115 >                        comprgb2rgbWBmat(mbcond.cmat, inprims, outprims);
116                  else
117 <                        compxyz2rgbmat(mbcond.cmat, outprims);
118 <        if (what2do&DO_ACUITY) {
103 < #ifdef DEBUG
104 <                fprintf(stderr, "%s: initializing acuity sampling...",
105 <                                progname);
106 < #endif
117 >                        compxyz2rgbWBmat(mbcond.cmat, outprims);
118 >        if (what2do&DO_ACUITY)
119                  initacuity();
108 #ifdef DEBUG
109                fprintf(stderr, "done\n");
110 #endif
111        }
120          scanbuf = (COLOR *)malloc(scanlen(&inpres)*sizeof(COLOR));
121          if (scanbuf == NULL)
122                  syserror("malloc");
123          nread = 0;
116 #ifdef DEBUG
117        fprintf(stderr, "%s: processing image...", progname);
118 #endif
124          return(nextscan());
125   }
126  
127  
128 < sfscan(sl, len, sf)                     /* apply scalefactor to scanline */
129 < register COLOR  *sl;
130 < int     len;
131 < double  sf;
128 > static void
129 > sfscan(                 /* apply scalefactor to scanline */
130 >        register COLOR  *sl,
131 >        int     len,
132 >        double  sf
133 > )
134   {
135          while (len--) {
136                  scalecolor(sl[0], sf);
# Line 132 | Line 139 | double sf;
139   }
140  
141  
142 < matscan(sl, len, mat)                   /* apply color matrix to scaline */
143 < register COLOR  *sl;
144 < int     len;
145 < COLORMAT        mat;
142 > static void
143 > matscan(                        /* apply color matrix to scaline */
144 >        register COLOR  *sl,
145 >        int     len,
146 >        COLORMAT        mat
147 > )
148   {
149          while (len--) {
150                  colortrans(sl[0], mat, sl[0]);
151 +                clipgamut(sl[0], bright(sl[0]), CGAMUT, cblack, cwhite);
152                  sl++;
153          }
154   }
155  
156  
157 < mbscan(sl, len, mb)                     /* apply macbethcal adj. to scaline */
158 < COLOR   *sl;
159 < int     len;
160 < register struct mbc     *mb;
157 > static void
158 > mbscan(                 /* apply macbethcal adj. to scaline */
159 >        COLOR   *sl,
160 >        int     len,
161 >        register struct mbc     *mb
162 > )
163   {
164          double  d;
165          register int    i, j;
166  
167          while (len--) {
168 +                colortrans(sl[0], mb->cmat, sl[0]);
169 +                clipgamut(sl[0], bright(sl[0]), CGAMUT, mb->cmin, mb->cmax);
170                  for (i = 0; i < 3; i++) {
171                          d = colval(sl[0],i);
172                          for (j = 0; j < 4 && mb->xa[i][j+1] <= d; j++)
# Line 161 | Line 175 | register struct mbc    *mb;
175                                          (d - mb->xa[i][j])*mb->ya[i][j+1] ) /
176                                          (mb->xa[i][j+1] - mb->xa[i][j]);
177                  }
164                colortrans(sl[0], mb->cmat, sl[0]);
178                  sl++;
179          }
180   }
181  
182  
183 < getmbcalfile(fn, mb)                    /* load macbethcal file */
184 < char    *fn;
185 < register struct mbc     *mb;
183 > static void
184 > cwscan(                 /* apply color space warp to scaline */
185 >        COLOR   *sl,
186 >        int     len,
187 >        WARP3D  *wp
188 > )
189   {
190 <        extern char     *fgets();
190 >        int     rval;
191 >
192 >        while (len--) {
193 >                rval = warp3d(sl[0], sl[0], wp);
194 >                if (rval & W3ERROR)
195 >                        syserror("warp3d");
196 >                if (rval & W3BADMAP) {
197 >                        fprintf(stderr, "%s: %s: bad color space map\n",
198 >                                        progname, cwarpfile);
199 >                        exit(1);
200 >                }
201 >                clipgamut(sl[0], bright(sl[0]), CGAMUT, cblack, cwhite);
202 >                sl++;
203 >        }
204 > }
205 >
206 >
207 > static void
208 > getmbcalfile(                   /* load macbethcal file */
209 >        char    *fn,
210 >        register struct mbc     *mb
211 > )
212 > {
213          char    buf[128];
214          FILE    *fp;
215          int     inpflags = 0;
216 +        register int    i;
217  
218          if ((fp = fopen(fn, "r")) == NULL)
219                  syserror(fn);
# Line 253 | Line 292 | register struct mbc    *mb;
292                  exit(1);
293          }
294          fclose(fp);
295 +                                        /* compute gamut */
296 +        for (i = 0; i < 3; i++) {
297 +                colval(mb->cmin,i) = mb->xa[i][0] -
298 +                                mb->ya[i][0] *
299 +                                (mb->xa[i][1]-mb->xa[i][0]) /
300 +                                (mb->ya[i][1]-mb->ya[i][0]);
301 +                colval(mb->cmax,i) = mb->xa[i][4] +
302 +                                (1.-mb->ya[i][4]) *
303 +                                (mb->xa[i][5] - mb->xa[i][4]) /
304 +                                (mb->ya[i][5] - mb->ya[i][4]);
305 +        }
306   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines