[mod.sources] tools for editing Sun icons

sources-request@panda.UUCP (05/13/86)

Mod.sources:  Volume 4, Issue 119
Submitted by: David C. Martin <decvax!ucbvax!dcmartin>

As you may know the Sun icon editor only edits icons of the size 64x64
or 16x16.  I have written three small utility programs to edit and show
icons on a terminal.

moveicon: moves a 64x64 icon in the X/Y plane (either -/-, -/+, +/-  or +/+)
          and outputs an icon-style file of a 64x64 icon.
trimicon: takes a 64x64 icon, trims off bits beyond the specified width and
	  height and outputs a width by height size icon file.
showicon: shows a 64x64 icon on a terminal using x's.

There is a fourth program called showpix (still being hacked w/ from time 
to time) which shows arbitrary sized pixrects on a Sun.  It takes a list 
of files as arguments and opens a tool for viewing them.

Enjoy

dcm
-----
David C. Martin
-----
University of California at Berkeley
College of Engineering
Electronics Research Lab
434 Evans Hall
Berkeley, CA 94720
-----
arpa: dcmartin@ingres.Berkeley.EDU                 home: 5433 Thomas Avenue
uucp: {ihnp4,decvax}!ucbvax!dcmartin                     Oakland, CA 94618
at&t: 415/642-3560 (O) - 415/547-8569 (H)

------------------------- CUT HERE ---------------------------------------
#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	Makefile
#	bitmap.c
#	bitmap.h
#	moveicon.c
#	showicon.c
#	showpix.c
#	showpix.icon
#	trimicon.c
# This archive created: Mon May 12 23:37:59 1986
export PATH; PATH=/bin:$PATH
echo shar: extracting "'Makefile'" '(547 characters)'
if test -f 'Makefile'
then
	echo shar: will not over-write existing file "'Makefile'"
else
cat << \SHAR_EOF > 'Makefile'
DEBUG	=
CFLAGS	= -O $(DEBUG)
AFLAGS	= -A-m68010
OFILES	= showpix.o bitmap.o
CC	= /bin/cc
LIBS 	= -lsuntool -lsunwindow -lpixrect

all:	showpix moveicon showicon trimicon
showpix			: $(OFILES)
			$(CC) $(CFLAGS) -o showpix $(OFILES) $(LIBS)

bitmap.o		: bitmap.c bitmap.h
			$(CC) $(CFLAGS) -c bitmap.c

showpix.o		: showpix.c bitmap.h
			$(CC) $(CFLAGS) -c showpix.c

moveicon		: moveicon.c
			$(CC) $(CFLAGS) -o $@ moveicon.c

showicon		: showicon.c
			$(CC) $(CFLAGS) -o $@ showicon.c

trimicon		: trimicon.c
			$(CC) $(CFLAGS) -o $@ trimicon.c
SHAR_EOF
if test 547 -ne "`wc -c < 'Makefile'`"
then
	echo shar: error transmitting "'Makefile'" '(should have been 547 characters)'
fi
fi
echo shar: extracting "'bitmap.c'" '(3054 characters)'
if test -f 'bitmap.c'
then
	echo shar: will not over-write existing file "'bitmap.c'"
else
cat << \SHAR_EOF > 'bitmap.c'
#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <pixrect/pixrect_hs.h>
#include "bitmap.h"

#define HEADER_FORMAT	"/* Format_version=%d, Width=%d, Height=%d, Depth=%d, \
				Valid_bits_per_item=%d"

/*
 * Load bitmap header.
 */
