1 |
– |
/* Copyright (c) 1988 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* Send pictures to PC animation system. |
6 |
|
* |
8 |
|
*/ |
9 |
|
|
10 |
|
#include <stdio.h> |
14 |
– |
#include <rasterfile.h> |
11 |
|
|
12 |
|
#include "random.h" |
13 |
|
#include "color.h" |
16 |
|
|
17 |
|
#define GAMMA 2.0 /* gamma correction factor */ |
18 |
|
|
19 |
+ |
FILE *popen(); |
20 |
+ |
|
21 |
+ |
char *pcom = NULL; /* pipe command */ |
22 |
+ |
|
23 |
|
BYTE gammamap[256]; /* gamma correction table */ |
24 |
|
|
25 |
|
|
35 |
|
for (progname = *argv++; --argc; argv++) |
36 |
|
if (!strcmp(*argv, "-p") && argv[1]) { |
37 |
|
port = atoi(*++argv); argc--; |
38 |
+ |
} else if (!strcmp(*argv, "-u") && argv[1]) { |
39 |
+ |
pcom = *++argv; argc--; |
40 |
|
} else |
41 |
|
break; |
42 |
|
if (!argc) { |
43 |
|
fputs("Usage: ", stderr); |
44 |
|
fputs(progname, stderr); |
45 |
< |
fputs(" [-p port] hostname [-c copies][-r record] [frame] ..\n", |
45 |
> |
fputs(" [-p port] [-u uncompress] hostname [-c copies][-r record] [frame] ..\n", |
46 |
|
stderr); |
47 |
|
exit(1); |
48 |
|
} |
73 |
|
sendframe(file) /* convert and send a frame */ |
74 |
|
char *file; |
75 |
|
{ |
76 |
+ |
char command[128]; |
77 |
|
COLR scanin[SCANLINE]; |
78 |
|
int xres, yres; |
79 |
|
int xbeg, ybeg; |
82 |
|
register int x; |
83 |
|
/* open file */ |
84 |
|
if (file == NULL) { |
85 |
< |
fp = stdin; |
85 |
> |
if (pcom != NULL) |
86 |
> |
fp = popen(pcom, "r"); |
87 |
> |
else |
88 |
> |
fp = stdin; |
89 |
|
file = "<stdin>"; |
90 |
< |
} else if ((fp = fopen(file, "r")) == NULL) { |
90 |
> |
} 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 |
|
perror(file); |
99 |
|
exit(1); |
100 |
|
} |
101 |
|
/* get dimensions */ |
102 |
|
getheader(fp, NULL); |
103 |
+ |
if (checkheader(fp, COLRFMT, NULL) < 0) { |
104 |
+ |
fputs(file, stderr); |
105 |
+ |
fputs(": not a Radiance picture\n", stderr); |
106 |
+ |
exit(1); |
107 |
+ |
} |
108 |
|
if (fgetresolu(&xres, &yres, fp) != (YMAJOR|YDECR) || |
109 |
|
xres > SCANLINE || yres > NUMSCANS) { |
110 |
|
fputs(file, stderr); |
133 |
|
/* send frame */ |
134 |
|
scry_send_frame(); |
135 |
|
/* close file */ |
136 |
< |
fclose(fp); |
136 |
> |
if (pcom != NULL) |
137 |
> |
pclose(fp); |
138 |
> |
else |
139 |
> |
fclose(fp); |
140 |
|
} |
141 |
|
|
142 |
|
|
146 |
|
register int i, val; |
147 |
|
|
148 |
|
for (i = 0; i < 256; i++) { |
149 |
< |
val = pow(i/256.0, 1.0/GAMMA) * 256.0; |
149 |
> |
val = pow((i+0.5)/256.0, 1.0/GAMMA) * 256.0; |
150 |
|
if (val > 248) val = 248; |
151 |
|
gammamap[i] = val; |
152 |
|
} |