[comp.sys.mac] How does UnpackBits work?

mp1w+@andrew.cmu.edu (Marc Russell Pawliger) (05/29/87)

I have been trying to implement UnpackBits in c with mediocre success.  As I
understand it, packbits does the following:
	
Read a byte called control
	control  < 128?
		Next control+1 bytes are straight bitmap
	control  >= 128?
		The next byte in the input stream is repeated 256-control
times
		(2s complement of control times)

I am able to read in a file I made that consists of straight lines of bitmap,
however when I have to read a compressed file (a MacPaint file), the routine
gets messed up.

Any code fragments greatly appreciated.

			Marc Pawliger
			mp1w+@andrew.cmu.edu
			mp1w@cmuccvma.bitnet

sbb@esquire.UUCP (06/03/87)

In article <UUjSY6y00Vs4AKo08H@andrew.cmu.edu> mp1w+@andrew.cmu.edu (Marc Russell Pawliger) writes:
>
>I have been trying to implement UnpackBits in c with mediocre success.
>
>I am able to read in a file I made that consists of straight lines of bitmap,
>however when I have to read a compressed file (a MacPaint file), the routine
>gets messed up.
>
>Any code fragments greatly appreciated.

Brian Powell recently posted paintps.shar to comp.sources.mac, and it does just
what you and another poster interested in UnpackBits want.  Paintps takes an
uploaded MacPaint file and turns it into PostScript so that it can be printed
on a LaserWriter.  His UnpackBits routine looks pretty straightforward and
it's all commented, so I guess you could get his permission and use it.

In addition to paintps, the shar file also includes 3 different version of the
LaserPrep header, so that ANY PostScript generated on a Mac (by doing the CMD-F
trick while printing from any application) can be printed on a LW connected
to a Sun, mainframe, or whatever.

If you (or anyone else) missed the original posting, I'll be glad to repost
to this group, since it works perfectly and I use it all the time myself.

- Steve