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

Comparing ray/src/common/lamps.c (file contents):
Revision 1.3 by greg, Fri Dec 14 13:12:28 1990 UTC vs.
Revision 2.9 by schorsch, Sun Jun 8 12:03:09 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1990 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   * Load lamp data.
6   */
7  
8 + #include "copyright.h"
9 +
10   #include  <stdio.h>
11 + #include  <stdlib.h>
12   #include  <ctype.h>
13  
14 < extern char     *eindex(), *expsave(), *malloc();
15 < extern FILE     *fropen();
14 > #include  "standard.h"
15 > #include  "color.h"
16  
17 + extern char     *eindex(), *expsave();
18 + extern FILE     *frlibopen();
19 +
20   typedef struct lamp {
21          char    *pattern;                       /* search pattern */
22          float   *color;                         /* pointer to lamp value */
# Line 24 | Line 27 | static LAMP    *lamps = NULL;          /* lamp list */
27  
28  
29   float *
30 < matchlamp(s)                            /* see if string matches any lamp */
31 < char    *s;
30 > matchlamp(                              /* see if string matches any lamp */
31 > char    *s
32 > )
33   {
34          register LAMP   *lp;
35  
# Line 38 | Line 42 | char   *s;
42   }
43  
44  
45 < loadlamps(file)                                 /* load lamp type file */
46 < char    *file;
45 > int
46 > loadlamps(                                      /* load lamp type file */
47 > char    *file
48 > )
49   {
50          LAMP    *lastp;
51          register LAMP   *lp;
# Line 48 | Line 54 | char   *file;
54          char    buf[128], str[128];
55          register char   *cp1, *cp2;
56  
57 <        if ((fp = fropen(file)) == NULL)
57 >        if ((fp = frlibopen(file)) == NULL)
58                  return(0);
59          lastp = NULL;
60          while (fgets(buf, sizeof(buf), fp) != NULL) {
# Line 92 | Line 98 | char   *file;
98                                  goto fmterr;
99                          }
100                  } else {                        /* or read specificaion */
101 <                        if ((lp->color=(float *)malloc(3*sizeof(float)))==NULL)
101 >                        if ((lp->color=(float *)malloc(6*sizeof(float)))==NULL)
102                                  goto memerr;
103 <                        if (sscanf(cp1, "%f %f %f", &lp->color[0], &
104 <                                        lp->color[1], &lp->color[2]) != 3) {
103 >                        if (sscanf(cp1, "%f %f %f", &lp->color[3], &
104 >                                        lp->color[4], &lp->color[5]) != 3) {
105                                  cp1 = "bad lamp data";
106                                  goto fmterr;
107                          }
108                                                  /* convert xyY to XYZ */
109 <                        xyz[1] = lp->color[2];
110 <                        xyz[0] = lp->color[0]/lp->color[1] * xyz[1];
111 <                        xyz[2] = xyz[1]*(1./lp->color[1] - 1.) - xyz[0];
109 >                        xyz[1] = lp->color[5];
110 >                        xyz[0] = lp->color[3]/lp->color[4] * xyz[1];
111 >                        xyz[2] = xyz[1]*(1./lp->color[4] - 1.) - xyz[0];
112                                                  /* XYZ to RGB */
113                          cie_rgb(lp->color, xyz);
114                  }
# Line 125 | Line 131 | fmterr:
131   }
132  
133  
134 < freelamps()                     /* free our lamps list */
134 > void
135 > freelamps(void)                 /* free our lamps list */
136   {
137          register LAMP   *lp1, *lp2;
138          
139 <        for (lp1 = lamps; lp1 != NULL; lp1 = lp1->next) {
139 >        for (lp1 = lamps; lp1 != NULL; lp1 = lp2) {
140                  free(lp1->pattern);
141                  if (lp1->color != NULL) {
142                          for (lp2 = lp1->next; lp2 != NULL; lp2 = lp2->next)
143                                  if (lp2->color == lp1->color)
144                                          lp2->color = NULL;
145 <                        free((char *)lp1->color);
145 >                        free((void *)lp1->color);
146                  }
147 <                free((char *)lp1);
147 >                lp2 = lp1->next;
148 >                free((void *)lp1);
149          }
150          lamps = NULL;
151   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines