| 1 |
greg |
1.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 |
|
|
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 |
|
|
} else |
| 39 |
|
|
break; |
| 40 |
|
|
if (!argc) { |
| 41 |
|
|
fputs("Usage: ", stderr); |
| 42 |
|
|
fputs(progname, stderr); |
| 43 |
|
|
fputs(" [-p port] hostname [-c copies][-r record] [frame] ..\n", |
| 44 |
|
|
stderr); |
| 45 |
|
|
exit(1); |
| 46 |
|
|
} |
| 47 |
|
|
scry_open(*argv++, TCP, port); |
| 48 |
|
|
scry_set_compress(NONE); |
| 49 |
|
|
scry_set_image(TARGA_IMAGE); |
| 50 |
|
|
scry_set_record(PREVIEW); |
| 51 |
|
|
scry_set_copy_num(3); |
| 52 |
|
|
/* send frames */ |
| 53 |
|
|
nframes = 0; |
| 54 |
|
|
for ( ; --argc; argv++) |
| 55 |
|
|
if (!strcmp(*argv, "-r") && argv[1]) { |
| 56 |
|
|
scry_set_record(atoi(*++argv)); argc--; |
| 57 |
|
|
} else if (!strcmp(*argv, "-c") && argv[1]) { |
| 58 |
|
|
scry_set_copy_num(atoi(*++argv)); argc--; |
| 59 |
|
|
} else { |
| 60 |
|
|
sendframe(*argv); |
| 61 |
|
|
nframes++; |
| 62 |
|
|
} |
| 63 |
|
|
if (nframes == 0) /* get stdin */ |
| 64 |
|
|
sendframe(NULL); |
| 65 |
|
|
/* clean up */ |
| 66 |
|
|
scry_close(); |
| 67 |
|
|
exit(0); |
| 68 |
|
|
} |
| 69 |
|
|
|
| 70 |
|
|
|
| 71 |
|
|
sendframe(file) /* convert and send a frame */ |
| 72 |
|
|
char *file; |
| 73 |
|
|
{ |
| 74 |
|
|
COLR scanin[SCANLINE]; |
| 75 |
|
|
int xres, yres; |
| 76 |
|
|
int xbeg, ybeg; |
| 77 |
|
|
FILE *fp; |
| 78 |
greg |
1.3 |
int y; |
| 79 |
|
|
register int x; |
| 80 |
greg |
1.1 |
/* open file */ |
| 81 |
|
|
if (file == NULL) { |
| 82 |
|
|
fp = stdin; |
| 83 |
|
|
file = "<stdin>"; |
| 84 |
|
|
} else if ((fp = fopen(file, "r")) == NULL) { |
| 85 |
|
|
perror(file); |
| 86 |
|
|
exit(1); |
| 87 |
|
|
} |
| 88 |
|
|
/* get dimensions */ |
| 89 |
|
|
getheader(fp, NULL); |
| 90 |
greg |
1.2 |
if (fgetresolu(&xres, &yres, fp) != (YMAJOR|YDECR) || |
| 91 |
greg |
1.1 |
xres > SCANLINE || yres > NUMSCANS) { |
| 92 |
|
|
fputs(file, stderr); |
| 93 |
|
|
fputs(": bad picture size\n", stderr); |
| 94 |
|
|
exit(1); |
| 95 |
|
|
} |
| 96 |
|
|
/* compute center */ |
| 97 |
|
|
xbeg = (SCANLINE-xres)/2; |
| 98 |
|
|
ybeg = (NUMSCANS-yres)/2; |
| 99 |
|
|
/* clear output */ |
| 100 |
|
|
bzero(sc_frame_arr, sizeof(sc_frame_arr)); |
| 101 |
|
|
/* get frame */ |
| 102 |
greg |
1.3 |
for (y = yres-1; y >= 0; y--) { |
| 103 |
greg |
1.1 |
if (freadcolrs(scanin, xres, fp) < 0) { |
| 104 |
|
|
fputs(file, stderr); |
| 105 |
|
|
fputs(": read error\n", stderr); |
| 106 |
|
|
exit(1); |
| 107 |
|
|
} |
| 108 |
greg |
1.4 |
normcolrs(scanin, xres, 0); /* normalize */ |
| 109 |
greg |
1.3 |
for (x = 0; x < xres; x++) /* convert */ |
| 110 |
|
|
sc_frame_arr[y+ybeg][x+xbeg] = |
| 111 |
|
|
((gammamap[scanin[x][RED]]+(random()&7))&0xf8)<<7 |
| 112 |
|
|
| ((gammamap[scanin[x][GRN]]+(random()&7))&0xf8)<<2 |
| 113 |
|
|
| (gammamap[scanin[x][BLU]]+(random()&7))>>3; |
| 114 |
greg |
1.1 |
} |
| 115 |
|
|
/* send frame */ |
| 116 |
|
|
scry_send_frame(); |
| 117 |
|
|
/* close file */ |
| 118 |
|
|
fclose(fp); |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
|
|
| 122 |
|
|
compgamma() /* compute gamma correction map */ |
| 123 |
|
|
{ |
| 124 |
|
|
extern double pow(); |
| 125 |
|
|
register int i, val; |
| 126 |
|
|
|
| 127 |
|
|
for (i = 0; i < 256; i++) { |
| 128 |
|
|
val = pow(i/256.0, 1.0/GAMMA) * 256.0; |
| 129 |
|
|
if (val > 248) val = 248; |
| 130 |
|
|
gammamap[i] = val; |
| 131 |
|
|
} |
| 132 |
|
|
} |