| 16 |
|
#include "resolu.h" |
| 17 |
|
|
| 18 |
|
const char *cm_fmt_id[] = { |
| 19 |
< |
"unknown", "ascii", COLRFMT, CIEFMT, |
| 20 |
< |
"float", "double" |
| 19 |
> |
"unknown", COLRFMT, CIEFMT, |
| 20 |
> |
"float", "ascii", "double" |
| 21 |
|
}; |
| 22 |
|
|
| 23 |
|
const int cm_elem_size[] = { |
| 155 |
|
return(NULL); |
| 156 |
|
} |
| 157 |
|
|
| 158 |
+ |
/* Allocate and load image data into matrix */ |
| 159 |
+ |
static CMATRIX * |
| 160 |
+ |
cm_load_rgbe(FILE *fp, int nrows, int ncols) |
| 161 |
+ |
{ |
| 162 |
+ |
CMATRIX *cm; |
| 163 |
+ |
COLORV *mp; |
| 164 |
+ |
/* header already loaded */ |
| 165 |
+ |
if ((nrows <= 0) | (ncols <= 0) && !fscnresolu(&ncols, &nrows, fp)) { |
| 166 |
+ |
error(USER, "bad picture resolution string"); |
| 167 |
+ |
return(NULL); |
| 168 |
+ |
} |
| 169 |
+ |
cm = cm_alloc(nrows, ncols); |
| 170 |
+ |
if (!cm) |
| 171 |
+ |
return(NULL); |
| 172 |
+ |
mp = cm->cmem; |
| 173 |
+ |
while (nrows--) { |
| 174 |
+ |
if (freadscan((COLOR *)mp, ncols, fp) < 0) { |
| 175 |
+ |
error(USER, "error reading color picture as matrix"); |
| 176 |
+ |
cm_free(cm); |
| 177 |
+ |
return(NULL); |
| 178 |
+ |
} |
| 179 |
+ |
mp += 3*ncols; |
| 180 |
+ |
} /* caller closes stream */ |
| 181 |
+ |
return(cm); |
| 182 |
+ |
} |
| 183 |
+ |
|
| 184 |
|
/* Allocate and load a matrix from the given input (or stdin if NULL) */ |
| 185 |
|
CMATRIX * |
| 186 |
|
cm_load(const char *inspec, int nrows, int ncols, int dtype) |
| 219 |
|
case DTfloat: |
| 220 |
|
case DTdouble: |
| 221 |
|
break; |
| 222 |
+ |
case DTrgbe: |
| 223 |
+ |
case DTxyze: |
| 224 |
+ |
cm = cm_load_rgbe(fp, nrows, ncols); |
| 225 |
+ |
goto cleanup; |
| 226 |
|
default: |
| 227 |
|
error(USER, "unexpected data type in cm_load()"); |
| 228 |
|
} |
| 342 |
|
else if (dtype == DTdouble) |
| 343 |
|
swap64((char *)cm->cmem, 3*cm->nrows*cm->ncols); |
| 344 |
|
} |
| 345 |
+ |
cleanup: |
| 346 |
|
if (fp != stdin) { |
| 347 |
|
if (inspec[0] != '!') |
| 348 |
|
fclose(fp); |
| 359 |
|
EOFerror: |
| 360 |
|
sprintf(errmsg, "unexpected EOF reading %s", inspec); |
| 361 |
|
error(USER, errmsg); |
| 362 |
+ |
return(NULL); |
| 363 |
|
not_handled: |
| 364 |
|
error(INTERNAL, "unhandled data size or length in cm_load()"); |
| 365 |
|
return(NULL); /* gratis return */ |