🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.mac
Article #30911

MacPaint file conversion

#30911
From: Chuck Lukaszewski
Date: Thu, 04 Aug 1988 18:05
126 lines
3530 bytes
Since there has been a lot of interest in MacPaint format and transferring
such files to Unix machines, I am taking the liberty of posting the source
for paintraster.c, which takes a MacPaint file already on a UNIX machine
and converts it to a Sun rasterfile.  The format of the MacPaint file is
very simple run-length encoding and is described in Apple Technote #96.

We routinely use a Mac II to generate title/credit frames for a Gould Image
Processor.  Once the frame is made with MacPaint, we use NCSA Telnet's ftp
mode.  We have never had a problem, whether we go straight onto the ethernet
with a EtherTalk card, or go via AppleTalk and a Kinetics gateway.  Be sure
to use binary mode.  This solves any problems with carriage returns getting
inserted into the transferred file.

/*
 *	paintraster -- read macpaint document and output Sun rasterfile
 *
 *	cc -O -o paintraster -c paintraster.c -lpixrect
 *
 *	Ron Hitchens,	U. of Texas @ Austin,	hitchens@sally.utexas.edu
 *
 */

#include <stdio.h>
#include <pixrect/pixrect_hs.h>

#define MACPAINT_HDRSIZE	512
#define	MACPAINT_BITWIDTH	576
#define	MACPAINT_BITHEIGHT	720

unsigned char paint_data [MACPAINT_BITWIDTH/8][MACPAINT_BITHEIGHT];
mpr_static(paint_mpr, MACPAINT_BITWIDTH, MACPAINT_BITHEIGHT, 1, paint_data);



main(argc, argv)
char **argv;
{
	static	FILE	*fp[2] = {stdin, stdout};
	static	char	*mode [2] = {"r", "w"};
	int		i = 0;


	argc--; argv++;
	if (argc > 2) {
		fprintf (stderr, "usage: paintraster [infile | -] [outfile]\n");
		exit (1);
	}
	while (argc) {
		if (argv [0][0] == '-')
			/* nothing */ ;
		else
			fp[i] = fopen(argv [0], mode [i]);
		if (fp[i] == NULL) {
			perror(argv [0]);
			exit (1);
		}
		i++;
		argc--;	argv++;
	}

	load_paint(fp[0]);
	dump_raster (fp[1]);
	exit (0);
}

load_paint (fp)
	FILE *fp;
{
	int	i, j;

	for (i = 0; i < MACPAINT_HDRSIZE; i++)	/* eat the header */
		if (getc (fp) == EOF) {
			fprintf (stderr, "unexpected EOF reading MP header\n");
			exit (1);
		}
	for (i = 0; i < MACPAINT_BITWIDTH/8; i++)
		for (j = 0; j < MACPAINT_BITHEIGHT; j++)
			paint_data [i][j] = (unsigned char)getbits(fp);
}

dump_raster (fp)
	FILE	*fp;
{
	colormap_t	cmt;

	cmt.type = RMT_NONE;
	cmt.length = 0;
	pr_dump (&paint_mpr, fp, &cmt, RT_STANDARD, 0);
}



/* macpaint input routines */

getbits(fp)	FILE *fp;
{
	/* This routine expands the packbits encoded MacPaint file,
	   delivering one byte per call */

	static int count, rep, chr;
	int c;

	if (rep) {
		rep--;
		return chr;
	}
	if (count) {
		count--;
		return getc(fp);
	}
	c = getc(fp);
	if (c & 0x80) {			/* repeated character count */
		rep = 0x100 - c;	/* byte length 2's comp + 1 */
					/* 	allow for this call */
		chr = getc(fp);		/* character to repeat */
		return chr;
	}
	else {
		count = c;		/* already counted this char */
		return getc(fp);
	}
}

---===---===---===---===---===---===---===---===---===---===---===---===---
ARPAnet:                   AppleLink:  SnailMail:              Ma Bell:
imp@crayview.msi.umn.edu   UG0138      Minneapolis MN 55418    612/789-0931
Technical Details
Message-ID: <6525@umn-cs.cs.umn.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!attcan!uunet!husc6!uwvax!umn-d-ub!umn-cs!crayview!imp

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!attcan!uunet!husc6!uwvax!umn-d-ub!umn-cs!crayview!imp
From: imp@crayview.msi.umn.edu (Chuck Lukaszewski)
Newsgroups: comp.sys.mac,comp.sys.mac.programmer
Subject: MacPaint file conversion
Keywords: macpaint paintraster bitmaps
Message-ID: <6525@umn-cs.cs.umn.edu>
Date: 4 Aug 88 18:05:08 GMT
Sender: news@umn-cs.cs.umn.edu
Lines: 126