extern FILE *
bm_open(filename, bmh_ptr)
char		*filename;
Bitmap_hdr	*bmh_ptr;
{
	register int	c;
	FILE		*fp;
	char		buf[BUFSIZ];
	struct stat	statbuf;

	/* stat(2) the file to make sure it is a ``regular'' file */
	if (stat(filename, &statbuf) == -1) {
		perror("stat");
		return(NULL);
	}
	if (statbuf.st_mode & S_IFMT != S_IFREG) {
		return(NULL);
	}
	/* open the file */
	if ((fp = fopen(filename, "r")) == NULL) {
		return(NULL);
	}
	/* read header information */
	for (;;) {
		/* get a line */
		if (fgets(buf, BUFSIZ, fp) == NULL) {
			(void) fclose(fp);
			return(NULL);
		}
		/* check to see if a '=' character appears in the line */
		if (index(buf, '=') == 0) continue;
		/* since the '=' was present, assume this line is the format */
		if (sscanf(buf, HEADER_FORMAT, &bmh_ptr->format_version, 
		    &bmh_ptr->width, &bmh_ptr->height, &bmh_ptr->depth, 
	    	    &bmh_ptr->valid_bits_per_item) != 5) {
			(void) fclose(fp);
			return(NULL);
		}
		break;
	} /* end for */
	/* read until we get past all the comments */
	while ((c = getc(fp)) != EOF && c != '\t');
	/* if <c> equals EOF the file is improperly formatted */
	if (c == EOF) {
		(void) fclose(fp);
		return(NULL);
	}
	/* return the file pointer */
	return(fp);
} /* end bm_open() */

/*
 * Load specific bitmap.
 */
extern Bitmap *
bm_load(filename)
char	*filename;
{
	register int		i, nitem;
	register u_int		*data, *data_ptr;
	Bitmap			*bm_ptr;
	Bitmap_hdr		bmh_buf;
	FILE			*fp;

	/* open icon file and read header information */
	if ((fp = bm_open(filename, &bmh_buf)) == NULL) {
		return(NULL_BM);
	}
	/* check to make sure we still are using version 1 */
	if (bmh_buf.format_version != 1) {
		(void) fclose(fp);
		return(NULL_BM);
	}
	/* compute the number of items */
	nitem = ((bmh_buf.width + WORDSIZE - 1) / WORDSIZE) * bmh_buf.height;
	/* create data space for bitmap */
	data_ptr = data = (u_int *) malloc(sizeof(u_int) * nitem);
	/* read data from file */
	for (i = 0; i < nitem; i++) {
		if (fscanf(fp, " 0x%X,", data_ptr++) != 1) {
			free(data);
			(void) fclose(fp);
			return(NULL_BM);
		}
	}
	/* create bitmap */
	bm_ptr = (Bitmap *) malloc(sizeof(Bitmap));
	/* initialize values */
	bm_ptr->width = bmh_buf.width;
	bm_ptr->height = bmh_buf.height;
	bm_ptr->depth = bmh_buf.depth;
	/* create bitmap pixrect */
	if ((bm_ptr->bitmap_pr = mem_create(bm_ptr->width, 
	    bm_ptr->height, bm_ptr->depth)) == NULL) {
		free(data);
		free(bm_ptr);
		(void) fclose(fp);
		return(NULL_BM);
	}
	/* put data into bitmap */
	data_ptr = (u_int *) mpr_d(bm_ptr->bitmap_pr)->md_image;
	for (i = ((nitem % 2 == 0) ? nitem : nitem + 1); i-- > 0; i--) {
		data_ptr[i / 2] = data[i];
		data_ptr[i / 2] |= (data[i - 1] << WORDSIZE);
	}
	free(data);
	(void) fclose(fp);
	return(bm_ptr);
} /* end bm_load() */
SHAR_EOF
if test 3054 -ne "`wc -c < 'bitmap.c'`"
then
	echo shar: error transmitting "'bitmap.c'" '(should have been 3054 characters)'
fi
fi
echo shar: extracting "'bitmap.h'" '(401 characters)'
if test -f 'bitmap.h'
then
	echo shar: will not over-write existing file "'bitmap.h'"
else
cat << \SHAR_EOF > 'bitmap.h'
#ifndef BITMAP_HDR
#define BITMAP_HDR

#define	WORDSIZE	16

typedef struct bitmapStruct {
	int		height;
	int		width;
	int		depth;
	struct pixrect	*bitmap_pr;
} Bitmap;

typedef struct bitmap_hdrStruct {
	int		depth;
	int		height;
	int		format_version;
	int		valid_bits_per_item;
	int		width;
} Bitmap_hdr;

