| 18 |
|
|
| 19 |
|
#include "calcomp.h" |
| 20 |
|
|
| 21 |
< |
#define MAXINP 16 /* maximum number of input files */ |
| 21 |
> |
#define MAXINP 32 /* maximum number of input files */ |
| 22 |
|
|
| 23 |
|
struct { |
| 24 |
|
char *name; /* file name */ |
| 25 |
|
FILE *fp; /* stream pointer */ |
| 26 |
|
COLOR *scan; /* input scanline */ |
| 27 |
+ |
COLOR coef; /* coefficient */ |
| 28 |
|
} input[MAXINP]; /* input pictures */ |
| 29 |
|
|
| 30 |
|
int nfiles; /* number of input files */ |
| 54 |
|
int argc; |
| 55 |
|
char *argv[]; |
| 56 |
|
{ |
| 57 |
< |
extern double l_redin(), l_grnin(), l_bluin(); |
| 57 |
> |
extern double l_redin(), l_grnin(), l_bluin(), atof(); |
| 58 |
> |
double f; |
| 59 |
|
int a; |
| 60 |
|
|
| 61 |
|
funset(vcolin[RED], 1, l_redin); |
| 66 |
|
if (argv[a][0] == '-') |
| 67 |
|
switch (argv[a][1]) { |
| 68 |
|
case '\0': |
| 69 |
+ |
case 's': |
| 70 |
+ |
case 'c': |
| 71 |
|
goto getfiles; |
| 72 |
|
case 'x': |
| 73 |
|
xres = atoi(argv[++a]); |
| 82 |
|
fcompile(argv[++a]); |
| 83 |
|
break; |
| 84 |
|
case 'e': |
| 85 |
< |
scompile(NULL, argv[++a]); |
| 85 |
> |
scompile(argv[++a], NULL, 0); |
| 86 |
|
break; |
| 87 |
|
default: |
| 88 |
< |
eputs("Usage: "); |
| 85 |
< |
eputs(argv[0]); |
| 86 |
< |
eputs(" [-w][-x xres][-y yres][-e expr][-f file] [picture ..]\n"); |
| 87 |
< |
quit(1); |
| 88 |
> |
goto usage; |
| 89 |
|
} |
| 90 |
|
else |
| 91 |
|
break; |
| 92 |
|
getfiles: |
| 93 |
+ |
for (nfiles = 0; nfiles < MAXINP; nfiles++) |
| 94 |
+ |
setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); |
| 95 |
|
nfiles = 0; |
| 96 |
|
for ( ; a < argc; a++) { |
| 97 |
|
if (nfiles >= MAXINP) { |
| 99 |
|
eputs(": too many picture files\n"); |
| 100 |
|
quit(1); |
| 101 |
|
} |
| 102 |
< |
if (argv[a][0] == '-') { |
| 103 |
< |
input[nfiles].name = "<stdin>"; |
| 104 |
< |
input[nfiles].fp = stdin; |
| 105 |
< |
} else { |
| 102 |
> |
if (argv[a][0] == '-') |
| 103 |
> |
switch (argv[a][1]) { |
| 104 |
> |
case '\0': |
| 105 |
> |
input[nfiles].name = "<stdin>"; |
| 106 |
> |
input[nfiles].fp = stdin; |
| 107 |
> |
break; |
| 108 |
> |
case 's': |
| 109 |
> |
f = atof(argv[++a]); |
| 110 |
> |
scalecolor(input[nfiles].coef, f); |
| 111 |
> |
continue; |
| 112 |
> |
case 'c': |
| 113 |
> |
colval(input[nfiles].coef,RED)*=atof(argv[++a]); |
| 114 |
> |
colval(input[nfiles].coef,GRN)*=atof(argv[++a]); |
| 115 |
> |
colval(input[nfiles].coef,BLU)*=atof(argv[++a]); |
| 116 |
> |
continue; |
| 117 |
> |
default: |
| 118 |
> |
goto usage; |
| 119 |
> |
} |
| 120 |
> |
else { |
| 121 |
|
input[nfiles].name = argv[a]; |
| 122 |
|
input[nfiles].fp = fopen(argv[a], "r"); |
| 123 |
|
if (input[nfiles].fp == NULL) { |
| 124 |
< |
eputs(argv[a]); |
| 107 |
< |
eputs(": cannot open\n"); |
| 124 |
> |
perror(argv[a]); |
| 125 |
|
quit(1); |
| 126 |
|
} |
| 127 |
|
} |
| 128 |
|
fputs(input[nfiles].name, stdout); |
| 129 |
|
fputs(":\n", stdout); |
| 130 |
|
getheader(input[nfiles].fp, tputs); |
| 131 |
< |
if (fscanf(input[nfiles].fp, "-Y %d +X %d\n", &ypos, &xpos) != 2) { |
| 131 |
> |
if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != |
| 132 |
> |
(YMAJOR|YDECR)) { |
| 133 |
|
eputs(input[nfiles].name); |
| 134 |
|
eputs(": bad picture size\n"); |
| 135 |
|
quit(1); |
| 147 |
|
} |
| 148 |
|
printargs(argc, argv, stdout); |
| 149 |
|
putchar('\n'); |
| 150 |
< |
printf("-Y %d +X %d\n", yres, xres); |
| 150 |
> |
fputresolu(YMAJOR|YDECR, xres, yres, stdout); |
| 151 |
|
combine(); |
| 152 |
|
quit(0); |
| 153 |
+ |
usage: |
| 154 |
+ |
eputs("Usage: "); |
| 155 |
+ |
eputs(argv[0]); |
| 156 |
+ |
eputs(" [-w][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] picture ..]\n"); |
| 157 |
+ |
quit(1); |
| 158 |
|
} |
| 159 |
|
|
| 160 |
|
|
| 161 |
|
combine() /* combine pictures */ |
| 162 |
|
{ |
| 163 |
< |
int coldef[3]; |
| 163 |
> |
EPNODE *coldef[3]; |
| 164 |
|
COLOR *scanout; |
| 165 |
|
register int i, j; |
| 166 |
|
/* check defined variables */ |
| 167 |
< |
for (j = 0; j < 3; j++) |
| 168 |
< |
coldef[j] = vardefined(vcolout[j]); |
| 167 |
> |
for (j = 0; j < 3; j++) { |
| 168 |
> |
if (vardefined(vcolout[j])) |
| 169 |
> |
coldef[j] = eparse(vcolout[j]); |
| 170 |
> |
else |
| 171 |
> |
coldef[j] = NULL; |
| 172 |
> |
} |
| 173 |
|
/* allocate scanline */ |
| 174 |
|
scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); |
| 175 |
|
/* combine files */ |
| 184 |
|
for (xpos = 0; xpos < xres; xpos++) { |
| 185 |
|
varset(vxpos, (double)xpos); |
| 186 |
|
eclock++; |
| 187 |
< |
for (j = 0; j < 3; j++) |
| 188 |
< |
if (coldef[j]) { |
| 189 |
< |
colval(scanout[xpos],j) = varvalue(vcolout[j]); |
| 190 |
< |
if (colval(scanout[xpos],j) < 0.0) |
| 164 |
< |
colval(scanout[xpos],j) = 0.0; |
| 187 |
> |
for (j = 0; j < 3; j++) { |
| 188 |
> |
if (coldef[j] != NULL) { |
| 189 |
> |
colval(scanout[xpos],j) = |
| 190 |
> |
evalue(coldef[j]); |
| 191 |
|
} else { |
| 192 |
|
colval(scanout[xpos],j) = 0.0; |
| 193 |
|
for (i = 0; i < nfiles; i++) |
| 194 |
< |
colval(scanout[xpos],j) += colval(input[i].scan[xpos],j); |
| 194 |
> |
colval(scanout[xpos],j) += |
| 195 |
> |
colval(input[i].coef,j) * |
| 196 |
> |
colval(input[i].scan[xpos],j); |
| 197 |
|
} |
| 198 |
+ |
if (colval(scanout[xpos],j) < 0.0) |
| 199 |
+ |
colval(scanout[xpos],j) = 0.0; |
| 200 |
+ |
} |
| 201 |
|
} |
| 202 |
|
if (fwritescan(scanout, xres, stdout) < 0) { |
| 203 |
< |
eputs("write error\n"); |
| 203 |
> |
perror("write error"); |
| 204 |
|
quit(1); |
| 205 |
|
} |
| 206 |
|
} |