From karn@thumper.bellcore.com Tue Jun 27 22:24:54 1989 Received: from thumper.bellcore.com by uunet.uu.net (5.61/1.14) with SMTP id AA02929; Tue, 27 Jun 89 22:24:25 -0400 Received: by thumper.bellcore.com (5.54/4.7) id AA14771; Tue, 27 Jun 89 18:16:17 EDT Received: by jupiter.bellcore.com (4.12/4.7) id AA15632; Tue, 27 Jun 89 18:14:16 edt Date: Tue, 27 Jun 89 18:14:16 edt From: karn@thumper.bellcore.com (Phil R. Karn) Message-Id: <8906272214.AA15632@jupiter.bellcore.com> To: rick@uunet.uu.net Subject: updated sunface.c Status: RO /* * Display a face from the uunet FaceSaver picture library. * * Uses SunView - Needs at least an 8-plane display for 256 gray levels. * (for a single-plane version see sunfaced.c, a dithered version) * * Date: Sun Apr 9 14:50:02 1989 * * Author: D. Murali Raju * Computing Facility, School of Engineering and Applied Science, * The George Washington University, Washington, DC 20052. * Internet: raju@gwusun.gwu.edu UUCP: ...!uunet!gwusun!raju * * Hacked from Jeff Michaud's xface program on uunet. * Rewrote header processing to handle additional header fields - P Karn * 27 June 1989 */ #include typedef unsigned char byte; #define True 1 #define False 0 #define BUFSIZE 1024 #define PIXSIZE 2 #define MAXBPL 15 /* Max bytes per output line in resultant XBM */ char line[BUFSIZE]; char firstname[BUFSIZE]; char lastname [BUFSIZE]; char email [BUFSIZE]; int depth; int iwidth, iheight, idepth; int totalpixels; byte *Image; /* The final image array */ int XC = 0, YC = 0, /* Output X and Y coords of current pixel */ Width, Height, /* image dimensions */ BytesPerScanline; /* bytes per scanline in output raster */ FILE *fp; char *cmd; Syntax() { printf("Usage: %s [-e expansion] [-x] filename\n",cmd); exit(1); } FatalError (identifier) char *identifier; { fprintf(stderr, "%s: %s\n",cmd, identifier); exit(-1); } ReadFace(fname) char *fname; { if (strcmp(fname,"-")==0) { fp = stdin; fname = ""; } else fp = fopen(fname,"r"); if (!fp) FatalError("file not found"); InitImage(); /* Allocate the Image */ Image = (byte *) malloc(Width*Height); if (!Image) FatalError("not enough memory for Image"); BytesPerScanline = Width; YC = Height - 1; XC = 0; ReadItIn(); } InitImage() { char tmp[BUFSIZE]; gethdr(fp,"FirstName",firstname,BUFSIZE); gethdr(fp,"LastName",lastname,BUFSIZE); gethdr(fp,"E-mail",email,BUFSIZE); gethdr(fp,"PicData",tmp,BUFSIZE); sscanf(tmp, "%d %d %d", &Width, &Height, &depth); gethdr(fp,"Image",tmp,BUFSIZE); sscanf(tmp, "%d %d %d", &iwidth, &iheight, &idepth); totalpixels = Width * Height; /* Position the file at the start of the image data */ rewind(fp); while(!feof(fp)){ fgets(tmp,BUFSIZE,fp); if(tmp[0] == '\n') break; } } /* Scan line Enum junk */ char *enum_ptr; /* local to enum routines */ void init_enum(buf) char *buf; { enum_ptr = buf; } int next_enum(out) char *out; { if( enum_ptr[0] == '\n' || enum_ptr[0] == '\0' ) return False; strncpy(out, enum_ptr, PIXSIZE); out[PIXSIZE] = '\0'; enum_ptr += PIXSIZE; return True; } ReadItIn() { while( fgets(line, BUFSIZE, fp) != NULL ) { char pixel[PIXSIZE+1]; init_enum(line); while( next_enum(pixel) ) { unsigned int value; sscanf(pixel, "%x", &value); AddToPixel((byte)value); } } } AddToPixel(Index) byte Index; { if (YC >= 0) *(Image + YC * BytesPerScanline + XC) = Index; /* Update the X-coordinate, and if it overflows, update the Y-coordinate */ if (++XC == Width) { XC = 0; YC--; } } /* --- SunView Stuff from here on --------------*/ #include #include #define CMS_SIZE 256 /* Color Map size (Lookup Table) */ Frame frame; /* Type defined by sunview */ Canvas canvas; /* Type defined by sunview */ Rect CanvRect; Rect *crect; Pixwin *pw; int MulFac, CanH, CanW; int ResX, ResY; /* Image size */ int debugFlag = 0; Load256Gray() { /* Set Gray Scale color map */ register int i; u_char r[CMS_SIZE], g[CMS_SIZE], b[CMS_SIZE]; for (i = 0 ; i < 256 ; ++i ) r[i] = g[i] = b[i] = i; pw_setcmsname(pw, "GRAY"); pw_putcolormap(pw, 0, CMS_SIZE, r, g, b); } LoadImage() { register int i, j; if (MulFac==1) { pw_lock (pw, crect); for (j=ResY-1;j>=0;j--) for (i=0;i=0;j--) { pw_lock (pw, crect); for (i=0;i (Size: %dx%dx%d)", firstname, lastname, email, Width, Height, depth); frame = window_create (0, FRAME, FRAME_LABEL, Wname, 0); CanH = MulFac * ResY; CanW = MulFac * ResX; canvas = window_create (frame, CANVAS, WIN_HEIGHT, CanH, WIN_WIDTH, CanW, 0); CanvRect.r_left = 0; CanvRect.r_top = 0; CanvRect.r_width = CanW; CanvRect.r_height = CanH; crect = (&CanvRect); window_fit(frame); pw = canvas_pixwin(canvas); if (debugFlag) printf ("Creating 256 Level Gray Scale Lookup Table ... \n"); Load256Gray(); if (debugFlag) printf ("Painting Image ...\n"); LoadImage(); if (debugFlag) printf ("Done. Waiting for a ^C or Quit from the Image Window.\n"); else fprintf (stderr, "Done. Waiting for a ^C or Quit from the Image Window.\n"); window_main_loop(frame); exit(0); } /* Search the file open on fp for a line of the form: * Label: value * and return the value string through "val". Returns 0 on success, -1 * if label could not be found. * 27 June 1989 Phil Karn */ int gethdr(fp,label,val,size) FILE *fp; char *label; char *val; int size; { char buf[BUFSIZE]; char *cp,*index(); rewind(fp); for(;;){ fgets(buf, BUFSIZE, fp); if(feof(fp) || buf[0] == '\n') /* Blank line or EOF? */ return -1; /* Read no further */ /* Look for a colon terminating the label */ if((cp = index(buf,':')) != NULL) *cp = '\0'; else continue; /* Ignore lines without colons */ if(strcmp(buf,label) != 0) continue; /* No match */ /* cp -> first char in value field */ cp++; while(*cp == ' ' && *cp != '\0') cp++; /* Give it to the user */ strncpy(val,cp,size); return 0; } }