From: tim@dciem.dciem.dnd.ca (Tim Pointing)
Newsgroups: rec.equestrian
Subject: Re: Horse GIF images
Date: 9 Sep 92 11:01:33 GMT
Organization: Defence and Civil Institute of Environmental Medicine

In article <92247.36762.6175190@LMSC5.IS.LMSC.LOCKHEED.COM> 6175190@LMSC5.IS.LMSC.LOCKHEED.COM writes:
>>Would the person who posted about enjoying the GIF images on their
>>Sun machine (or anyone else with a Sun) e-mail me (a novice Internet/Sun
>>user) on how to do this?
>>
>>Thx in advance.
>>
>Or could you post it here for some of us who didn't ask the very
>good question? **embarrassed grin**
>Susan

Finally, I get to contribute a little more to this newsgroup, rather than
just sucking the information out of the collective net.consciousness ;-).

Here is a rather old program which I got from another newsgroup long ago.
It is known to work on SunOS 3.x and 4.1.1 on 8-bit color Sun's. It is
fairly crude and has been hacked up a bit by me to add some additional
features that I wanted.

In addition to the mouse interactions mentioned in the leading comments 
in the source, the following keyboard commands were added:

	'q'	quit immediately
	'n'	on to the next picture
	' '	(same)
	'-'	decrease the brightness of the image
	'+'	increase the brightness of the image
	'='	restore the brightness to the unmodified state
	'?'	print out the current brightness and gamma corrections
	R7	increase the gamma correction by 0.1
	R9	(same)
	R13	decrease the gamma correction by 0.1
	R15	(same)
	R11	set the gamma correction to 1.0

Good luck. If anybody has trouble getting this to work on their color Sun,
feel free to send me e-mail. While I did not write this, I am willing to
try to help the generous rec.equestrian people with this.

Tim Pointing, DCIEM
tim@ben.dciem.dnd.ca
-------------------------------------------------
#! /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 shell archive."
# Contents:  shogif.c
# Wrapped by tim@dretor.dciem.dnd.ca on Wed Sep  9 06:45:50 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f shogif.c -a "${1}" != "-c" ; then 
  echo shar: Will not over-write existing file \"shogif.c\"
