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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines