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