[comp.sources.sun] v01i090: ALV - An Image Processing Toolkit, Part06/10

mcgrew@dartagnan.rutgers.edu (Charles Mcgrew) (12/12/89)

Submitted-by: everson@compsci.bristol.ac.uk
Posting-number: Volume 1, Issue 90
Archive-name: alv/part06



#! /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 6 (of 10)."
# Contents:  doc/changes.ms src/fconvolve.c src/p_event.c src/p_notif.c
#   src/scrload.c src/winlev8.c
# Wrapped by everson@kukini on Tue Oct 17 07:45:12 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'doc/changes.ms' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'doc/changes.ms'\"
else
echo shar: Extracting \"'doc/changes.ms'\" \(5676 characters\)
sed "s/^X//" >'doc/changes.ms' <<'END_OF_FILE'
X.SH
Modifications since release of V1.0 in December, 1987
X.IP "Wed Feb  3 13:01:14 GMT 1988"
Modified Makefile to enable convolve FILTERS_DIR to be passed OK
X.IP "Wed Feb  3 13:01:25 GMT 1988"
modified cdsp & dsp so as to not chop off 6 pixels on the side
X.IP "Wed Feb 17 08:54:24 GMT 1988"
modified alv.1 & alv.3 man pages to make them reflect reality
X.IP "Wed Apr 27 15:54:39 BST 1988"
modified readimage to get rid of annoying core dump bug (?)
X.IP "Wed Apr 27 15:55:32 BST 1988"
wrote idsp & cidsp command
X.IP "Wed Apr 27 15:55:48 BST 1988"
introduced updtitle function in library to automagically update title
X.IP "Thu Apr 28 14:02:20 BST 1988"
debugged freeup in dynamem & added delimage to library
X.IP "Thu Apr 28 14:02:51 BST 1988"
added cidsp - variant of idsp for colour monitors
X.IP "Wed Jun  8 19:41:43 BST 1988"
changed options of imagelw: -c becomes -h and introduce -l (quarter size
of -h option output)
X.IP "Sat Jun 18 12:25:10 BST 1988"
wrote imed v0.1 :->
X.IP "Mon Jun 20 11:48:50 BST 1988"
changed boxsize for colour workstations in imed to be 3 & added greyscale.
X.IP "Thu Jul  7 15:26:20 BST 1988"
Added ras2im & im2ras to toolkit - thanks Gareth!
X.IP "Thu Jul  7 16:33:52 BST 1988"
changed misnomer normalise to equalise
X.IP "Mon Jul 11 15:31:01 BST 1988"
added Barry's winwidth program, merged cdsp & dsp into 1 program. Also
hacked some of the documents
X.IP "Fri Jul 15 15:44:51 BST 1988"
added level & width to winwidth frame label and added coords display to
pixval. Altered manual page for winwidth in alv(1)
X.IP "Fri Jul 22 14:51:01 BST 1988"
Made winwidth thresholding precise
X.IP "Tue Aug 23 15:31:32 BST 1988"
Added stat program, minor alterations to manual page
X.IP "Thu Aug 25 20:25:05 BST 1988"
removed imed, modified manual pages alv.1 to reflect reality, added simple
tutorial file TUTORIAL, added sample_image, moved BUGFIX file to CHANGES.
X.IP "Thu Oct 20 16:20:46 BST 1988"
modified title of subarea, added beginings of transform tool
X(shear/rotate not there yet!)
X.IP "Wed Oct 26 12:15:27 BST 1988"
modified dynamem manual page to show correct way to call freeup
added new comment to Makefile.sample
X.IP "Wed Nov  9 14:18:29 GMT 1988"
made icon of dsp be a scaled down version of its image on colour workstations.
Dsp only displaying 254 greylevels to avoid screen flash on 3/260
X.IP "Thu Nov 10 08:48:08 GMT 1988"
Changed colourmap name of winwidth's colour map to be the same as that of dsp
so that cmap changes made with winwidth are kept even when winwidth is killed.
X.IP "Thu Nov 17 09:52:46 GMT 1988"
thresh now uses updtitle to update its title and therefore does it correctly.
minor mods to clean option of Makefile. 
changed Makefile so that distribution handled by makekit rather than mkshar.
split sample_image into 2 pieces.
X.IP "Mon Nov 21 12:26:21 GMT 1988"
requested by spacl@uk.ac.essex.cscvax:  imagelw now sends correct
Postscript magic string at start.  README now instructs you to type
X"make install" to compile and install all progs.  Lots of modifications
to Makefile.
X.IP "Tue Nov 22 14:59:48 GMT 1988"
winwidth now has cycle items for inverted/non-inverted & greyscale/false-colour.
Also added an extra canvas to show the current colourmap and icon.
X.IP "Thu Nov 24 16:46:53 GMT 1988"
winwidth now keeps colourmap entry 0 set to 255 so that canvas does not
change colour. Also changed colour display in dsp to may greylevels of
X0 to greylevel of 1.
X.IP "Wed Feb  8 14:28:05 GMT 1989"
Total rewrite and change of file format to produce Version 2.0
X.IP "Thu Mar  2 11:16:54 GMT 1989"
Addition of hough program from Bill Silvester. 
Mentioned SunOS3.2 compilation problems in documentation.
XFixed arguments bug when user has no alv_profile.
X.IP "Sun Mar 19 16:30:03 GMT 1989"
Added -DSUNOS3 flag to Makefile compilation to avoid rasfilter8to1 pathname
bug in dsp.
Modified dynamem.c to use varargs => convolve can be used on a Sun4.
X.IP "Mon Mar 27 10:57:33 BST 1989"
XFixed convolve scaling.
Added colour raster support to dsp
Added mono-override global option.
X.IP "Tue May  2 16:09:43 BST 1989"
fixed bug in dsp for black and white suns
X.IP "Tue May  9 15:56:42 BST 1989"
XFixed bug in hist preventing display of 0 and maxgreylevel histogram entries.
Consequently corrected bitrestrict option in many tools as they were off by 1
Ras2array no longer writes an array and then concatenates a pixrect after it!
X.IP "Mon May 29 15:49:31 BST 1989"
Added scrload (derived from scload by Ray Kreisel).
Added -c (print colourmap) and -n (don't print size/depth info) options
to rasinfo.
Added ras8to1 (derived from 8to1 by Hong Min). Lots of options.
XFixed bug that made a 1 bit image appear all black in dsp on a colour
workstation.
Changed default '8to1' filter for dsp to be ras8to1.
Removed SUNOS3 option from Makefile as it is now no longer necessary.
Added "Using ALV with a Black and White workstation" to documentation.
Added ability to compile tookit toolmerged.
X.IP "Sat Aug  5 14:39:32 BST 1989"
XFixed bug in ffill - program failed to scan the correct distance to the right.
Added 0 to argument list for execlp() in convolve
XFixed possible bug in invert - on some machines calling pr_put() with a
pr_get() as its argument caused an infintite loop.
XFixed bug in ras2lw that used to cause every 80th pixel to be ommited
when writting an image to the standard output.
Minor changes to the hardware section of the documentation to reflect
the fact that it work fully on Sun4s and on Sun386i-s with one
exception.
Added check to freeup in dynamem.c to check that a part of the array is
not equal to NULL before freeing it. Hopefully avoiding core dumps when
you attempt to allocate large arrays.
Added program glass.
END_OF_FILE
if test 5676 -ne `wc -c <'doc/changes.ms'`; then
    echo shar: \"'doc/changes.ms'\" unpacked with wrong size!
fi
# end of 'doc/changes.ms'
fi
if test -f 'src/fconvolve.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/fconvolve.c'\"
else
echo shar: Extracting \"'src/fconvolve.c'\" \(6524 characters\)
sed "s/^X//" >'src/fconvolve.c' <<'END_OF_FILE'
X#include <stdio.h>
X#include "defs.h"
X
X#define DEFAULT		0
X#define ENHANCED	1
X#define MANUAL		2
X#define SYMMETRIC	3
X
typedef struct {
X	float   **image;
X	short   xsize, ysize;
X	int     nflag;
X	float	spos, sneg;
X}       FILTER;
X
char   *progname;
char   *filename;
Pixrect *pr1, *pr2, *tmp1;
int     scale_method;
float   scale;
int     offset;
char   *filtername;
short   fcon_max_enhanced = -32768, fcon_min_enhanced = 32767;
int     mfx, mfy, newxsize, newysize;
int     levels;
XFILTER *filter;
X
X#ifdef STANDALONE
main(argc, argv, envp)
X#else
fconvolve_main(argc, argv, envp)
X#endif
X	int     argc;
X	char  **argv;
X	char  **envp;
X{
X	register int i, j;
X	FILTER *fconvolve_loadfilter();
X
X	scale_method = DEFAULT;
X	scale = 1.;
X	offset = 0;
X	filtername = strsave("non-specified");
X	progname = strsave(argv[0]);
X	parse_profile(&argc, argv, envp);
X
X	while ((gc = getopt(argc, argv, "sef:lm:M:")) != EOF)
X		switch (gc) {
X		case 's':
X			scale_method = SYMMETRIC;
X			break;
X		case 'e':
X			scale_method = ENHANCED;
X			break;
X		case 'f':
X			filtername = strsave(optarg);
X			break;
X		case 'l':
X			execlp("ls", "ls", "-C", FILTERS_DIR);
X			exit();
X			break;
X		case 'm':
X			scale_method = MANUAL;
X			scale = atof(optarg);
X			break;
X		case 'M':
X			scale_method = MANUAL;
X			offset = (int) atof(optarg);
X			break;
X		case '?':
X			errflag++;
X			break;
X		}
X
X	if (errflag)
X		error((char *) 0, "Usage: %s: [-e] [-s] [-f filter] [-l] [-m manual_scale] [-M manual_offset] [infile] [outfile]", progname);
X
X	for (stream = 0; optind < argc; stream++, optind++)
X		if (stream < 2 && strcmp(argv[optind], "-") != 0)
X			if (freopen(argv[optind], mode[stream], f[stream]) == NULL)
X				error("%s %s", PR_IO_ERR_INFILE, argv[optind]);
X
X	filter = fconvolve_loadfilter(filtername);
X
X	if ((pr1 = pr_load(stdin, NULL)) == NULL)
X		error(PR_IO_ERR_RASREAD);
X
X	if (bitrestrict)
X		levels = calc_max(pr1);
X	else
X		levels = MAXLEVEL(pr1->pr_depth);
X
X	if ((pr2 = mem_create(pr1->pr_size.x, pr1->pr_size.y, pr1->pr_depth)) == NULL)
X		error("mem_create returned NULL");
X
X	mfx = filter->xsize / 2;
X	mfy = filter->ysize / 2;
X
X	switch (scale_method) {
X	case DEFAULT:
X		fconvolve_calc_default_scale();
X		fconvolve_one_pass();
X		break;
X	case ENHANCED:
X	case SYMMETRIC:
X		fconvolve_two_pass();
X		break;
X	case MANUAL:
X		fconvolve_one_pass();
X		break;
X	}
X
X	pr_dump(pr2, stdout, NULL, RT_STANDARD, 0);
X}
X
X
XFILTER *
fconvolve_loadfilter(name)
X	char   *name;
X{
X	char    buf[BUFSIZ];
X	FILE   *fp;
X	char   *ep;
X	FILTER *filter;
X	int     xsize, ysize;
X	float 	fval;
X	register int i, j;
X	char   *getenv();
X
X	if ((ep = getenv("FILTERS")) == NULL)
X		strcpy(buf, FILTERS_DIR);
X	else
X		strcpy(buf, ep);
X
X	strcat(buf, "/");
X	strcat(buf, name);
X
X	if (!(fp = fopen(buf, "r")))
X		error("Couldn't open filter %s", name);
X
X	fscanf(fp, "%d %d", &xsize, &ysize);
X	filter = (FILTER *) malloc(sizeof(FILTER));
X	filter->image = (float **) dynamem(&(filter->image), sizeof(float), 2, ysize, xsize);
X
X	filter->nflag = FALSE;
X	filter->xsize = xsize;
X	filter->ysize = ysize;
X
X	for (j = 0; j < ysize; j++)
X		for (i = 0; i < xsize; i++) {
X			fscanf(fp, "%g", &fval);
X			filter->image[j][i] = fval;
X			if (fval < 0) {
X				filter->nflag = TRUE;
X				filter->sneg += fval;
X			} else
X				filter->spos += fval;
X		}
X	filter->sneg = fabs(filter->sneg);
X
X	return filter;
X}
enlarge_image()
X{
X	int i,j;
X	newxsize = pr1->pr_size.x + mfx * 2;
X	newysize = pr1->pr_size.y + mfy * 2;
X	if ((tmp1 = mem_create(newxsize, newysize, pr1->pr_depth)) == NULL)
X		error("mem_create returned NULL");
X	
X	for (j = 0; j<tmp1->pr_size.y; j++)
X		for(i = 0; i<tmp1->pr_size.y; i++){
X			if(i < mfx){
X				if(j < mfy)
X					pr_put(tmp1, i, j, pr_get(pr1, 0, 0));
X				else if(j < newysize - mfy)
X					pr_put(tmp1, i, j, pr_get(pr1, 0, j-mfy));
X				else
X					pr_put(tmp1, i, j, pr_get(pr1, 0, pr1->pr_size.y-1));
X				}
X			else if(i >= mfx && i < newxsize - mfx){
X				if(j < filter->ysize/2)
X					pr_put(tmp1, i, j, pr_get(pr1, i-mfx, 0));
X				else if(j >= newysize-mfy)
X					pr_put(tmp1, i, j, pr_get(pr1, i-mfx, pr1->pr_size.y-1));
X				else
X					pr_put(tmp1, i, j, pr_get(pr1, i-mfx, j-mfy));
X				}
X			else {
X				if(j < mfy)
X					pr_put(tmp1, i, j, pr_get(pr1, pr1->pr_size.x-1, 0));
X				else if(j < newysize-mfy)
X					pr_put(tmp1, i, j, pr_get(pr1, pr1->pr_size.x-1, j-mfy));
X				else
X					pr_put(tmp1, i, j, pr_get(pr1, pr1->pr_size.x-1, pr1->pr_size.y-1));
X				}
X			}
X}
X
fconvolve_calc_default_scale()
X{
X	if (filter->nflag) {
X		scale = 1.0 / (MAX(filter->spos, filter->sneg) * 2);
X		offset = levels / 2.;
X	} else {
X		scale = 1.0 / (MAX(filter->spos, filter->sneg));
X		offset = 0.;
X	}
X}
fconvolve_one_pass()
X{
X	float total;
X	register int fj, fi;
X	register int i, j;
X
X	warning("scale = %g on input, offset = %d on output", scale, offset);
X	
X	enlarge_image();
X
X	for (j = 0; j < tmp1->pr_size.y - filter->ysize; j++)
X		for (i = 0; i < tmp1->pr_size.x - filter->xsize; i++) {
X			total = 0;
X			for (fj = 0; fj < filter->ysize; fj++)
X				for (fi = 0; fi < filter->xsize; fi++)
X					total += ((float) pr_get(tmp1, i + fi, j + fj) * filter->image[fj][fi]);
X			pr_put(pr2, i, j, truncate((int)rint((total * scale) + offset), levels, 0));
X		}
X}
X
X
fconvolve_two_pass()
X{
X	float total, least, most;
X	register int fj, fi;
X	register int i, j;
X	int     tmppix;
X	Pixrect *tmp;
X	if ((tmp = mem_create(pr1->pr_size.x, pr1->pr_size.y, 32)) == NULL)
X		error("mem_create returned NULL");
X	enlarge_image();
X	/* first pass */
X	least = (2147483647.0);
X	most = (-2147483647.0);
X	for (j = 0; j <  tmp1->pr_size.y - filter->ysize; j++)
X		for (i = 0; i < tmp1->pr_size.x - filter->xsize; i++) {
X			total = 0;
X			for (fj = 0; fj < filter->ysize; fj++)
X				for (fi = 0; fi < filter->xsize; fi++)
X					total += ((float) pr_get(tmp1, i + fi, j + fj) * filter->image[fj][fi]);
X			pr_put(tmp, i, j, (int)rint(total));
X			if (total<least) least = total;
X			most = MAX(total, most);
X		}
X	least = fabs(least);
X	warning("least = %g, most = %g", least, most);
X	/* calculate scale and offset */
X	if (scale_method == SYMMETRIC) {
X		scale = (float) levels / MAX(least, most);
X		scale /= (filter->nflag) ? 2. : 1.;
X		offset = (filter->nflag) ? levels / 2 : 0;
X	} else {			    /* enhanced */
X		scale = (float) levels / (least + most);
X		offset = (filter->nflag) ? least * scale : 0;
X	}
X
X	warning("scale = %g on filter, output offset = %d on output", scale, offset);
X
X	/* second pass */
X	for (j = 0; j < pr1->pr_size.y; j++)
X		for (i = 0; i < pr1->pr_size.x; i++) {
X			tmppix = truncate((int) ((float) pr_get(tmp, i, j) * scale + offset), levels, 0);
X			pr_put(pr2, i, j, tmppix);
X		}
X}
X
X
END_OF_FILE
if test 6524 -ne `wc -c <'src/fconvolve.c'`; then
    echo shar: \"'src/fconvolve.c'\" unpacked with wrong size!
fi
# end of 'src/fconvolve.c'
fi
if test -f 'src/p_event.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/p_event.c'\"
else
echo shar: Extracting \"'src/p_event.c'\" \(7782 characters\)
sed "s/^X//" >'src/p_event.c' <<'END_OF_FILE'
X/********************************************** palette_event.c *********
X *
X *	Notes from  hsc%vanderbilt@csnet-relay
X *	Date:	7/1/87
X *
X *	Based on the version provided by the SunMicrosystem, Inc., the
X *	following features have been added to the palettetool:
X *
X *	1)	MS_RIGHT:	it paints the "selected color" over the
X *				colors through to the color selected by RM.
X *	2)	MS_MIDDLE:	this button reverses, or undoes, the last
X *				RM.
X *	3)	box lock:	the box is locked when the LM is pressed.
X *				Another LM or MM/RM will unlock the lock.
X *				This is intended to leave the box at the
X *				color when the mouse is been moved to the
X * 				control panel.  Caution: the user should
X *				allow time to let the box catch up the
X *				motion of the mouse, especially when the
X *				mouse is moved from outside of the multiple-
X *				canvas.
X *	4)	single_canvas:  the layout of the single_canvas has been
X *				changed to contain a colormap stripe reflecting
X *				the current colormap setting. The motion of the
X *				cursor within the single_canvas is traced by
X *				an arrow pointing at the colormap entry the mouse
X *				resides, together with the colormap entry number
X *				displayed.  A RM will select that color and lock
X *				the box at the corresponding color in the
X *				multiple_canvas.  The user may then move the
X *				mouse to the control panel and, if so wish,
X *				change that color.  Pressing Reset button will
X *				reset that color to its previous value before
X *				the change.
X */
X#include "p_include.h"
X
X
void
display_event_proc(canvas, event, arg)
X	Canvas  canvas;
X	Event  *event;
X	caddr_t arg;
X{
X	int     pix;
X
X	if (event_is_button(event)) {
X		pix = pw_get(canvas_pixwin(canvas), event_x(event), event_y(event));
X
X		advance_arrow(pix);
X
X		/*
X		 * fake a notifier procedure call to draw a
X		 * box over the corresponding color on the
X		 * multiple_canvas
X		 */
X		selected = FALSE;
X		event_set_id(event, LOC_MOVE);
X		event_set_x(event, (pix % 24) * (cwidth + xspace) + xoff);
X		event_set_y(event, (pix / 24) * (cheight + yspace) + yoff);
X		multiple_canvas_event_proc(multiple_canvas, event, arg);
X		/*
X		 * fake another notifier procedure call to
X		 * lock the box over the chosen color on
X		 * the multiple_canvas
X		 */
X		event_set_id(event, MS_LEFT);
X		multiple_canvas_event_proc(multiple_canvas, event, arg);
X	}
X}
X
void
multiple_canvas_event_proc(m_canvas, event, arg)
X	Window  m_canvas;
X	Event  *event;
X	caddr_t arg;
X{
X	int     x, y, i, j, x0, x1, y0, y1, hx0, hx1, hy0, hy1;
X	int     in_a_box, in_a_new_box;
X	float   m, n;
X	Pixwin *pw;
X
X	x = event_x(event);
X	y = event_y(event);
X
X	m = (x - xoff) / (cwidth + xspace);
X	n = (y - yoff) / (cheight + yspace);
X	i = (int) m;
X	j = (int) n;
X
X	pw = (Pixwin *) canvas_pixwin(m_canvas);
X
X	/*
X	 * trace the mouse motion and draw a box around the
X	 * color panel pointed by the mouse brush trace is
X	 * stopped when the LM is pressed, i.e., user has
X	 * selected a color to modify and is on his way to
X	 * the control panel (box sould not follow the
X	 * mouse when it's on its way to the control panel)
X	 */
X	if (event_id(event) == LOC_MOVE && !selected) {
X		x0 = xoff + i * (cwidth + xspace);
X		y0 = yoff + j * (cheight + yspace);
X		x1 = x0 + cwidth;
X		y1 = y0 + cheight;
X
X		in_a_box = ((m - i) * (cwidth + xspace) <= cwidth &&
X			    (n - j) * (cheight + yspace) <= cheight &&
X			    i < 24 && j < 11);
X		in_a_new_box = (in_a_box && (i != hi || j != hj));
X
X		if (in_a_new_box) {	    /* inside a box */
X			if (hi >= 0) {	    /* erase old box */
X				hx0 = xoff + hi * (cwidth + xspace);
X				hy0 = yoff + hj * (cheight + yspace);
X				hx1 = hx0 + cwidth;
X				hy1 = hy0 + cheight;
X				draw_a_box(pw, hx0 - 3, hy0 - 3, hx1 + 3, hy1 + 3, BGCOLOR);
X			}
X			draw_a_box(pw, x0 - 3, y0 - 3, x1 + 3, y1 + 3, FGCOLOR);	/* draw new box */
X			advance_arrow(ijton(i, j));
X			hi = i;
X			hj = j;
X			highlighted = 1;
X		} else {		    /* outside a box */
X			if (highlighted && (hi != i || hj != j) && hi >= 0) {
X				hx0 = xoff + hi * (cwidth + xspace);
X				hy0 = yoff + hj * (cheight + yspace);
X				hx1 = hx0 + cwidth;
X				hy1 = hy0 + cheight;
X				draw_a_box(pw, hx0 - 3, hy0 - 3, hx1 + 3, hy1 + 3, BGCOLOR);
X				advance_arrow(ijton(i, j));
X				highlighted = 0;
X			}
X		}
X	}
X	/*
X	 * when the LM is pressed, the mouse box is frozen
X	 * at wherever it currently resides, so the user
X	 * should allow time to let the box catch up the
X	 * motion of the mouse, i.e., the box should
X	 * confine the brush.
X	 */
X	if (event_id(event) == MS_LEFT && event_is_down(event) && highlighted) {
X		selected = !selected;
X		selected_i = i;
X		selected_j = j;
X		selected_n = ijton(i, j);
X		panel_set_value(red_slider, r[selected_n]);
X		panel_set_value(green_slider, g[selected_n]);
X		panel_set_value(blue_slider, b[selected_n]);
X		old_r = r[selected_n];
X		old_g = g[selected_n];
X		old_b = b[selected_n];	    /* save the overwritten
X					     * color for Reset */
X	}
X	/*
X	 * right-mouse-paint undo procedure
X	 */
X	if (event_id(event) == MS_MIDDLE && event_is_down(event)) {
X		unsigned tmp[3][MAX_CMAP_LEN];
X		int     i;
X
X		selected = FALSE;
X		if (undo_len == 0) {
X			post_msg("Nothing to be undone");
X			return;
X		}
X		for (i = 0; i < undo_len; i++) {
X			tmp[0][i] = undo_r[i];
X			tmp[1][i] = undo_g[i];
X			tmp[2][i] = undo_b[i];
X			undo_r[i] = r[i + undo_start];
X			undo_g[i] = g[i + undo_start];
X			undo_b[i] = b[i + undo_start];
X			r[i + undo_start] = tmp[0][i];
X			g[i + undo_start] = tmp[1][i];
X			b[i + undo_start] = tmp[2][i];
X		}
X		put_colors(undo_start, undo_len + 1, &r[undo_start], &g[undo_start],
X			   &b[undo_start]);
X	}
X	/*
X	 * copy color from selected_n through to that
X	 * pointed by the the right mouse button press
X	 */
X	if (event_id(event) == MS_RIGHT && event_is_down(event)) {
X		int     n = ijton(i, j);
X
X		selected = FALSE;
X		if (n >= 0 && n < MAX_CMAP_LEN && n != selected_n) {
X			int     i;
X
X			if (event_ctrl_is_down(event)) {
X				/*
X				 * paint the selected_n
X				 * color to pointed color
X				 */
X				undo_start = n;
X				undo_len = 1;
X			} else {
X				/*
X				 * paint the selected_n
X				 * color through to pointed
X				 * color
X				 */
X				undo_start = (n > selected_n) ? (selected_n + 1) : n;
X				undo_len = abs(n - selected_n);
X			}
X
X			/*
X			 * save the overwitten part for
X			 * undo
X			 */
X			pw_setcmsname(pw, CMAP_NAME);
X			pw_getcolormap(pw, undo_start, undo_len, undo_r, undo_g, undo_b);
X
X			/* do the right-mouse paint */
X			for (i = 0; i < undo_len; i++) {
X				r[undo_start + i] = r[selected_n];
X				g[undo_start + i] = g[selected_n];
X				b[undo_start + i] = b[selected_n];
X			}
X			put_colors(undo_start, undo_len,
X				   &r[undo_start], &g[undo_start], &b[undo_start]);
X			post_msg("Colors copied from LM through to RM.  Press MM to undo");
X		}
X	}
X}
X
X
void
single_canvas_event_proc(s_canvas, event, arg)
X	Window  s_canvas;
X	Event  *event;
X	caddr_t arg;
X{
X	int     y;
X	Pixwin *spw;
X
X	if (event_id(event) == MS_MIDDLE && event_is_down(event)) {
X		selected = FALSE;
X		return;
X	}
X	y = (event_y(event) - bar_offset) / 3;
X	if (y >= MAX_CMAP_LEN || selected == TRUE)
X		return;
X	spw = canvas_pixwin(s_canvas);
X	entry_id(spw, y);
X	advance_arrow(y);
X	if (event_id(event) == MS_LEFT && event_is_down(event)) {
X		entry_id(spw, y);
X		advance_arrow(y);
X		/*
X		 * fake a notifier procedure call to draw a
X		 * box over the corresponding color on the
X		 * multiple_canvas
X		 */
X		selected = FALSE;
X		event_set_id(event, LOC_MOVE);
X		event_set_x(event, (y % 24) * (cwidth + xspace) + xoff);
X		event_set_y(event, (y / 24) * (cheight + yspace) + yoff);
X		multiple_canvas_event_proc(multiple_canvas, event, arg);
X		/*
X		 * fake another notifier procedure call to
X		 * lock the box over the chosen color on
X		 * the multiple_canvas
X		 */
X		event_set_id(event, MS_LEFT);
X		multiple_canvas_event_proc(multiple_canvas, event, arg);
X	}
X}
END_OF_FILE
if test 7782 -ne `wc -c <'src/p_event.c'`; then
    echo shar: \"'src/p_event.c'\" unpacked with wrong size!
fi
# end of 'src/p_event.c'
fi
if test -f 'src/p_notif.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/p_notif.c'\"
else
echo shar: Extracting \"'src/p_notif.c'\" \(6365 characters\)
sed "s/^X//" >'src/p_notif.c' <<'END_OF_FILE'
X/*************************************************** palette_notif.c
X **********/
X
X#include "p_include.h"
X
void
draw_a_box(pw, x0, y0, x1, y1, color)
X	Pixwin *pw;
X	int     x0, y0, x1, y1, color;
X{
X	pw_vector(pw, x0, y0, x1, y0, PIX_SRC, color);
X	pw_vector(pw, x1, y0, x1, y1, PIX_SRC, color);
X	pw_vector(pw, x1, y1, x0, y1, PIX_SRC, color);
X	pw_vector(pw, x0, y1, x0, y0, PIX_SRC, color);
X}
X
void
fill_a_box(pw, x0, y0, w, h, color)
X	Pixwin *pw;
X	int     x0, y0, w, h, color;
X{
X	pw_rop(pw, x0, y0, w, h, PIX_SRC | PIX_COLOR(color), NULL, 0, 0);
X}
X
void
reset_proc(item, event)
X	Panel_item item;
X	Event  *event;
X{
X	panel_set_value(red_slider, old_r);
X	panel_set_value(green_slider, old_g);
X	panel_set_value(blue_slider, old_b);
X	r[selected_n] = old_r;
X	g[selected_n] = old_g;
X	b[selected_n] = old_b;
X	update_colors(selected_n, 1,
X		      &r[selected_n], &g[selected_n], &b[selected_n]
X	    );
X}
X
void
load_proc(item, event)
X	Panel_item item;
X	Event  *event;
X{
X	Pixwin *pw;
X	FILE   *fd;
X	int     i;
X
X	if (fd = fopen((char *) panel_get_value(file_name_item), "r")) {
X		if ((pr = pr_load(fd, &colormap)) == NULL)
X			post_msg(PR_IO_ERR_RASREAD);
X		else {
X			if (colormap.length == 0)
X				for (i = 0; i < 256; i++)
X					r[i] = g[i] = b[i] = i;
X			else
X				for (i = 0; i < colormap.length; i++) {
X					r[i] = (unsigned char) colormap.map[0][i];
X					g[i] = (unsigned char) colormap.map[1][i];
X					b[i] = (unsigned char) colormap.map[2][i];
X				}
X			fclose(fd);
X			window_set(display_canvas, CANVAS_RETAINED, FALSE,0);
X			put_colors(0, MAX_CMAP_LEN, r, g, b);
X			window_set(display_canvas, CANVAS_WIDTH, pr->pr_size.x, CANVAS_HEIGHT, pr->pr_size.y, CANVAS_RETAINED, TRUE, 0);
X			pw = canvas_pixwin(display_canvas);
X			pw_rop(pw, 0, 0, pr->pr_size.x, pr->pr_size.y, PIX_SRC, pr, 0, 0);
X			window_set(display_canvas,
X				WIN_VERTICAL_SCROLLBAR, scrollbar_create(0),
X				WIN_HORIZONTAL_SCROLLBAR, scrollbar_create(0),
X				0);
X		}
X	} else
X		post_msg("Error: file not found (or Permission denied)");
X}
post_msg(s)
X	char   *s;
X{
X	panel_set_value(msg_item, s);
X}
X
void
red_proc(item, value, event)
X	Panel_item item;
X	int     value;
X	Event  *event;
X{
X	r[selected_n] = (unsigned char) value;
X	update_colors(selected_n, 1,
X		      &r[selected_n], &g[selected_n], &b[selected_n]
X	    );
X}
X
void
green_proc(item, value, event)
X	Panel_item item;
X	int     value;
X	Event  *event;
X{
X	g[selected_n] = (unsigned char) value;
X	update_colors(selected_n, 1,
X		      &r[selected_n], &g[selected_n], &b[selected_n]
X	    );
X}
X
void
blue_proc(item, value, event)
X	Panel_item item;
X	int     value;
X	Event  *event;
X{
X	b[selected_n] = (unsigned char) value;
X	update_colors(selected_n, 1,
X		      &r[selected_n], &g[selected_n], &b[selected_n]
X	    );
X}
X
void
entry_id(pw, cmpentry)
X	Pixwin *pw;
X	int     cmpentry;
X{
X	char    yentry[12];
X
X	sprintf(yentry, "%d", cmpentry);
X	pw_rop(pw, 0, 0, 26, bar_offset + MAX_CMAP_LEN * 3 + 10, PIX_CLR, NULL, 0, 0);
X	pw_text(pw, 24 - 8 * strlen(yentry), bar_offset + cmpentry * 3 + 4, PIX_SRC | PIX_DST, NULL, yentry);
X}
X
short   markimage[] = {
X#include "../images/cursors/palette_mark.cursor"
X};
mpr_static(markpix, 16, 16, 1, markimage);
X
void
advance_arrow(n)
X	int     n;
X{
X	Pixwin *spw;
X
X	if (n >= MAX_CMAP_LEN)
X		return;
X	spw = canvas_pixwin(single_canvas);
X	pw_rop(spw, 80, 0, 100, 10 + (int) window_get(single_canvas, WIN_HEIGHT),
X	       PIX_CLR, NULL, 0, 0);
X	pw_rop(spw, 80, bar_offset + n * 3 - 7, 16, 16, PIX_SRC | PIX_DST, &markpix, 0, 0);
X	entry_id(spw, n);
X}
X
void
paint_multiple_canvas()
X{
X	int     i, j, x0, y0, x1, y1;
X
X	for (j = 0; j < 11; j++) {
X		for (i = 0; i < 24; i++) {
X			x0 = xoff + i * (cwidth + xspace);
X			y0 = yoff + j * (cheight + yspace);
X			x1 = x0 + cwidth;
X			y1 = y0 + cheight;
X			fill_a_box(canvas_pixwin(multiple_canvas), x0, y0, cwidth, cheight, ijton
X				   (i, j));
X			draw_a_box(canvas_pixwin(multiple_canvas), x0 - 1, y0 - 1, x1 + 1, y1 + 1,
X				   FGCOLOR);
X		} } }
X
void
paint_single_canvas()
X{
X	Pixwin *pw;
X	int     i, j;
X
X	pw = canvas_pixwin(single_canvas);
X	for (i = 0, j = bar_offset; i < MAX_CMAP_LEN; i++, j += 3) {
X		pw_rop(pw, 26, j, 50, 3, PIX_SRC | PIX_COLOR(i), (Pixrect *) NULL, 0, 0);
X	}
X}
X
void
put_colors(entry0, length, rd, gr, bl)
X	int     entry0, length;
X	unsigned char *rd, *gr, *bl;
X{
X	Pixwin *pw, *cpw;
X
X	pw = (Pixwin *) window_get(base_frame, WIN_PIXWIN);
X
X	pw_setcmsname(pw, CMAP_NAME);
X	pw_putcolormap(pw, entry0, length, rd, gr, bl);
X
X	pw = (Pixwin *) window_get(single_canvas, WIN_PIXWIN);
X	cpw = canvas_pixwin(single_canvas);
X
X	pw_setcmsname(pw, CMAP_NAME);
X	pw_putcolormap(pw, entry0, length, rd, gr, bl);
X	pw_setcmsname(cpw, CMAP_NAME);
X	pw_putcolormap(cpw, entry0, length, rd, gr, bl);
X
X	pw = (Pixwin *) window_get(multiple_canvas, WIN_PIXWIN);
X	cpw = canvas_pixwin(multiple_canvas);
X
X	pw_setcmsname(pw, CMAP_NAME);
X	pw_putcolormap(pw, entry0, length, rd, gr, bl);
X	pw_setcmsname(cpw, CMAP_NAME);
X	pw_putcolormap(cpw, entry0, length, rd, gr, bl);
X
X	pw = (Pixwin *) window_get(display_canvas, WIN_PIXWIN);
X	cpw = canvas_pixwin(display_canvas);
X
X	pw_setcmsname(pw, CMAP_NAME);
X	pw_putcolormap(pw, entry0, length, rd, gr, bl);
X	pw_setcmsname(cpw, CMAP_NAME);
X	pw_putcolormap(cpw, entry0, length, rd, gr, bl);
X
X	pw = (Pixwin *) window_get(control_panel, WIN_PIXWIN);
X
X	pw_setcmsname(pw, CMAP_NAME);
X	pw_putcolormap(pw, entry0, length, rd, gr, bl);
X}
X
void
update_colors(entry0, count, r, g, b)
X	int     entry0, count;
X	unsigned char *r, *g, *b;
X{
X	put_colors(entry0, count, r, g, b);
X	selected = FALSE;
X	undo_len = 0;
X}
X
void
quit_proc(item, event)
X	Panel_item item;
X	Event  *event;
X{
X	window_done(base_frame);
X}
X
void
save_proc(item, event)
X	Panel_item item;
X	Event  *event;
X{
X	char    file_name[120];
X	FILE   *fd;
X	int     i;
X	extern int confirm();
X
X	sprintf(file_name, "%s", panel_get_value(file_name_item));
X	if (strlen(file_name) == 0) {
X		post_msg("File not specified");
X		return;
X	}
X	if (access(file_name, 0) == 0) {
X		post_msg("File exists. Left mouse - confirm; Middle/Right mouse - concel");
X		if (!confirm()) {
X			post_msg("Write request cancelled");
X			return;
X		}
X	}
X	fd = fopen(file_name, "w");
X
X	for (i = 0; i < MAX_CMAP_LEN; i++) {
X		colormap.map[0][i] = (unsigned char) r[i];
X		colormap.map[1][i] = (unsigned char) g[i];
X		colormap.map[2][i] = (unsigned char) b[i];
X	}
X	pr_dump(pr, fd, &colormap, RT_STANDARD, 0);
X	fclose(fd);
X	mem_destroy(pr);
X	post_msg("File written");
X}
END_OF_FILE
if test 6365 -ne `wc -c <'src/p_notif.c'`; then
    echo shar: \"'src/p_notif.c'\" unpacked with wrong size!
fi
# end of 'src/p_notif.c'
fi
if test -f 'src/scrload.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/scrload.c'\"
else
echo shar: Extracting \"'src/scrload.c'\" \(6846 characters\)
sed "s/^X//" >'src/scrload.c' <<'END_OF_FILE'
X/*
X * Modified by Phill Everson <everson@cs.bris.ac.uk> 29th May, 1989 for
X * inclusion into the ALV toolkit.
X *
X */
X
X/**************************************************************************
X   The program "scload" is like Sun's "screenload" program, but more
X   entertaining, and actually better than screenload.
X
X   Copyright (c) 1988 by Raymond Kreisel
X   7/1/88 @ Suny Stony Brook
X
X   This program may be redistributed without fee as long as this copyright
X   notice is intact.
X
X==> PLEASE send comments and bug reports to one of the following addresses:
X
X	   Ray Kreisel
X	   CS Dept., SUNY at Stony Brook, Stony Brook NY 11794
X
X	   UUCP: {allegra, philabs, pyramid, research}!sbcs!rayk
X	   ARPA-Internet: rayk@sbcs.sunysb.edu
X	   CSnet: rayk@suny-sb
X	   (If nobody is home at any of the above addresses try:
X		S72QKRE@TOWSONVX.BITNET			        )
X
X "If I get home before daylight, I just might get some sleep tonight...."
X
X**************************************************************************/
X#include <pixrect/pixrect_hs.h>
X#include <stdio.h>
X#include <sys/time.h>
X#include <sys/types.h>
X#include <sys/stat.h>
X
X#include "defs.h"
X
char *progname;
char *filename;
Pixrect *pr;
X
X#ifdef STANDALONE
main(argc, argv, envp)
X#else
scrload_main(argc, argv, envp)
X#endif
X	int argc;
X	char **argv;
X	char **envp;
X{
X	register int i, j;
X	int levels;
X	char *fb;		/* frame buffer */
X
X	progname = strsave(argv[0]);
X	parse_profile(&argc, argv, envp);
X
X	fb = strsave("/dev/fb");
X	while ((gc = getopt(argc, argv, "f:")) != EOF)
X		switch (gc) {
X		case 'f':
X			fb = strsave(optarg);
X			break;
X		case '?':
X			errflag++;
X			break;
X		}
X
X	if (errflag)
X		error((char *) 0, "Usage: %s: [infile ...]\n", progname);
X
X	setup_greylevelmap();
X
X	if (optind == argc || strcmp(argv[optind], "-") == 0)
X		new_sc_load("", fb);
X	else
X		for (; optind < argc; optind++)
X			new_sc_load(argv[optind], fb);
X}
X
new_sc_load(filename, fb)
X	char *filename, *fb;
X{
X	char colormapname[256];
X	struct rasterfile rh;
X	colormap_t colormap;
X	FILE *fp, *fopen();
X	int i, j, width, height, off_x, off_y;
X	struct pixrect *line, *screen, *screen_temp;
X	int sleep_time = 500;
X
X	srand((int) time((time_t *) 0));
X	if (filename[0]) {
X		if ((fp = fopen(filename, "r")) == NULL) {
X			warning("%s %s", PR_IO_ERR_INFILE, filename);
X			return;
X		}
X	} else
X		fp = stdin;
X
X	screen = pr_open(fb);
X	if (!screen)
X		error("Couldn't open screen");
X
X	if (screen->pr_depth > 1) {
X		sleep_time = 0;
X		if (pr_load_header(fp, &rh))
X			error("pr_load_header failed for %s", (*filename) ? filename : "stdin");
X		if (pr_load_colormap(fp, &rh, &colormap))
X			error("pr_load_colormap failed for %s", (*filename) ? filename : "stdin");
X		if (!(screen_temp = pr_load_image(fp, &rh, &colormap)))
X			error("pr_load_image failed for %s", (*filename) ? filename : "stdin");
X		if (colormap.length)
X			pr_putcolormap(screen, 0, rh.ras_maplength / 3, colormap.map[0],
X				       colormap.map[1], colormap.map[2]);
X		else
X			pr_putcolormap(screen, 0, 256, greylevelmap, greylevelmap, greylevelmap);
X
X	} else if ((screen_temp = pr_load(fp, NULL)) == NULL)
X		error("Error reading rasterfile header for %s", (*filename) ? filename : "stdin");
X
X	width = screen_temp->pr_size.x;
X	height = screen_temp->pr_size.y;
X	if (screen->pr_size.x > screen_temp->pr_size.x)
X		off_x = (screen->pr_size.x - screen_temp->pr_size.x) / 2;
X	if (screen->pr_size.y > screen_temp->pr_size.y)
X		off_y = (screen->pr_size.y - screen_temp->pr_size.y) / 2;
X
X	switch (rand() % 8) {
X	case 0:
X		for (j = height - 16; j > 0; j -= 16) {
X			pr_rop(screen, off_x, j + off_y, width, height - j, PIX_SRC, screen_temp, 0, 0);
X			usleep(sleep_time);
X		}
X		pr_rop(screen, off_x, off_y, width, height, PIX_SRC, screen_temp, 0, 0);
X
X		break;
X	case 1:
X
X		for (j = 0; j < height; j += 32)
X			for (i = 0; i < width; i += 32)
X				pr_rop(screen, i + off_x, j + off_y, 16, 16, PIX_SRC, screen_temp, i, j);
X		for (j = 16; j < height; j += 32)
X			for (i = 16; i < width; i += 32)
X				pr_rop(screen, i + off_x, j + off_y, 16, 16, PIX_SRC, screen_temp, i, j);
X		for (j = 16; j < height; j += 32)
X			for (i = 0; i < width; i += 32)
X				pr_rop(screen, i + off_x, j + off_y, 16, 16, PIX_SRC, screen_temp, i, j);
X		for (j = 0; j < height; j += 32)
X			for (i = 16; i < width; i += 32)
X				pr_rop(screen, i + off_x, j + off_y, 16, 16, PIX_SRC, screen_temp, i, j);
X		break;
X
X	case 2:
X		for (j = height - 16; j > 0; j -= 16) {
X
X			pr_rop(screen, off_x, off_y, width, height - j, PIX_SRC, screen_temp, 0, j);
X			usleep(sleep_time);
X		}
X		pr_rop(screen, off_x, off_y, width, height, PIX_SRC, screen_temp, 0, 0);
X		break;
X
X	case 3:
X		for (j = height - 16; j > 0; j -= 16) {
X
X			pr_rop(screen, off_x, j + off_y, width / 2, height - j, PIX_SRC, screen_temp, 0, 0);
X			pr_rop(screen, off_x + width / 2, off_y, width / 2, height - j, PIX_SRC, screen_temp, width / 2, j);
X			usleep(sleep_time);
X		}
X		pr_rop(screen, off_x, off_y, width, height, PIX_SRC, screen_temp, 0, 0);
X		break;
X	case 4:
X		for (j = height - 16; j > 0; j -= 16) {
X
X			pr_rop(screen, off_x + width / 2, j + off_y, width / 2, height - j, PIX_SRC, screen_temp, width / 2, 0);
X			pr_rop(screen, off_x, off_y, width / 2, height - j, PIX_SRC, screen_temp, 0, j);
X			usleep(sleep_time);
X		}
X		pr_rop(screen, off_x, off_y, width, height, PIX_SRC, screen_temp, 0, 0);
X		break;
X
X	case 5:
X		for (j = height - 16; j > 0; j -= 16) {
X
X			pr_rop(screen, off_x, off_y, width / 4, height - j, PIX_SRC, screen_temp, 0, j);
X			pr_rop(screen, off_x + width / 4, j + off_y, width / 4 + 2, height - j, PIX_SRC, screen_temp, width / 4, 0);
X			pr_rop(screen, off_x + width / 4 * 3, j + off_y, width / 4, height - j, PIX_SRC, screen_temp, width / 4 * 3, 0);
X			pr_rop(screen, off_x + width / 2, off_y, width / 4, height - j, PIX_SRC, screen_temp, width / 2, j);
X			usleep(sleep_time);
X		}
X		pr_rop(screen, off_x, off_y, width, height, PIX_SRC, screen_temp, 0, 0);
X		break;
X	case 6:
X		for (j = height - 16; j > 0; j -= 16) {
X
X			pr_rop(screen, off_x, off_y, width / 4, height - j, PIX_SRC, screen_temp, 0, j);
X			pr_rop(screen, off_x + width / 4, j + off_y, width / 4, height - j, PIX_SRC, screen_temp, width / 4, 0);
X			pr_rop(screen, off_x + width / 2, j + off_y, width / 4, height - j, PIX_SRC, screen_temp, width / 2, 0);
X			pr_rop(screen, off_x + width / 4 * 3, off_y, width / 4, height - j, PIX_SRC, screen_temp, width / 4 * 3, j);
X			usleep(sleep_time);
X		}
X		pr_rop(screen, off_x, off_y, width, height, PIX_SRC, screen_temp, 0, 0);
X		break;
X
X	case 7:
X		for (j = 16; j < width / 2; j += 16) {
X
X			pr_rop(screen, off_x + width / 2 - j, off_y, j, height, PIX_SRC, screen_temp, 0, 0);
X			pr_rop(screen, off_x + width / 2, off_y, j, height, PIX_SRC, screen_temp, width - j, 0);
X			usleep(sleep_time);
X		}
X		pr_rop(screen, off_x, off_y, width, height, PIX_SRC, screen_temp, 0, 0);
X		break;
X	}
X	pr_destroy(screen_temp);
X	pr_close(screen);
X	fclose(fp);
X}
END_OF_FILE
if test 6846 -ne `wc -c <'src/scrload.c'`; then
    echo shar: \"'src/scrload.c'\" unpacked with wrong size!
fi
# end of 'src/scrload.c'
fi
if test -f 'src/winlev8.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'src/winlev8.c'\"
else
echo shar: Extracting \"'src/winlev8.c'\" \(7572 characters\)
sed "s/^X//" >'src/winlev8.c' <<'END_OF_FILE'
X#include <suntool/sunview.h>
X#include <suntool/canvas.h>
X#include <suntool/panel.h>
X#include <stdio.h>
X#include "defs.h"
X
X#define WINLEVFONT "/usr/lib/fonts/fixedwidthfonts/cour.r.16"
X#define XSIZE 256
X#define YSIZE 256
X
char           *progname;
X
static short    winicon[] =
X{
X#include "../images/icons/winlev8.icon"
X};
X
DEFINE_ICON_FROM_IMAGE(icon, winicon);
X
int             boxsize = 2;
static void     getcoords(), repaint_canvas(), invert_proc(), colour_proc(), quit_proc(), reset_proc();
int             invert = 0;
int             colour = 0;
int             base = 20;
int             window = 255, level = 127;
char           *progname;
X
XFrame           frame;
Canvas          canvas, canvas2;
Panel           panel, inv_panel, col_panel;
Pixfont        *font;
Pixwin         *pw, *pw2;
char            cmsname[CMS_NAMESIZE];
u_char          red[256], green[256], blue[256];
X
X#ifdef STANDALONE
main(argc, argv, envp)
X#else
winlev8_main(argc, argv, envp)
X#endif
X	int             argc;
X	char          **argv;
X	char          **envp;
X
X{
X	int             i, j, x, y;
X	u_char         *pi;
X	char           *makelabel();
X
X	progname = strsave(argv[0]);
X	parse_profile(&argc, argv, envp);
X
X	while ((gc = getopt(argc, argv, " ")) != EOF)
X		switch (gc) {
X		case '?':
X			errflag++;
X			break;
X		}
X
X	if (errflag)
X		error((char *) 0, "Usage: %s:\n", progname);
X
X	if ((font = pf_open(WINLEVFONT)) == NULL) {
X		fprintf(stderr, "%s : Cannot open %s\n", argv[0], WINLEVFONT);
X		exit(1);
X	}
X	boxsize = 1;
X
X	/* Initialise variables used to set colour map segment */
X	for (i = 0; i < 256; i++) {
X		red[i] = i;
X		green[i] = i;
X		blue[i] = i;
X	}
X	if (mono_override) {
X		red[0] = blue[0] = green[0] = 255;
X		red[254] = blue[254] = green[254] = 255;
X		red[255] = blue[255] = green[255] = 0;
X		}
X
X	/* create frame and canvas */
X	frame = window_create(NULL, FRAME,
X			      FRAME_LABEL, makelabel(),
X			      WIN_HEIGHT, YSIZE * boxsize + 78 + base,
X			      WIN_WIDTH, XSIZE * boxsize + 10,
X			      FRAME_ICON, &icon,
X			      FRAME_ARGS, argc, argv,
X			      0);
X
X	panel = window_create(frame, PANEL, 0);
X
X	inv_panel = panel_create_item(panel, PANEL_CYCLE,
X				   PANEL_CHOICE_STRINGS, "Normal", "Inv", 0,
X				      PANEL_NOTIFY_PROC, invert_proc,
X				      0);
X	col_panel = panel_create_item(panel, PANEL_CYCLE,
X				      PANEL_CHOICE_STRINGS, "Grey", "Col", 0,
X				      PANEL_NOTIFY_PROC, colour_proc,
X				      0);
X	panel_create_item(panel, PANEL_BUTTON,
X		PANEL_LABEL_IMAGE, panel_button_image(panel, "Reset", 0, 0),
X			  PANEL_NOTIFY_PROC, reset_proc,
X			  0);
X	panel_create_item(panel, PANEL_BUTTON,
X		 PANEL_LABEL_IMAGE, panel_button_image(panel, "Quit", 0, 0),
X			  PANEL_NOTIFY_PROC, quit_proc,
X			  0);
X
X	window_fit(panel);
X	window_set(panel, WIN_WIDTH, XSIZE, 0);
X
X	canvas2 = window_create(frame, CANVAS,
X				WIN_BELOW, panel,
X				WIN_X, 0,
X				WIN_WIDTH, XSIZE,
X				WIN_HEIGHT, 10,
X				0);
X	pw2 = canvas_pixwin(canvas2);
X
X	/* Set colour map segment */
X	pw_setcmsname(pw2, "greyscale8");
X	pw_putcolormap(pw2, 0, 256, red, green, blue);
X	draw_ramp();
X
X	canvas = window_create(frame, CANVAS,
X			       WIN_BELOW, canvas2,
X			       WIN_X, 0,
X			       WIN_EVENT_PROC, getcoords,
X			       0);
X
X	/* get the canvas pixwin to draw into */
X	pw = canvas_pixwin(canvas);
X
X	/* Set colour map segment */
X	pw_setcmsname(pw, "greyscale8");
X	pw_putcolormap(pw, 0, 256, red, green, blue);
X
X	window_set(canvas, WIN_CONSUME_PICK_EVENTS, LOC_DRAG, 0, 0);
X
X	pw_vector(pw, 0, 255, 255, 255, PIX_SRC, 255);
X	pw_vector(pw, 127, 255, 127, 0, PIX_SRC, 255);
X	pw_vector(pw, 0, 255, 255, 0, PIX_SRC, 255);
X	pw_vector(pw, 255, 255, 0, 0, PIX_SRC, 255);
X	pr_text(pw->pw_prretained, 0, 128, PIX_SRC, font, "Window");
X	pr_text(pw->pw_prretained, 108, 250, PIX_SRC, font, "Level");
X
X	window_main_loop(frame);
X}
X
static void
invert_proc(item, value, event)
X	Panel_item      item;
X	int             value;
X	Event          *event;
X{
X	invert = value;
X	setupcolourmap();
X}
X
static void
colour_proc(item, value, event)
X	Panel_item      item;
X	int             value;
X	Event          *event;
X{
X	colour = value;
X	setupcolourmap();
X}
X
X
static void
getcoords(canvas, event, arg)
X	Canvas          canvas;
X	Event          *event;
X	caddr_t         arg;
X{
X	char           *makelabel();
X
X	if ((event_id(event) == LOC_DRAG)
X	    || (event_id(event) == MS_LEFT)
X	    || (event_id(event) == MS_RIGHT)
X	    || (event_id(event) == MS_MIDDLE)) {
X		window = (255 - event_y(event)) * 2;	/* allows double window
X							 * if desired */
X		window = (window < 0) ? 0 : window;
X		level = event_x(event);
X
X		setupcolourmap();
X		window_set(frame, FRAME_LABEL, makelabel(), 0);
X	}
X}
X
setupcolourmap()
X{
X	int             col, i;
X	double          m;
X
X	/* Initialise variables used to set colour map segment */
X	for (i = 0; i < 256; i++) {
X		if (window) {
X			m = 256.0 / window;
X			col = m * (i - level) + 127;
X		} else
X			col = (i < level) ? 0 : 255;
X		col = (col < 0) ? 0 :
X			(col > 255) ? 255 : col;
X		col = (invert) ? 255 - col : col;
X		if (colour) {
X			getrgb(col, &red[i], &green[i], &blue[i]);
X		} else {
X			red[i] = col;
X			green[i] = col;
X			blue[i] = col;
X		}
X	}
X	if (mono_override) {
X		red[0] = green[0] = blue[0] = 255;
X		/*red[254] = blue[254] = green[254] = 255;*/
X		red[255] = blue[255] = green[255] = 0;
X		}
X	pw_putcolormap(pw, 0, 256, red, green, blue);
X	pw_putcolormap(pw2, 0, 256, red, green, blue);
X}
X
char           *
makelabel()
X{
X	static char     buf[BUFSIZ];
X	char           *sprintf();
X
X	return sprintf(buf, "Window = %3d  Level = %3d", window, level);
X}
X
getrgb(val, r, g, b)
X	int             val;
X	u_char         *r, *g, *b;
X{
X	static float    coltab[48][3] = {
X		1.0, 1.0, 1.0,
X		1.0, 0.75, 0.75,
X		1.0, 0.5, 0.5,
X		1.0, 0.25, 0.25,
X		1.0, 0.0, 0.0,
X		/* 1.0, 0.064, 0.0, */
X		1.0, 0.193, 0.0,
X		1.0, 0.258, 0.0,
X		1.0, 0.323, 0.0,
X		1.0, 0.387, 0.0,
X		1.0, 0.452, 0.0,
X		1.0, 0.516, 0.0,
X		1.0, 0.548, 0.0,
X		1.0, 0.613, 0.0,
X		1.0, 0.677, 0.0,
X		1.0, 0.742, 0.0,
X		1.0, 0.806, 0.0,
X		1.0, 0.871, 0.0,
X		1.0, 0.936, 0.0,
X		1.0, 1.0, 0.0,
X		0.903, 1.0, 0.0,
X		0.806, 1.0, 0.0,
X		0.677, 1.0, 0.0,
X		0.516, 1.0, 0.0,
X		0.0, 1.0, 0.452,
X		0.0, 1.0, 0.710,
X		0.0, 1.0, 1.0,
X		0.0, 0.871, 1.0,
X		0.0, 0.677, 1.0,
X		0.0, 0.613, 1.0,
X		0.0, 0.548, 1.0,
X		0.0, 0.484, 1.0,
X		0.0, 0.419, 1.0,
X		0.0, 0.355, 1.0,
X		0.0, 0.290, 1.0,
X		0.0, 0.226, 1.0,
X		0.0, 0.161, 1.0,
X		0.0, 0.0, 1.0,
X		0.516, 0.0, 1.0,
X		0.581, 0.0, 1.0,
X		0.645, 0.0, 1.0,
X		0.710, 0.0, 1.0,
X		0.774, 0.0, 1.0,
X		0.839, 0.0, 1.0,
X		0.903, 0.0, 1.0,
X		0.968, 0.0, 1.0,
X		1.0, 0.0, 0.935,
X		1.0, 0.0, 0.839,
X		1.0, 0.0, 0.742
X
X		/*
X		 * 1.0, 0.0, 0.613, 1.0, 0.0, 0.484, 1.0, 0.0, 0.097
X		 */
X	};
X
X	int             val48;
X	float           rval48, roffset;
X	float           rr, rg, rb;
X
X	rval48 = val / 5.426;
X	val48 = rval48;
X	roffset = rval48 - (float) val48;
X
X	rr = (coltab[val48][0] * (1.0 - roffset) + coltab[val48 + 1][0] * roffset);
X	rg = (coltab[val48][1] * (1.0 - roffset) + coltab[val48 + 1][1] * roffset);
X	rb = (coltab[val48][2] * (1.0 - roffset) + coltab[val48 + 1][2] * roffset);
X	*r = ((rr * 0.9 + 0.1) * 255.0 + 0.5);
X	*g = ((rg * 0.85 + 0.15) * 255.0 + 0.5);
X	*b = ((rb * 0.9 + 0.1) * 255.0 + 0.5);
X}
X
static void
quit_proc()
X{
X	window_set(frame, FRAME_NO_CONFIRM, TRUE, 0);
X	window_destroy(frame);
X}
X
static void
reset_proc()
X{
X	window = 255;
X	level = 127;
X	invert = 0;
X	colour = 0;
X	panel_set_value(inv_panel, invert);
X	panel_set_value(col_panel, colour);
X	setupcolourmap();
X	window_set(frame, FRAME_LABEL, makelabel(), 0);
X}
X
draw_ramp()
X{
X	register        i;
X
X	for (i = 0; i < XSIZE; i++)
X		pw_vector(pw2, i, 0, i, 10, PIX_SRC, i);
X}
END_OF_FILE
if test 7572 -ne `wc -c <'src/winlev8.c'`; then
    echo shar: \"'src/winlev8.c'\" unpacked with wrong size!
fi
# end of 'src/winlev8.c'
fi
echo shar: End of archive 6 \(of 10\).
cp /dev/null ark6isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 10 ; do
    if test ! -f ark${I}isdone ; then
	MISSING="${MISSING} ${I}"
    fi
done
if test "${MISSING}" = "" ; then
    echo You have unpacked all 10 archives.
    rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
    echo You still need to unpack the following archives:
    echo "        " ${MISSING}
fi
##  End of shell archive.
exit 0