Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!decvax!mcnc!gatech!bloom-beacon!mit-eddie!killer!codas!flnexus!kimbal!rick From: rick@kimbal.UUCP (Rick Kimball) Newsgroups: comp.sys.mac.programmer Subject: Re: compression algorithm used my MAC on macpaint documents Message-ID: <686@kimbal.UUCP> Date: 27 Feb 88 03:04:30 GMT References: Organization: Mac Source BBS, Altamonte Spgs, FL Lines: 104 Summary: Here's an implementation. In article , 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