Repost: FaceSaver display for UNIX-pc (1 of 2)

Gil Kloepfer Jr. gil at limbic.UUCP
Fri Jun 30 13:54:55 AEST 1989


I sent out a cancel message for the last posting of this program,
although some may have leaked by.  The last posting was truncated
by some internet sites.  This one should get through OK.

Those that were at the Summer USENIX conference probably participated
in the FaceSaver project, which digitized lots of our faces and put
them in an archive on uunet.  This is a program for the UNIX-pc which
allows you to display those files.  Enjoy.

COMING SOON:  UNIX-pc utility to simplify the use of on-line manual pages

======
| Gil Kloepfer, Jr.
| ICUS Software Systems/Bowne Management Systems (depending on where I am)
| ...icus!limbic!gil   or    gil at icus.islp.ny.us

-----Cut Here----

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of archive 1 (of 2)."
# Contents:  122.ft.uue Makefile README facedisp.c raster.c
# Wrapped by gil at limbic on Thu Jun 29 22:33:29 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 122.ft.uue -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"122.ft.uue\"
else
echo shar: Extracting \"122.ft.uue\" \(3049 characters\)
sed "s/^X//" >122.ft.uue <<'END_OF_122.ft.uue'
Xbegin 644 122.ft
XM   !C@ &"@@                                &"P#W!@ "^@$( _@&
XM  ,( P,"^ 8  Q %" 'X!@ ##@0* ?@&  ,6! @!^ 8  R(%" 'X!@ #*@$#
XM _@&  ,R PD"^ 8  S #"0'X!@ #. at 4% ?H&  -$!04!^@8  T8"! +^!@ #
XM2 0! ?P&  -( @("_ at 8  T($" 'X!@ #/@0' ?D&  -& P<!^08  TP$!P'Y
XM!@ #4 at 0( ?D&  -8!0D!^ 8  V $" 'Y!@ #:@0( ?@&  -R! @!^08  WH$
XM" 'X!@ #@@0( ?D&  .* @8"^@8  Y("" +Z!@ #E at 0' ?D&  .>! ,!^P8 
XM Z0$!P'Y!@ #H at 0( ?@&  .H!0D!^ 8  [ $" 'X!@ #N at 4( ?@&  /"! @!
XM^ 8  \H$" 'X!@ #T at 0( ?@&  /:! @!^ 8  ^($" 'X!@ #Z at 0( ?@&  /R
XM P@"^ 8  _H$" 'X!@ $ @4( ?@&  0*! @!^ 8 !!(%" 'X!@ $&@4( ?@&
XM  0B! @!^ 8 !"H$" 'X!@ $, at 4) ?@&  0Z!0@!^ 8 !$0$" 'X!@ $3 4(
XM ?@&  14! @!^ 8 !%P%" 'X!@ $9 4( ?@&  1L!0@!^ 8 !'0%" 'X!@ $
XM? 0( ?@&  2$ PD"^ 8 !(P$" 'X!@ $E@,) ?@&  2>!0,!^ 8 !*@& 0  
XM!@ $I@,# ?@&  2@! 8!^@8 !)X$" 'X!@ $H at 0& ?H&  2J! @!^ 8 !*X$
XM!@'Z!@ $M at 4( ?@&  2Z! @!^@8 !,($" 'X!@ $R at 0( ?@&  32 PH!^ 8 
XM!-H%" 'X!@ $Y at 0( ?@&  3N!08!^@8 !/8$!@'Z!@ $^@0& ?H&  3^! @!
XM^@8 !0($" 'Z!@ %"@0& ?H&  42! 8!^@8 !18$" 'X!@ %&@0& ?H&  4B
XM!08!^@8 !28%!@'Z!@ %*@4& ?H&  4N!0@!^@8 !3($!@'Z!@ %. at 0) ?@&
XM  4^ 0L#]P8 !4@$"0'X!@ %5 at 4# ?L&  5@!@L ]P8 !5X             
XM                  $  0 !  $       $  0 %  4 !0 *  H 'P *  H 
XM'P *  H !  $  X  0 "  0 "  '  (  @ #  , "  $  (  0 ,  P !@ )
XM  D !@ 5  D "0 6  $  0 !  0  @ "  $  0 !  (  @ $  $  @ "  0 
XM!  $  (  @ !  0 %0 . !4 !  $  0 'P $  0  P #  (  0 /  ,  P (
XM  @ !  $  (  @ !  $ #@ )  D "0 )  D !P $  8 !0 $  0 !  $  < 
XM"  (  0  @ !  \ !P (  @ !@ (  @ "  '  (  @ *  H "@ ) !\ "  (
XM  \  0 !  < "  (  0  P ,  (  0 '  D "0 )  8 #P (  @ !  $  ( 
XM @ "  8 "0 )  8 "0 )  D !@ &  D "0 )  X "  $  ,  P #       #
XM  ,  P #       #  ,  @ !  @ !  "  $  @ $  @ #P    \  0 "  0 
XM"  $  (  0 '  @ "  $  (    "  ( #@ 1 !D %0 5 !T  0 !  X !@ )
XM  D "0 /  D "0 )  < "0 )  \ $0 1 !$ #P .  $  0 !  $  0 !  X 
XM!P )  D "0 )  D "0 '  \  0 !  <  0 !  $ #P /  $  0 !  <  0 !
XM  $ #@ !  $  0 -  D "0 .  D "0 )  \ "0 )  D "0 '  (  @ "  ( 
XM @ "  < "  (  @ "  )  D "0 &  D "0 %  4  P %  D $0 !  $  0 !
XM  $  0 !  \ $0 1 !L %0 5 !$ $0 1 !$ $P 5 !D $0 1 !$ $0 &  D 
XM"0 )  D "0 )  8 !P )  D "0 '  $  0 !  8 "0 )  D "0 )  4 "@ 0
XM  < "0 )  D !P %  D $0 .  $  0 "  0 "  (  < 'P $  0 !  $  0 
XM!  $  D "0 )  D "0 )  D !@ 1 !$ $0 1  H "@ $  0 $0 1 !$ %0 5
XM !4 "@ * !$ $0 *  0 !  * !$ $0 1 !$ "@ *  0 !  $  0 #P (  0 
XM!  "  (  0 /  <  0 !  $  0 !  $  0 '  $  0 "  ( !  $  @ "  '
XM  0 !  $  0 !  $  0 !P $  H $0 _  ,  @ $  < "  .  D "0 .  $ 
XM 0 '  D "0 )  D !P .  $  0 !  $ #@ (  @ #@ )  D "0 )  X !@ )
XM  \  0 !  X '  "  ( #P "  (  @ "  X "0 )  D #@ (  @ !P !  $ 
XM!P )  D "0 )  D !@    8 !  $  0 !  /  8    '  0 !  $  0 !  $
XM  ,  0 !  D "0 %  < "0 1  8 !  $  0 !  $  0 #P + !4 %0 5 !4 
XM$0 '  D "0 )  D "0 &  D "0 )  D !@ '  D "0 )  D !P !  $ #@ )
XM  D "0 )  X "  (  T  P !  $  0 !  X  0 "  0 "  '  (  @ /  ( 
XM @ "  ( #  )  D "0 )  D #@ 1 !$ $0 *  H !  1 !4 %0 5  H "@ 1
XM  H !  $  H $0 1 !$ "@ *  0 !  $  , #P $  0  @ "  \ "  $  0 
XM!  #  0 !  $  @  0 !  $  0 !     0 !  $  0 !  $  @ "  ( #  "
XB  (  @ ! !( %0 ) #\ /P _ #\ /P _ #\ /P _ #\ /P$ 
X 
Xend
END_OF_122.ft.uue
if test 3049 -ne `wc -c <122.ft.uue`; then
    echo shar: \"122.ft.uue\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f Makefile -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"Makefile\"
else
echo shar: Extracting \"Makefile\" \(781 characters\)
sed "s/^X//" >Makefile <<'END_OF_Makefile'
X#
X# Makefile for facedisp version 1.0
X# By Gil Kloepfer, Jr.  ICUS Software Systems        6/23/89
X#
X
XCFLAGS=-v -O
XLDFLAGS=-s
XSHAREDLIB=/lib/shlib.ifile /lib/crt0s.o
XDESTDIR=/usr/lbin
XMANDIR=/usr/man/man1
X
Xfacedisp: facedisp.o raster.o
X	$(LD) $(LDFLAGS) -o facedisp facedisp.o raster.o $(SHAREDLIB)
X
Xinstall: facedisp
X	/bin/mv facedisp $(DESTDIR)
X	/bin/chmod 755 $(DESTDIR)/facedisp
X	/bin/chown bin $(DESTDIR)/facedisp
X	/bin/chgrp bin $(DESTDIR)/facedisp
X	/bin/mv facedisp.1 $(MANDIR)
X	/bin/chmod 644 $(MANDIR)/facedisp.1
X	/bin/chown bin $(MANDIR)/facedisp.1
X	/bin/chgrp bin $(MANDIR)/facedisp.1
X	/bin/mv 122.ft /usr/lib/wfont
X	/bin/chmod 644 /usr/lib/wfont/122.ft
X	/bin/chown bin /usr/lib/wfont/122.ft
X	/bin/chgrp bin /usr/lib/wfont/122.ft
X
Xclean:
X	rm -f facedisp.o raster.o core
END_OF_Makefile
if test 781 -ne `wc -c <Makefile`; then
    echo shar: \"Makefile\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f README -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"README\"
else
echo shar: Extracting \"README\" \(3525 characters\)
sed "s/^X//" >README <<'END_OF_README'
X"README" file for facedisp v1.0     Last update: 6/27/1989
X
XThis "shar" file contains a program which allows a FaceSaver file to be
Xdisplayed on the UNIX-pc's single-intensity monochrome bitmapped display.
XMuch of the theory necessary to write the program was obtained from the
X"sunfaced" program by D. Murali Raju.
X
XInstallation is easy.  The makefile is set so that you can "make facedisp"
Xto make the program alone, or "make install" to install it on your system.
XYou should uudecode the font file BEFORE invoking "make install."  The
Xmakefile should execute without modification on your UNIX-pc, but it would
Xbe a good idea to check it first.  Again, if you don't uudecode the font
Xfile before you perform the make, the font file will not be placed in
X/usr/lib/wfont, and you won't get the headers in smaller print.
X
XYou may check your installation by invoking facedisp on file "gil," which
Xis the FaceSaver file for the author of this program (me!).
X
XThe program works by reading the face file in its entirety, then formatting
Xand coding the bitmap intensity data into a format close to what the
XUNIX-pc requires.  This bitmap is then pasted to the screen and the
Xheader information is displayed over a blank section of the bitmapped
Xdisplay.
X
XIntensities are coded by using a 3x3 dither matrix.  The dither matrix
Xis a codification and grouping of pixels which are grouped in such a way
Xthat they appear on the display as "one" multi-intensity pixel.  This
X3x3 matrix gives a total of nine different shades of "grey."  I have chosen
Xthe values so that the grey scales increase in a linear fashion.  I don't
Xsuggest fooling with the values.  It took a good deal of work to find ones
Xthat seemed to look good for a majority of faces.
X
XOne major advantage of this program over sunfaced is that it can be modified
Xfairly easily to work on a wide range of different machines.  One should
Xlook at the file "raster.c" to find the names of all the raster routines,
Xand then write equivalent routines for their favorite monitor.  There is
Xa #define which sets the pixel ratio (width to height) which should be
Xdefined for your particular system.  I used a ruler to measure a NxN pixel
Xarray and computed the value using "bc."  Your mileage may vary.  On the
XUNIX-pc, the pixels are taller than wider, so the "y" values are all 
Xmultiplied by 0.64.  Also note the direct writes to the window will
Xmore than likely need to be changed.  The escape sequences do font
Xchanges and cursor addressing.
X
XThe format of the face files can be obtained by writing sending a request
Xto the FaceSaver daemon at uunet!faceserver ("send format"), while help
Xcan be requested using "send help."  The full index is rather lengthy...
Xbe forewarned.
X
XI would appreciate hearing any comments or improvements that you may have
Xfor this program.  Please mail a copy of all modifications or ports that
Xyou make to the code so I can keep an up-to-date copy here.  I will do
Xmy best to keep an up-to-date version posted as changes come in.
X
XAgain, my thanks to D. Murali Raju for the theory in his program, to Helen
Xand Jeff for discussing with me their ideas at USENIX, and to Lenny for
Xlending a hand and beta testing this beast.  Finally, thanks to Muhammad
XBenten for his 122x28 font that he posted a while ago, and which appeared
Xin some recent postings.
X
XPlease send any correspondence regarding this program to me at icus!limbic!gil.
X
XGil Kloepfer, Jr.
XICUS Software Systems, Western Development Center
XEast Meadow, Long Island, NY
Xicus!limbic!gil
END_OF_README
if test 3525 -ne `wc -c <README`; then
    echo shar: \"README\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f facedisp.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"facedisp.c\"
else
echo shar: Extracting \"facedisp.c\" \(9424 characters\)
sed "s/^X//" >facedisp.c <<'END_OF_facedisp.c'
X/***************************************************************************\
X * File name:		facedisp.c					   *
X *									   *
X * Purpose:		Display a face file that is generated by the folks *
X *			at the FaceSaver project on the UNIX-pc video      *
X *			display.					   *
X *									   *
X * Programmer:		Gil Kloepfer, Jr.  ICUS Software Systems	   *
X *									   *
X * Revision history:    22-Jun-89  1.0    Program created                  *
X *                      28-Jun-89  1.1    Multiple files on argument line  *
X *                                        (Lenny Tropiano <lenny at icus>)    *
X *									   *
X * Restrictions:	This program is specifically written for the       *
X *			UNIX-pc (7300 or 3B1)				   *
X *									   *
X *			This program requires the use of the ICUS raster   *
X *			function library (raster.c).			   *
X *									   *
X * Usage:		This program takes one argument, that is the name  *
X *			of a FaceSaver file to be displayed.  If this arg  *
X *			is missing, it will attempt to read this file from *
X *			stdin.  All errors are displayed on stderr, and    *
X *			all output is displayed on another window.         *
X *									   *
X * Other credits:	Thanks to D. Murali Raju for his insight which I   *
X *			obtained from his sunfaced program.  Thanks also   *
X *			to Lenny, Helen, and Jeff for their encouragement  *
X *			and suggestions.				   *
X *									   *
X * Copyright/		(C) 1989 Gil Kloepfer, Jr., ICUS Software Systems  *
X * Disclaimer:		All Rights Reserved				   *
X *			Permission is granted to use, copy, or redistribute*
X *			this software provided that this header in its     *
X *			entirety is kept in the source code, that all      *
X *			copyright notices are left intact, and that it is  *
X *			not distributed or used for monetary gain of any   *
X *			kind without the express, written permission of    *
X *			the copyright holder(s).  Furthermore, if this     *
X *			software is modified, all changes should be mailed *
X *			to icus!gil.					   *
X *									   *
X *			The user of this program agrees and understands    *
X *			that this software is distributed on an "as-is"    *
X *			basis, and shall not use this program as the basis *
X *			for any claims, now or in the future, against      *
X *			any individual, organization, or entity.	   *
X\***************************************************************************/
X
X#include <stdio.h>
X#include <sys/window.h>
X#include <sys/font.h>
X
X#define	XWLIMIT		700	/* Horiz size so we can add text */
X#define	YWLIMIT		180	/* Vert size so we can add text */
X#define	S_RATIO		0.64	/* Pixel size ratio horizontal/vertical */
X#define	DITHER		3	/* Dither matrix size (do not change!) */
X#define	MAX_INFO	20	/* Maximum header lines in face file */
X
X#ifndef TINYFONT
X# define	TINYFONT	"/usr/lib/wfont/122.ft"
X#endif
X
Xchar *progname;		/* Keep the name of this program global */
X
X/*
X * Variables which originate from the read_face() routine and are used in
X * various places throughout the program
X */
X
Xchar *infoline[MAX_INFO]; /* Up to 20 pointers to header information strings */
Xint xpixels;		/* Number of x pixels as read from the face file */
Xint ypixels;		/* Number of y pixels as read from the face file */
Xint *picdata;		/* Picture data array */
X
X
X/*
X * Subroutine "main" ... we all know what this does...
X */
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X	int	curarg, i;
X
X	/* Initialize some of the variables */
X
X	infoline[0]=NULL;	/* End of headers marker */
X	progname=argv[0];
X
X	/* Read the face file */
X
X	curarg = 1;		/* if nothing there, it's NULL */
X
X	do {
X
X		read_face(argv[curarg]);
X
X		/* Display the picture */
X
X		disp_picture();
X
X		free(picdata);		/* do some memory housekeeping */
X		for (i=0; i<MAX_INFO; i++)
X			if (infoline[i] != NULL)
X				free(infoline[i]);
X		infoline[0]=NULL;	/* End of headers marker */
X
X		curarg++;	/* go to next file */
X
X	} while (curarg < argc);
X
X	/* Done */
X
X	exit(0);
X}
X
X
X/*
X * Read the face file.  Create the values of various global variables
X * which are formatted by other routines later.  If "file" is NULL, then
X * use stdin as the file.
X */
X
Xread_face(file)
X{
X	register int i;
X	char	string[128], *(*infoptr);
X	int	*picptr, found, picsize;
X	FILE	*fp, *fopen();
X
X	/* Open the face file or assign to stdin depending on the file */
X
X	if (file != NULL) {
X		if ((fp=fopen(file,"r")) == NULL) {
X			perror(file);
X			exit(2);
X		}
X	} else
X		fp=stdin;
X
X	/*
X	 * Read all the header information and place pointers to those
X	 * header strings in the infoline array.  When done, position
X	 * the file pointer to the beginning of the data (this is indicated
X	 * by a blank line after the headers).
X	 */
X
X	infoptr=infoline;
X	do {
X		if (fgets(string,128,fp) == NULL) {
X			fprintf(stderr,"%s: bad picture file\n", progname);
X			exit(1);
X		}
X		string[strlen(string)-1]='\0'; /* get rid of the newline */
X		if (string[0] != '\0') {
X			*infoptr=(char *)malloc(strlen(string)+1);
X			strcpy(*infoptr,string);
X			*(++infoptr)=NULL;
X		}
X	} while (string[0] != '\0');
X
X	/* Find the PicData: keyword to get the face dimensions */
X
X	infoptr=infoline; found=0;
X	while ((*infoptr != NULL) && (!found)) {
X		if (strncmp(*infoptr,"PicData:",8) == 0) {
X			found=1;
X			sscanf(*infoptr,"%*s %d %d %*d", &xpixels, &ypixels);
X		}
X		infoptr++;
X	}
X
X	if (!found || xpixels <= 0 || ypixels <= 0) {
X		fprintf(stderr,"%s: PicData is invalid for some reason\n",
X				progname);
X		exit(2);
X	}
X
X	/*
X	 * mallocate memory for the picture data.  We keep picsize as
X	 * a variable so that we can verify that when all the data is
X	 * done being read in the code below
X	 */
X
X	picsize=xpixels*ypixels;
X	if ((picdata=(int *)malloc(picsize*sizeof(int))) == NULL) {
X		fprintf(stderr,"%s: cannot get memory for picture data\n",
X				progname);
X		exit(2);
X	}
X
X
X	/* Read the picture data */
X
X	picptr=picdata;
X	while(fgets(string,128,fp) != NULL && picsize > 0) {
X		for (i=0; i<strlen(string)-1; i+=2) {
X			sscanf(&string[i],"%2x",picptr);
X			picptr++;
X			picsize--;
X		}
X	}
X
X	if (picsize != 0)
X		fprintf(stderr,"%s: picture data may be corrupt\n",progname);
X
X	/* Close the input file if not stdin */
X
X	if (fp != stdin) fclose(fp);
X}
X
X
X/*
X * Display the picture and textual data on the display.  Note that the
X * escape sequences embedded in this routine are used for cursor
X * positioning inside the opened window.
X */
X
Xdisp_picture()
X{
X	int	rast_getwin(), wd, line, dx, dy, xlim, ylim;
X	char	*(*infoptr), junk;
X
X	/*
X	 * The X and Y limits are set so that there is a minimum X and
X	 * Y. This is so we can fit the text into the window...
X	 */
X
X	xlim=xpixels*DITHER;
X	xlim=(xlim<XWLIMIT) ? XWLIMIT : xlim;
X	ylim=(int)(ypixels*DITHER*S_RATIO)+4;
X	ylim=(ylim<YWLIMIT) ? YWLIMIT : ylim;
X	rast_init(xlim,ylim);
X
X	/* Clear the display */
X
X	write(1,"\033[H\033[2J",7);
X
X	/* Setup the rest of the stuff... */
X
X	draw_border();
X	rast_paste();
X
X	wd=rast_getwin();
X	win_write(wd,10,10,0,"Hold on...");
X
X	/* Load the smaller font for the header information */
X
X	load_font(wd,1,TINYFONT);
X
X	/* Draw the picture */
X
X	for (dx=0; dx<xpixels; dx++)
X		for (dy=0; dy<ypixels; dy++)
X			dith_point(dx,(int)(dy*S_RATIO),picdata[dx+(xpixels*dy)]);
X
X	rast_paste();
X
X	win_write(wd,2,40,0,"FaceSaver Picture Display Program");
X
X	infoptr=infoline;
X	line=4;
X	while (*infoptr != NULL) {
X		win_write(wd,line,45,1,*infoptr);
X		line++;
X		infoptr++;
X	}
X
X	win_write(wd,19,45,0,"[Press RETURN to continue]");
X	read(wd,&junk,1);
X
X	rast_close();	/* Finish with window I/O this pass */
X}
X
X
X/*
X * This routine implements a pixel display combined with a 3x3 dither
X * matrix which is used to simulate an intensity on the display where
X * there isn't any.  Don't fool with the numbers unless you can come-up
X * with better ones...
X *
X * x and y are the x & y values from the data, and inten is the integer
X * encoded intensity value for the pixel (0-255).
X */
X
Xdith_point(x,y,inten)
Xint x, y, inten;
X{
X	int	px, py;
X
X	px=x*DITHER;
X	py=y*DITHER;
X
X	if (inten >= 93)  rast_point(px,py+2,1);
X	if (inten >= 31)  rast_point(px+1,py+2,1);
X	if (inten >= 186) rast_point(px+2,py+2,1);
X	if (inten >= 217) rast_point(px,py+1,1);
X	if (inten >= 0)   rast_point(px+1,py+1,1);
X	if (inten >= 248) rast_point(px+2,py+1,1);
X	if (inten >= 124) rast_point(px,py,1);
X	if (inten >= 62)  rast_point(px+1,py,1);
X	if (inten >= 155) rast_point(px+2,py,1);
X}
X
X
X/*
X * This subroutine is called after the size of the window is determined
X * and will make a border around the window and picture
X */
X
Xdraw_border()
X{
X	int	x, y, xedge, xpedge, yedge;
X
X	rast_getlim(&xedge,&yedge);
X	xpedge=(DITHER*xpixels)-1;
X
X	for (x=0; x<=xedge; x++) {
X		rast_point(x,0,1);
X		rast_point(x,yedge,1);
X	}
X
X	for (y=0; y<=yedge; y++) {
X		rast_point(0,y,1);
X		rast_point(xpedge,y,1);
X		rast_point(xedge,y,1);
X	}
X}
X
X
X/*
X * Write some data to the window.  Note that this data doesn't get saved,
X * so if you repaste the display you will lose what you displayed!
X */
X
Xwin_write(wfd,line,col,slot,text)
Xint wfd, line, col, slot;
Xchar *text;
X{
X	char	string[128];
X
X	sprintf(string,"\033[%d;%dH\033[1%1dm%s", line, col, slot, text);
X	write(wfd,string,strlen(string));
X}
X
X
X/*
X * Load a font into a slot number (thanks Lenny)
X */
X
Xload_font(window,slot,font)
Xint window, slot;
Xchar *font;
X{
X	struct ufdata ufd;
X
X	ufd.uf_slot = slot;
X	strcpy(ufd.uf_name,font);
X	ioctl(window,WIOCUFONT,&ufd);	/* unload any previous font */
X
X	if (ioctl(window,WIOCLFONT,&ufd) < 0) {
X		fprintf(stderr,"%s: cannot load font %s -- continuing\n",
X				progname, font);
X	}
X}
END_OF_facedisp.c
if test 9424 -ne `wc -c <facedisp.c`; then
    echo shar: \"facedisp.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
if test -f raster.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"raster.c\"
else
echo shar: Extracting \"raster.c\" \(6508 characters\)
sed "s/^X//" >raster.c <<'END_OF_raster.c'
X/***************************************************************************\
X * File name:		raster.c					   *
X *									   *
X * Purpose:		Library of functions used to address individual    *
X *			pixels in the UNIX-pc video display using raster   *
X *			operations.					   *
X *									   *
X *			rast_init() - Startup raster functions and open    *
X *				a window to work with.			   *
X *			rast_clear() - Clear the raster bitmap.  Called    *
X *				automatically when rast_init() is called.  *
X *			rast_point() - Set or reset a point in the bitmap  *
X *			rast_paste() - Paste the bitmap to the display     *
X *			rast_close() - Close and stop the raster functions *
X *			rast_getwin() - Return file descriptor of window   *
X *			rast_getlim() - Return X and Y screen limits       *
X *									   *
X * Programmer:		Gil Kloepfer, Jr.  ICUS Software Systems	   *
X *									   *
X * Revision history:	22-Jun-89  1.0    Program created		   *
X *									   *
X * Restrictions:	This program is specifically written for the       *
X *			UNIX-pc (7300 or 3B1)				   *
X *									   *
X * Copyright/		(C) 1989 Gil Kloepfer, Jr., ICUS Software Systems  *
X * Disclaimer:		All Rights Reserved				   *
X *			Permission is granted to use, copy, or redistribute*
X *			this software provided that this header in its     *
X *			entirety is kept in the source code, that all      *
X *			copyright notices are left intact, and that it is  *
X *			not distributed or used for monetary gain of any   *
X *			kind without the express, written permission of    *
X *			the copyright holder(s).  Furthermore, if this     *
X *			software is modified, all changes should be mailed *
X *			to icus!gil.					   *
X *									   *
X *			The user of this program agrees and understands    *
X *			that this software is distributed on an "as-is"    *
X *			basis, and shall not use this program as the basis *
X *			for any claims, now or in the future, against      *
X *			any individual, organization, or entity.	   *
X\***************************************************************************/
X
X#include <fcntl.h>
X#include <stdio.h>
X#include <sys/window.h>
X
X/*
X * The following 2 defines define some limits of the screen which don't
X * changed, but are defined in lieu of hard coding some cryptic numbers
X */
X
X#define	X_LIMIT		60		/* Max X chunks display can handle */
X#define	Y_LIMIT		288		/* Max Y chunks display can handle */
X
X/*
X * The following variables are control variables for use with the raster
X * display routines only and should not be accessed or modified directly
X * by a user program.
X */
X
Xstatic unsigned short r_image[X_LIMIT][Y_LIMIT];
X
Xstatic unsigned short r_masks[16] = {
X		0x0001,0x0002,0x0004,0x0008,
X		0x0010,0x0020,0x0040,0x0080,
X		0x0100,0x0200,0x0400,0x0800,
X		0x1000,0x2000,0x4000,0x8000 };
X
Xstatic int r_window;	/* Window channel for raster operations */
Xstatic int r_xsize;	/* X-size (in pixels) of the current window */
Xstatic int r_ysize;	/* Y-size (in pixels) of the current window */
Xstatic struct uwdata r_wcntl; /* Window control structure */
Xstatic struct urdata r_rast;  /* Rastop control structure */
Xstatic unsigned short r_data[16];  /* Rastop temp data area */
X
X
X/*
X * Initialize the raster display function package.  This function must
X * be called before the other functions are invoked.
X *
X * xsize and ysize are the size to open the window in pixels
X */
X
Xrast_init(xsize,ysize)
Xint xsize, ysize;
X{
X
X	/* Assign xsize and ysize to their corresponding internal vars */
X
X	r_xsize=xsize;
X	r_ysize=ysize;
X
X	/* Complain if the x or y sizes are outside the legal ranges */
X
X	if (r_xsize > 720 || r_ysize > 288 || r_xsize <1 || r_ysize < 1) {
X		fprintf(stderr,"(rast_init): xs=%d  ys=%d  size out of range\n",
X				r_xsize, r_ysize);
X		exit(2);
X	}
X
X	/* Open the window for raster I/O */
X
X	if ((r_window=open("/dev/window",O_RDWR)) < 0) {
X		perror("window device");
X		exit(2);
X	}
X
X	/* Shut off the cursor so we aren't bothered by the flashing */
X
X	write(r_window,"\033[=1C",5);
X
X	/* Set-up some window parameters, including the size */
X
X	ioctl(r_window,WIOCGETD,&r_wcntl);
X	r_wcntl.uw_x = 0;
X	r_wcntl.uw_y = 0;
X	r_wcntl.uw_width = r_xsize+16;
X	r_wcntl.uw_height = r_ysize+16;
X	r_wcntl.uw_uflags = NBORDER;
X	ioctl(r_window,WIOCSETD,&r_wcntl);
X
X	/* Setup raster operation data structure */
X
X	r_rast.ur_srcbase=NULL;
X	r_rast.ur_srcwidth=0;
X	r_rast.ur_dstbase=NULL;
X	r_rast.ur_dstwidth=0;
X	r_rast.ur_width=16;
X	r_rast.ur_height=16;
X	r_rast.ur_srcop=SRCPAT;
X	r_rast.ur_dstop=DSTSRC;
X	r_rast.ur_pattern=r_data;
X
X	/* Clear out the bitmap */
X
X	rast_clear();
X}
X
X
X/*
X * Clear the raster image arrays
X */
X
Xrast_clear()
X{
X	register int i, j;
X
X	for (i=0; i<X_LIMIT; i++)
X		for (j=0; j<Y_LIMIT; j++)
X			r_image[i][j]=0;
X}
X
X
X/*
X * Set pixel at (x,y) to "val" -- where "val" is either 0 or 1.
X * The x and y values are checked to conform with the size established
X * at initialization time -- and complaints are issued if this boundary
X * is violated
X */
X
Xrast_point(x,y,val)
Xint x, y, val;
X{
X	register int xchnk, ychnk;
X
X	/* Check for inside established boundaries */
X
X	if (x >= r_xsize || x < 0 || y >= r_ysize || y < 0) {
X		fprintf(stderr,"(rast_point): x=%d  y=%d  xm=%d ym=%d  -- out of bounds\n",
X				x, y, r_xsize, r_ysize);
X		exit(2);
X	}
X
X	/* Get the chunk coordinates for this pair */
X
X	xchnk=x>>4;	/* This divides 16 and tosses the remainder */
X	ychnk=r_ysize-y-1;  /* Keep it in cartesian direction */
X
X	/* Set the bit offset within the chunk to the value */
X
X	if (val)
X		r_image[xchnk][ychnk] |= r_masks[x%16];
X	else
X		r_image[xchnk][ychnk] &= ~r_masks[x%16];
X}
X
X
X/*
X * Flush out the raster buffer to the screen.  This will draw the whole
X * raster image that could possibly be stored.  Not the most efficient
X * method in the world, but useful.
X */
X
Xrast_paste()
X{
X	register int i, j, k;
X	int	xchnk;
X
X	xchnk=(r_xsize>>4) + (r_xsize%16 ? 1:0);
X	for (i=0; i<xchnk; i++)
X		for (j=0; j<r_ysize; j+=16) {
X			for (k=0; k<16; k++)
X				r_data[k]=r_image[i][j+k];
X			r_rast.ur_dstx=(unsigned short)(i<<4);
X			r_rast.ur_dsty=(unsigned short)j;
X			ioctl(r_window,WIOCRASTOP,&r_rast);
X		}
X}
X
X
X/*
X * Finish with the raster routines
X */
X
Xrast_close()
X{
X	close(r_window);
X	r_xsize=0;
X	r_ysize=0;
X}
X
X
X/*
X * Return the window channel that is being used for the raster image
X */
X
Xint rast_getwin()
X{
X	return(r_window);
X}
X
X
X/*
X * Return the x and y limits as they were initialized by rast_init, but
X * subtract 1 so they really are the limits.
X */
X
Xrast_getlim(xlim,ylim)
Xint *xlim, *ylim;
X{
X	*xlim=r_xsize-1;
X	*ylim=r_ysize-1;
X}
END_OF_raster.c
if test 6508 -ne `wc -c <raster.c`; then
    echo shar: \"raster.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of archive 1 \(of 2\).
cp /dev/null ark1isdone
MISSING=""
for I in 1 2 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked both archives.
    rm -f ark[1-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0



More information about the Unix-pc.sources mailing list