From karn@thumper.bellcore.com Wed Jun 28 03:05:53 1989 Received: from thumper.bellcore.com by uunet.uu.net (5.61/1.14) with SMTP id AA12947; Wed, 28 Jun 89 03:05:20 -0400 Received: by thumper.bellcore.com (5.54/4.7) id AA14775; Tue, 27 Jun 89 18:16:21 EDT Received: by jupiter.bellcore.com (4.12/4.7) id AA15634; Tue, 27 Jun 89 18:14:24 edt Date: Tue, 27 Jun 89 18:14:24 edt From: karn@thumper.bellcore.com (Phil R. Karn) Message-Id: <8906272214.AA15634@jupiter.bellcore.com> To: rick@uunet.uu.net Subject: updated xfaceload.c Status: RO /* */ #include "xface.h" typedef int boolean; FILE *fp; int XC = 0, YC = 0, /* Output X and Y coords of current pixel */ Width, Height, /* image dimensions */ BytesPerScanline; /* bytes per scanline in output raster */ boolean HasColormap = True; boolean Verbose = False; byte *Image; /* The result array */ byte Red[256], Green[256], Blue[256], used[256]; int numused = 0; /*****************************/ LoadFACE(fname) char *fname; /*****************************/ { int i; if (strcmp(fname,"-")==0) { fp = stdin; fname = ""; } else fp = fopen(fname,"r"); if (!fp) FatalError("file not found"); init(); numcols = 256; for( i = 0 ; i < 256 ; ++i ) used[i] = 0, Red[i] = Green[i] = Blue[i] = cols[i] = i; /* Allocate the X Image */ Image = (byte *) malloc(Width*Height); if (!Image) FatalError("not enough memory for XImage"); theImage = XCreateImage(theDisp,theVisual,8,ZPixmap,0,Image, Width,Height,8,Width); if (!theImage) FatalError("unable to create XImage"); BytesPerScanline = Width; YC = Height - 1; fillitup(); ColorDicking(fname); } AddToPixel(Index) byte Index; { if (!used[Index]) { used[Index]=1; numused++; } 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--; } } /*************************/ ColorDicking(fname) char *fname; { /* we've got the picture loaded, we know what colors are needed. get 'em */ register int i,j; static byte lmasks[8] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80}; byte lmask, *ptr; if (!HasColormap) return; /* Allocate the X colors for this picture */ if (nostrip) { /* nostrip was set. try REAL hard to do it */ for (i=j=0; i>8)) + abs(g - (ctab[j].green>>8)) + abs(b - (ctab[j].blue>>8)); if (d=0; i--) if (used[i]) XFreeColors(theDisp,theCmap,cols+i,1,0L); } else break; } if (j && strip<8) fprintf(stderr,"%s: %s stripped %d bits\n",cmd,fname,strip); if (strip==8) { fprintf(stderr,"UTTERLY failed to allocate the desired colors.\n"); for (i=0; i first char in value field */ cp++; while(*cp == ' ' && *cp != '\0') cp++; /* Give it to the user */ strncpy(val,cp,size); return 0; } }