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