1 |
greg |
1.1 |
#ifndef lint |
2 |
greg |
1.2 |
static const char RCSid[] = "$Id$"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Send Sun rasterfiles to PC animation system. |
6 |
|
|
* |
7 |
|
|
* 6/20/88 |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#include <stdio.h> |
11 |
|
|
#include <rasterfile.h> |
12 |
|
|
|
13 |
|
|
#include "client/clnt.h" |
14 |
|
|
|
15 |
|
|
FILE *popen(); |
16 |
|
|
|
17 |
|
|
char *pcom = NULL; /* uncompress command */ |
18 |
|
|
|
19 |
|
|
|
20 |
|
|
main(argc, argv) |
21 |
|
|
int argc; |
22 |
|
|
char **argv; |
23 |
|
|
{ |
24 |
|
|
int startrec = 0; |
25 |
|
|
char *progname; |
26 |
|
|
int prognum = PCPROGRAM; |
27 |
|
|
/* initialize */ |
28 |
|
|
for (progname = *argv++; --argc; argv++) |
29 |
|
|
if (!strcmp(*argv, "-p") && argv[1]) { |
30 |
|
|
prognum = atoi(*++argv); argc--; |
31 |
|
|
} else if (!strcmp(*argv, "-u") && argv[1]) { |
32 |
|
|
pcom = *++argv; argc--; |
33 |
|
|
} else if (!strcmp(*argv, "-r") && argv[1]) { |
34 |
|
|
startrec = atoi(*++argv); argc--; |
35 |
|
|
} else |
36 |
|
|
break; |
37 |
|
|
if (!argc) { |
38 |
|
|
fputs("Usage: ", stderr); |
39 |
|
|
fputs(progname, stderr); |
40 |
|
|
fputs(" [-p prognum] [-u uncompress] [-r record] hostname [frame..]\n", |
41 |
|
|
stderr); |
42 |
|
|
exit(1); |
43 |
|
|
} |
44 |
|
|
scry_open(*argv++, prognum); argc--; |
45 |
|
|
scry_get_info(1) ; |
46 |
|
|
scry_set_compress(NONE); |
47 |
|
|
if (startrec > 0) |
48 |
|
|
scry_init_record(startrec, argc>0?argc:1); |
49 |
|
|
else |
50 |
|
|
scry_init_record(PREVIEW,0); |
51 |
|
|
/* send frames */ |
52 |
|
|
if (argc <= 0) |
53 |
|
|
sendframe(NULL); |
54 |
|
|
else |
55 |
|
|
for ( ; argc > 0; argc--, argv++) |
56 |
|
|
sendframe(*argv); |
57 |
|
|
/* clean up */ |
58 |
|
|
scry_close(); |
59 |
|
|
exit(0); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
|
63 |
|
|
sendframe(file) /* convert and send a frame */ |
64 |
|
|
char *file; |
65 |
|
|
{ |
66 |
|
|
static struct rasterfile head; |
67 |
|
|
char command[128]; |
68 |
|
|
unsigned char cmap[3][256]; |
69 |
|
|
unsigned char dmap[256][3] ; |
70 |
|
|
static unsigned short targa[256]; |
71 |
|
|
static int xbeg, ybeg; |
72 |
|
|
register FILE *fp; |
73 |
|
|
register int i, j; |
74 |
|
|
register int c; |
75 |
|
|
/* DAVIDR */ |
76 |
|
|
unsigned char *image_read, *newimage, *compdata ; |
77 |
|
|
int new_ht, new_wd, new_depth ; |
78 |
|
|
/* end DAVIDR */ |
79 |
|
|
/* open file */ |
80 |
|
|
if (file == NULL) { |
81 |
|
|
if (pcom != NULL) |
82 |
|
|
fp = popen(pcom, "r"); |
83 |
|
|
else |
84 |
|
|
fp = stdin; |
85 |
|
|
file = "<stdin>"; |
86 |
|
|
} else { |
87 |
|
|
if (pcom != NULL) { |
88 |
|
|
sprintf(command, "( %s ) < %s", pcom, file); |
89 |
|
|
fp = popen(command, "r"); |
90 |
|
|
} else |
91 |
|
|
fp = fopen(file, "r"); |
92 |
|
|
} |
93 |
|
|
if (fp == NULL) { |
94 |
|
|
perror(file); |
95 |
|
|
exit(1); |
96 |
|
|
} |
97 |
|
|
/* check format */ |
98 |
|
|
if (fread(&head, sizeof(head), 1, fp) != 1) |
99 |
|
|
goto rasfmt; |
100 |
|
|
if (head.ras_magic != RAS_MAGIC || head.ras_type != RT_STANDARD) |
101 |
|
|
goto rasfmt; |
102 |
|
|
if (head.ras_maptype != RMT_EQUAL_RGB || head.ras_maplength != 3*256) |
103 |
|
|
goto rasfmt; |
104 |
|
|
/* get color table */ |
105 |
|
|
if (fread(cmap, 256, 3, fp) != 3) |
106 |
|
|
goto readerr; |
107 |
|
|
/* convert table */ |
108 |
|
|
#ifdef LATER |
109 |
|
|
for (j = 0; j < 253; j++) |
110 |
|
|
targa[j+1] = (cmap[0][j] & 0xf8)<<7 | |
111 |
|
|
(cmap[1][j] & 0xf8)<<2 | cmap[2][j]>>3; |
112 |
|
|
#endif |
113 |
|
|
for (j = 0 ; j < 256 ; j++) |
114 |
|
|
{ |
115 |
|
|
dmap[j][0] = cmap[0][j] ; |
116 |
|
|
dmap[j][1] = cmap[1][j] ; |
117 |
|
|
dmap[j][2] = cmap[2][j] ; |
118 |
|
|
} |
119 |
|
|
/* send table */ |
120 |
|
|
scry_set_map(254, dmap); |
121 |
|
|
image_read = (unsigned char *) malloc(head.ras_width*head.ras_height) ; |
122 |
|
|
for (j = 0 ; j < head.ras_height ; j++) |
123 |
|
|
fread (&(image_read[(head.ras_height-j-1)*head.ras_width]),head.ras_width,1,fp) ; |
124 |
|
|
fread(image_read,head.ras_width*head.ras_height,1,fp) ; |
125 |
|
|
newimage = NULL ; |
126 |
|
|
/* send frame */ |
127 |
|
|
scry_conv_vis (image_read,&newimage,head.ras_height,head.ras_width,&new_ht,&new_wd,1,&new_depth) ; |
128 |
|
|
free (image_read) ; |
129 |
|
|
compdata = NULL ; |
130 |
|
|
scry_compress(newimage,&compdata,new_ht,new_wd,new_depth) ; |
131 |
|
|
scry_send_frame(compdata); |
132 |
|
|
free(compdata) ; |
133 |
|
|
free (newimage) ; |
134 |
|
|
/* close file */ |
135 |
|
|
if (pcom != NULL) |
136 |
|
|
pclose(fp); |
137 |
|
|
else |
138 |
|
|
fclose(fp); |
139 |
|
|
return; |
140 |
|
|
rasfmt: |
141 |
|
|
fputs(file, stderr); |
142 |
|
|
fputs(": wrong rasterfile format\n", stderr); |
143 |
|
|
exit(1); |
144 |
|
|
readerr: |
145 |
|
|
fputs(file, stderr); |
146 |
|
|
fputs(": read error\n", stderr); |
147 |
|
|
exit(1); |
148 |
|
|
} |