[comp.sys.mac.programmer] PackBits/UnpackBits Format

rmorgan@network.ucsd.edu (Robert Morgan) (06/05/90)

Hi,

Does anyone know what format PackBits/UnpackBits uses ?
Inside Mac vI-p470 is no help at all.  Does anybody have
any C or Pascal code that "mimics" the two routines ?
Any idea where I could find some better documentation about them ?

I have to write such a routine on a non-macintosh (in order to unpack/pack
bitmaps/PixMaps in PICT files).

Thanks,
John

mjohnson@Apple.COM (Mark B. Johnson) (06/05/90)

In article <2519@network.ucsd.edu> rmorgan@network.ucsd.edu (Robert Morgan) writes:
>Hi,
>
>Does anyone know what format PackBits/UnpackBits uses ?
>Inside Mac vI-p470 is no help at all.  Does anybody have
>any C or Pascal code that "mimics" the two routines ?
>Any idea where I could find some better documentation about them ?
>
>I have to write such a routine on a non-macintosh (in order to unpack/pack
>bitmaps/PixMaps in PICT files).
>

Macintosh Technical Note #171, Things You Wanted to Know About _PackBits*

*But Were Afraid To Ask

may help you.  Available in all the usual places, including Apple.com.


-- 
Mark B. Johnson                                            AppleLink: mjohnson
Developer Technical Support                         domain: mjohnson@Apple.com
Apple Computer, Inc.         UUCP:  {amdahl,decwrl,sun,unisoft}!apple!mjohnson

"You gave your life to become the person you are right now.  Was it worth it?"
                                                         - Richard Bach, _One_

Michael.Burton@p3.f200.n226.z1.FIDONET.ORG (Michael Burton) (06/08/90)

   Robert Morgan asked:
> Does anyone know what format PackBits/UnpackBits uses ?
> Inside Mac vI-p470 is no help at all.
> ...
> I have to write such a routine on a non-macintosh (in order to
> unpack/pack bitmaps/PixMaps in PICT files).

   Quoting from Tech Note #171: PackBits Data Format:

First there is a byte which specifies whether or not the the data is
packed, and is also the count byte. It is a negative number if packed
(i.e. the high bit is set). If the high bit is set, then that complete
byte is a twos complement number that tells you how many bytes were
packed. If it is a positive number, then it is simply a zero based count
of how many discrete data bytes there are. Consider the following
example:

Unpacked data:

AA AA AA 80 00 2A AA AA AA AA 80 00 2A 22 AA AA AA AA AA AA AA AA AA AA

After being packed by PackBits:

FE AA; (-(-2)+1) = 3 bytes of the pattern $AA
02 80 00 2A; (2)+1 = 3 bytes of discrete data
FD AA; (-(-3)+1) = 4 bytes of the pattern $AA
03 80 00 2A 22; (3)+1 = 4 bytes of discrete data
F7 AA; (-(-9)+1) = 10 bytes of the pattern $AA

-OR-

FE AA 02 80 00 2A FD AA 03 80 00 2A 22 F7 AA
*     *           *     *              *

The bytes with the * under them are the count/flag bytes. PackBits
will only pack the data when there are 3 or more consecutive bytes with
the same data, otherwise it just copies the data byte for byte (and adds
the count byte).
END QUOTE.

   You should also note this caveat from the Tech Note:

> WARNING! This information is provided for informational purposes only!
> It is accurate for now, but may change in the future.


--  
Michael Burton via cmhGate - Net 226 fido<=>uucp gateway Col, OH
UUCP: ...!osu-cis!n8emr!cmhgate!200.3!Michael.Burton
INET: Michael.Burton@p3.f200.n226.z1.FIDONET.ORG