1 |
greg |
1.1 |
#ifndef lint |
2 |
schorsch |
1.3 |
static const char RCSid[] = "$Id: t16anim.c,v 1.2 2003/02/22 02:07:30 greg Exp $"; |
3 |
greg |
1.1 |
#endif |
4 |
|
|
/* |
5 |
|
|
* Send Targa 16-bit files to PC animation system. |
6 |
|
|
* |
7 |
|
|
* 6/20/88 |
8 |
|
|
*/ |
9 |
|
|
|
10 |
|
|
#include <stdio.h> |
11 |
|
|
|
12 |
schorsch |
1.3 |
#include "rtprocess.h" |
13 |
greg |
1.1 |
#include "client/clnt.h" |
14 |
|
|
#include "targa.h" |
15 |
|
|
|
16 |
|
|
#define goodpic(h) (((h)->dataType==IM_RGB || (h)->dataType==IM_CRGB) \ |
17 |
|
|
&& (h)->dataBits==16) |
18 |
|
|
|
19 |
|
|
|
20 |
|
|
char *pcom = NULL; /* uncompress command */ |
21 |
|
|
|
22 |
|
|
|
23 |
|
|
main(argc, argv) |
24 |
|
|
int argc; |
25 |
|
|
char **argv; |
26 |
|
|
{ |
27 |
|
|
int startrec = 0; |
28 |
|
|
char *progname; |
29 |
|
|
int prognum = PCPROGRAM; |
30 |
|
|
/* initialize */ |
31 |
|
|
for (progname = *argv++; --argc; argv++) |
32 |
|
|
if (!strcmp(*argv, "-p") && argv[1]) { |
33 |
|
|
prognum = atoi(*++argv); argc--; |
34 |
|
|
} else if (!strcmp(*argv, "-u") && argv[1]) { |
35 |
|
|
pcom = *++argv; argc--; |
36 |
|
|
} else if (!strcmp(*argv, "-r") && argv[1]) { |
37 |
|
|
startrec = atoi(*++argv); argc--; |
38 |
|
|
} else |
39 |
|
|
break; |
40 |
|
|
if (!argc) { |
41 |
|
|
fputs("Usage: ", stderr); |
42 |
|
|
fputs(progname, stderr); |
43 |
|
|
fputs(" [-p prognum] [-u uncompress] [-r record] hostname [frame..]\n", |
44 |
|
|
stderr); |
45 |
|
|
exit(1); |
46 |
|
|
} |
47 |
|
|
scry_open(*argv++, prognum); argc--; |
48 |
|
|
scry_get_info(2) ; |
49 |
|
|
scry_set_compress(NONE); |
50 |
|
|
if (startrec > 0) |
51 |
|
|
scry_init_record(startrec, argc>0?argc:1); |
52 |
|
|
else |
53 |
|
|
scry_init_record(PREVIEW,0); |
54 |
|
|
/* send frames */ |
55 |
|
|
if (argc <= 0) |
56 |
|
|
sendframe(NULL); |
57 |
|
|
else |
58 |
|
|
for ( ; argc > 0; argc--, argv++) |
59 |
|
|
sendframe(*argv); |
60 |
|
|
/* clean up */ |
61 |
|
|
scry_close(); |
62 |
|
|
exit(0); |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
|
66 |
|
|
sendframe(file) /* convert and send a frame */ |
67 |
|
|
char *file; |
68 |
|
|
{ |
69 |
|
|
static struct hdStruct head; |
70 |
|
|
char command[128]; |
71 |
|
|
register FILE *fp; |
72 |
|
|
register int i, j; |
73 |
|
|
register int c; |
74 |
|
|
/* DAVIDR */ |
75 |
|
|
unsigned char *image_read,*newimage,*compdata ; |
76 |
|
|
int new_ht, new_wd, new_depth ; |
77 |
|
|
/* end DAVIDR */ |
78 |
|
|
/* open file */ |
79 |
|
|
if (file == NULL) { |
80 |
|
|
if (pcom != NULL) |
81 |
|
|
fp = popen(pcom, "r"); |
82 |
|
|
else |
83 |
|
|
fp = stdin; |
84 |
|
|
file = "<stdin>"; |
85 |
|
|
} else { |
86 |
|
|
if (pcom != NULL) { |
87 |
|
|
sprintf(command, "( %s ) < %s", pcom, file); |
88 |
|
|
fp = popen(command, "r"); |
89 |
|
|
} else |
90 |
|
|
fp = fopen(file, "r"); |
91 |
|
|
} |
92 |
|
|
if (fp == NULL) { |
93 |
|
|
perror(file); |
94 |
|
|
exit(1); |
95 |
|
|
} |
96 |
|
|
/* check format */ |
97 |
|
|
if (getthead(&head, NULL, fp) == -1 || !goodpic(&head)) |
98 |
|
|
goto badfmt; |
99 |
|
|
/* DAVIDR */ |
100 |
|
|
image_read = (unsigned char *) malloc((head.dataBits)/8 * head.x * head.y) ; |
101 |
|
|
/* get frame */ |
102 |
|
|
for (i = 0 ; i < head.y ; i++) |
103 |
|
|
fread(&(image_read[(head.y-i-1)*head.x*(head.dataBits/8)]),(head.dataBits)/8,head.x,fp) ; |
104 |
|
|
newimage = NULL ; |
105 |
|
|
/* convert to server size and visual */ |
106 |
|
|
scry_conv_vis (image_read,&newimage,head.y,head.x,&new_ht,&new_wd,(head.dataBits)/8,&new_depth) ; |
107 |
|
|
free (image_read) ; |
108 |
|
|
compdata = NULL ; |
109 |
|
|
/* compress if necessary */ |
110 |
|
|
scry_compress(newimage,&compdata,new_ht,new_wd,new_depth) ; |
111 |
|
|
/* send frame */ |
112 |
|
|
scry_send_frame(compdata); |
113 |
|
|
free(newimage) ; |
114 |
|
|
free(compdata) ; |
115 |
|
|
/* end DAVIDR */ |
116 |
|
|
/* close file */ |
117 |
|
|
if (pcom != NULL) |
118 |
|
|
pclose(fp); |
119 |
|
|
else |
120 |
|
|
fclose(fp); |
121 |
|
|
return; |
122 |
|
|
badfmt: |
123 |
|
|
fputs(file, stderr); |
124 |
|
|
fputs(": wrong targa format\n", stderr); |
125 |
|
|
exit(1); |
126 |
|
|
readerr: |
127 |
|
|
fputs(file, stderr); |
128 |
|
|
fputs(": read error\n", stderr); |
129 |
|
|
exit(1); |
130 |
|
|
} |
131 |
|
|
|
132 |
|
|
|
133 |
|
|
getthead(hp, ip, fp) /* read header from input */ |
134 |
|
|
struct hdStruct *hp; |
135 |
|
|
char *ip; |
136 |
|
|
register FILE *fp; |
137 |
|
|
{ |
138 |
|
|
int nidbytes; |
139 |
|
|
|
140 |
|
|
if ((nidbytes = getc(fp)) == EOF) |
141 |
|
|
return(-1); |
142 |
|
|
hp->mapType = getc(fp); |
143 |
|
|
hp->dataType = getc(fp); |
144 |
|
|
hp->mapOrig = getint2(fp); |
145 |
|
|
hp->mapLength = getint2(fp); |
146 |
|
|
hp->CMapBits = getc(fp); |
147 |
|
|
hp->XOffset = getint2(fp); |
148 |
|
|
hp->YOffset = getint2(fp); |
149 |
|
|
hp->x = getint2(fp); |
150 |
|
|
hp->y = getint2(fp); |
151 |
|
|
hp->dataBits = getc(fp); |
152 |
|
|
hp->imType = getc(fp); |
153 |
|
|
|
154 |
|
|
if (ip != NULL) |
155 |
|
|
if (nidbytes) |
156 |
|
|
fread(ip, nidbytes, 1, fp); |
157 |
|
|
else |
158 |
|
|
*ip = '\0'; |
159 |
|
|
else if (nidbytes) |
160 |
|
|
fseek(fp, (long)nidbytes, 1); |
161 |
|
|
|
162 |
|
|
return(feof(fp) || ferror(fp) ? -1 : 0); |
163 |
|
|
} |
164 |
|
|
|
165 |
|
|
|
166 |
|
|
|
167 |
|
|
|
168 |
|
|
int |
169 |
|
|
getint2(fp) /* get a 2-byte positive integer */ |
170 |
|
|
register FILE *fp; |
171 |
|
|
{ |
172 |
|
|
register int b1, b2; |
173 |
|
|
|
174 |
|
|
if ((b1 = getc(fp)) == EOF || (b2 = getc(fp)) == EOF) { |
175 |
|
|
fputs("Unexpected EOF\n", stderr); |
176 |
|
|
exit(1); |
177 |
|
|
} |
178 |
|
|
return(b1 | b2<<8); |
179 |
|
|
} |
180 |
|
|
|
181 |
|
|
|