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.1 by greg, Sat Dec 8 09:28:16 1990 UTC vs.
Revision 2.4 by greg, Wed Mar 1 10:40:18 1995 UTC

# Line 12 | Line 12 | static char SCCSid[] = "$SunId$ LBL";
12   #include  <ctype.h>
13  
14   extern char     *eindex(), *expsave(), *malloc();
15 < extern FILE     *fropen();
15 > extern FILE     *frlibopen();
16  
17   typedef struct lamp {
18          char    *pattern;                       /* search pattern */
# Line 48 | Line 48 | char   *file;
48          char    buf[128], str[128];
49          register char   *cp1, *cp2;
50  
51 <        if ((fp = fropen(file)) == NULL)
51 >        if ((fp = frlibopen(file)) == NULL)
52                  return(0);
53          lastp = NULL;
54          while (fgets(buf, sizeof(buf), fp) != NULL) {
# Line 92 | Line 92 | char   *file;
92                                  goto fmterr;
93                          }
94                  } else {                        /* or read specificaion */
95 <                        if ((lp->color=(float *)malloc(3*sizeof(float)))==NULL)
95 >                        if ((lp->color=(float *)malloc(6*sizeof(float)))==NULL)
96                                  goto memerr;
97 <                        if (sscanf(cp1, "%f %f %f", &lp->color[0], &
98 <                                        lp->color[1], &lp->color[2]) != 3) {
97 >                        if (sscanf(cp1, "%f %f %f", &lp->color[3], &
98 >                                        lp->color[4], &lp->color[5]) != 3) {
99                                  cp1 = "bad lamp data";
100                                  goto fmterr;
101                          }
102                                                  /* convert xyY to XYZ */
103 <                        xyz[1] = lp->color[2];
104 <                        xyz[0] = lp->color[0]/lp->color[1] * xyz[1];
105 <                        xyz[2] = xyz[1]*(1./lp->color[1] - 1.) - xyz[0];
103 >                        xyz[1] = lp->color[5];
104 >                        xyz[0] = lp->color[3]/lp->color[4] * xyz[1];
105 >                        xyz[2] = xyz[1]*(1./lp->color[4] - 1.) - xyz[0];
106                                                  /* XYZ to RGB */
107                          cie_rgb(lp->color, xyz);
108                  }
# Line 114 | Line 114 | char   *file;
114                  lastp = lp;
115          }
116          fclose(fp);
117 <        return(1);
117 >        return(lastp != NULL);
118   memerr:
119          fputs("Out of memory in loadlamps\n", stderr);
120          return(-1);
# Line 122 | Line 122 | fmterr:
122          fputs(buf, stderr);
123          fprintf(stderr, "%s: %s\n", file, cp1);
124          return(-1);
125 + }
126 +
127 +
128 + freelamps()                     /* free our lamps list */
129 + {
130 +        register LAMP   *lp1, *lp2;
131 +        
132 +        for (lp1 = lamps; lp1 != NULL; lp1 = lp2) {
133 +                free(lp1->pattern);
134 +                if (lp1->color != NULL) {
135 +                        for (lp2 = lp1->next; lp2 != NULL; lp2 = lp2->next)
136 +                                if (lp2->color == lp1->color)
137 +                                        lp2->color = NULL;
138 +                        free((char *)lp1->color);
139 +                }
140 +                lp2 = lp1->next;
141 +                free((char *)lp1);
142 +        }
143 +        lamps = NULL;
144   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines