[comp.sys.mac.programmer] compression algorithm used my MAC on macpaint documents

ghosh@hubcap.UUCP (Amitava Ghosh) (02/23/88)

I believe that all macpaint documents are stored in compressed form.
I know how i can uncompress it on the Mac using UnPackBits routine.
I have a need , where I would like to do the uncompressing on the mainframe
after I have transferred the compressed document over (since it will reduce
the amount of data I would have to transfer). Can anyone tell me or point
me to a source where I can find out the compression algorithm. I have looked
in Inside Macintosh and I was unable to find any info. Also, does someone
have info on the format of the Macpaint document itself. 
 Thanks in advance for any info.

 Amitava Ghosh

Email:       Bitnet   ghosh@clemson
             internet ghosh@prism.clemson.edu
             UUCP     ...!hubcap!ghosh 

sas1@sphinx.uchicago.edu (Stuart Schmukler) (02/24/88)

There are a number of programs that handle macpaint documents on a mainframe.
 MACHP.PAS.1
 MACIMP.PAS.1
 MACPTX.PAS.1
 MACQMS.PAS.1
 MACIMP.C.1
 MACLGP.C.1
 MACQMS.C.1
 PAINT2QMS.C.1
 PAINTIMP.C.1

are the ones in the SUMEX-AIM archive.  But, since you are on BITNET
you should try the archive at PUCC via:
	TELL MACSERV AT PUCC HELP
under VM/CMS.

SaS

PS: I am not sure that the syntax is 'exactly' correct check with the
local systems people to be safe.

gs1g+@andrew.cmu.edu (Gregory Jacob Stein) (02/26/88)

There is a Tech Note which describes the packing algorithm used in PackBits.  
Note, though, that Apple reserves the right to change this at any time.

		Greg

rick@kimbal.UUCP (Rick Kimball) (02/27/88)

In article <oW96M2y00XoH8Qo0=9@andrew.cmu.edu>, gs1g+@andrew.cmu.edu (Gregory Jacob Stein) writes:
> 
> There is a Tech Note which describes the packing algorithm used in PackBits.  
> Note, though, that Apple reserves the right to change this at any time.
> 
> 		Greg
 
Here's another kind of answer (the kind I like ...  show me 
the way ...  don't give me theory).  A while back I wrote a 
program that runs on my UNIX-PC.  It reads MacPaint files and 
displays them on the console.  

I had to write my own UnPackBits function for UNIX.
Here it is:

-------------- Snip Snip Snip -------------- 
/*
    Name: UnPackBits.c

    Synopsis: UnPackBits( char **src, **dst, short rowBytes );

    Description: See Apple Tech Notes:
                         #86: MacPaint Document Format
                        #171: PackBits Data Format

    This software is Copyright (c) 1987 by Rick Kimball.

    Permission is hereby granted to copy, reproduce, redistribute or
    otherwise use this software as long as: there is no monetary
    profit gained specifically from the use or reproduction or this
    software, it is not sold, rented, traded or otherwise marketed, and
    this copyright notice is included prominently in any copy
    made.

    The author make no claims as to the fitness or correctness of
    this software for any use whatsoever, and it is provided as is.
    Any use of this software is at the user's own risk.

    Sample Call Sequence:

    char **srcPtr, **dstPtr;
    char macPaintFile[(576/8)*720];
    char bitImage[51840];

    ...
    srcPtr = (char **)&macPaintFile[512];
    dstPtr = (char **)&bitImage[0];

    for( x = 0; x < 720; x++)
    {
        UnPackBits(&srcPtr,&dstPtr, 576/8);
    }
    ...


*/

#define HIGH_BIT_ON 0x80

UnPackBits(src, dst, cnt)
register unsigned char **src;
register unsigned char **dst;
register short cnt;
{
	register short noOfBytes;
	register unsigned char bit15;

	if ( cnt <= 0 )
		return(0);

	bit15 = HIGH_BIT_ON;

	while ( cnt )
	{
		if ( **src & bit15 )	/* Is High bit set ? */
		{
			noOfBytes = abs((char)*(*src)++);
			cnt -= ++noOfBytes;
			while( noOfBytes-- )
			{
				*(*dst)++ = **src;
			}
			(*src)++;
		}
		else	/* It is a normal zero based counter */
		{
			noOfBytes = (char)*(*src)++;
			cnt -= ++noOfBytes;
			while( noOfBytes-- )
			{
				*(*dst)++ = *(*src)++;
			}
		}
	}
	return(0);
}



-- 
Rick Kimball       Software Design Group
                   Maitland, FL 32751
                   (305) 660-0006
                   UUCP: rick@kimbal, ...codas!flnexus!kimbal!rick