| 1 |
< |
/* Copyright (c) 1989 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1991 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 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 */ |
| 31 |
|
|
| 32 |
|
char *vcolin[3] = {"ri", "gi", "bi"}; |
| 33 |
|
char *vcolout[3] = {"ro", "go", "bo"}; |
| 34 |
+ |
#define vbrtin "li" |
| 35 |
+ |
#define vbrtout "lo" |
| 36 |
|
|
| 37 |
+ |
#define vnfiles "nfiles" |
| 38 |
+ |
#define vxres "xres" |
| 39 |
+ |
#define vyres "yres" |
| 40 |
|
#define vxpos "x" |
| 41 |
|
#define vypos "y" |
| 42 |
|
|
| 59 |
|
int argc; |
| 60 |
|
char *argv[]; |
| 61 |
|
{ |
| 62 |
< |
extern double l_redin(), l_grnin(), l_bluin(); |
| 62 |
> |
extern double l_redin(), l_grnin(), l_bluin(), l_brtin(), atof(); |
| 63 |
> |
double f; |
| 64 |
|
int a; |
| 65 |
|
|
| 66 |
|
funset(vcolin[RED], 1, l_redin); |
| 67 |
|
funset(vcolin[GRN], 1, l_grnin); |
| 68 |
|
funset(vcolin[BLU], 1, l_bluin); |
| 69 |
+ |
funset(vbrtin, 1, l_brtin); |
| 70 |
|
|
| 71 |
|
for (a = 1; a < argc; a++) |
| 72 |
|
if (argv[a][0] == '-') |
| 73 |
|
switch (argv[a][1]) { |
| 74 |
|
case '\0': |
| 75 |
+ |
case 's': |
| 76 |
+ |
case 'c': |
| 77 |
|
goto getfiles; |
| 78 |
|
case 'x': |
| 79 |
|
xres = atoi(argv[++a]); |
| 88 |
|
fcompile(argv[++a]); |
| 89 |
|
break; |
| 90 |
|
case 'e': |
| 91 |
< |
scompile(NULL, argv[++a]); |
| 91 |
> |
scompile(argv[++a], NULL, 0); |
| 92 |
|
break; |
| 93 |
|
default: |
| 94 |
< |
eputs("Usage: "); |
| 85 |
< |
eputs(argv[0]); |
| 86 |
< |
eputs(" [-w][-x xres][-y yres][-e expr][-f file] [picture ..]\n"); |
| 87 |
< |
quit(1); |
| 94 |
> |
goto usage; |
| 95 |
|
} |
| 96 |
|
else |
| 97 |
|
break; |
| 98 |
|
getfiles: |
| 99 |
+ |
for (nfiles = 0; nfiles < MAXINP; nfiles++) |
| 100 |
+ |
setcolor(input[nfiles].coef, 1.0, 1.0, 1.0); |
| 101 |
|
nfiles = 0; |
| 102 |
|
for ( ; a < argc; a++) { |
| 103 |
|
if (nfiles >= MAXINP) { |
| 105 |
|
eputs(": too many picture files\n"); |
| 106 |
|
quit(1); |
| 107 |
|
} |
| 108 |
< |
if (argv[a][0] == '-') { |
| 109 |
< |
input[nfiles].name = "<stdin>"; |
| 110 |
< |
input[nfiles].fp = stdin; |
| 111 |
< |
} else { |
| 108 |
> |
if (argv[a][0] == '-') |
| 109 |
> |
switch (argv[a][1]) { |
| 110 |
> |
case '\0': |
| 111 |
> |
input[nfiles].name = "<stdin>"; |
| 112 |
> |
input[nfiles].fp = stdin; |
| 113 |
> |
break; |
| 114 |
> |
case 's': |
| 115 |
> |
f = atof(argv[++a]); |
| 116 |
> |
scalecolor(input[nfiles].coef, f); |
| 117 |
> |
continue; |
| 118 |
> |
case 'c': |
| 119 |
> |
colval(input[nfiles].coef,RED)*=atof(argv[++a]); |
| 120 |
> |
colval(input[nfiles].coef,GRN)*=atof(argv[++a]); |
| 121 |
> |
colval(input[nfiles].coef,BLU)*=atof(argv[++a]); |
| 122 |
> |
continue; |
| 123 |
> |
default: |
| 124 |
> |
goto usage; |
| 125 |
> |
} |
| 126 |
> |
else { |
| 127 |
|
input[nfiles].name = argv[a]; |
| 128 |
|
input[nfiles].fp = fopen(argv[a], "r"); |
| 129 |
|
if (input[nfiles].fp == NULL) { |
| 130 |
< |
eputs(argv[a]); |
| 107 |
< |
eputs(": cannot open\n"); |
| 130 |
> |
perror(argv[a]); |
| 131 |
|
quit(1); |
| 132 |
|
} |
| 133 |
|
} |
| 134 |
|
fputs(input[nfiles].name, stdout); |
| 135 |
|
fputs(":\n", stdout); |
| 136 |
|
getheader(input[nfiles].fp, tputs); |
| 137 |
< |
if (fscanf(input[nfiles].fp, "-Y %d +X %d\n", &ypos, &xpos) != 2) { |
| 137 |
> |
if (fgetresolu(&xpos, &ypos, input[nfiles].fp) != |
| 138 |
> |
(YMAJOR|YDECR)) { |
| 139 |
|
eputs(input[nfiles].name); |
| 140 |
|
eputs(": bad picture size\n"); |
| 141 |
|
quit(1); |
| 153 |
|
} |
| 154 |
|
printargs(argc, argv, stdout); |
| 155 |
|
putchar('\n'); |
| 156 |
< |
printf("-Y %d +X %d\n", yres, xres); |
| 156 |
> |
fputresolu(YMAJOR|YDECR, xres, yres, stdout); |
| 157 |
|
combine(); |
| 158 |
|
quit(0); |
| 159 |
+ |
usage: |
| 160 |
+ |
eputs("Usage: "); |
| 161 |
+ |
eputs(argv[0]); |
| 162 |
+ |
eputs(" [-w][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] picture ..]\n"); |
| 163 |
+ |
quit(1); |
| 164 |
|
} |
| 165 |
|
|
| 166 |
|
|
| 167 |
|
combine() /* combine pictures */ |
| 168 |
|
{ |
| 169 |
< |
int coldef[3]; |
| 169 |
> |
EPNODE *coldef[3], *brtdef; |
| 170 |
|
COLOR *scanout; |
| 171 |
+ |
double d; |
| 172 |
|
register int i, j; |
| 173 |
|
/* check defined variables */ |
| 174 |
< |
for (j = 0; j < 3; j++) |
| 175 |
< |
coldef[j] = vardefined(vcolout[j]); |
| 174 |
> |
for (j = 0; j < 3; j++) { |
| 175 |
> |
if (vardefined(vcolout[j])) |
| 176 |
> |
coldef[j] = eparse(vcolout[j]); |
| 177 |
> |
else |
| 178 |
> |
coldef[j] = NULL; |
| 179 |
> |
} |
| 180 |
> |
if (vardefined(vbrtout)) |
| 181 |
> |
brtdef = eparse(vbrtout); |
| 182 |
> |
else |
| 183 |
> |
brtdef = NULL; |
| 184 |
> |
/* predefine variables */ |
| 185 |
> |
varset(vnfiles, (double)nfiles); |
| 186 |
> |
varset(vxres, (double)xres); |
| 187 |
> |
varset(vyres, (double)yres); |
| 188 |
|
/* allocate scanline */ |
| 189 |
|
scanout = (COLOR *)emalloc(xres*sizeof(COLOR)); |
| 190 |
|
/* combine files */ |
| 191 |
|
for (ypos = yres-1; ypos >= 0; ypos--) { |
| 192 |
< |
for (i = 0; i < nfiles; i++) |
| 193 |
< |
if (freadscan(input[i].scan, xres, input[i].fp) < 0) { |
| 194 |
< |
eputs(input[i].name); |
| 195 |
< |
eputs(": read error\n"); |
| 196 |
< |
quit(1); |
| 192 |
> |
for (i = 0; i < nfiles; i++) |
| 193 |
> |
if (freadscan(input[i].scan, xres, input[i].fp) < 0) { |
| 194 |
> |
eputs(input[i].name); |
| 195 |
> |
eputs(": read error\n"); |
| 196 |
> |
quit(1); |
| 197 |
> |
} |
| 198 |
> |
varset(vypos, (double)ypos); |
| 199 |
> |
for (xpos = 0; xpos < xres; xpos++) { |
| 200 |
> |
varset(vxpos, (double)xpos); |
| 201 |
> |
eclock++; |
| 202 |
> |
if (brtdef != NULL) { |
| 203 |
> |
d = evalue(brtdef); |
| 204 |
> |
if (d < 0.0) |
| 205 |
> |
d = 0.0; |
| 206 |
> |
setcolor(scanout[xpos], d, d, d); |
| 207 |
> |
} else { |
| 208 |
> |
for (j = 0; j < 3; j++) { |
| 209 |
> |
if (coldef[j] != NULL) { |
| 210 |
> |
colval(scanout[xpos],j) = evalue(coldef[j]); |
| 211 |
> |
} else { |
| 212 |
> |
colval(scanout[xpos],j) = 0.0; |
| 213 |
> |
for (i = 0; i < nfiles; i++) |
| 214 |
> |
colval(scanout[xpos],j) += |
| 215 |
> |
colval(input[i].coef,j) * |
| 216 |
> |
colval(input[i].scan[xpos],j); |
| 217 |
|
} |
| 218 |
< |
varset(vypos, (double)ypos); |
| 219 |
< |
for (xpos = 0; xpos < xres; xpos++) { |
| 220 |
< |
varset(vxpos, (double)xpos); |
| 159 |
< |
eclock++; |
| 160 |
< |
for (j = 0; j < 3; j++) |
| 161 |
< |
if (coldef[j]) { |
| 162 |
< |
colval(scanout[xpos],j) = varvalue(vcolout[j]); |
| 163 |
< |
if (colval(scanout[xpos],j) < 0.0) |
| 164 |
< |
colval(scanout[xpos],j) = 0.0; |
| 165 |
< |
} else { |
| 166 |
< |
colval(scanout[xpos],j) = 0.0; |
| 167 |
< |
for (i = 0; i < nfiles; i++) |
| 168 |
< |
colval(scanout[xpos],j) += colval(input[i].scan[xpos],j); |
| 169 |
< |
} |
| 218 |
> |
if (colval(scanout[xpos],j) < 0.0) |
| 219 |
> |
colval(scanout[xpos],j) = 0.0; |
| 220 |
> |
} |
| 221 |
|
} |
| 222 |
< |
if (fwritescan(scanout, xres, stdout) < 0) { |
| 223 |
< |
eputs("write error\n"); |
| 224 |
< |
quit(1); |
| 225 |
< |
} |
| 222 |
> |
} |
| 223 |
> |
if (fwritescan(scanout, xres, stdout) < 0) { |
| 224 |
> |
perror("write error"); |
| 225 |
> |
quit(1); |
| 226 |
> |
} |
| 227 |
|
} |
| 228 |
|
efree(scanout); |
| 229 |
|
} |
| 261 |
|
l_bluin() /* get blue color */ |
| 262 |
|
{ |
| 263 |
|
return(colin((int)(argument(1)+.5), BLU)); |
| 264 |
+ |
} |
| 265 |
+ |
|
| 266 |
+ |
|
| 267 |
+ |
double |
| 268 |
+ |
l_brtin() /* get brightness value */ |
| 269 |
+ |
{ |
| 270 |
+ |
register int fn; |
| 271 |
+ |
|
| 272 |
+ |
fn = argument(1)+.5; |
| 273 |
+ |
if (fn == 0) |
| 274 |
+ |
return((double)nfiles); |
| 275 |
+ |
if (fn < 1 || fn > nfiles) { |
| 276 |
+ |
errno = EDOM; |
| 277 |
+ |
return(0.0); |
| 278 |
+ |
} |
| 279 |
+ |
return(bright(input[fn-1].scan[xpos])); |
| 280 |
|
} |
| 281 |
|
|
| 282 |
|
|