[comp.sys.mac.programmer] Format of MacPaint files?

gaulandm@tekigm2.MEN.TEK.COM (Mike Gauland) (08/07/90)

Does anyone know how MacPaint stores its files?  I want to convert a bitmap
to a file readable by MacPaint.

thanks,
mike

stevec@Apple.COM (Steve Christensen) (08/08/90)

In article <9653@tekigm2.MEN.TEK.COM> Mike Gauland writes:
>Does anyone know how MacPaint stores its files?  I want to convert a bitmap
>to a file readable by MacPaint.

MacPaint uses an image that's 576 pixels wide by 720 pixels tall (even if it's
all white).  The file contains 512 bytes which contain the patterns used for
fills, etc., followed by the packed image data.  The pattern bytes can be all
zeroes if you like.

To pack the image, you'll need to copy one line of the bitmap at a time into
a 72 byte (=576/8) buffer and call PackBits with a byte count of 72.  PackBits
is described in the ToolBox Utilities chapter of Inside Mac volume 1.  If your
bitmap isn't the full height of the image, you can fill the rest of the image
with white lines.  In pseudo code it looks something like this:

create a new file
get the file info and change the type to "PNTG" and the creator to "MPNT"
set the new file info
open the file

write 512 bytes of zeroes (or use real patterns if you like)

for i = 1 to bitmapHeight do
  copy line i of bitmap to sourceBuffer
  sourceBufPtr = pointer to start of sourceBuffer
  destBufPtr = pointer to start of destBuffer
  PackBits(sourceBufPtr,destBufPtr,72);
  packedBytes = destBufPtr - pointer to start of destBuffer
  write packedBytes bytes from destBuffer to the file

if bitmapHeight<720 then
  fill sourceBuffer with all zeroes
  sourceBufPtr = pointer to start of sourceBuffer
  destBufPtr = pointer to start of destBuffer
  PackBits(sourceBufPtr,destBufPtr,72);
  packedBytes = destBufPtr - pointer to start of destBuffer
  for i = bitMapHeight+1 to 720 do
    write packedBytes bytes from destBuffer to the file

close the file


steve

-- 
____________________________________________________________________

  Steve Christensen             Internet:   stevec@goofy.apple.com
  Apple Computer, Inc.          AppleLink:  STEVEC
  20525 Mariani Ave, MS 81-CS   CompuServe: 76174,1712
  Cupertino, CA  95014

  "You just contradicted me."  "No I didn't."
____________________________________________________________________