[comp.sys.mac.programmer] CalcMask

gft_james@gsbacd.uchicago.edu (08/31/90)

I need to generate masks for a whole pile o' bitmaps, and I don't want to do it
manually.  My "Inside Mac" DA lists a routine:

PROCEDURE CalcMask (srcPtr,dstPtr: Ptr; srcRow, dstRow, height,
                    words: INTEGER);

    Given a source bit image, CalcMask computes a destination bit image
with 1's only in the pixels where paint could not leak from any of
the outer edges, like the MacPaint lasso tool. Calls to CalcMask are
not clipped to the current port and are not stored into QuickDraw
pictures.

This sounds like exactly what I need, but I can't for the life of me figger out
what the arguments should be, and I can't find any reference to this routine in
Inside Mac I, II, II, or V.  I don't have IV.  V has documentation for CalcCMask
(apparently the color version of this routine), but the argument set is totally
different, and I want to work in B&W.  Can someone help me out?  Thanks in
advance.
  -James-

jackiw@cs.swarthmore.edu (Nick Jackiw) (09/01/90)

gft_james@gsbacd.uchicago.edu writes:
> 
> PROCEDURE CalcMask (srcPtr,dstPtr: Ptr; srcRow, dstRow, height,
>                     words: INTEGER);
> 
> This sounds like exactly what I need, but I can't for the life of me figger out
> [what the arguments should be]

"The SeedFill+CalcMask procedures operate on a portion of a bitmap. In both
routines, srcPtr and dstPtr point to [the bits themselves, not the bitmap.
e. g. srcPtr:=yourBitMap.baseAddr]. SrcRow and dstRow specify the row
width in bytes (i. e. the rowBytes field of the BitMap record) ... .
Height and words determine the number of bits to be filled or calculated;
words is the width of the rectangle in words and height is the height
off the rectangle in pixels." [IV-24]

Thus, in two equi-sized and bounded bitmaps, aBits and bBits, to calculate
in bBits an image of the portion of aBits stored in aRect, do:

const
 pixPerByte=8; {Assume B&W}

var aRect:Rect; aBits, bBits:BitMap;
    srcPtr,dstPtr:ptr;
    offset:longint;

begin
{Assume aBits, aRect, and bBits are all appropriately initialized}
{aRect must delimit an area which begins and ends on word boundaries}
{in the bitmaps.}

 {The bits we want to mask begin somewhere at or past aBits.baseaddr.}
 offset:=aBits.rowBytes*(aRect.top-aBits.bounds.top);  {Move some rows down}
 offset:=offset+(aRect.left-aBits.bounds.left) div pixPerByte; {Move over}
 
 CalcMask(ptr(ord(aBits.baseAddr)+offset),
          ptr(ord(bBits.baseAddr)+offset),
          aBits.rowBytes,bBits.rowBytes,
          (aRect.bottom-aRect.top),
          (aRect.right-aRect.left) div (2*pixPerByte));
 end;

Hint: Without Inside Mac IV, life itself would be impossible.

-- 
+-------------------+-jackiw@cs.swarthmore.edu / !rutgers!bpa!swatsun!jackiw-+
|  nicholas jackiw  | jackiw%campus.swarthmore.edu@swarthmr.bitnet           |
+-------------------+-VGP/MathDept/Swarthmore College, Swarthmore, PA 19081--+
"Ah...I've got this CHRONIC pain."                             _True Believer_