83 |
|
int dtype; /* data type */ |
84 |
|
int need2swap; /* need byte swap? */ |
85 |
|
int nrows, ncols; /* matrix size */ |
86 |
+ |
COLOR expos; /* exposure value */ |
87 |
|
char *err; /* error message */ |
88 |
|
} CMINFO; /* header info record */ |
89 |
|
|
110 |
|
ip->need2swap = (nativebigendian() != i); |
111 |
|
return(0); |
112 |
|
} |
113 |
+ |
if (isexpos(s)) { |
114 |
+ |
double d = exposval(s); |
115 |
+ |
scalecolor(ip->expos, d); |
116 |
+ |
return(0); |
117 |
+ |
} |
118 |
+ |
if (iscolcor(s)) { |
119 |
+ |
COLOR ctmp; |
120 |
+ |
colcorval(ctmp, s); |
121 |
+ |
multcolor(ip->expos, ctmp); |
122 |
+ |
return(0); |
123 |
+ |
} |
124 |
|
if (!formatval(fmt, s)) |
125 |
|
return(0); |
126 |
|
for (i = 1; i < DTend; i++) |
131 |
|
|
132 |
|
/* Load header to obtain/check data type and number of columns */ |
133 |
|
char * |
134 |
< |
cm_getheader(int *dt, int *nr, int *nc, int *swp, FILE *fp) |
134 |
> |
cm_getheader(int *dt, int *nr, int *nc, int *swp, COLOR scale, FILE *fp) |
135 |
|
{ |
136 |
|
CMINFO cmi; |
137 |
|
/* read header */ |
138 |
|
cmi.dtype = DTfromHeader; |
139 |
|
cmi.need2swap = 0; |
140 |
+ |
cmi.expos[0] = cmi.expos[1] = cmi.expos[2] = 1.f; |
141 |
|
cmi.nrows = cmi.ncols = 0; |
142 |
|
cmi.err = "unexpected EOF in header"; |
143 |
|
if (getheader(fp, get_cminfo, &cmi) < 0) |
165 |
|
} |
166 |
|
if (swp) /* get/check swap? */ |
167 |
|
*swp = cmi.need2swap; |
168 |
+ |
if (scale) { /* transfer exposure comp. */ |
169 |
+ |
scale[0] = 1.f/cmi.expos[0]; |
170 |
+ |
scale[1] = 1.f/cmi.expos[1]; |
171 |
+ |
scale[2] = 1.f/cmi.expos[2]; |
172 |
+ |
} |
173 |
|
return(NULL); |
174 |
|
} |
175 |
|
|
176 |
|
/* Allocate and load image data into matrix */ |
177 |
|
static CMATRIX * |
178 |
< |
cm_load_rgbe(FILE *fp, int nrows, int ncols) |
178 |
> |
cm_load_rgbe(FILE *fp, int nrows, int ncols, COLOR scale) |
179 |
|
{ |
180 |
+ |
int doscale; |
181 |
|
CMATRIX *cm; |
182 |
|
COLORV *mp; |
183 |
|
/* header already loaded */ |
188 |
|
cm = cm_alloc(nrows, ncols); |
189 |
|
if (!cm) |
190 |
|
return(NULL); |
191 |
+ |
doscale = (scale[0] < .99) | (scale[0] > 1.01) | |
192 |
+ |
(scale[1] < .99) | (scale[1] > 1.01) | |
193 |
+ |
(scale[2] < .99) | (scale[2] > 1.01) ; |
194 |
|
mp = cm->cmem; |
195 |
|
while (nrows--) { |
196 |
|
if (freadscan((COLOR *)mp, ncols, fp) < 0) { |
198 |
|
cm_free(cm); |
199 |
|
return(NULL); |
200 |
|
} |
201 |
< |
mp += 3*ncols; |
201 |
> |
if (doscale) { |
202 |
> |
int i = ncols; |
203 |
> |
while (i--) { |
204 |
> |
*mp++ *= scale[0]; |
205 |
> |
*mp++ *= scale[1]; |
206 |
> |
*mp++ *= scale[2]; |
207 |
> |
} |
208 |
> |
} else |
209 |
> |
mp += 3*ncols; |
210 |
|
} /* caller closes stream */ |
211 |
|
return(cm); |
212 |
|
} |
218 |
|
const int ROWINC = 2048; |
219 |
|
FILE *fp = stdin; |
220 |
|
int swap = 0; |
221 |
+ |
COLOR scale; |
222 |
|
CMATRIX *cm; |
223 |
|
|
224 |
|
if (!inspec) |
239 |
|
if (dtype != DTascii) |
240 |
|
SET_FILE_BINARY(fp); /* doesn't really work */ |
241 |
|
if (!dtype | !ncols) { /* expecting header? */ |
242 |
< |
char *err = cm_getheader(&dtype, &nrows, &ncols, &swap, fp); |
242 |
> |
char *err = cm_getheader(&dtype, &nrows, &ncols, &swap, scale, fp); |
243 |
|
if (err) |
244 |
|
error(USER, err); |
245 |
|
if (ncols <= 0) |
252 |
|
break; |
253 |
|
case DTrgbe: |
254 |
|
case DTxyze: |
255 |
< |
cm = cm_load_rgbe(fp, nrows, ncols); |
255 |
> |
cm = cm_load_rgbe(fp, nrows, ncols, scale); |
256 |
|
goto cleanup; |
257 |
|
default: |
258 |
|
error(USER, "unexpected data type in cm_load()"); |