#define	NULL_BM		((Bitmap *) NULL)

extern FILE	*bm_open();
extern Bitmap	*bm_load();

#endif
SHAR_EOF
if test 401 -ne "`wc -c < 'bitmap.h'`"
then
	echo shar: error transmitting "'bitmap.h'" '(should have been 401 characters)'
fi
fi
echo shar: extracting "'moveicon.c'" '(3878 characters)'
if test -f 'moveicon.c'
then
	echo shar: will not over-write existing file "'moveicon.c'"
else
cat << \SHAR_EOF > 'moveicon.c'
#include <stdio.h>
#include <sys/types.h>

#define WIDTH		64
#define HEIGHT		64
#define WORDSIZ		16
#define NCOL		(WIDTH / WORDSIZ)
#define NROW		(HEIGHT)

main(argc, argv)
int	argc;
char	**argv;
{
	register int	i, j, k;
	register char	c;
	int		off_x, off_y;
	u_int		data[NROW][NCOL];
	FILE		*fp;

	/* check to make sure they specified the correct # of args */
	if (argc != 3 && argc != 4) {
		fprintf(stderr, "usage: moveicon offset_x offset_y { icon }\n");
		exit(1);
	}
	/* get the offset */
	off_x = atoi(argv[1]);
	off_y = atoi(argv[2]);
	/* did they specify a filename? */
	if (argc == 4 && argv[3] != (char *) NULL) {
		/* yes -- open it */
		if ((fp = fopen(argv[3], "r")) == NULL) {
			fprintf(stderr, "Can't open file %s for reading\n", 
				argv[3]);
			exit(1);
		}
	} else {
		/* no -- set <fp> to be stdin */
		fp = stdin;
	}
		
	/* skip the comments */
	while ((c = getc(fp)) != '\t');

	/* read in the icon */
	for (i = 0; i < NROW; i++) {
		for (j = 0; j < NCOL; j++) {
			if (fscanf(fp, " 0x%x,", &data[i][j]) != 1) {
				fprintf("Error reading file %s\n", argv[3]);
				exit(1);
			}
		} /* end for */
	} /* end for */

	/* close the file */
	fclose(fp);

	/* move the icon vertically */
	if (off_y < 0) {
		for (i = 0; i < NROW; i++) {
			if (i - off_y < NROW) {
				for (j = 0; j < NCOL; j++) {
					data[i][j] = data[i - off_y][j];
				} /* end for */
			} else {
				for (j = 0; j < NCOL; j++) {
					data[i][j] = (u_int) 0;
				} /* end for */
			} /* end else */
		} /* end for */
	} else {
		for (i = NROW - 1; i >= 0; i--) {
			if (i - off_y >= 0) {
				for (j = 0; j < NCOL; j++) {
					data[i][j] = data[i - off_y][j];
				} /* end for */
			} else {
				for (j = 0; j < NCOL; j++) {
					data[i][j] = (u_int) 0;
				} /* end for */
			} /* end else */
		} /* end for */
	} /* end else */

	/* move the icon horizontally */
	for (i = 0; i < NROW; i++) {
		u_int	ofbits = 0;		/* overflow bits */
		u_int	prev = 0;		/* previous overflow bits */

		if (off_x > 0) { 
			/* do we need to shift words to the right? */
			if (off_x >= WORDSIZ) {
				/* yes -- shift low to high */
				j = NCOL - 1;
				k = j - off_x / WORDSIZ;
				/* shift words to the right */
				while (j >= 0) {
					data[i][j] = data[i][k];
					data[i][k] = (u_int) 0;
					j--, k--;
				} /* end while */
				/* subtract the word shift from the offset */
				off_x = off_x % WORDSIZ;
			} /* end if */
			/* shift the bits in the words */
			for (j = 0; j < NCOL; j++) {
				/* store the overflow bits */
				ofbits = data[i][j] << (WORDSIZ - off_x);
				/* set the new value */
				data[i][j] = prev | (data[i][j] >> off_x);
				/* make the current overflow bits previous */
				prev = ofbits;
			} /* end for */
		} else {
			int	tmp_x = abs(off_x);

			/* do we need to shift words to the left? */
			if (tmp_x >= 16) {
				/* yes -- shift high to low */
				j = tmp_x / WORDSIZ;
				k = 0;
				while (j < NCOL) {
					data[i][k] = data[i][j];
					data[i][j] = (u_int) 0;
					j++, k++;
				} /* end while */
				/* subtract the word shift from the offset */
				tmp_x = tmp_x % WORDSIZ;
			} /* end if */
			/* shift the bits in the words */
			for (j = NCOL - 1; j >= 0; j--) {
				/* store the overflow bits */
				ofbits = data[i][j] >> (WORDSIZ - tmp_x);
				/* set the new value */
				data[i][j] = prev | (data[i][j] << tmp_x);
				/* make the current overflow bits previous */
				prev = ofbits;
			} /* end for */
		} /* end else */
	} /* end for */

	/* output the icon file */
	printf("/* Format_version=1, Width=%d, Height=%d, ", WIDTH, HEIGHT);
	printf("Depth=1, Valid_bits_per_item=%d */", WORDSIZ);
	for (i = 0; i < NROW; i++) {
		/* print two rows on a line */
		if (i % 2 == 0) printf("\n\t");
		/* print the row */
		for (j = 0; j < NCOL; j++) {
			printf("0x%04x,", data[i][j] & 0xffff);
		} /* end for */
	} /* end for */
	printf("\n");
} /* end main() */
SHAR_EOF
if test 3878 -ne "`wc -c < 'moveicon.c'`"
then
	echo shar: error transmitting "'moveicon.c'" '(should have been 3878 characters)'
