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 |
|
|
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] hostname [-c copies][-r record] [frame] ..\n", |
49 |
> |
fputs(" [-p port] [-u uncompress] hostname [-c copies][-r record] [frame] ..\n", |
50 |
|
stderr); |
51 |
|
exit(1); |
52 |
|
} |
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 j; |
86 |
< |
register int k, c; |
80 |
< |
register BYTE *in; |
81 |
< |
short *out; |
85 |
> |
int y; |
86 |
> |
register int x; |
87 |
|
/* open file */ |
88 |
|
if (file == NULL) { |
89 |
< |
fp = stdin; |
89 |
> |
if (pcom != NULL) |
90 |
> |
fp = popen(pcom, "r"); |
91 |
> |
else |
92 |
> |
fp = stdin; |
93 |
|
file = "<stdin>"; |
94 |
< |
} else if ((fp = fopen(file, "r")) == NULL) { |
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 (fscanf(fp, "-Y %d +X %d\n", &yres, &xres) != 2 || |
107 |
> |
if (fgetresolu(&xres, &yres, fp) != (YMAJOR|YDECR) || |
108 |
|
xres > SCANLINE || yres > NUMSCANS) { |
109 |
|
fputs(file, stderr); |
110 |
|
fputs(": bad picture size\n", stderr); |
116 |
|
/* clear output */ |
117 |
|
bzero(sc_frame_arr, sizeof(sc_frame_arr)); |
118 |
|
/* get frame */ |
119 |
< |
for (j = yres-1; j >= 0; j--) { |
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 |
< |
for (in = scanin[0], out = sc_frame_arr[ybeg+j]+xbeg; |
126 |
< |
in < scanin[xres]; in += 4, out++) { |
127 |
< |
k = in[EXP] - COLXS; |
128 |
< |
if (k >= 8) { |
129 |
< |
in[RED] = |
130 |
< |
in[GRN] = |
116 |
< |
in[BLU] = 255; |
117 |
< |
} else if (k <= -8) { |
118 |
< |
in[RED] = |
119 |
< |
in[GRN] = |
120 |
< |
in[BLU] = 0; |
121 |
< |
} else if (k > 0) { |
122 |
< |
c = in[RED] << k; |
123 |
< |
in[RED] = c > 255 ? 255 : c; |
124 |
< |
c = in[GRN] << k; |
125 |
< |
in[GRN] = c > 255 ? 255 : c; |
126 |
< |
c = in[BLU] << k; |
127 |
< |
in[BLU] = c > 255 ? 255 : c; |
128 |
< |
} else if (k < 0) { |
129 |
< |
in[RED] = in[RED] >> -k; |
130 |
< |
in[GRN] = in[GRN] >> -k; |
131 |
< |
in[BLU] = in[BLU] >> -k; |
132 |
< |
} |
133 |
< |
for (k = 0; k < 3; k++) |
134 |
< |
*out = *out<<5 | (gammamap[in[k]]+(random()&0x7))>>3; |
135 |
< |
} |
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 |
< |
fclose(fp); |
135 |
> |
if (pcom != NULL) |
136 |
> |
pclose(fp); |
137 |
> |
else |
138 |
> |
fclose(fp); |
139 |
|
} |
140 |
|
|
141 |
|
|