Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site uw-beaver
Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxj!houxm!vax135!cornell!uw-beaver!info-mac
From: info-mac@uw-beaver
Newsgroups: fa.info-mac
Subject: [Steve Johnson : Using Printronix to display macpaint images]
Message-ID:
Date: Fri, 18-Jan-85 05:56:13 EST
Article-I.D.: uw-beave.460
Posted: Fri Jan 18 05:56:13 1985
Date-Received: Sat, 19-Jan-85 01:10:18 EST
Sender: daemon@uw-beaver
Organization: U of Washington Computer Science
Lines: 565
From: John Mark Agosta
# This is a shell archive. Remove anything before this line, then
# unpack it by saving it in a file and typing "sh file". (Files
# unpacked will be owned by you and have default permissions.)
#
# This archive contains:
# macprint.c
echo x - macprint.c
cat > "macprint.c" where is between 1 and 4. This is an indication
of how much to magnify (and is called the "magfactor")
Written by Richard Furuta, Computer Science, University of Washington.
Hacked by Steve Johnson for Printronix, ACC (Oct 16, 1984)
Please report changes and fixes back to me. By Arpanet and CSNet,
I am Furuta@Washington. By uucp, I am ihnp4!uw-beaver!furuta. I
prefer the Arpanet/CSNet address.
I benefitted greatly from Ed Pattermann's code for macimp. The
following description of the MacPaint font format comes from that
code.
=============
First, the Macintosh file ; This format is the common
interchange format for full-page bitmap images on the Macintosh.
The first 512 bytes of the file are the header. The first four bytes
comprise the version number, followed by 38*8 = 304 bytes of
patterns. The remaining 204 bytes of the header are reserved for
future expansion. If the version number is zero, the patterns are
ignored. Hence, programs that wish to create files to be read into
MACpaint can just write out 512 bytes of zero as the header.
Following the header are 720 compressed scanlines of data which form
the 576 wide by 720 tall bitmap. The bitmap is compressed as follows ;
Any run of three or more equal bytes is compressed into a count byte
and a single data byte. Runs of unequal bytes are passed on literally,
preceded also by a count byte. i.e.
count = -1..-127 --> replicate byte 2..128 times
count = 0.. 127 --> copy 1..128 bytes uncompressed
count = -128 ignored for backward compatibility
=============
This program produces a series of DEVICE "Define a Block of Raster Data"
commands which are used to produce a dump of the screen. You have to be
careful about the syntax of the arguments to this command. I had a bit of
trouble caused by forgetting that the byte ordering and bit ordering of the
raster words given to this command differ from those of the parameters to
the command. I could have used the "Screen Dump" DEVICE command instead of
this command to dump the raster. The advantage would have been that the
resolution of the device would have been halved probably eliminating the
need to half tone. The disadvantage is that it is harder to support the
magnification factor of 3 that seems to make the most sense to me.
An arbitrary magnification is used to blow up the figure in both dimensions
(x and y). This is controlled by "magfactor" which should be at least one.
If it gets larger than 4, you'll have to expand the amount of storage given
to "outline" in procedure "makebitmap". I try detect and skip blank scan
lines to help conserve bandwidth to the printer which is pretty horrid at
9600 baud. Maybe one of these days our DR11/C interface will work again and
bandwidth won't be such a problem!
*/
#include
#define TRUE 1
#define FALSE 0
/* for command line option processing */
char *ProgName;
extern char *optarg;
extern int optind;
int checkwhite();
char flipbits();
int intoout();
/* a macpaint document in the worst case should occupy twice as many bytes
as a straight screen dump. This pathological case comes when you have
only count bytes of 1. Since the Mac screen is 576 x 720 bits or
72 x 720 bytes == 51840 bytes, this worst case would occupy 103680
bytes */
char compressed[200]; /* lookahead storage for input - 152 is enough */
int nextcompbyte; /* next index into this array */
int whitestateflg; /* TRUE if we last looked at a blank line */
/* The DEVICE washes out large black areas. As an attempt to address this,
I'm trying to halftone the output */
#define DMASK 0377 /* 11111111 pass everything through */
#define EMASK 0252 /* 10101010 even bits only */
#define OMASK 0125 /* 01010101 odd bits only */
char curmask; /* the current one to use */
int hflg; /* TRUE if we want to halftone */
#define CTRL_E 05 /* control E */
#define LF 10 /* linefeed */
#define void int
main(argc, argv)
int argc;
char **argv;
{
int optch; /* option character */
int ctr; /* temporary counter */
int scanctr; /* count the 720 scan lines */
int byte; /* incoming information */
int countbyte; /* gives meaning of subsequent input bytes */
int linebytecount; /* how many bytes seen so far on
input? 0..71 */
int magfactor; /* how many times do you want to expand
this? 1..4 */
int linestart; /* when collecting a line, recall where it
all began */
magfactor = 1; /* by default, show at true size */
curmask = DMASK; /* by default, in case no halftoning is set */
hflg = FALSE; /* by default, halftoning */
ProgName = *argv;
/* grab some options */
while ((optch = getopt (argc, argv, "hm:")) != EOF) {
switch (optch) {
case 'h': /* want halftoning */
hflg = TRUE;
curmask = DMASK; /* unnecessary but for safety... */
break;
case 'm': /* magnification factor */
magfactor = atoi(optarg);
break;
case '?':
fprintf(stderr, "Usage: %s [-m magfactor]\n",
ProgName);
(void)fflush(stderr);
exit(1); /* a bit harsh, but ... */
}
}
if((magfactor 4)) {
fprintf(stderr, "%s: Sorry, magfactor can't be %d, must be between 1 and 4\n",
ProgName, magfactor);
exit(1);
}
/* jump over the 512 bytes of header */
for(ctr=0; ctr 127) {
/* replicated bytes follow */
countbyte = 256-countbyte+1;
byte = getc(stdin) & 0377;
compressed[nextcompbyte++] = byte;
}
else {
/* unreplicated bytes follow */
countbyte++;
for(ctr = 0; ctr 127) {
/* replicated bytes follow */
countbyte = 256-countbyte+1;
byte = compressed[compcnt++] & 0377;
for(ctr = 0; ctr =0; i--) /* 8 bits per byte */
bit_stream[j++] = !!( abyte & (1 0; octr--) { /* output 96 bytes */
out_byte = 0; /* clean start */
for (i=0; i= 0; bitctr--) {
bit = (byte >> bitctr) & 01;
/* replicate the bit in the output */
for(magctr=0; magctr > 8) & 0377, outf);
}
putdevbyte(value, outf)
int value;
FILE *outf;
{
putc(value & 0377, outf);
}
dv_eof(outf)
FILE *outf;
{
;
}
put_white(outf)
FILE *outf;
{
putc(CTRL_E & 0377, outf);
putc(LF & 0377, outf);
}
char flipbits(oldbyte)
char oldbyte;
{
char newbyte;
newbyte = 0;
/* 7 6 5 4 3 2 1 0 */
newbyte = ((oldbyte & 01) > 1) | /* old 4 to new 3 */
((oldbyte & 040) >> 3) | /* old 5 to new 2 */
((oldbyte & 0100) >> 5) | /* old 6 to new 1 */
((oldbyte & 0200) >> 7); /* old 7 to new 0 */
return(newbyte);
}
/* see if this line is all white */
int checkwhite(bytes)
char *bytes;
{
int countbyte;
int linebytecount;
int iswhite;
int ctr;
iswhite = TRUE;
linebytecount = 0;
while(iswhite && (linebytecount 127) {
/* replicated byte case */
countbyte = 256-countbyte+1;
if(*bytes) {
iswhite = FALSE;
break;
}
bytes++;
}
else {
/* unreplicated bytes follow */
countbyte++;
for(ctr = 0; ctr */
char *optarg; /* Global argument pointer. */
int optind; /* Global argv index. */
static char *scan; /* Private scan pointer. */
extern char *index();
int
getopt (argc, argv, optstring)
register int argc;
register char **argv;
char *optstring;
{
register int c;
register char *place;
optarg = NULL;
if (scan == NULL || *scan == 0) {
if (optind == 0)
optind++;
if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == 0)
return EOF;
if (strcmp (argv[optind], "--") == 0) {
optind++;
return EOF;
}
scan = argv[optind] + 1;
optind++;
}
c = *scan++;
place = index (optstring, c);
if (place == NULL || c == ':') {
fprintf (stderr, "%s: unknown option -%c\n", argv[0], c);
return '?';
}
place++;
if (*place == ':') {
if (*scan != '\0') {
optarg = scan;
scan = NULL;
}
else {
if (optind >= argc) {
fprintf (stderr, "%s: missing argument after -%c\n",
argv[0], c);
return '?';
}
optarg = argv[optind];
optind++;
}
}
return c;
}
//E*O*F macprint.c//
echo Possible errors detected by \'wc\' [hopefully none]:
temp=/tmp/shar$$
trap "rm -f $temp; exit" 0 1 2 3 15
cat > $temp
Received: from ACC.ARPA by SUMEX-AIM.ARPA with TCP; Mon 14 Jan 85 12:01:01-PST
Date: 14 Jan 1985 11:51 PST
From: Steve Johnson
Subject: Using Printronix to display macpaint images
To: INFO-MAC@SUMEX
Reply-To: SAJ@ACC
ReSent-date: Thu 17 Jan 85 10:04:29-PST
ReSent-From: John Mark Agosta
ReSent-To: info-mac: ;
Macpaint -> Printronix filter. The following shell archive contains
a quick and dirty adaptation of a previously posted program. The
adaptation permits the conversion of macpaint files to a form which
can be sent directly to a Printronix printer. Caveats: 1) some
distortion is introduced; 2) this has only been tested on VAX 4.2BSD;
3) the file sent to the Printronix contains control chararcters, which
some 4.2 print commands may strip.
------------------------------------------------------------------
[ Find the shell script saved in MPTOPRTRNX.SH -jma ]
-------