fi
fi
echo shar: extracting "'showicon.c'" '(619 characters)'
if test -f 'showicon.c'
then
	echo shar: will not over-write existing file "'showicon.c'"
else
cat << \SHAR_EOF > 'showicon.c'
#include <stdio.h>
#include <sys/types.h>

main(argc, argv)
int	argc;
char	**argv;
{
	register int	i, j, k;
	register char	c;
	u_int		data[256];
	FILE		*fp;

	if (argc < 2) {
		fp = stdin;
	} else {
		if ((fp = fopen(argv[1], "r")) == NULL) exit(1);
	}
	while ((c = getc(fp)) != '\t');
	for (i = 0; i < 256; i++) {
		if (fscanf(fp, " 0x%x,", &data[i]) != 1) {
			exit(1);
		}
	}
	for (i = 0; i < 256; i+= 4) {
		for (j = 0; j < 4; j++) {
			for (k = 15; k >= 0; k--) {
				if (data[i+j] & (1 << k)) {
					putchar('x');
				} else {
					putchar(' ');
				}
			}
		}
		putchar('\n');
	}
	fclose(fp);
} /* end main() */
SHAR_EOF
if test 619 -ne "`wc -c < 'showicon.c'`"
then
	echo shar: error transmitting "'showicon.c'" '(should have been 619 characters)'
fi
fi
echo shar: extracting "'showpix.c'" '(6991 characters)'
if test -f 'showpix.c'
then
	echo shar: will not over-write existing file "'showpix.c'"
else
cat << \SHAR_EOF > 'showpix.c'
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <suntool/sunview.h>
#include <suntool/canvas.h>
#include "bitmap.h"

/*
 * Typedef'ing things...
 */
typedef struct pixrect	Pixrect;

/*
 * Unique menu identifiers 
 */
#define FILEN			((caddr_t) 1)
#define MORE			((caddr_t) 2)
#define QUIT			((caddr_t) 3)

#define MAX_BITMAPS		256
#define NULL_PR			((Pixrect *) NULL)
#define canvas_width(canvas)	(int) window_get(canvas, CANVAS_WIDTH)
#define canvas_height(canvas)	(int) window_get(canvas, CANVAS_HEIGHT)

