| 1 |
< |
/* Copyright (c) 1991 Regents of the University of California */ |
| 1 |
> |
/* Copyright (c) 1992 Regents of the University of California */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ LBL"; |
| 12 |
|
|
| 13 |
|
#include <stdio.h> |
| 14 |
|
|
| 15 |
+ |
#ifdef MSDOS |
| 16 |
+ |
#include <fcntl.h> |
| 17 |
+ |
#endif |
| 18 |
+ |
|
| 19 |
+ |
#include <math.h> |
| 20 |
+ |
|
| 21 |
|
#include <errno.h> |
| 22 |
|
|
| 23 |
|
#include "color.h" |
| 24 |
|
|
| 25 |
+ |
#include "resolu.h" |
| 26 |
+ |
|
| 27 |
|
#include "calcomp.h" |
| 28 |
|
|
| 29 |
|
#define MAXINP 32 /* maximum number of input files */ |
| 30 |
|
#define WINSIZ 9 /* scanline window size */ |
| 31 |
|
#define MIDSCN 4 /* current scan position */ |
| 32 |
|
|
| 25 |
– |
#define BRT (-1) /* special index for brightness */ |
| 26 |
– |
|
| 33 |
|
struct { |
| 34 |
|
char *name; /* file or command name */ |
| 35 |
|
FILE *fp; /* stream pointer */ |
| 40 |
|
|
| 41 |
|
int nfiles; /* number of input files */ |
| 42 |
|
|
| 43 |
< |
char *vcolin[3] = {"ri", "gi", "bi"}; |
| 44 |
< |
char *vcolout[3] = {"ro", "go", "bo"}; |
| 43 |
> |
char Command[] = "<Command>"; |
| 44 |
> |
char vcolin[3][4] = {"ri", "gi", "bi"}; |
| 45 |
> |
char vcolout[3][4] = {"ro", "go", "bo"}; |
| 46 |
|
char vbrtin[] = "li"; |
| 47 |
|
char vbrtout[] = "lo"; |
| 48 |
< |
char *vcolexp[3] = {"re", "ge", "be"}; |
| 48 |
> |
char vcolexp[3][4] = {"re", "ge", "be"}; |
| 49 |
|
char vbrtexp[] = "le"; |
| 50 |
|
|
| 51 |
|
char vnfiles[] = "nfiles"; |
| 70 |
|
|
| 71 |
|
FILE *popen(); |
| 72 |
|
|
| 73 |
+ |
extern char *emalloc(); |
| 74 |
|
|
| 75 |
+ |
|
| 76 |
|
main(argc, argv) |
| 77 |
|
int argc; |
| 78 |
|
char *argv[]; |
| 79 |
|
{ |
| 71 |
– |
char buf[128]; |
| 80 |
|
int original; |
| 81 |
|
double f; |
| 82 |
|
int a, i; |
| 83 |
+ |
#ifdef MSDOS |
| 84 |
+ |
extern int _fmode; |
| 85 |
+ |
_fmode = O_BINARY; |
| 86 |
+ |
setmode(fileno(stdin), O_BINARY); |
| 87 |
+ |
setmode(fileno(stdout), O_BINARY); |
| 88 |
+ |
#endif |
| 89 |
|
/* scan options */ |
| 90 |
|
for (a = 1; a < argc; a++) { |
| 91 |
|
if (argv[a][0] == '-') |
| 125 |
|
break; |
| 126 |
|
case 'o': |
| 127 |
|
original++; |
| 128 |
< |
break; |
| 128 |
> |
continue; |
| 129 |
|
case 's': |
| 130 |
|
f = atof(argv[++a]); |
| 131 |
|
scalecolor(input[nfiles].coef, f); |
| 139 |
|
goto usage; |
| 140 |
|
} |
| 141 |
|
else { |
| 142 |
< |
input[nfiles].name = argv[a]; |
| 143 |
< |
input[nfiles].fp = argv[a][0]=='!' ? |
| 144 |
< |
popen(argv[a]+1, "r") : |
| 145 |
< |
fopen(argv[a], "r"); |
| 142 |
> |
if (argv[a][0] == '!') { |
| 143 |
> |
input[nfiles].name = Command; |
| 144 |
> |
input[nfiles].fp = popen(argv[a]+1, "r"); |
| 145 |
> |
} else { |
| 146 |
> |
input[nfiles].name = argv[a]; |
| 147 |
> |
input[nfiles].fp = fopen(argv[a], "r"); |
| 148 |
> |
} |
| 149 |
|
if (input[nfiles].fp == NULL) { |
| 150 |
|
perror(argv[a]); |
| 151 |
|
quit(1); |
| 169 |
|
if (argv[a][0] == '-') |
| 170 |
|
switch (argv[a][1]) { |
| 171 |
|
case 'x': |
| 172 |
< |
strcpy(buf, vxres); |
| 156 |
< |
strcat(buf, ":"); |
| 157 |
< |
strcat(buf, argv[++a]); |
| 158 |
< |
scompile(buf, NULL, 0); |
| 172 |
> |
varset(vxres, ':', eval(argv[++a])); |
| 173 |
|
continue; |
| 174 |
|
case 'y': |
| 175 |
< |
strcpy(buf, vyres); |
| 162 |
< |
strcat(buf, ":"); |
| 163 |
< |
strcat(buf, argv[++a]); |
| 164 |
< |
scompile(buf, NULL, 0); |
| 175 |
> |
varset(vyres, ':', eval(argv[++a])); |
| 176 |
|
continue; |
| 177 |
|
case 'w': |
| 178 |
|
continue; |
| 201 |
|
printargs(argc, argv, stdout); |
| 202 |
|
fputformat(COLRFMT, stdout); |
| 203 |
|
putchar('\n'); |
| 204 |
< |
fputresolu(YMAJOR|YDECR, xres, yres, stdout); |
| 204 |
> |
fprtresolu(xres, yres, stdout); |
| 205 |
|
/* combine pictures */ |
| 206 |
|
combine(); |
| 207 |
|
quit(0); |
| 209 |
|
eputs("Usage: "); |
| 210 |
|
eputs(argv[0]); |
| 211 |
|
eputs( |
| 212 |
< |
" [-w][-x xr][-y yr][-e expr][-f file] [ [-s f][-c r g b] pic ..]\n"); |
| 212 |
> |
" [-w][-x xr][-y yr][-e expr][-f file] [ [-o][-s f][-c r g b] pic ..]\n"); |
| 213 |
|
quit(1); |
| 214 |
|
} |
| 215 |
|
|
| 252 |
|
eputs(": not in Radiance picture format\n"); |
| 253 |
|
quit(1); |
| 254 |
|
} |
| 255 |
< |
if (fgetresolu(&xinp, &yinp, input[nfiles].fp) != (YMAJOR|YDECR)) { |
| 255 |
> |
if (fgetresolu(&xinp, &yinp, input[nfiles].fp) < 0) { |
| 256 |
|
eputs(input[nfiles].name); |
| 257 |
|
eputs(": bad picture size\n"); |
| 258 |
|
quit(1); |
| 361 |
|
input[i].scan[0] = st; |
| 362 |
|
if (yscan <= MIDSCN) /* hit bottom? */ |
| 363 |
|
continue; |
| 364 |
< |
if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ |
| 364 |
> |
if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ |
| 365 |
|
eputs(input[i].name); |
| 366 |
|
eputs(": read error\n"); |
| 367 |
|
quit(1); |
| 368 |
|
} |
| 369 |
< |
for (j = 0; j < xmax; j++) /* adjust color */ |
| 370 |
< |
multcolor(st[j], input[i].coef); |
| 369 |
> |
if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 || |
| 370 |
> |
fabs(colval(input[i].coef,GRN)-1.0) > 1e-3 || |
| 371 |
> |
fabs(colval(input[i].coef,BLU)-1.0) > 1e-3) |
| 372 |
> |
for (j = 0; j < xmax; j++) /* adjust color */ |
| 373 |
> |
multcolor(st[j], input[i].coef); |
| 374 |
|
} |
| 375 |
|
} |
| 376 |
|
|
| 467 |
|
} |
| 468 |
|
|
| 469 |
|
|
| 470 |
< |
quit(code) |
| 471 |
< |
int code; |
| 470 |
> |
quit(code) /* exit gracefully */ |
| 471 |
> |
int code; |
| 472 |
|
{ |
| 473 |
+ |
register int i; |
| 474 |
+ |
/* close input files */ |
| 475 |
+ |
for (i = 0; i < nfiles; i++) |
| 476 |
+ |
if (input[i].name == Command) |
| 477 |
+ |
pclose(input[i].fp); |
| 478 |
+ |
else |
| 479 |
+ |
fclose(input[i].fp); |
| 480 |
|
exit(code); |
| 481 |
|
} |