1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
2.2 |
static const char RCSid[] = "$Id$"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Send pictures to PC animation system. |
6 |
|
|
* |
7 |
|
|
* 6/20/88 |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#include <stdio.h> |
11 |
|
|
|
12 |
|
|
#include "random.h" |
13 |
|
|
#include "color.h" |
14 |
|
|
#include "clntrpc.h" |
15 |
|
|
#include "scan.h" |
16 |
|
|
|
17 |
|
|
#define GAMMA 2.0 /* gamma correction factor */ |
18 |
|
|
|
19 |
greg |
1.5 |
FILE *popen(); |
20 |
|
|
|
21 |
|
|
char *pcom = NULL; /* pipe command */ |
22 |
|
|
|
23 |
greg |
1.1 |
BYTE gammamap[256]; /* gamma correction table */ |
24 |
|
|
|
25 |
|
|
|
26 |
|
|
main(argc, argv) |
27 |
|
|
int argc; |
28 |
|
|
char *argv[]; |
29 |
|
|
{ |
30 |
|
|
char *progname; |
31 |
|
|
int nframes; |
32 |
|
|
int port = PCPROGRAM; |
33 |
|
|
/* initialize */ |
34 |
|
|
compgamma(); |
35 |
|
|
for (progname = *argv++; --argc; argv++) |
36 |
|
|
if (!strcmp(*argv, "-p") && argv[1]) { |
37 |
|
|
port = atoi(*++argv); argc--; |
38 |
greg |
1.5 |
} else if (!strcmp(*argv, "-u") && argv[1]) { |
39 |
|
|
pcom = *++argv; argc--; |
40 |
greg |
1.1 |
} else |
41 |
|
|
break; |
42 |
|
|
if (!argc) { |
43 |
|
|
fputs("Usage: ", stderr); |
44 |
|
|
fputs(progname, stderr); |
45 |
greg |
1.5 |
fputs(" [-p port] [-u uncompress] hostname [-c copies][-r record] [frame] ..\n", |
46 |
greg |
1.1 |
stderr); |
47 |
|
|
exit(1); |
48 |
|
|
} |
49 |
|
|
scry_open(*argv++, TCP, port); |
50 |
|
|
scry_set_compress(NONE); |
51 |
|
|
scry_set_image(TARGA_IMAGE); |
52 |
|
|
scry_set_record(PREVIEW); |
53 |
|
|
scry_set_copy_num(3); |
54 |
|
|
/* send frames */ |
55 |
|
|
nframes = 0; |
56 |
|
|
for ( ; --argc; argv++) |
57 |
|
|
if (!strcmp(*argv, "-r") && argv[1]) { |
58 |
|
|
scry_set_record(atoi(*++argv)); argc--; |
59 |
|
|
} else if (!strcmp(*argv, "-c") && argv[1]) { |
60 |
|
|
scry_set_copy_num(atoi(*++argv)); argc--; |
61 |
|
|
} else { |
62 |
|
|
sendframe(*argv); |
63 |
|
|
nframes++; |
64 |
|
|
} |
65 |
|
|
if (nframes == 0) /* get stdin */ |
66 |
|
|
sendframe(NULL); |
67 |
|
|
/* clean up */ |
68 |
|
|
scry_close(); |
69 |
|
|
exit(0); |
70 |
|
|
} |
71 |
|
|
|
72 |
|
|
|
73 |
|
|
sendframe(file) /* convert and send a frame */ |
74 |
|
|
char *file; |
75 |
|
|
{ |
76 |
greg |
1.5 |
char command[128]; |
77 |
greg |
1.1 |
COLR scanin[SCANLINE]; |
78 |
|
|
int xres, yres; |
79 |
|
|
int xbeg, ybeg; |
80 |
|
|
FILE *fp; |
81 |
greg |
1.3 |
int y; |
82 |
|
|
register int x; |
83 |
greg |
1.1 |
/* open file */ |
84 |
|
|
if (file == NULL) { |
85 |
greg |
1.5 |
if (pcom != NULL) |
86 |
|
|
fp = popen(pcom, "r"); |
87 |
|
|
else |
88 |
|
|
fp = stdin; |
89 |
greg |
1.1 |
file = "<stdin>"; |
90 |
greg |
1.5 |
} else { |
91 |
|
|
if (pcom != NULL) { |
92 |
|
|
sprintf(command, "( %s ) < %s", pcom, file); |
93 |
|
|
fp = popen(command, "r"); |
94 |
|
|
} else |
95 |
|
|
fp = fopen(file, "r"); |
96 |
|
|
} |
97 |
|
|
if (fp == NULL) { |
98 |
greg |
1.1 |
perror(file); |
99 |
|
|
exit(1); |
100 |
|
|
} |
101 |
|
|
/* get dimensions */ |
102 |
|
|
getheader(fp, NULL); |
103 |
greg |
1.8 |
if (checkheader(fp, COLRFMT, NULL) < 0) { |
104 |
|
|
fputs(file, stderr); |
105 |
|
|
fputs(": not a Radiance picture\n", stderr); |
106 |
|
|
exit(1); |
107 |
|
|
} |
108 |
greg |
1.2 |
if (fgetresolu(&xres, &yres, fp) != (YMAJOR|YDECR) || |
109 |
greg |
1.1 |
xres > SCANLINE || yres > NUMSCANS) { |
110 |
|
|
fputs(file, stderr); |
111 |
|
|
fputs(": bad picture size\n", stderr); |
112 |
|
|
exit(1); |
113 |
|
|
} |
114 |
|
|
/* compute center */ |
115 |
|
|
xbeg = (SCANLINE-xres)/2; |
116 |
|
|
ybeg = (NUMSCANS-yres)/2; |
117 |
|
|
/* clear output */ |
118 |
|
|
bzero(sc_frame_arr, sizeof(sc_frame_arr)); |
119 |
|
|
/* get frame */ |
120 |
greg |
1.3 |
for (y = yres-1; y >= 0; y--) { |
121 |
greg |
1.1 |
if (freadcolrs(scanin, xres, fp) < 0) { |
122 |
|
|
fputs(file, stderr); |
123 |
|
|
fputs(": read error\n", stderr); |
124 |
|
|
exit(1); |
125 |
|
|
} |
126 |
greg |
1.4 |
normcolrs(scanin, xres, 0); /* normalize */ |
127 |
greg |
1.3 |
for (x = 0; x < xres; x++) /* convert */ |
128 |
|
|
sc_frame_arr[y+ybeg][x+xbeg] = |
129 |
|
|
((gammamap[scanin[x][RED]]+(random()&7))&0xf8)<<7 |
130 |
|
|
| ((gammamap[scanin[x][GRN]]+(random()&7))&0xf8)<<2 |
131 |
|
|
| (gammamap[scanin[x][BLU]]+(random()&7))>>3; |
132 |
greg |
1.1 |
} |
133 |
|
|
/* send frame */ |
134 |
|
|
scry_send_frame(); |
135 |
|
|
/* close file */ |
136 |
greg |
1.5 |
if (pcom != NULL) |
137 |
|
|
pclose(fp); |
138 |
|
|
else |
139 |
|
|
fclose(fp); |
140 |
greg |
1.1 |
} |
141 |
|
|
|
142 |
|
|
|
143 |
|
|
compgamma() /* compute gamma correction map */ |
144 |
|
|
{ |
145 |
|
|
extern double pow(); |
146 |
|
|
register int i, val; |
147 |
|
|
|
148 |
|
|
for (i = 0; i < 256; i++) { |
149 |
greg |
1.7 |
val = pow((i+0.5)/256.0, 1.0/GAMMA) * 256.0; |
150 |
greg |
1.1 |
if (val > 248) val = 248; |
151 |
|
|
gammamap[i] = val; |
152 |
|
|
} |
153 |
|
|
} |