#define NUM_ROW			5
#define NUM_COLUMN		5
#define ROW_GAP			10
#define ROW_HEIGHT		64
#define COLUMN_GAP		10
#define COLUMN_WIDTH		64
#define DISPLAY_MARGIN		10
#define DISPLAY_WIDTH		((COLUMN_WIDTH + COLUMN_GAP) * NUM_COLUMN)
#define DISPLAY_HEIGHT		((ROW_HEIGHT + ROW_GAP) * NUM_ROW)
#define WINDOW_MARGIN		10
#define WINDOW_WIDTH		(DISPLAY_WIDTH + 2 * DISPLAY_MARGIN + \
					2 * WINDOW_MARGIN)
#define WINDOW_HEIGHT		(DISPLAY_HEIGHT + 2 * DISPLAY_MARGIN + \
					2 * WINDOW_MARGIN)

/*
 * The tool's icon
 */
static short	icon_data[] = {
#include "showpix.icon"
};
mpr_static(icon_pixrect, 64, 64, 1, icon_data);

/*
 * The data for grey background
 */
static short	grey_data[] = {
        0xAAAA,0x5555,0xAAAA,0x5555,
	0xAAAA,0x5555,0xAAAA,0x5555,
	0xAAAA,0x5555,0xAAAA,0x5555,
	0xAAAA,0x5555,0xAAAA,0x5555
};

/*
 * The data for white background
 */
static short	white_data[] = {
			0x0000, 0x0000, 0x0000, 0x0000,
			0x0000, 0x0000, 0x0000, 0x0000,
			0x0000, 0x0000, 0x0000, 0x0000,
			0x0000, 0x0000, 0x0000, 0x0000
};

/*
 * Local variables
 */
Bitmap		*bitmaps[MAX_BITMAPS];
static int	nbitmap;
static Menu	menu;
static int	display_width = DISPLAY_WIDTH;
static int	display_height = DISPLAY_HEIGHT;
static int	canvas_resized = FALSE;
static int	ending_bitmap = 0;
static Pixrect	*bkg_pr;

static void
usage()
{
	printf("usage: showpix [ -grey ] bitmap1 [ bitmap2 ... ]\n");
	exit(1);
} /* end usage() */

static void
punt(str)
char	*str;
{
	fprintf(stderr, "%s\n", str);
	exit(1);
} /* end punt() */

/*
 * Load all bitmaps specified on command line.
 */
static void
load_bitmaps(argc, argv)
int	argc;
char	**argv;
{
	register int	i;
	struct stat	statbuf;
	Bitmap		*tmp_bitmap;

	/* process each argument */
	for (i = 0, nbitmap = 0; i < argc; i++) {
		/* check that this is a regular file */
		stat(argv[i], &statbuf);
		if (statbuf.st_mode & S_IFMT != TRUE) {
			fprintf(stderr, "File %s not a plain file.\n", argv[i]);
			continue;
		} 
		/* load the bitmap */
		if ((tmp_bitmap = bm_load(argv[i])) == NULL_BM) {
			fprintf(stderr, "Error loading %s\n", argv[i]);
			continue;
		} else {
			bitmaps[nbitmap++] = tmp_bitmap;
		}
	} /* end for */
} /* end load_bitmaps() */

/* 
 * Print the bitmap pixrects into the canvas pixwin.
 */
