[comp.sys.handhelds] X bitmaps to Graphics Objects

jco@lightning.cis.ufl.edu (Dumpmaster John) (08/06/90)

#!/bin/sh
# This is a shell archive (shar 3.32)
# made 08/06/1990 15:45 UTC by jco@lightning
# Source directory /net/bikini/0/jco/48sx/xbm2grob
#
# existing files WILL be overwritten
# This format requires very little intelligence at unshar time.
# "echo" and "sed" will be needed.
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#    425 -rw------- Makefile
#   1060 -rw------- README
#   3287 -rw------- mantaray.icon
#   2171 -rw------- xbm2grob.c
#     52 -rw------- loadimage
#
# ============= Makefile ==============
echo "x - extracting Makefile (Text)"
sed 's/^X//' << 'SHAR_EOF' > Makefile &&
X# File: Makefile
X# Author: John C. Orthoefer (Internet: jco@ufl.edu)
X# Date: 6 Aug 1990
X#
X
Xxbm2grob: xbm2grob.o
X	cc xbm2grob.o -o xbm2grob
X
Xclean:
X	rm -f core a.out xbm2grob xbm2grob.o
X
Xdepend:
X	mkdep xbm2grob.c
X
X# DO NOT DELETE THIS LINE -- mkdep uses it.
X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
X
Xxbm2grob.o: xbm2grob.c /usr/include/stdio.h /usr/include/strings.h
X
X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
SHAR_EOF
# ============= README ==============
echo "x - extracting README (Text)"
sed 's/^X//' << 'SHAR_EOF' > README &&
X				  xbm2grob
X				  --------
X
XPurpose: This program converts xbitmaps to the HP 48sx Graphics Object
X(GROB) format.  Suitable for downloading to a HP 48sx.  Also include is a
Xsimple loadimage which will let you view the image (and scroll around on
Xwith the cursor keys if the image is bigger than the screen.)
X
XTo make: the make file has no flags so just type make.
X
XTo run: The usage is:
X
X	xbm2grob [-v] filename1 [filename2 ...]
X
X	flags:
X		-v	Verbose
X
X	One filename is required.  However, more than one can be placed on
Xthe command one at one time.  The output filename is the input filename with
X.GROB appended.
X
Xloadimage:
X	okay this is a realy simple program for looking at bitmaps and
Xscrolling them around.  I wrote it in 10 mins today.  I'm playing with the
Xgraphics on this machine so look for it to get better.
X
XFor now you put the grob on level 1 and hit the loadimage key.  You can use
Xthe arrow keys to scroll around.
X
XAny questions, comments, or other junk mail to jco@ufl.edu.  
X
XDisclaimer:  I'm not responsible for any damage this may cause.
SHAR_EOF
# ============= mantaray.icon ==============
echo "x - extracting mantaray.icon (Text)"
sed 's/^X//' << 'SHAR_EOF' > mantaray.icon &&
X#define mantaray_width 64
X#define mantaray_height 64
Xstatic char mantaray_bits[] = {
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00,
X   0x00, 0xe0, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0xf0, 0x00, 0x00,
X   0x00, 0x00, 0xe0, 0x00, 0x00, 0xf0, 0x01, 0x00, 0x00, 0x00, 0xf0, 0x00,
X   0x00, 0xf0, 0x01, 0x00, 0x00, 0x00, 0xf8, 0x00, 0x00, 0xf0, 0x03, 0x00,
X   0x00, 0x00, 0xfc, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0x00, 0xfe, 0x00,
X   0x00, 0xf8, 0x07, 0x00, 0x00, 0x00, 0xff, 0x00, 0x00, 0xf8, 0x07, 0x00,
X   0x00, 0x80, 0x7f, 0x00, 0x00, 0xf8, 0x07, 0x00, 0x00, 0xc0, 0x7f, 0x00,
X   0x00, 0xf8, 0x0f, 0x00, 0x00, 0xc0, 0x7f, 0x00, 0x00, 0xf8, 0x0f, 0x00,
X   0x00, 0xe0, 0x7f, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xf0, 0x3f, 0x00,
X   0x00, 0xf8, 0x3f, 0x00, 0x00, 0xf8, 0x3f, 0x00, 0x00, 0xf0, 0x7f, 0x00,
X   0x00, 0xfc, 0x3f, 0x00, 0x00, 0xf0, 0xff, 0x00, 0x00, 0xfe, 0x1f, 0x00,
X   0x00, 0xf0, 0xff, 0x03, 0x00, 0xff, 0x0f, 0x00, 0x00, 0xf0, 0xff, 0x07,
X   0x80, 0xff, 0x0f, 0x00, 0x00, 0xf0, 0xff, 0x3f, 0xe0, 0xff, 0x07, 0x00,
X   0x00, 0xf0, 0xff, 0x7f, 0xf8, 0xff, 0x07, 0x00, 0x00, 0xe0, 0xff, 0xff,
X   0xff, 0xff, 0x03, 0x00, 0x00, 0xe0, 0xff, 0xff, 0xfe, 0xff, 0x01, 0x00,
X   0x00, 0xe0, 0xef, 0xbf, 0xff, 0xff, 0x01, 0x00, 0x00, 0xe0, 0xfb, 0xff,
X   0xff, 0xff, 0x01, 0x00, 0x00, 0xe0, 0xfe, 0xef, 0xff, 0xff, 0x01, 0x00,
X   0x00, 0xe0, 0xff, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0xe0, 0xff, 0xfb,
X   0xff, 0xff, 0x00, 0x00, 0x00, 0xe0, 0xff, 0xfe, 0xff, 0xff, 0x00, 0x00,
X   0x00, 0x60, 0xfe, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0xe0, 0xf8, 0xff,
X   0xff, 0xff, 0x01, 0x00, 0x40, 0xc0, 0xf0, 0xff, 0xff, 0xff, 0x1f, 0x00,
X   0x08, 0x00, 0xfe, 0xf0, 0xff, 0xff, 0xff, 0x07, 0x50, 0x00, 0x3e, 0x00,
X   0x00, 0xf0, 0xff, 0xff, 0x60, 0x05, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xff,
X   0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5e, 0x05, 0x00, 0x00,
X   0x00, 0x00, 0x00, 0x00, 0xee, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X   0xd0, 0x3b, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x7c, 0x0f, 0x00, 0x00,
X   0x10, 0x2a, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0x06, 0x3c, 0x00, 0x00,
X   0xf5, 0x07, 0x00, 0xe0, 0x01, 0xf6, 0x00, 0x00, 0x56, 0x58, 0x09, 0xfe,
X   0x00, 0xb8, 0x55, 0x00, 0x5b, 0x68, 0xa4, 0xdc, 0x00, 0xd8, 0xfb, 0x5f,
X   0xb4, 0x54, 0x20, 0xea, 0x2a, 0xf0, 0x7f, 0xb5, 0x48, 0x9f, 0x04, 0x02,
X   0xaa, 0xf2, 0xfe, 0xef, 0x42, 0x20, 0x26, 0x00, 0x30, 0x3c, 0x5a, 0xee,
X   0x41, 0xf1, 0x15, 0xe0, 0x00, 0x4c, 0xfd, 0x93, 0x88, 0x01, 0xae, 0x10,
X   0x05, 0x35, 0xfb, 0x1b, 0x01, 0x08, 0x1b, 0x05, 0x11, 0x04, 0xe0, 0x2f,
X   0xf0, 0xc7, 0xdb, 0x1a, 0x45, 0xc6, 0x81, 0x3c, 0xfc, 0xd7, 0x7f, 0x63,
X   0x86, 0x91, 0x48, 0xa4, 0xfd, 0xff, 0x4f, 0x08, 0x10, 0xb0, 0x00, 0x00,
X   0x7e, 0x08, 0x07, 0x80, 0x80, 0x30, 0x01, 0x20};
SHAR_EOF
# ============= xbm2grob.c ==============
echo "x - extracting xbm2grob.c (Text)"
sed 's/^X//' << 'SHAR_EOF' > xbm2grob.c &&
X/* File: xbm2grob.c
X** Author: John C. Orthoefer (Internet: jco@ufl.edu)
X** Date: 3 Aug 1990
X** Program: Converts Xbitmaps to GROB (Graphics Object) format for 
X**		the HP 48sx
X** History: 
X**	6 Aug 1990 - Cleaned up code and released
X**	3 Aug 1990 - Code version 1.0
X*/
X#include <stdio.h>
X#include <strings.h>
X
X#define MaxNameSize 256
X#define PARAMS "v"
X
X/* This is a table of backward nibbles */
Xint table[] = { 0x0, 0x8, 0x4, 0xc, 
X		0x2, 0xa, 0x6, 0xe, 
X		0x1, 0x9, 0x5, 0xd,
X		 0x3, 0xb, 0x7, 0xf };
X
Xint verbose = 0;
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X	FILE *xbitmap;
X	FILE *outfile;
X	int i;
X	extern int optind;
X	char filename[MaxNameSize];
X	char c;
X
X	while ((c = getopt(argc, argv, PARAMS)) != EOF) {
X		switch(c) {
X		default:
X		case '?': 
X			fprintf(stderr, "Usage: %s [-v] file [file ...]\n", argv[0]);
X			exit(1);
X			break;
X		case 'v': verbose = 1;
X			break;
X		}
X	}
X
X	for (i = optind; i < argc; i++) {
X		if ((xbitmap = fopen(argv[i], "r")) == NULL) {
X			perror(argv[0]);
X			exit(1);
X		} else {
X		strcpy(filename, argv[i]);
X		strcat(filename, ".grob");
X		if ((outfile = fopen(filename, "w")) == NULL) {
X			perror(argv[0]);
X			exit(1);
X		} else {
X			if (verbose)
X				printf("XBM: %s\nGROB: %s\n", argv[i], filename);
X			convert( xbitmap, outfile);
X			close(xbitmap);
X			close(outfile);
X		}
X		}
X	}
X}
X
Xconvert( xbitmap, outfile)
XFILE *xbitmap;
XFILE *outfile;
X{
X	int width, height;
X	int i;
X	int data;
X
X/* scan for #define filename_width */
X	while (1 != fscanf(xbitmap, "_width %d\n", &width)) {
X		fgetc(xbitmap);
X	}
X
X/* scan for #define filename_height */
X	while (1 != fscanf(xbitmap, "_height %d\n", &height)) {
X		fgetc(xbitmap);
X	}
X
X/* verbose option */
X	if (verbose)
X		printf("X-bitmap: Height = %d, Width = %d\n", height, width);
X
X	fprintf(outfile, "GROB %d %d ", width, height);
X
X	while('{' != fgetc(xbitmap)) {
X	}
X
X	i = 0;
X	while (fgetc(xbitmap) != '}') {
X		if (1 == fscanf(xbitmap, " 0x%x", &data)) { 
X			i++;
X			fprintf(outfile, "%1X%1X", data & 0xf, (data & 0xf0) >> 4);
X#ifdef DEBUG
X			printf("%x(%1X%1X)  ", data, data & 0xf, (data & 0xf0) >> 4);
X#endif
X		}
X	}
X
X	if (verbose) 
X		printf("converted: %d\n", i);
X	fclose(xbitmap);
X	fclose(outfile);
X}
SHAR_EOF
# ============= loadimage ==============
echo "x - extracting loadimage (Text)"
sed 's/^X//' << 'SHAR_EOF' > loadimage &&
X%%HP: T(1)A(D)F(.);
X+ PICT STO { }
XPVIEW 7 FREEZE
X;
SHAR_EOF
exit 0
--
"What would Rock and Roll be without feedback?" -- D. Gilmour
In Real Life:		UUCP: {gatech|mailrus}!uflorida!beach.cis.ufl.edu!jco
John C. Orthoefer	Internet: jco@beach.cis.ufl.edu
University of Florida	Floyd Mailing List: eclipse-request@beach.cis.ufl.edu