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