static void
paint_bitmaps(canvas)
Canvas	canvas;
{
	register int	i, dst_x, dst_y, off_x;
	Pixwin		*canvas_pw;
	Pixrect		*canvas_mpr;

	/* initalialize canvas pixwin */
	canvas_pw = canvas_pixwin(canvas);
	/* get the memory pixrect */
	canvas_mpr = canvas_pw->pw_prretained;
	/* replicate background source pixrect over background pixwin */
	pr_replrop(canvas_mpr, 0, 0, display_width, display_height, PIX_SRC, 
		bkg_pr, 0, 0);
	/* initialize vertical offset into memory pixrect */
	dst_y = ROW_GAP;
	/* copy bitmaps into memory pixrect */
	for (i = ending_bitmap; i < nbitmap; ) {
		if (dst_y + bitmaps[i]->height > display_height) break;
		/* initialize horizontal offset into memory pixrect */
		dst_x = COLUMN_GAP;
		off_x = 0;
		while (i < nbitmap) {
		    	if (dst_x + bitmaps[i]->width > display_width) break;
			pr_rop(canvas_mpr, dst_x, dst_y, bitmaps[i]->width, 
				bitmaps[i]->height, PIX_SRC, 
				bitmaps[i]->bitmap_pr, 0, 0);
			dst_x += (bitmaps[i]->width + COLUMN_GAP);
			if (bitmaps[i]->height > off_x) {
				off_x = bitmaps[i]->height;
			}
			i++;
		} /* end while */
		dst_y += (off_x + ROW_GAP);
	} /* end while */
	/* refresh the screen image */
	pw_write(canvas_pw, 0, 0, display_width, display_height, PIX_SRC,
		canvas_mpr, 0, 0);
	/* if we have hit the end, cycle around */
	ending_bitmap = (i < nbitmap) ? i : 0;
} /* end paint_bitmaps() */

static void
canvas_resize_proc(canvas, width, height)
Canvas	canvas;
int	width;
int	height;
{
	/* reset height && width */
	display_height = canvas_height(canvas);
	display_width = canvas_width(canvas);
	/* cycle to beginning */
	ending_bitmap = 0;
	/* repaint the bitmaps */
	paint_bitmaps(canvas);
} /* end canvas_resize_proc() */

static void
canvas_event_proc(canvas, eventp, arg)
Canvas	canvas;
Event	*eventp;
caddr_t	arg;
{
	caddr_t	mi;	/* a menu item */

	/* handle the mouse button events */
	switch(event_id(eventp)) {
		case MS_LEFT:		/* handle left button events */
			break;
		case MS_MIDDLE:		/* handle middle button events */
			break;
		case MS_RIGHT:		/* handle right button events */
			mi = menu_show(menu, canvas, eventp, 0);
			if (mi == NULL) break;
			switch (mi) {
				case FILEN:
					/* get new file name(s) */
					break;
				case MORE:
					/* show next page */
					paint_bitmaps(canvas);
					break;
				case QUIT:
					/* destroy all windows && exit */
					window_done(canvas);
					break;
			} /* end switch */
			break;
	} /* end switch */
} /* end canvas_event_proc() */

main(argc, argv)
int	argc;
char	**argv;
{
	Canvas		canvas;
	Frame		base_frame;

	/* check for usage */
	if (argc < 2) usage();
	/* skip over the program name */
	argc--;
	argv++;
	/* check to see what kind of background they want */
	if (strcmp(*argv, "-grey") == 0) {
		bkg_pr = mem_point(16, 16, 1, grey_data); 
		/* skip over the background option */
		argv++;
		if (argc-- < 1) usage();
	} else {
		bkg_pr = mem_point(16, 16, 1, white_data);
	}
	/* create the root window */
	if ((base_frame = window_create(NULL, FRAME, 
	    WIN_WIDTH,			WINDOW_WIDTH,
	    WIN_HEIGHT,			WINDOW_HEIGHT,
	    FRAME_SHOW_LABEL,		FALSE,
	    FRAME_ICON,			icon_create(ICON_IMAGE, &icon_pixrect),
	    0)) == NULL) {
		punt("Error creating base frame.");
	}
	/* create its child */
	if ((canvas = window_create(base_frame, CANVAS, 
	    CANVAS_WIDTH,		DISPLAY_WIDTH,
	    CANVAS_HEIGHT,		DISPLAY_HEIGHT,
	    CANVAS_MARGIN,		DISPLAY_MARGIN,
	    CANVAS_AUTO_EXPAND,		TRUE,
	    CANVAS_AUTO_SHRINK,		TRUE,
	    CANVAS_FIXED_IMAGE,		FALSE,
	    CANVAS_RETAINED,		TRUE,
	    CANVAS_RESIZE_PROC,		canvas_resize_proc,
	    WIN_EVENT_PROC,		canvas_event_proc,
	    0)) == NULL) {
		punt("Error creating canvas.");
	}
	/* create a menu w/ the three menu items (FILEN, MORE && QUIT) */
	if ((menu = menu_create(
	    MENU_ITEM, MENU_STRING_ITEM, 	"File ...", FILEN, 0,
	    MENU_ITEM, MENU_STRING_ITEM, 	"More", MORE, 0,
	    MENU_ITEM, MENU_STRING_ITEM, 	"Quit", QUIT, 0,
	    MENU_INITIAL_SELECTION_SELECTED,    TRUE,
	    MENU_INITIAL_SELECTION,             MENU_SELECTED,
	    0)) == NULL) {
		punt("Error creating menu.");
	}
	/* load the bitmaps */
	load_bitmaps(argc, argv);
	/* start the program */
	window_main_loop(base_frame);
} /* end main() */
SHAR_EOF
if test 6991 -ne "`wc -c < 'showpix.c'`"
then
	echo shar: error transmitting "'showpix.c'" '(should have been 6991 characters)'
