ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/t16anim.c
Revision: 1.1
Committed: Tue Mar 12 13:05:16 1991 UTC (33 years, 1 month ago) by greg
Content type: text/plain
Branch: MAIN
Log Message:
Initial revision

File Contents

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