7 |
|
*/ |
8 |
|
|
9 |
|
#include <math.h> |
10 |
– |
|
10 |
|
#include "platform.h" |
11 |
|
#include "color.h" |
12 |
|
#include "resolu.h" |
20 |
|
double expcomp = 1.0; /* exposure compensation */ |
21 |
|
int doflat = -1; /* produce flat file? */ |
22 |
|
double origexp = -1.0; /* original exposure */ |
24 |
– |
char *progname; |
23 |
|
|
24 |
|
static gethfunc headline; |
25 |
|
static void quiterr(char *err); |
72 |
|
main(int argc, char *argv[]) |
73 |
|
{ |
74 |
|
int i; |
75 |
+ |
|
76 |
|
SET_DEFAULT_BINARY(); |
77 |
|
SET_FILE_BINARY(stdin); |
78 |
|
SET_FILE_BINARY(stdout); |
79 |
< |
progname = argv[0]; |
79 |
> |
fixargv0(argv[0]); |
80 |
|
|
81 |
|
for (i = 1; i < argc; i++) |
82 |
|
if (argv[i][0] == '-') |
133 |
|
getheader(stdin, headline, NULL); |
134 |
|
if (infmt == InpUNK) |
135 |
|
quiterr("unrecognized/missing input file format"); |
136 |
+ |
if (infmt == InpSPEC ? (NCSAMP <= 3) | (NCSAMP > MAXCSAMP) : |
137 |
+ |
NCSAMP != 3) |
138 |
+ |
quiterr("bad number of color components"); |
139 |
|
printargs(argc, argv, stdout); /* add to header */ |
140 |
|
convert(); /* convert picture */ |
141 |
|
exit(0); |
163 |
|
myreadscan(COLOR *scn, int len) |
164 |
|
{ |
165 |
|
if (infmt == InpSPEC) { /* read & convert to XYZ */ |
166 |
< |
SCOLR sclr; |
167 |
< |
SCOLOR scol; |
166 |
> |
static COLOR *scomp = NULL; |
167 |
> |
SCOLR sclr; |
168 |
> |
SCOLOR scol; |
169 |
> |
COLOR xyz; |
170 |
> |
int n; |
171 |
> |
if (scomp == NULL) { /* initialize conversion */ |
172 |
> |
scomp = (COLOR *)malloc(sizeof(COLOR)*NCSAMP); |
173 |
> |
if (scomp == NULL) |
174 |
> |
quiterr("out of memory in myreadscan"); |
175 |
> |
for (n = NCSAMP; n--; ) |
176 |
> |
spec_cie(scomp[n], |
177 |
> |
WLPART[0] + (WLPART[3] - WLPART[0])*(n+1)/NCSAMP, |
178 |
> |
WLPART[0] + (WLPART[3] - WLPART[0])*n/NCSAMP); |
179 |
> |
} |
180 |
|
while (len-- > 0) { |
181 |
|
if (getbinary(sclr, LSCOLR, 1, stdin) != 1) |
182 |
|
goto readerr; |
183 |
|
scolr_scolor(scol, sclr); |
184 |
< |
scolor_cie(*scn++, scol); |
184 |
> |
setcolor(*scn, 0, 0, 0); |
185 |
> |
for (n = NCSAMP; n--; ) { |
186 |
> |
copycolor(xyz, scomp[n]); |
187 |
> |
scalecolor(xyz, scol[n]); |
188 |
> |
addcolor(*scn, xyz); |
189 |
> |
} |
190 |
> |
scn++; |
191 |
|
} |
192 |
|
return; |
193 |
|
} /* else read as RGBE/XYZE */ |