fi
fi
echo shar: extracting "'showpix.icon'" '(1933 characters)'
if test -f 'showpix.icon'
then
	echo shar: will not over-write existing file "'showpix.icon'"
else
cat << \SHAR_EOF > 'showpix.icon'
/* Format_version=1, Width=64, Height=64, Depth=1, Valid_bits_per_item=16
 */
	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,
	0xC000,0x0000,0x0000,0x0003,0xC000,0x0000,0x0000,0x0003,
	0xC000,0x0000,0x0000,0x0003,0xC000,0x0000,0x0000,0x0003,
	0xC000,0x0000,0x0000,0x0003,0xC1FF,0xFFFF,0xFFFF,0xFF03,
	0xC100,0x4000,0x0200,0x0183,0xC100,0x5E00,0x0200,0x0183,
	0xC100,0x4000,0x0180,0x2183,0xC100,0x4000,0x0080,0x2183,
	0xC100,0x9800,0x0100,0x2183,0xC100,0x8600,0x87E0,0x2183,
	0xC101,0x0003,0x66A0,0x5183,0xC102,0x4004,0x1560,0x5183,
	0xC10C,0x2008,0x0EA0,0x5183,0xC1F0,0x1030,0x0760,0x5183,
	0xC102,0x0040,0x01A0,0x5183,0xC122,0x0080,0x00E0,0x5183,
	0xC121,0x0300,0x0060,0x5183,0xC121,0x0400,0x0010,0x5183,
	0xC120,0x0AF8,0x0FA8,0x5183,0xC100,0x12A8,0x0AA4,0x8983,
	0xC100,0x02F8,0x0FA0,0x8983,0xC100,0x02A8,0x0AA0,0x8983,
	0xC100,0x02F8,0x0FA0,0x8983,0xC100,0x0200,0x0020,0x8983,
	0xC100,0x0203,0xF020,0x8983,0xC100,0x0202,0x1021,0x0583,
	0xC100,0x0202,0x1021,0x0583,0xC100,0x0202,0x1021,0x0583,
	0xC100,0x0202,0x9021,0xFD83,0xC100,0x0202,0x1020,0x2183,
	0xC100,0x0202,0x1020,0x2183,0xC100,0x0202,0x1020,0x2183,
	0xC1FF,0x8602,0x103F,0xFF83,0xC100,0xFBFF,0xFFE0,0x0183,
	0xC100,0x0000,0x0000,0x0183,0xC1FF,0xFFFF,0xFFFF,0xFF83,
	0xC0FF,0xFFFF,0xFFFF,0xFF83,0xC000,0x0000,0x0000,0x0003,
	0xC000,0x0000,0x0000,0x0003,0xC000,0x000F,0xF000,0x0003,
	0xC000,0x0008,0x1000,0x0003,0xC000,0x0008,0x1000,0x0003,
	0xC000,0x000F,0xF000,0x0003,0xC000,0x0000,0x0000,0x0003,
	0xC000,0x0000,0x0000,0x0003,0xC3EE,0x0000,0x0001,0x8003,
	0xC666,0x0000,0x0001,0x8003,0xC606,0x0000,0x0000,0x0003,
	0xC706,0xC3CE,0x7DC7,0x8773,0xC3C7,0x6666,0x2661,0x8363,
	0xC0E6,0x6666,0xA661,0x81C3,0xC066,0x6666,0xA661,0x81C3,
	0xC666,0x6663,0xE661,0x8363,0xC7CF,0x73C3,0x67C7,0xE773,
	0xC000,0x0000,0x0600,0x0003,0xC000,0x0000,0x0600,0x0003,
	0xC000,0x0000,0x0F00,0x0003,0xC000,0x0000,0x0000,0x0003,
	0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF
