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

Comparing ray/src/cv/mgflib/context.c (file contents):
Revision 1.22 by greg, Wed May 10 17:46:09 1995 UTC vs.
Revision 1.26 by gregl, Mon Dec 15 09:41:37 1997 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1994 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 10 | Line 10 | static char SCCSid[] = "$SunId$ LBL";
10  
11   #include <stdio.h>
12   #include <math.h>
13 + #include <stdlib.h>
14   #include <string.h>
15   #include "parser.h"
16   #include "lookup.h"
# Line 37 | Line 38 | static LUTAB   mat_tab = LU_SINIT(free,free);  /* materia
38   static LUTAB    vtx_tab = LU_SINIT(free,free);  /* vertex lookup table */
39  
40                                  /* CIE 1931 Standard Observer curves */
41 < static C_COLOR  cie_xf = { 1, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
41 > static C_COLOR  cie_xf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
42                          {14,42,143,435,1344,2839,3483,3362,2908,1954,956,
43                          320,49,93,633,1655,2904,4334,5945,7621,9163,10263,
44                          10622,10026,8544,6424,4479,2835,1649,874,468,227,
45                          114,58,29,14,7,3,2,1,0}, 106836L, .467, .368, 362.230
46                          };
47 < static C_COLOR  cie_yf = { 1, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
47 > static C_COLOR  cie_yf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
48                          {0,1,4,12,40,116,230,380,600,910,1390,2080,3230,
49                          5030,7100,8620,9540,9950,9950,9520,8700,7570,6310,
50                          5030,3810,2650,1750,1070,610,320,170,82,41,21,10,
51                          5,2,1,1,0,0}, 106856L, .398, .542, 493.525
52                          };
53 < static C_COLOR  cie_zf = { 1, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
53 > static C_COLOR  cie_zf = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY|C_CSEFF,
54                          {65,201,679,2074,6456,13856,17471,17721,16692,
55                          12876,8130,4652,2720,1582,782,422,203,87,39,21,17,
56                          11,8,3,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
57                          106770L, .147, .077, 54.363
58                          };
59                                  /* Derived CIE 1931 Primaries (imaginary) */
60 < static C_COLOR  cie_xp = { 1, C_CDSPEC|C_CSSPEC|C_CSXY,
60 > static C_COLOR  cie_xp = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY,
61                          {-174,-198,-195,-197,-202,-213,-235,-272,-333,
62                          -444,-688,-1232,-2393,-4497,-6876,-6758,-5256,
63                          -3100,-815,1320,3200,4782,5998,6861,7408,7754,
# Line 64 | Line 65 | static C_COLOR cie_xp = { 1, C_CDSPEC|C_CSSPEC|C_CSXY,
65                          8336,8336,8336,8336,8336,8336},
66                          127424L, 1., .0,
67                          };
68 < static C_COLOR  cie_yp = { 1, C_CDSPEC|C_CSSPEC|C_CSXY,
68 > static C_COLOR  cie_yp = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY,
69                          {-451,-431,-431,-430,-427,-417,-399,-366,-312,
70                          -204,57,691,2142,4990,8810,9871,9122,7321,5145,
71                          3023,1123,-473,-1704,-2572,-3127,-3474,-3704,
# Line 72 | Line 73 | static C_COLOR cie_yp = { 1, C_CDSPEC|C_CSSPEC|C_CSXY,
73                          -4066,-4066,-4066,-4066,-4066,-4066},
74                          -23035L, .0, 1.,
75                          };
76 < static C_COLOR  cie_zp = { 1, C_CDSPEC|C_CSSPEC|C_CSXY,
76 > static C_COLOR  cie_zp = { 1, NULL, C_CDSPEC|C_CSSPEC|C_CSXY,
77                          {4051,4054,4052,4053,4054,4056,4059,4064,4071,
78                          4074,4056,3967,3677,2933,1492,313,-440,-795,
79                          -904,-918,-898,-884,-869,-863,-855,-855,-851,
# Line 130 | Line 131 | register char  **av;
131                          c_ccname = lp->key;
132                          c_ccolor = (C_COLOR *)lp->data;
133                          c_ccolor->clock = 0;
134 +                        c_ccolor->client_data = NULL;
135                  }
136                  i = c_ccolor->clock;
137                  if (ac == 3) {          /* use default template */
# Line 177 | Line 179 | register char  **av;
179                  if (!isflt(av[1]))
180                          return(MG_ETYPE);
181                  wsum = atof(av[1]);
180                if (wsum < 0.)
181                        return(MG_EILL);
182                  if ((lp = lu_find(&clr_tab, av[2])) == NULL)
183                          return(MG_EMEM);
184                  if (lp->data == NULL)
# Line 188 | Line 188 | register char  **av;
188                          if (!isflt(av[i]))
189                                  return(MG_ETYPE);
190                          w = atof(av[i]);
191                        if (w < 0.)
192                                return(MG_EILL);
191                          if ((lp = lu_find(&clr_tab, av[i+1])) == NULL)
192                                  return(MG_EMEM);
193                          if (lp->data == NULL)
# Line 198 | Line 196 | register char  **av;
196                                          w, (C_COLOR *)lp->data);
197                          wsum += w;
198                  }
199 +                if (wsum <= 0.)
200 +                        return(MG_EILL);
201                  c_ccolor->clock++;
202                  return(MG_OK);
203          }
# Line 248 | Line 248 | register char  **av;
248                          c_cmname = lp->key;
249                          c_cmaterial = (C_MATERIAL *)lp->data;
250                          c_cmaterial->clock = 0;
251 +                        c_cmaterial->client_data = NULL;
252                  }
253                  i = c_cmaterial->clock;
254                  if (ac == 3) {          /* use default template */
# Line 394 | Line 395 | register char  **av;
395                                  return(MG_EMEM);
396                          c_cvname = lp->key;
397                          c_cvertex = (C_VERTEX *)lp->data;
398 +                        c_cvertex->clock = 0;
399 +                        c_cvertex->client_data = NULL;
400                  }
401                  i = c_cvertex->clock;
402                  if (ac == 3) {          /* use default template */
# Line 606 | Line 609 | char   **av;
609                  }
610                  if (n > 1)
611                          va[i] /= (double)n;
609                if (va[i] < 0.)
610                        return(MG_EILL);
612                  if (va[i] > scale)
613                          scale = va[i];
614 +                else if (va[i] < -scale)
615 +                        scale = -va[i];
616          }
617          if (scale <= FTINY)
618                  return(MG_EILL);
# Line 667 | Line 670 | double w1, w2;
670          } else {                                        /* CIE xy mixing */
671                  c_ccvt(c1, C_CSXY);
672                  c_ccvt(c2, C_CSXY);
673 <                scale = 1. / (w1/c1->cy + w2/c2->cy);
673 >                scale = w1/c1->cy + w2/c2->cy;
674 >                if (scale == 0.)
675 >                        return;
676 >                scale = 1. / scale;
677                  cres->cx = (c1->cx*w1/c1->cy + c2->cx*w2/c2->cy) * scale;
678                  cres->cy = (w1 + w2) * scale;
679                  cres->flags = C_CDXY|C_CSXY;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines