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); |
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]) { |