| 1 |
greg |
1.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 Sun rasterfiles to PC animation system.
|
| 9 |
|
|
*
|
| 10 |
|
|
* 6/20/88
|
| 11 |
|
|
*/
|
| 12 |
|
|
|
| 13 |
|
|
#include <stdio.h>
|
| 14 |
|
|
#include <rasterfile.h>
|
| 15 |
|
|
|
| 16 |
|
|
#include "client/clnt.h"
|
| 17 |
|
|
|
| 18 |
|
|
FILE *popen();
|
| 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(1) ;
|
| 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 rasterfile head;
|
| 70 |
|
|
char command[128];
|
| 71 |
|
|
unsigned char cmap[3][256];
|
| 72 |
|
|
unsigned char dmap[256][3] ;
|
| 73 |
|
|
static unsigned short targa[256];
|
| 74 |
|
|
static int xbeg, ybeg;
|
| 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 (fread(&head, sizeof(head), 1, fp) != 1)
|
| 102 |
|
|
goto rasfmt;
|
| 103 |
|
|
if (head.ras_magic != RAS_MAGIC || head.ras_type != RT_STANDARD)
|
| 104 |
|
|
goto rasfmt;
|
| 105 |
|
|
if (head.ras_maptype != RMT_EQUAL_RGB || head.ras_maplength != 3*256)
|
| 106 |
|
|
goto rasfmt;
|
| 107 |
|
|
/* get color table */
|
| 108 |
|
|
if (fread(cmap, 256, 3, fp) != 3)
|
| 109 |
|
|
goto readerr;
|
| 110 |
|
|
/* convert table */
|
| 111 |
|
|
#ifdef LATER
|
| 112 |
|
|
for (j = 0; j < 253; j++)
|
| 113 |
|
|
targa[j+1] = (cmap[0][j] & 0xf8)<<7 |
|
| 114 |
|
|
(cmap[1][j] & 0xf8)<<2 | cmap[2][j]>>3;
|
| 115 |
|
|
#endif
|
| 116 |
|
|
for (j = 0 ; j < 256 ; j++)
|
| 117 |
|
|
{
|
| 118 |
|
|
dmap[j][0] = cmap[0][j] ;
|
| 119 |
|
|
dmap[j][1] = cmap[1][j] ;
|
| 120 |
|
|
dmap[j][2] = cmap[2][j] ;
|
| 121 |
|
|
}
|
| 122 |
|
|
/* send table */
|
| 123 |
|
|
scry_set_map(254, dmap);
|
| 124 |
|
|
image_read = (unsigned char *) malloc(head.ras_width*head.ras_height) ;
|
| 125 |
|
|
for (j = 0 ; j < head.ras_height ; j++)
|
| 126 |
|
|
fread (&(image_read[(head.ras_height-j-1)*head.ras_width]),head.ras_width,1,fp) ;
|
| 127 |
|
|
fread(image_read,head.ras_width*head.ras_height,1,fp) ;
|
| 128 |
|
|
newimage = NULL ;
|
| 129 |
|
|
/* send frame */
|
| 130 |
|
|
scry_conv_vis (image_read,&newimage,head.ras_height,head.ras_width,&new_ht,&new_wd,1,&new_depth) ;
|
| 131 |
|
|
free (image_read) ;
|
| 132 |
|
|
compdata = NULL ;
|
| 133 |
|
|
scry_compress(newimage,&compdata,new_ht,new_wd,new_depth) ;
|
| 134 |
|
|
scry_send_frame(compdata);
|
| 135 |
|
|
free(compdata) ;
|
| 136 |
|
|
free (newimage) ;
|
| 137 |
|
|
/* close file */
|
| 138 |
|
|
if (pcom != NULL)
|
| 139 |
|
|
pclose(fp);
|
| 140 |
|
|
else
|
| 141 |
|
|
fclose(fp);
|
| 142 |
|
|
return;
|
| 143 |
|
|
rasfmt:
|
| 144 |
|
|
fputs(file, stderr);
|
| 145 |
|
|
fputs(": wrong rasterfile format\n", stderr);
|
| 146 |
|
|
exit(1);
|
| 147 |
|
|
readerr:
|
| 148 |
|
|
fputs(file, stderr);
|
| 149 |
|
|
fputs(": read error\n", stderr);
|
| 150 |
|
|
exit(1);
|
| 151 |
|
|
}
|