From usenix!metron!face Wed Jun 21 20:42:38 1989 Received: from usenix.ORG by uunet.uu.net (5.61/1.14) with SMTP id AA25529; Wed, 21 Jun 89 20:42:08 -0400 Received: by usenix.ORG (5.61/1.29-emg890317) id AA04648; Wed, 21 Jun 89 17:46:08 -0700 From: usenix!metron!face Message-Id: <8906220046.AA04648@usenix.ORG> To: rick Subject: Revised printuface.c Date: Wed Jun 21 17:33:31 1989 Status: R /* Simple program to read in an 8-bit deep picture file from a Targa M8 * board and display it via PostScript. * * Copyright 1988,1989 Metron Computerware, Ltd. Oakland, CA 94602 * Unpublished work of Metron Computerware, Ltd. All rights reserved. * * Small pictures have already been rotated from the original raster by the * capture program to print in a proper orientation on the paper. * * Last revised 07 June 1989 for indefinite input. * * This program first outputs a postscript program to stdout. * It then reads stdin or a file to get the hexified image. * It sends this postscript stuff to stdout. * * Usage: printuface [fn] [< hexpicturefile] > postscriptdevice * if any argument is supplied at all, the program expects to read * that as a uunet formatted file. Otherwise it reads that format * from stdin. * * cc -o printface printface.c * * The pixels on a Targa board are not quite square. In fact, they are * off by the ratio 96:108, very nearly */ #include #define SERIAL char scanline[256]; /* Input for one scanline */ main(argc,argv) int argc; char **argv; { int d,i,j,k,l,m,x; char inbuffer[256]; char textout[256]; char fname[128]; /* The first name behind the face */ char lname[128]; /* The last name behind the face */ char company[128]; char address1[128]; /* Street address */ char address2[128]; /* Street address */ char citystatezip[128]; char telephone[128]; char netaddr[128]; /* Net address, if any */ char pixinfo[128]; /* width, height, depth of data */ char imageinfo[128]; /* width, height, depth of image */ unsigned char ch,*cp; FILE *fp; int done; int pt = 18; /* pointsize for message */ char *facesave = "USENIX Baltimore Conference FaceSaver Project, Metron Studios, June 1989"; k = 128; /* Normal image */ l = 108; if (argc > 1) { fp = fopen(argv[1],"r"); if (fp == NULL) { printf("Can't open %s for input\n",argv[1]); exit (1); } } else fp = stdin; /* Get the header text input, remove assumptions about order */ done = 0; while(fgets(inbuffer, 127,fp)) { switch(ch = inbuffer[0]) { case '\0': case '\n': done = 1; break; case 'F': /* First Name */ strcpy(fname,inbuffer); break; case 'L': /* Last Name */ strcpy(lname,inbuffer); break; case 'E': /* E-mail */ strcpy(netaddr,inbuffer); break; case 'C': /* Company */ if (inbuffer[1] == 'o') strcpy(company,inbuffer); else /* CityStateZip */ strcpy(citystatezip,inbuffer); break; case 'A': /* Street address*/ if (inbuffer[7] == '1') strcpy(address1,inbuffer,1); else strcpy(address2,inbuffer,1); break; case 'T': /* Voice telephone */ strcpy(telephone,inbuffer); break; case 'P': /* Picture */ strcpy(pixinfo,inbuffer); break; case 'I': /* Image */ default: /* Discard anything else */ /* Throw away aspect info, as we assume it */ break; } if (done) break; } sscanf(pixinfo,"%s %d %d %d",scanline,&l,&k,&d); if (l == 108 || l == 96) k = 128; else { printf("Bad picture width %d\n", l); exit (1); } scanline[0] = '\0'; d = 0; /* Text positioning */ x = 96; /* Simpleminded stupid construction and output of a postscript */ /* program. This IS NOT proper encapsulated PostScript format */ sprintf(textout,"/piktur %d %d mul string def\n",k,l); write(1,textout,strlen(textout)); sprintf(textout,"/main {\n/Helvetica findfont %d scalefont setfont\n",pt); write(1,textout,strlen(textout)); sprintf(textout,"currentscreen /p exch def\n"); write(1,textout,strlen(textout)); sprintf(textout,"pop pop 40 45 /p load setscreen\n"); write(1,textout,strlen(textout)); /* This transfer function prevents pure white on 300 dpi laser printers */ sprintf(textout, " { 1.05 mul 0.05 add dup .99 gt { pop .99 } if } settransfer\n"); write(1,textout,strlen(textout)); sprintf(textout,"gsave\n72 116 translate %d %d moveto\n",x,d); write(1,textout,strlen(textout)); sprintf(textout,"(%s) show\n",fname); write(1,textout,strlen(textout)); d -= (pt+2); sprintf(textout,"%d %d moveto\n",x,d); write(1,textout,strlen(textout)); sprintf(textout,"(%s) show\n",lname); write(1,textout,strlen(textout)); d -= (pt+2); sprintf(textout,"%d %d moveto\n",x,d); write(1,textout,strlen(textout)); sprintf(textout,"(%s) show\n",netaddr); write(1,textout,strlen(textout)); d -= (pt+2); sprintf(textout,"%d %d moveto\n",x,d); write(1,textout,strlen(textout)); sprintf(textout,"(%s) show\n",telephone); write(1,textout,strlen(textout)); sprintf(textout,"%d %d moveto\n",96,-106); write(1,textout,strlen(textout)); sprintf(textout,"/Helvetica findfont %d scalefont setfont\n",8); write(1,textout,strlen(textout)); sprintf(textout,"(%s) show grestore\n",facesave); write(1,textout,strlen(textout)); /* This line causes the hex image to be read into the string 'piktur'*/ sprintf(textout,"currentfile piktur readhexstring pop pop \n"); write(1,textout,strlen(textout)); sprintf(textout,"72 -1090 translate\n0 0 moveto\n2.5 2.5 scale\n"); write(1,textout,strlen(textout)); /*The factor 1.125 compensates for rectangular pixels in the Targa Board*/ if (l == 108) sprintf(textout, "360 1.125 div 1.375 mul 360 1.375 mul scale\n"); else sprintf(textout, "360 1.375 mul 360 1.375 mul scale\n"); write(1,textout,strlen(textout)); /* These lines setup the matrix and display a large copy of the picture */ sprintf(textout,"%d %d 8 ",l,k); write(1,textout,strlen(textout)); sprintf(textout,"[ 256 0 0 256 0 -256 ] \n"); write(1,textout,strlen(textout)); sprintf(textout,"{ piktur } image \n"); write(1,textout,strlen(textout)); sprintf(textout,"0.0 0.8 translate\n0.25 0.25 scale\n"); write(1,textout,strlen(textout)); /* These lines setup the matrix and display a small copy of the picture */ sprintf(textout,"currentscreen /p exch def\n"); write(1,textout,strlen(textout)); sprintf(textout,"pop pop 70 45 /p load setscreen\n"); write(1,textout,strlen(textout)); sprintf(textout,"%d %d 8 ",l,k); write(1,textout,strlen(textout)); sprintf(textout,"[ 512 0 0 512 0 -256 ] \n"); write(1,textout,strlen(textout)); sprintf(textout," { piktur } "); write(1,textout,strlen(textout)); sprintf(textout,"image showpage} def\n"); write(1,textout,strlen(textout)); sprintf(textout,"main\n"); write(1,textout,strlen(textout)); /* The Hexified file has the ouput scanlines broken into 4 pieces, * and each piece is twice as wide as the number of pixels, since * each byte is converted to two hex digits. * Thus each piece is not too wide, for screen readability. */ m = l + 1; /* Hexified info plus newline */ for (i=0;i