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.5 by greg, Tue Jan 28 16:31:16 1997 UTC vs.
Revision 3.8 by greg, Wed Feb 5 16:08:18 1997 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1996 Regents of the University of California */
1 > /* Copyright (c) 1997 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ LBL";
# Line 9 | Line 9 | static char SCCSid[] = "$SunId$ LBL";
9   */
10  
11   #include "pcond.h"
12 + #include "warp3d.h"
13  
14  
15   RGBPRIMP        inprims = stdprims;     /* input primaries */
# Line 19 | Line 20 | double (*lumf)() = rgblum;             /* input luminance functio
20   double  inpexp = 1.0;                   /* input exposure value */
21  
22   char    *mbcalfile = NULL;              /* macbethcal mapping file */
23 + char    *cwarpfile = NULL;              /* color space warping file */
24  
25   static struct mbc {
24        float   xa[3][6], ya[3][6];
26          COLORMAT        cmat;
27 +        float   xa[3][6], ya[3][6];
28 +        COLOR   cmin, cmax;
29   }       mbcond;                         /* macbethcal conditioning struct */
30  
31 + static WARP3D   *cwarp;                 /* color warping structure */
32 +
33   static COLOR    *scanbuf;               /* scanline processing buffer */
34   static int      nread;                  /* number of scanlines processed */
35  
# Line 60 | Line 65 | COLOR *
65   nextscan()                              /* read and condition next scanline */
66   {
67          if (nread >= numscans(&inpres)) {
68 +                if (cwarpfile != NULL)
69 +                        free3dw(cwarp);
70                  free((char *)scanbuf);
71                  return(scanbuf = NULL);
72          }
# Line 80 | Line 87 | nextscan()                             /* read and condition next scanline */
87                  mapscan(scanbuf, scanlen(&inpres));
88          if (mbcalfile != NULL)                  /* device color correction */
89                  mbscan(scanbuf, scanlen(&inpres), &mbcond);
90 +        else if (cwarpfile != NULL)             /* device color space warp */
91 +                cwscan(scanbuf, scanlen(&inpres), cwarp);
92          else if (lumf == cielum | inprims != outprims)
93                  matscan(scanbuf, scanlen(&inpres), mbcond.cmat);
94          nread++;
# Line 92 | Line 101 | firstscan()                            /* return first processed scanline */
101   {
102          if (mbcalfile != NULL)          /* load macbethcal file */
103                  getmbcalfile(mbcalfile, &mbcond);
104 <        else
104 >        else if (cwarpfile != NULL) {
105 >                if ((cwarp = load3dw(cwarpfile, NULL)) == NULL)
106 >                        syserror(cwarpfile);
107 >        } else
108                  if (lumf == rgblum)
109                          comprgb2rgbmat(mbcond.cmat, inprims, outprims);
110                  else
# Line 126 | Line 138 | COLORMAT       mat;
138   {
139          while (len--) {
140                  colortrans(sl[0], mat, sl[0]);
141 +                clipgamut(sl[0], bright(sl[0]), CGAMUT, cblack, cwhite);
142                  sl++;
143          }
144   }
# Line 140 | Line 153 | register struct mbc    *mb;
153          register int    i, j;
154  
155          while (len--) {
156 +                colortrans(sl[0], mb->cmat, sl[0]);
157 +                clipgamut(sl[0], bright(sl[0]), CGAMUT, mb->cmin, mb->cmax);
158                  for (i = 0; i < 3; i++) {
159                          d = colval(sl[0],i);
160                          for (j = 0; j < 4 && mb->xa[i][j+1] <= d; j++)
# Line 148 | Line 163 | register struct mbc    *mb;
163                                          (d - mb->xa[i][j])*mb->ya[i][j+1] ) /
164                                          (mb->xa[i][j+1] - mb->xa[i][j]);
165                  }
151                colortrans(sl[0], mb->cmat, sl[0]);
166                  sl++;
167          }
168   }
169  
170  
171 + cwscan(sl, len, wp)                     /* apply color space warp to scaline */
172 + COLOR   *sl;
173 + int     len;
174 + WARP3D  *wp;
175 + {
176 +        int     rval;
177 +
178 +        while (len--) {
179 +                rval = warp3d(sl[0], sl[0], wp);
180 +                if (rval & W3ERROR)
181 +                        syserror("warp3d");
182 +                if (rval & W3BADMAP) {
183 +                        fprintf(stderr, "%s: %s: bad color space map\n",
184 +                                        progname, cwarpfile);
185 +                        exit(1);
186 +                }
187 +                clipgamut(sl[0], bright(sl[0]), CGAMUT, cblack, cwhite);
188 +                sl++;
189 +        }
190 + }
191 +
192 +
193   getmbcalfile(fn, mb)                    /* load macbethcal file */
194   char    *fn;
195   register struct mbc     *mb;
# Line 162 | Line 198 | register struct mbc    *mb;
198          char    buf[128];
199          FILE    *fp;
200          int     inpflags = 0;
201 +        register int    i;
202  
203          if ((fp = fopen(fn, "r")) == NULL)
204                  syserror(fn);
# Line 216 | Line 253 | register struct mbc    *mb;
253                          inpflags |= 040;
254                  else if (!(inpflags & 0100) &&
255                                  sscanf(buf,
256 <                                "ro = %f*rn + %f*gn + %f*bn",
256 >                                "r = %f*r1 + %f*g1 + %f*b1",
257                                  &mb->cmat[0][0], &mb->cmat[0][1],
258                                  &mb->cmat[0][2]) == 3)
259                          inpflags |= 0100;
260                  else if (!(inpflags & 0200) &&
261                                  sscanf(buf,
262 <                                "go = %f*rn + %f*gn + %f*bn",
262 >                                "g = %f*r1 + %f*g1 + %f*b1",
263                                  &mb->cmat[1][0], &mb->cmat[1][1],
264                                  &mb->cmat[1][2]) == 3)
265                          inpflags |= 0200;
266                  else if (!(inpflags & 0400) &&
267                                  sscanf(buf,
268 <                                "bo = %f*rn + %f*gn + %f*bn",
268 >                                "b = %f*r1 + %f*g1 + %f*b1",
269                                  &mb->cmat[2][0], &mb->cmat[2][1],
270                                  &mb->cmat[2][2]) == 3)
271                          inpflags |= 0400;
# Line 240 | Line 277 | register struct mbc    *mb;
277                  exit(1);
278          }
279          fclose(fp);
280 +                                        /* compute gamut */
281 +        for (i = 0; i < 3; i++) {
282 +                colval(mb->cmin,i) = mb->xa[i][0] -
283 +                                mb->ya[i][0] *
284 +                                (mb->xa[i][1]-mb->xa[i][0]) /
285 +                                (mb->ya[i][1]-mb->ya[i][0]);
286 +                colval(mb->cmax,i) = mb->xa[i][4] +
287 +                                (1.-mb->ya[i][4]) *
288 +                                (mb->xa[i][5] - mb->xa[i][4]) /
289 +                                (mb->ya[i][5] - mb->ya[i][4]);
290 +        }
291   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines