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 |
+ |
|
19 |
|
typedef struct lamp { |
20 |
|
char *pattern; /* search pattern */ |
21 |
|
float *color; /* pointer to lamp value */ |
26 |
|
|
27 |
|
|
28 |
|
float * |
29 |
< |
matchlamp(s) /* see if string matches any lamp */ |
30 |
< |
char *s; |
29 |
> |
matchlamp( /* see if string matches any lamp */ |
30 |
> |
char *s |
31 |
> |
) |
32 |
|
{ |
33 |
|
register LAMP *lp; |
34 |
|
|
41 |
|
} |
42 |
|
|
43 |
|
|
44 |
< |
loadlamps(file) /* load lamp type file */ |
45 |
< |
char *file; |
44 |
> |
int |
45 |
> |
loadlamps( /* load lamp type file */ |
46 |
> |
char *file |
47 |
> |
) |
48 |
|
{ |
49 |
|
LAMP *lastp; |
50 |
|
register LAMP *lp; |
53 |
|
char buf[128], str[128]; |
54 |
|
register char *cp1, *cp2; |
55 |
|
|
56 |
< |
if ((fp = fropen(file)) == NULL) |
56 |
> |
if ((fp = frlibopen(file)) == NULL) |
57 |
|
return(0); |
58 |
|
lastp = NULL; |
59 |
|
while (fgets(buf, sizeof(buf), fp) != NULL) { |
97 |
|
goto fmterr; |
98 |
|
} |
99 |
|
} else { /* or read specificaion */ |
100 |
< |
if ((lp->color=(float *)malloc(3*sizeof(float)))==NULL) |
100 |
> |
if ((lp->color=(float *)malloc(6*sizeof(float)))==NULL) |
101 |
|
goto memerr; |
102 |
< |
if (sscanf(cp1, "%f %f %f", &lp->color[0], & |
103 |
< |
lp->color[1], &lp->color[2]) != 3) { |
102 |
> |
if (sscanf(cp1, "%f %f %f", &lp->color[3], & |
103 |
> |
lp->color[4], &lp->color[5]) != 3) { |
104 |
|
cp1 = "bad lamp data"; |
105 |
|
goto fmterr; |
106 |
|
} |
107 |
|
/* convert xyY to XYZ */ |
108 |
< |
xyz[1] = lp->color[2]; |
109 |
< |
xyz[0] = lp->color[0]/lp->color[1] * xyz[1]; |
110 |
< |
xyz[2] = xyz[1]*(1./lp->color[1] - 1.) - xyz[0]; |
108 |
> |
xyz[1] = lp->color[5]; |
109 |
> |
xyz[0] = lp->color[3]/lp->color[4] * xyz[1]; |
110 |
> |
xyz[2] = xyz[1]*(1./lp->color[4] - 1.) - xyz[0]; |
111 |
|
/* XYZ to RGB */ |
112 |
|
cie_rgb(lp->color, xyz); |
113 |
|
} |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
< |
freelamps() /* free our lamps list */ |
133 |
> |
void |
134 |
> |
freelamps(void) /* free our lamps list */ |
135 |
|
{ |
136 |
|
register LAMP *lp1, *lp2; |
137 |
|
|
141 |
|
for (lp2 = lp1->next; lp2 != NULL; lp2 = lp2->next) |
142 |
|
if (lp2->color == lp1->color) |
143 |
|
lp2->color = NULL; |
144 |
< |
free((char *)lp1->color); |
144 |
> |
free((void *)lp1->color); |
145 |
|
} |
146 |
|
lp2 = lp1->next; |
147 |
< |
free((char *)lp1); |
147 |
> |
free((void *)lp1); |
148 |
|
} |
149 |
|
lamps = NULL; |
150 |
|
} |