else
echo shar: Extracting \"shogif.c\" \(23229 characters\)
sed "s/^X//" >shogif.c <<'END_OF_shogif.c'
X/*********************************************
X *             GIF viewer on SUNVIEW         *
X *                                           *
X *      March 23 1989 By Marcel J.E. Mol     *
X *                                           *
X * I hereby place this program               *
X * in the public domain, i.e. there are no   *
X * copying restrictions of any kind.         *
X *********************************************/
X
X/* 
X * Here is a gif viewer for the SUN running suntools (or sunview).
X * It is intended for color monitors (8 planes) and I don't
X * know how it will react on a monochrome screen.
X * It is rather slow because it uses call to sunview for 
X * each pixel. Should be converted to use rasterfiles one day...
X * 
X * Little help:
X *     left button: exit a picture being drawn, and starts the following
X *                  picture, if any.
X *     right button: exit program immediately.
X *     middle button: when a picture is ready pressing the middle button
X *                    will start the following picture, if any.
X * 
X * Usage:
X *        shogif [-sn -ln -Gf -af -b -g] <gif-files>
X * 
X *       -sn : tries to expand a picture n times.
X *       -ln : number of lines to hold for sunview batch mode.
X *	 -Gf : apply gamma correction 'f'.
X *	 -af : add 'f' to all colour values to brighten image.
X *       -b  : disable optimization done by not drawing pixels in 
X *             the background color.
X *	 -g  : display the image in shades of gray rather than colour.
X * 
X * Compile:
X            cc shogif.c -o shogif -lsuntool -lsunwindow -lpixrect -lm
X * 
X */ 
X
X#include <stdio.h>
X#include <suntool/sunview.h>
X#include <suntool/panel.h>
X#include <suntool/canvas.h>
X
X/* Change event_action to event_id(event) for pre 4.0 */
X#ifndef event_action
X#define event_action event_id
X#define oldSunOS
X#endif
X
X#ifndef oldSunOS
X#include <suntool/alert.h>	/* Only for SunOS 4 */
X#include <alloca.h>		/* Cannot find this on 3.5 */
X#endif
X
Xchar *malloc();
Xint strncmp();
X
X#define FALSE 0
X#define TRUE 1
X#define COLSIZE 256
X#define MAX_COLOR 255		/* max value for r,g,b value in colour-map */
X#define PICSIZE 1
X#define SHOWCOUNT 10
X
X#define BUTTONFONT "/usr/lib/fonts/fixedwidthfonts/gallant.r.19"
Xstatic char *default_font =
X       "DEFAULT_FONT=/usr/lib/fonts/fixedwidthfonts/screen.r.13";
X
X/*
X * Sunview variables 
X */
Xstatic Frame fr;
Xstatic Canvas cv;
Xstatic Pixwin *pw;
Xstatic Panel pn;
Xstatic Pixfont *bf, *pf;
X
X/*
X * LZW structures and variables
X */
Xtypedef int bool;
Xunsigned char *stackp;
Xunsigned int prefix[4096];
Xunsigned char suffix[4096];
Xunsigned char stack[4096];
Xint datasize,codesize,codemask;     /* Decoder working variables */
Xint clear,eoi;                      /* Special code values */
Xint avail;
Xint oldcode;
X
X/*
X * GIF variables
X */
XFILE *infile;
Xunsigned int screenwidth;           /* The dimensions of the screen */
Xunsigned int screenheight;          /*   (not those of the image)   */
Xbool global;                        /* Is there a global color map? */
Xint globalbits;                     /* Number of bits of global colors */
Xunsigned char globalmap[COLSIZE][3];/* RGB values for global color map */
Xchar bgcolor;                       /* background color */
Xchar cms_name[256];
Xunsigned char *raster;              /* Decoded image data */
Xunsigned left,top,width,height;
X
Xchar *progname;
Xchar *filename;
Xunsigned int windowwidth = 0;
Xunsigned int windowheight = 0;
Xunsigned int size;                  /* scale factor */
Xdouble gamma = 1.0;
Xdouble add_me = 0.0;
Xextern double pow(), atof();
X
Xunsigned int initsize = PICSIZE;
Xint endpicflag = FALSE;
Xint fast_mode = TRUE;
Xint drawflag;
Xunsigned int showcount = SHOWCOUNT;
Xint dobgflag = FALSE;
Xint grayflag = FALSE;
X
Xvoid convert();
Xint  checksignature();
Xvoid readscreen();
Xint  readimage();
Xvoid readextension();
Xint  readraster();
Xint  process();
Xvoid outcode();
Xvoid initsunview();
Xvoid setupsunview();
Xvoid initcolors();
Xint  rasterize();
Xvoid waitevent();
Xvoid handlevent();
Xvoid panelevent();
Xvoid usage();
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{
X    extern int optind;
X    extern char *optarg;
X    int flag;
X
X    if (getenv("GAMMA") != NULL)
X    {
X	gamma = atof(getenv("GAMMA"));
X	if (gamma < 0.1)
X	    gamma = 1.0;
X    }
X
X    progname = *argv;
X    while ((flag = getopt(argc, argv, "s:l:G:a:bg")) != EOF) {
X        switch (flag) {
X            case 's' : if ((initsize = atoi(optarg)) <= 0) {
X                           initsize = PICSIZE;
X                           fprintf(stderr, "scale factor must more than 1\n");
X                       }
X		       fast_mode = FALSE;
X                       break;
X            case 'l' : if ((showcount = atoi(optarg)) <= 0) {
X                           showcount = SHOWCOUNT;
X                           fprintf(stderr, "showcount must more than 1\n");
X                       }
X		       fast_mode = FALSE;
X                       break;
X	    case 'G' : gamma = atof(optarg);
X		       if (gamma <= 0.0) {
X			   gamma = 0.5;
X			   fprintf(stderr, "gamma correction must be positive; using '0.5'\n");
X		       }
X		       break;
X	    case 'a' : add_me = atof(optarg);
X		       if (add_me < -1.0 || add_me >= 1.0) {
X			   add_me = 0.0;
X			   fprintf(stderr, "add value must be between 0 and 1\n");
X		       }
X		       break;
X            case 'b' : dobgflag = TRUE;
X                       break;
X            case 'g' : grayflag = TRUE;
X                       break;
X            default  : fprintf(stderr, "ignoring unknown flag %c\n", flag);
X                       usage();
X        }
X    }
X
X    initsunview();
X    if (optind >= argc) {
X        filename = "stdin";
X	infile = stdin;
X        convert();
X    }
X    else
X        while (optind < argc) {
X            filename = argv[optind];
X            optind++;
X            if ((infile = fopen(filename,"r")) == NULL) {
X                perror(filename);
X                continue;
X            }
X            convert();
X            fclose(infile);
X        }
X
X    if (drawflag)        /* wait for last picture if fully drawn */
X        waitevent();
X
X} /* main */
X
X
X
Xvoid convert()
X{
X    char ch;
X
X    printf("%s:\n", filename);
X    if (checksignature())
X        return;
X    readscreen();
X    size = initsize;
X    while ((ch = getc(infile)) != ';' && ch != EOF) {
X        switch (ch) {
X            case '\0':  break;  /* this kludge for non-standard files */
X            case ',':   if (readimage())
X                           return;
X                        break;
X            case '!':   readextension();
X                        break;
X            default:    printf(stderr, "illegal GIF block type\n");
X                        return;
X                        break;
X        }
X    }
X
X} /* convert */
X
X
X
Xchecksignature()
X{
X    char buf[6];
X
X    fread(buf,1,6,infile);
X    if (strncmp(buf,"GIF",3)) {
X        fprintf(stderr, "file is not a GIF file\n");
X        return 1;
X    }
X    if (strncmp(&buf[3],"87a",3) && strncmp(&buf[3],"89a",3)) {
X        fprintf(stderr, "unknown GIF version number\n");
X        return 1;
X    }
X    return 0;
X
X} /* checksignature */
X
X
X
X/*
X * Get information which is global to all the images stored in the file
X */
X
Xvoid readscreen()
X{
X    unsigned char buf[7];
X
X    fread(buf,1,7,infile);
X    screenwidth = buf[0] + (buf[1] << 8);
X    screenheight = buf[2] + (buf[3] << 8);
X    global = buf[4] & 0x80;
X    if (global) {
X        globalbits = (buf[4] & 0x07) + 1;
X        fread(globalmap,3,1<<globalbits,infile);
X    }
X    bgcolor = buf[5];
X    printf("    global screen: %dx%dx%d, backgroundcolor: %d\n",
X                screenwidth, screenheight, 1<<globalbits, bgcolor);
X
X} /* readscreen */
X
X
X
X
Xreadimage()
X{
X    unsigned char buf[9];
X    bool local, interleaved;
X    char localmap[256][3];
X    int localbits;
X    register row;
X    register i;
X    static int waitflag = FALSE;
X
X    fread(buf, 1, 9, infile);
X    left = buf[0] + (buf[1] << 8);
X    top = buf[2] + (buf[3] << 8);
X    width = buf[4] + (buf[5] << 8);
X    height = buf[6] + (buf[7] << 8);
X    local = buf[8] & 0x80;
X    interleaved = buf[8] & 0x40;
X    printf("    image: %dx%d %s  org: %d,%d\n", width, height,
X              interleaved ? "interleaved" : "", left, top);
X    if (local == 0 && global == 0) {
X        fprintf(stderr, "no colormap present for image\n");
X        return 1;
X    }
X    if ((raster = (unsigned char*) malloc(width*height)) == NULL) {
X        fprintf(stderr, "not enough memory for image\n");
X        return 1;
X    }
X    if (readraster(width, height))
X        return 1;
X
X    if (waitflag)         /* if first picture or previous picture is   */
X        waitevent();      /* interrupted, don't wait for a buttonpress */
X
X    setupsunview(screenwidth, screenheight);
X    if (local) {
X        localbits = (buf[8] & 0x7) + 1;
X        printf("   local colors: %d\n", 1<<localbits);
X        fread(localmap, 3, 1<<localbits, infile);
X        initcolors(localmap, 1<<localbits, bgcolor);
X    } else if (global)
X        initcolors(globalmap, 1<<globalbits, bgcolor);
X
X    waitflag = rasterize(interleaved, raster);
X    free(raster);
X
X    return 0;
X
X} /* readimage */
X
X
X
X/*
X * Read a GIF extension block (and do nothing with it).
X */
X
Xvoid readextension()
X{
X    unsigned char code;
X    int count;
X    char buf[255];
X
X    code = getc(infile);
X    while (count = getc(infile)) fread(buf, 1, count, infile);
X
X} /* readextension */
X
X
X
X/*
X * Decode a raster image
X */
X
Xreadraster(width, height)
Xunsigned width,height;
X{
X        unsigned char *fill = raster;
X        unsigned char buf[255];
X        register bits=0;
X        register unsigned datum=0;
X        register unsigned char *ch;
X        register int count, code;
X
X        datasize = getc(infile);
X        clear = 1 << datasize;
X        eoi = clear + 1;
X        avail = clear + 2;
X        oldcode = -1;
X        codesize = datasize + 1;
X        codemask = (1 << codesize) - 1;
X        for (code = 0; code < clear; code++) {
X            prefix[code] = 0;
X            suffix[code] = code;
X        }
X        stackp = stack;
X        for (count = getc(infile); count > 0; count = getc(infile)) {
X            fread(buf,1,count,infile);
X            for (ch=buf; count-- > 0; ch++) {
X                datum += *ch << bits;
X                bits += 8;
X                while (bits >= codesize) {
X                    code = datum & codemask;
X                    datum >>= codesize;
X                    bits -= codesize;
X                    if (code == eoi) {               /* This kludge put in */
X#if defined(DEBUG)
X                        printf("found eoi code\n");
X#endif
X                        goto exitloop;               /* because some GIF files */
X                    }                                /* aren't standard */
X                    if (process(code, &fill)) 
X                        goto exitloop;
X                }
X            }
Xnotify_dispatch();
X            if (fill >= raster + width*height) {
X                fprintf(stderr, "raster full before eoi code\n");
X                goto exitloop;
X            }
X        }
Xexitloop:
X        if (fill != raster + width*height)  {
X            fprintf(stderr, "warning: wrong rastersize: %ld bytes\n",
X                      (long) (fill-raster));
X            fprintf(stderr, "         instead of %ld bytes\n",
X                      (long) width*height);
X            return 0;  /* but try to show picture ... */
X        }
X
X        return 0;
X
X} /* readraster */
X
X
X
X
X/*
X * Process a compression code.  "clear" resets the code table.  Otherwise
X * make a new code table entry, and output the bytes associated with the
X * code.
X */
X
Xprocess(code, fill)
Xregister code;
Xunsigned char **fill;
X{
X        int incode;
X        static unsigned char firstchar;
X
X        if (code == clear) {
X#if defined(DEBUG)
X            fprintf(stderr, "clear encountered\n");
X#endif
X            codesize = datasize + 1;
X            codemask = (1 << codesize) - 1;
X            avail = clear + 2;
X            oldcode = -1;
X            return 0;
X        }
X
X        if (code > avail) {
X            fprintf(stderr, "code %d to large for %d\n", code, avail);
X            code = avail;
X            return 1;  
X        }
X
X        if (oldcode == -1) {
X            *(*fill)++ = suffix[code];
X            firstchar = oldcode = code;
X            return 0;
X        }
X
X        incode = code;
X        if (code == avail) {      /* the first code is always < avail */
X            *stackp++ = firstchar;
X            code = oldcode;
X        }
X        while (code > clear) {
X            *stackp++ = suffix[code];
X            code = prefix[code];
X        }
X
X        *stackp++ = firstchar = suffix[code];
X        prefix[avail] = oldcode;
X        suffix[avail] = firstchar;
Xif (avail < 4096)
X        avail++;
X
X        if (((avail & codemask) == 0) && (avail < 4096)) {
X            codesize++;
X            codemask += avail;
X        }
X#if defined(DEBUG)
X        if (avail >= 4096) {
X            fprintf(stderr, "tables full, avail = %d\n", avail);
X        }
X#endif
X
X        oldcode = incode;
X        do {
X            *(*fill)++ = *--stackp;
X        } while (stackp > stack);
X
X        return 0;
X
X} /* process */
X
X
X
Xvoid initsunview()
X{
X
X    if (getenv("WINDOW_PARENT") == NULL || getenv("WINDOW_ME") == NULL ||
X       getenv("WINDOW_GFX") == NULL || getenv("WMGR_ENV_PLACEHOLDER") == NULL)
X	{
X	fprintf(stderr, "sunview/suntools not running - bye-bye!\n");
X	exit(1);
X    }
X    (void) putenv(default_font);
X    bf = pf_open(BUTTONFONT);
X    pf = pf_default();
X
X} /* initsunview */
X
X
X
Xvoid setupsunview(width, height)
Xunsigned width, height;
X{
X    static havewin = FALSE;
X    static int extra_x, extra_y;
X    char title[128];
X    unsigned rwidth;
X
X    rwidth = width + width%2;    /* compensate for odd width */
X    /* UNLIMITED SIZE NOW
X    while ((size*rwidth > 1280) && (size > 1))
X        size--;
X    */
X    rwidth *= size;
X    height *= size;
X
X    windowwidth = rwidth;
X    windowheight = height;
X    if (!havewin)
X    {
X	    fr = window_create(0, FRAME,
X		 WIN_X, 5,
X		 WIN_Y, 50,
X		 WIN_SHOW, TRUE,
X		 FRAME_LABEL, "Gif to Sun",
X		 0);
X	    havewin = TRUE;
X	    pn = window_create(fr, PANEL, 0);
X	    panel_create_item(pn, PANEL_MESSAGE,
X			       PANEL_ITEM_X, 5,
X			       PANEL_ITEM_Y, 5,
X			       PANEL_LABEL_STRING, "File:",
X			       0);
X	    window_fit_height(pn);
X
X	    cv = window_create(fr, CANVAS,
X			       WIN_WIDTH, windowwidth,
X			       WIN_HEIGHT, windowheight,
X			       WIN_CONSUME_PICK_EVENTS,
X				       MS_RIGHT, MS_MIDDLE, MS_LEFT, 0,
X			       WIN_CONSUME_KBD_EVENTS,
X				       WIN_RIGHT_KEYS, WIN_ASCII_EVENTS, 0,
X			       WIN_EVENT_PROC, handlevent, 
X			       0);
X	    window_fit(fr);
X	    extra_x = (int)window_get(fr, WIN_WIDTH) - windowwidth;
X	    extra_y = (int)window_get(fr, WIN_HEIGHT) - windowheight;
X    }
X    else
X    {
X	    window_set(cv, WIN_HEIGHT, windowheight,
X			WIN_WIDTH,  windowwidth,
X			0);
X	    window_set(fr, WIN_HEIGHT, windowheight+extra_y,
X			WIN_WIDTH,  windowwidth+extra_x,
X			0);
X	    window_fit(cv);
X    }
X
X    pw = canvas_pixwin(cv);
X    if (grayflag)
X	sprintf(cms_name, "gif colours (B&W) %05d\n", getpid());
X    else
X	sprintf(cms_name, "gif colours %05d\n", getpid());
X    pw_setcmsname(pw, cms_name);
X
X    notify_dispatch();     /* show the correct window */
X    sprintf(title, "%-20s", filename);
X    panel_pw_text(pn, 50, 5+panel_fonthome(pf), PIX_SRC, pf, title);
X
X} /* setupsunview */
X
X
X
X/*
X * Convert a color map (local or global) to arrays with R, G and B
X * values. Pass colors to SUNVIEW and set the background color.
X */
X
Xunsigned char red_nogamma[256], green_nogamma[256], blue_nogamma[256];
X
Xvoid initcolors(colormap, ncolors, bgcolor)
Xunsigned char colormap[COLSIZE][3];
Xint ncolors;
Xint bgcolor;
X{
X    register i;
X
X#if defined(DEBUG)
X    printf("            ");
X#endif
X
X    for (i = 0; i < ncolors; i++) {
X	if (grayflag)
X	{
X	    red_nogamma[i] = green_nogamma[i] = blue_nogamma[i] =
X		    (unsigned char)  (0.299 * (double) colormap[i][0] +
X				      0.587 * (double) colormap[i][1] +
X				      0.114 * (double) colormap[i][2]);
X	}
X	else
X	{
X	    red_nogamma[i]   = colormap[i][0];
X	    green_nogamma[i] = colormap[i][1];
X	    blue_nogamma[i]  = colormap[i][2];
X	}
X    }
X
X    re_gamma(gamma);
X
X    if (bgcolor >= 0)
X	    pw_writebackground(pw, 0, 0, windowwidth, windowheight,
X				   PIX_SET | PIX_COLOR(bgcolor));
X
X} /* initcolors */
X
X/*
X * Re-do the gamma correction on the current image.
X */
X
Xre_gamma(new_gamma)
Xdouble new_gamma;
X{
X	unsigned char red[256], green[256], blue[256];
X	register int i;
X	double one_over_gamma = 1.0 / gamma;
X
X	for (i=0; i<COLSIZE; i++)
X	{
X		register int vr, vg, vb;
X
X		vr = red_nogamma[i];
X		vg = green_nogamma[i];
X		vb = blue_nogamma[i];
X
X		if (add_me != 0.0) {
X			vr = (int)vr + (MAX_COLOR * add_me) + 0.5;
X			if (vr < 0) vr = 0;
X			vg = (int)vg + (MAX_COLOR * add_me) + 0.5;
X			if (vg < 0) vg = 0;
X			vb = (int)vb + (MAX_COLOR * add_me) + 0.5;
X			if (vb < 0) vb = 0;
X		}
X
X		if (gamma != 1.0 || add_me != 0.0) {
X			vr = (MAX_COLOR * pow(vr/(double)MAX_COLOR, one_over_gamma)) + 0.5;
X			vg = (MAX_COLOR * pow(vg/(double)MAX_COLOR, one_over_gamma)) + 0.5;
X			vb = (MAX_COLOR * pow(vb/(double)MAX_COLOR, one_over_gamma)) + 0.5;
X		}
X
X		if (vr > MAX_COLOR) vr = MAX_COLOR;
X		if (vg > MAX_COLOR) vg = MAX_COLOR;
X		if (vb > MAX_COLOR) vb = MAX_COLOR;
X
X		red[i] = vr;
X		green[i] = vg;
X		blue[i] = vb;
X	}
X
X	if (red[0] == red[COLSIZE-1] && green[0] == green[COLSIZE-1] &&
X	    blue[0] == blue[COLSIZE-1])
X		    red[0] ^= 1, green[0] ^= 1, blue[0] ^= 1;
X
X	pw_putcolormap(pw, 0, COLSIZE, red, green, blue);
X}
X
X
X/*
X * Read a row out of the raster image and write it to the screen
X */
Xrasterize(interleaved, raster)
Xint interleaved;
Xregister unsigned char *raster;
X{
X	if (fast_mode)
X		fast_rasterize(interleaved, raster);
X	else
X		slow_rasterize(interleaved, raster);
X}
X
Xfast_rasterize(interleaved, raster)
Xint interleaved;
Xregister unsigned char *raster;
X{
X    register row, col;
X    register unsigned char *rr;
X    unsigned char * newras;
X    Pixrect *picture;
X    int rwidth;
X    
X#define DRAWSEGMENT(offset, step)                             \
X        for (row = offset; row < height; row += step) {       \
X            rr = newras + row*rwidth;                          \
X            bcopy(raster, rr, rwidth);                         \
X            raster += width;                                  \
X        }
X
X
X    panel_pw_text(pn, 250, 5+panel_fonthome(pf), PIX_SRC, pf, "Drawing");
X    drawflag = TRUE;
X    rwidth = width + width%2;    /* compensate for odd width */
X        if ((newras = (unsigned char*) malloc(rwidth*height)) == NULL) {
X            fprintf(stderr, "not enough memory for image\n");
X            return 1;
X        }
X    if (interleaved) {
X        DRAWSEGMENT(0, 8);
X        DRAWSEGMENT(4, 8);
X        DRAWSEGMENT(2, 4);
X        DRAWSEGMENT(1, 2);
X    }
X    else 
X       DRAWSEGMENT(0, 1);
X/*        newras = raster; */
X
X    picture = mem_point(screenwidth, screenheight, 8, newras);
X    pw_rop(pw, left, top, width, height,
X                PIX_SRC, picture, 0, 0); 
X
X    /*if (interleaved) */
X        free(newras);
X    panel_pw_text(pn, 250, 5+panel_fonthome(pf), PIX_SET, pf, "       ");
X    return drawflag;
X
X} /* fast_rasterize */
X
X
Xslow_rasterize(interleaved, raster)
Xint interleaved;
Xregister unsigned char *raster;
X{
X   
Xfprintf(stderr, " you use the slow version\n");
X
X    panel_pw_text(pn, 250, 5+panel_fonthome(pf), PIX_SRC, pf, "Drawing");
X    pw_batch_on(pw);
X    drawflag = TRUE;
X    if (interleaved) {
X        SLOW_DRAWSEGMENT(0, 8);
X        SLOW_DRAWSEGMENT(4, 8);
X        SLOW_DRAWSEGMENT(2, 4);
X        SLOW_DRAWSEGMENT(1, 2);
X    }
X    else {
X        SLOW_DRAWSEGMENT(0, 1);
X    }
X
Xquitdraw:
X    pw_batch_off(pw);
X    panel_pw_text(pn, 250, 5+panel_fonthome(pf), PIX_SRC, pf, "       ");
X    return drawflag;
X
X} /* slow_rasterize */
X
XSLOW_DRAWSEGMENT(offset, step)
Xregister int offset, step;
X{
X    register c, lc = 0;
X    register row, col;
X
X        for (row = top+offset; row < top+height; row += step) {
X            notify_dispatch();
X            if (!drawflag)
X                return;
X            for (col = left; col < left+width; col++)
X              if ((c = *raster++) != bgcolor || dobgflag)
X                pw_rop(pw, size*col, size*row, size, size,
X                           PIX_SRC | PIX_COLOR(c), (Pixrect *) 0, 0, 0);
X            if (lc++ == showcount) {
X                lc = 0;
X                pw_show(pw);
X            }
X        }
X}
X
Xvoid waitevent()
X{
X
Xprintf("in waitevent()\n");
X    while(endpicflag == FALSE) {
X        notify_dispatch();
X        usleep(50000);
X    }
X    endpicflag = FALSE;
X
X} /* waitevent */
X
X
X
Xvoid handlevent(canvas, event, arg)
XCanvas *canvas;
XEvent *event;
Xchar *arg;
X{
X
X    switch (event_action(event)) {
X	case 'q':
X	case 'Q':
X	case '\003':	/* ^C */
X        case MS_RIGHT:
X                if (event_is_down(event))
X#ifdef oldSunOS
X                exit(0);	/* You won't miss the following fancy stuff.. */
X#else
X                    if (alert_prompt(fr, (Event *)0, ALERT_MESSAGE_STRINGS,
X		          "Please confirm:", "Do you know what you're doing??",
X		          0,
X		          ALERT_BUTTON_YES, "Of course, quit bugging me!",
X		          ALERT_BUTTON_NO, "Sorry, I hit the wrong button...",
X		          ALERT_MESSAGE_FONT, bf,
X		          ALERT_BUTTON_FONT, pf,
X		          0)
X                          == ALERT_YES) 
X                        exit(0);
X                    else
X                        notify_veto_destroy(fr);
X#endif
X                break;
X
X        case MS_LEFT:
X                if (event_is_down(event))
X                    drawflag = FALSE;
X                break;
X
X	case ' ':
X	case 'n':
X        case MS_MIDDLE:
X                if (event_is_down(event))
X		{
X                    endpicflag = TRUE;
X		    drawflag = FALSE;
X		    printf("on to the next?\n");
X		}
X                break;
X
X        case KEY_RIGHT(7):
X        case KEY_RIGHT(8):
X        case KEY_RIGHT(9):
X                if (event_is_down(event))
X		{
X			gamma += 0.1;
X			re_gamma(gamma);
X		}
X                break;
X
X        case KEY_RIGHT(13):
X        case KEY_RIGHT(14):
X        case KEY_RIGHT(15):
X                if (event_is_down(event))
X		{
X			gamma -= 0.1;
X			if (gamma <= 0.1)
X				gamma = 0.1;
X			re_gamma(gamma);
X		}
X                break;
X
X	case KEY_RIGHT(10):
X        case KEY_RIGHT(11):
X	case KEY_RIGHT(12):
X                if (event_is_down(event))
X		{
X			gamma = 1.0;
X			re_gamma(gamma);
X		}
X                break;
X
X	case '-':
X                if (event_is_down(event))
X		{
X			add_me -= 0.02;
X			if (add_me < -1.0)
X				add_me = -1.0;
X			re_gamma(gamma);
X		}
X		break;
X
X	case '=':
X                if (event_is_down(event))
X		{
X			add_me = 0.0;
X			re_gamma(gamma);
X		}
X		break;
X
X	case '+':
X                if (event_is_down(event))
X		{
X			add_me += 0.02;
X			if (add_me > 1.0)
X				add_me = 1.0;
X			re_gamma(gamma);
X		}
X		break;
X
X	case '?':
X                if (event_is_down(event))
X		{
X			printf("Current adjustments: offset %f, gamma %f\n", add_me, gamma);
X		}
X		break;
X
X	default:
X		/*
X		printf("event type %d, arg 0x%x", event_action(event), arg);
X		fflush(stdout);
X		if (arg != NULL)
X			printf(" %o (%c)\n", *arg, *arg);
X		else
X			printf("\n");
X		*/
X		break;
X    }
X
X} /* handlevent */
X
Xvoid usage()
X{
X
X        fprintf(stderr, "usage: %s [-l<num] [-s<num>] [-b] gif-files\n",
X                        progname);
X
X} /* usage */
END_OF_shogif.c
if test 23229 -ne `wc -c <shogif.c`; then
    echo shar: \"shogif.c\" unpacked with wrong size!
fi
# end of overwriting check
fi
echo shar: End of shell archive.
exit 0
-- 
	  Tim Pointing, DCIEM
Internet: tim@dciem.dnd.ca or tim@ben.dciem.dnd.ca
UUCP:	  ...!utzoo!dciem!tim
Organization: Graduate School of Industrial Administr., Carnegie Mellon, Pittsburgh, PA