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 <errno.h> |
20 |
|
|
21 |
|
#include "color.h" |
38 |
|
|
39 |
|
int nfiles; /* number of input files */ |
40 |
|
|
41 |
+ |
char Command[] = "<Command>"; |
42 |
|
char vcolin[3][4] = {"ri", "gi", "bi"}; |
43 |
|
char vcolout[3][4] = {"ro", "go", "bo"}; |
44 |
|
char vbrtin[] = "li"; |
68 |
|
|
69 |
|
FILE *popen(); |
70 |
|
|
71 |
+ |
extern char *emalloc(); |
72 |
|
|
73 |
+ |
|
74 |
|
main(argc, argv) |
75 |
|
int argc; |
76 |
|
char *argv[]; |
78 |
|
int original; |
79 |
|
double f; |
80 |
|
int a, i; |
81 |
+ |
#ifdef MSDOS |
82 |
+ |
extern int _fmode; |
83 |
+ |
_fmode = O_BINARY; |
84 |
+ |
setmode(fileno(stdin), O_BINARY); |
85 |
+ |
setmode(fileno(stdout), O_BINARY); |
86 |
+ |
#endif |
87 |
|
/* scan options */ |
88 |
|
for (a = 1; a < argc; a++) { |
89 |
|
if (argv[a][0] == '-') |
137 |
|
goto usage; |
138 |
|
} |
139 |
|
else { |
140 |
< |
input[nfiles].name = argv[a]; |
141 |
< |
input[nfiles].fp = argv[a][0]=='!' ? |
142 |
< |
popen(argv[a]+1, "r") : |
143 |
< |
fopen(argv[a], "r"); |
140 |
> |
if (argv[a][0] == '!') { |
141 |
> |
input[nfiles].name = Command; |
142 |
> |
input[nfiles].fp = popen(argv[a]+1, "r"); |
143 |
> |
} else { |
144 |
> |
input[nfiles].name = argv[a]; |
145 |
> |
input[nfiles].fp = fopen(argv[a], "r"); |
146 |
> |
} |
147 |
|
if (input[nfiles].fp == NULL) { |
148 |
|
perror(argv[a]); |
149 |
|
quit(1); |
347 |
|
|
348 |
|
advance() /* read in data for next scanline */ |
349 |
|
{ |
350 |
+ |
extern double fabs(); |
351 |
|
int ytarget; |
352 |
|
register COLOR *st; |
353 |
|
register int i, j; |
360 |
|
input[i].scan[0] = st; |
361 |
|
if (yscan <= MIDSCN) /* hit bottom? */ |
362 |
|
continue; |
363 |
< |
if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ |
363 |
> |
if (freadscan(st, xmax, input[i].fp) < 0) { /* read */ |
364 |
|
eputs(input[i].name); |
365 |
|
eputs(": read error\n"); |
366 |
|
quit(1); |
367 |
|
} |
368 |
< |
for (j = 0; j < xmax; j++) /* adjust color */ |
369 |
< |
multcolor(st[j], input[i].coef); |
368 |
> |
if (fabs(colval(input[i].coef,RED)-1.0) > 1e-3 || |
369 |
> |
fabs(colval(input[i].coef,GRN)-1.0) > 1e-3 || |
370 |
> |
fabs(colval(input[i].coef,BLU)-1.0) > 1e-3) |
371 |
> |
for (j = 0; j < xmax; j++) /* adjust color */ |
372 |
> |
multcolor(st[j], input[i].coef); |
373 |
|
} |
374 |
|
} |
375 |
|
|
466 |
|
} |
467 |
|
|
468 |
|
|
469 |
< |
quit(code) |
470 |
< |
int code; |
469 |
> |
quit(code) /* exit gracefully */ |
470 |
> |
int code; |
471 |
|
{ |
472 |
+ |
register int i; |
473 |
+ |
/* close input files */ |
474 |
+ |
for (i = 0; i < nfiles; i++) |
475 |
+ |
if (input[i].name == Command) |
476 |
+ |
pclose(input[i].fp); |
477 |
+ |
else |
478 |
+ |
fclose(input[i].fp); |
479 |
|
exit(code); |
480 |
|
} |