SHAR_EOF
if test 1933 -ne "`wc -c < 'showpix.icon'`"
then
	echo shar: error transmitting "'showpix.icon'" '(should have been 1933 characters)'
fi
fi
echo shar: extracting "'trimicon.c'" '(2015 characters)'
if test -f 'trimicon.c'
then
	echo shar: will not over-write existing file "'trimicon.c'"
else
cat << \SHAR_EOF > 'trimicon.c'
#include <stdio.h>
#include <sys/types.h>

#define WIDTH		64
#define HEIGHT		64
#define WORDSIZ		16
#define NCOL		(WIDTH / WORDSIZ)
#define NROW		(HEIGHT)

main(argc, argv)
int	argc;
char	**argv;
{
	register int	i, j, k;
	register char	c;
	int		width, height;
	u_int		data[NROW][NCOL];
	FILE		*fp;

	/* check to make sure they specified the correct # of args */
	if (argc != 3 && argc != 4) {
		fprintf(stderr, "usage: trimicon width height { icon }\n");
		exit(1);
	}
	/* get the size */
	width = abs(atoi(argv[1]));
	height = abs(atoi(argv[2]));
	/* did they specify a filename? */
	if (argc == 4 && argv[3] != (char *) NULL) {
		/* yes -- open it */
		if ((fp = fopen(argv[3], "r")) == NULL) {
			fprintf(stderr, "Can't open file %s for reading\n", 
				argv[3]);
			exit(1);
		}
	} else {
		/* no -- set <fp> to be stdin */
		fp = stdin;
	}
		
	/* skip the comments */
	while ((c = getc(fp)) != '\t');

	/* read in the icon */
	for (i = 0; i < NROW; i++) {
		for (j = 0; j < NCOL; j++) {
			if (fscanf(fp, " 0x%x,", &data[i][j]) != 1) {
				fprintf("Error reading file %s\n", argv[3]);
				exit(1);
			}
		} /* end for */
	} /* end for */

	/* close the file */
	fclose(fp);

	for (i = 0; i < NROW; i++) {
		if (i > height) {
			for (j = 0; j < NCOL; j++) {
				data[i][j] = (u_int) 0;
			}
		} else {
			for (j = 0; j < NCOL; j++) {
				if (j * WORDSIZ > width) {
					data[i][j] = (u_int) 0;
				} else if (j == width / WORDSIZ) {
					k = width - j * WORDSIZ;
					data[i][j] = (data[i][j] >> k) << k;
				} /* end else */
			} /* end for */
		} /* end else */
	} /* end for */

	/* output the icon file */
	printf("/* Format_version=1, Width=%d, Height=%d, ", width, height);
	printf("Depth=1, Valid_bits_per_item=%d */", WORDSIZ);
	for (i = 0; i < height; i++) {
		/* print two rows on a line */
		if (i % 2 == 0) printf("\n\t");
		/* print the row */
		for (j = 0; j * WORDSIZ < width; j++) {
			printf("0x%04x,", data[i][j] & 0xffff);
		} /* end for */
	} /* end for */
	printf("\n");
} /* end main() */
SHAR_EOF
if test 2015 -ne "`wc -c < 'trimicon.c'`"
then
	echo shar: error transmitting "'trimicon.c'" '(should have been 2015 characters)'
fi
fi
exit 0
#	End of shell archive