| 26 |
|
int i, y; |
| 27 |
|
|
| 28 |
|
if (cv->ncols != 1) |
| 29 |
< |
error(INTERNAL, "expected vector in sum_images()"); |
| 29 |
> |
error(INTERNAL, "expected matrix in sum_images()"); |
| 30 |
|
for (i = 0; i < cv->nrows; i++) { |
| 31 |
|
const COLORV *scv = cv_lval(cv,i); |
| 32 |
|
char fname[1024]; |
| 33 |
|
FILE *fp; |
| 34 |
|
int dt, xr, yr; |
| 35 |
|
COLORV *psp; |
| 36 |
+ |
char *err; |
| 37 |
|
/* check for zero */ |
| 38 |
|
if ((scv[RED] == 0) & (scv[GRN] == 0) & (scv[BLU] == 0) && |
| 39 |
|
(myDT != DTfromHeader) | (i < cv->nrows-1)) |
| 40 |
|
continue; |
| 41 |
|
/* open next picture */ |
| 42 |
|
sprintf(fname, fspec, i); |
| 43 |
< |
if ((fp = fopen(fname, "r")) == NULL) { |
| 43 |
> |
if ((fp = fopen(fname, "rb")) == NULL) { |
| 44 |
|
sprintf(errmsg, "cannot open picture '%s'", fname); |
| 45 |
|
error(SYSTEM, errmsg); |
| 46 |
|
} |
| 47 |
< |
SET_FILE_BINARY(fp); |
| 48 |
< |
dt = getDTfromHeader(fp); |
| 47 |
> |
dt = DTfromHeader; |
| 48 |
> |
if ((err = cm_getheader(&dt, NULL, NULL, fp)) != NULL) |
| 49 |
> |
error(USER, err); |
| 50 |
|
if ((dt != DTrgbe) & (dt != DTxyze) || |
| 51 |
|
!fscnresolu(&xr, &yr, fp)) { |
| 52 |
|
sprintf(errmsg, "file '%s' not a picture", fname); |
| 134 |
|
switch (argv[a][1]) { |
| 135 |
|
case 'n': |
| 136 |
|
nsteps = atoi(argv[++a]); |
| 137 |
< |
if (nsteps <= 0) |
| 137 |
> |
if (nsteps < 0) |
| 138 |
|
goto userr; |
| 139 |
|
break; |
| 140 |
|
case 'i': |
| 148 |
|
case 'a': |
| 149 |
|
skyfmt = DTascii; |
| 150 |
|
break; |
| 151 |
+ |
case 'h': |
| 152 |
+ |
skyfmt = DTfromHeader; |
| 153 |
+ |
break; |
| 154 |
|
default: |
| 155 |
|
goto userr; |
| 156 |
|
} |
| 263 |
|
progname, fnbuf); |
| 264 |
|
return(1); |
| 265 |
|
} |
| 266 |
+ |
#ifdef getc_unlocked |
| 267 |
+ |
flockfile(ofp); |
| 268 |
+ |
#endif |
| 269 |
|
cm_write(rvec, outfmt, ofp); |
| 270 |
|
if (fclose(ofp) == EOF) { |
| 271 |
|
fprintf(stderr, |
| 277 |
|
cm_free(rvec); |
| 278 |
|
} |
| 279 |
|
} else { |
| 280 |
+ |
#ifdef getc_unlocked |
| 281 |
+ |
flockfile(ofp); |
| 282 |
+ |
#endif |
| 283 |
|
if (outfmt != DTascii) |
| 284 |
|
SET_FILE_BINARY(ofp); |
| 285 |
|
if (rmtx->ncols > 1) { /* header if actual matrix */ |
| 286 |
|
newheader("RADIANCE", ofp); |
| 287 |
|
printargs(argc, argv, ofp); |
| 288 |
|
fputnow(ofp); |
| 289 |
+ |
fprintf(ofp, "NCOLS=%d\n", rmtx->ncols); |
| 290 |
+ |
fputs("NCOMP=3\n", ofp); |
| 291 |
|
fputformat((char *)cm_fmt_id[outfmt], ofp); |
| 292 |
|
fputc('\n', ofp); |
| 293 |
|
} |