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