14 |
|
#include "platform.h" |
15 |
|
#include "resolu.h" |
16 |
|
|
17 |
– |
char *progname; /* global argv[0] */ |
18 |
– |
|
17 |
|
/* Sum together a set of images and write result to fout */ |
18 |
|
static int |
19 |
|
sum_images(const char *fspec, const CMATRIX *cv, FILE *fout) |
20 |
|
{ |
21 |
+ |
static int runcnt = 0; |
22 |
|
int myDT = DTfromHeader; |
23 |
|
COLR *scanline = NULL; |
24 |
|
CMATRIX *pmat = NULL; |
27 |
|
|
28 |
|
if (cv->ncols != 1) |
29 |
|
error(INTERNAL, "expected vector in sum_images()"); |
30 |
< |
for (i = 0; i < cv->nrows; i++) { |
31 |
< |
const COLORV *scv = cv_lval(cv,i); |
30 |
> |
for (i = cv->nrows; i-- > 0; ) { |
31 |
> |
const int r = runcnt&1 ? i : cv->nrows-1 - i; |
32 |
> |
const COLORV *scv = cv_lval(cv,r); |
33 |
|
int flat_file = 0; |
34 |
|
char fname[1024]; |
35 |
|
FILE *fp; |
39 |
|
char *err; |
40 |
|
/* check for zero */ |
41 |
|
if ((scv[RED] == 0) & (scv[GRN] == 0) & (scv[BLU] == 0) && |
42 |
< |
(myDT != DTfromHeader) | (i < cv->nrows-1)) |
42 |
> |
(myDT != DTfromHeader) | (i > 0)) |
43 |
|
continue; |
44 |
|
/* open next picture */ |
45 |
< |
sprintf(fname, fspec, i); |
45 |
> |
sprintf(fname, fspec, r); |
46 |
|
if ((fp = fopen(fname, "rb")) == NULL) { |
47 |
|
sprintf(errmsg, "cannot open picture '%s'", fname); |
48 |
|
error(SYSTEM, errmsg); |
49 |
|
} |
50 |
+ |
#ifdef getc_unlocked |
51 |
+ |
flockfile(fp); |
52 |
+ |
#endif |
53 |
|
dt = DTfromHeader; |
54 |
|
if ((err = cm_getheader(&dt, NULL, NULL, NULL, NULL, fp)) != NULL) |
55 |
|
error(USER, err); |
77 |
|
} |
78 |
|
/* flat file check */ |
79 |
|
if ((data_start = ftell(fp)) > 0 && fseek(fp, 0L, SEEK_END) == 0) { |
80 |
< |
flat_file = (ftell(fp) == data_start + sizeof(COLR)*xr*yr); |
80 |
> |
flat_file = (ftell(fp) >= data_start + sizeof(COLR)*xr*yr); |
81 |
|
if (fseek(fp, data_start, SEEK_SET) < 0) { |
82 |
|
sprintf(errmsg, "cannot seek on picture '%s'", fname); |
83 |
|
error(SYSTEM, errmsg); |
107 |
|
free(scanline); |
108 |
|
i = cm_write(pmat, myDT, fout); /* write picture */ |
109 |
|
cm_free(pmat); /* free data */ |
110 |
+ |
++runcnt; /* for zig-zagging */ |
111 |
|
return(i); |
112 |
|
} |
113 |
|
|
178 |
|
CMATRIX *cmtx; /* component vector/matrix result */ |
179 |
|
char fnbuf[256]; |
180 |
|
int a, i; |
181 |
< |
|
182 |
< |
progname = argv[0]; |
181 |
> |
/* set global progname */ |
182 |
> |
fixargv0(argv[0]); |
183 |
|
/* get options */ |
184 |
|
for (a = 1; a < argc && argv[a][0] == '-'; a++) |
185 |
|
switch (argv[a][1]) { |
248 |
|
nsteps = smtx->ncols; |
249 |
|
/* load BSDF */ |
250 |
|
if (argv[a+1][0] != '!' && |
251 |
< |
(ccp = strrchr(argv[a+1], '.')) != NULL && |
251 |
> |
(ccp = strrchr(argv[a+1], '.')) > argv[a+1] && |
252 |
|
!strcasecmp(ccp+1, "XML")) |
253 |
|
Tmat = cm_loadBTDF(argv[a+1]); |
254 |
|
else |
268 |
|
} |
269 |
|
/* prepare output stream */ |
270 |
|
if ((ofspec != NULL) & (nsteps == 1) && hasNumberFormat(ofspec)) { |
271 |
< |
sprintf(fnbuf, ofspec, 1); |
271 |
> |
sprintf(fnbuf, ofspec, 0); |
272 |
|
ofspec = fnbuf; |
273 |
|
} |
274 |
|
if (ofspec != NULL && !hasNumberFormat(ofspec)) { |
279 |
|
} |
280 |
|
ofspec = NULL; /* only need to open once */ |
281 |
|
} |
282 |
< |
if (hasNumberFormat(argv[a])) { /* generating image(s) */ |
282 |
> |
if (hasNumberFormat(argv[a])) { /* loading image vector(s) */ |
283 |
|
if (outfmt != DTrgbe) { |
284 |
|
error(WARNING, "changing output type to -oc"); |
285 |
|
outfmt = DTrgbe; |
321 |
|
} |
322 |
|
else if (!sum_images(argv[a], cmtx, ofp)) |
323 |
|
return(1); |
324 |
< |
} else { /* generating vector/matrix */ |
324 |
> |
} else { /* loading view matrix */ |
325 |
|
CMATRIX *Vmat = cm_load(argv[a], 0, cmtx->nrows, DTfromHeader); |
326 |
|
CMATRIX *rmtx = cm_multiply(Vmat, cmtx); |
327 |
|
cm_free(Vmat); |
349 |
|
if ((outfmt != DTrgbe) & (outfmt != DTxyze)) { |
350 |
|
fprintf(ofp, "NROWS=%d\n", rvec->nrows); |
351 |
|
fprintf(ofp, "NCOLS=%d\n", rvec->ncols); |
352 |
< |
fputs("NCOMP=3\n", ofp); |
352 |
> |
fputncomp(3, ofp); |
353 |
|
} |
354 |
|
if ((outfmt == DTfloat) | (outfmt == DTdouble)) |
355 |
|
fputendian(ofp); |
381 |
|
if ((outfmt != DTrgbe) & (outfmt != DTxyze)) { |
382 |
|
fprintf(ofp, "NROWS=%d\n", rmtx->nrows); |
383 |
|
fprintf(ofp, "NCOLS=%d\n", rmtx->ncols); |
384 |
< |
fputs("NCOMP=3\n", ofp); |
384 |
> |
fputncomp(3, ofp); |
385 |
|
} |
386 |
|
if ((outfmt == DTfloat) | (outfmt == DTdouble)) |
387 |
|
fputendian(ofp); |