15 |
|
#include "paths.h" |
16 |
|
#include "resolu.h" |
17 |
|
|
18 |
– |
const char stdin_name[] = "<stdin>"; |
19 |
– |
|
20 |
– |
const char *cm_fmt_id[] = { |
21 |
– |
"unknown", COLRFMT, CIEFMT, |
22 |
– |
"float", "ascii", "double" |
23 |
– |
}; |
24 |
– |
|
25 |
– |
const int cm_elem_size[] = { |
26 |
– |
0, 4, 4, 3*sizeof(float), 0, 3*sizeof(double) |
27 |
– |
}; |
28 |
– |
|
18 |
|
/* Allocate a color coefficient matrix */ |
19 |
|
CMATRIX * |
20 |
|
cm_alloc(int nrows, int ncols) |
85 |
|
char fmt[MAXFMTLEN]; |
86 |
|
int i; |
87 |
|
|
88 |
< |
if (!strncmp(s, "NCOMP=", 6) && atoi(s+6) != 3) { |
88 |
> |
if (isncomp(s) && ncompval(s) != 3) { |
89 |
|
ip->err = "unexpected # components (must be 3)"; |
90 |
|
return(-1); |
91 |
|
} |
166 |
|
|
167 |
|
/* Allocate and load image data into matrix */ |
168 |
|
static CMATRIX * |
169 |
< |
cm_load_rgbe(FILE *fp, int nrows, int ncols, COLOR scale) |
169 |
> |
cm_load_rgbe(FILE *fp, int nrows, int ncols) |
170 |
|
{ |
182 |
– |
int doscale; |
171 |
|
CMATRIX *cm; |
172 |
|
COLORV *mp; |
173 |
|
/* header already loaded */ |
174 |
|
cm = cm_alloc(nrows, ncols); |
175 |
|
if (!cm) |
176 |
|
return(NULL); |
189 |
– |
doscale = (scale[0] < .99) | (scale[0] > 1.01) | |
190 |
– |
(scale[1] < .99) | (scale[1] > 1.01) | |
191 |
– |
(scale[2] < .99) | (scale[2] > 1.01) ; |
177 |
|
mp = cm->cmem; |
178 |
|
while (nrows--) { |
179 |
|
if (freadscan((COLOR *)mp, ncols, fp) < 0) { |
181 |
|
cm_free(cm); |
182 |
|
return(NULL); |
183 |
|
} |
184 |
< |
if (doscale) { |
200 |
< |
int i = ncols; |
201 |
< |
while (i--) { |
202 |
< |
*mp++ *= scale[0]; |
203 |
< |
*mp++ *= scale[1]; |
204 |
< |
*mp++ *= scale[2]; |
205 |
< |
} |
206 |
< |
} else |
207 |
< |
mp += 3*ncols; |
184 |
> |
mp += 3*ncols; |
185 |
|
} /* caller closes stream */ |
186 |
|
return(cm); |
187 |
|
} |
234 |
|
break; |
235 |
|
case DTrgbe: |
236 |
|
case DTxyze: |
237 |
< |
cm = cm_load_rgbe(fp, nrows, ncols, scale); |
237 |
> |
cm = cm_load_rgbe(fp, nrows, ncols); |
238 |
|
goto cleanup; |
239 |
|
default: |
240 |
|
error(USER, "unexpected data type in cm_load()"); |
371 |
|
else |
372 |
|
funlockfile(fp); |
373 |
|
#endif |
374 |
+ |
if ((scale[0] < .99) | (scale[0] > 1.01) | |
375 |
+ |
(scale[1] < .99) | (scale[1] > 1.01) | |
376 |
+ |
(scale[2] < .99) | (scale[2] > 1.01)) { |
377 |
+ |
size_t n = (size_t)ncols*nrows; |
378 |
+ |
COLORV *mp = cm->cmem; |
379 |
+ |
while (n--) { /* apply exposure scaling */ |
380 |
+ |
*mp++ *= scale[0]; |
381 |
+ |
*mp++ *= scale[1]; |
382 |
+ |
*mp++ *= scale[2]; |
383 |
+ |
} |
384 |
+ |
} |
385 |
|
return(cm); |
386 |
|
EOFerror: |
387 |
|
sprintf(errmsg, "unexpected EOF reading %s", inspec); |
484 |
|
|
485 |
|
if (!cm) |
486 |
|
return(0); |
487 |
+ |
#ifdef getc_unlocked |
488 |
+ |
flockfile(fp); |
489 |
+ |
#endif |
490 |
|
mp = cm->cmem; |
491 |
|
switch (dtype) { |
492 |
|
case DTascii: |
538 |
|
fputs("Unsupported data type in cm_write()!\n", stderr); |
539 |
|
return(0); |
540 |
|
} |
541 |
+ |
#ifdef getc_unlocked |
542 |
+ |
funlockfile(fp); |
543 |
+ |
#endif |
544 |
|
return(fflush(fp) == 0); |
545 |
|
} |