TweetFollow Us on Twitter

Safe Dissolve
Volume Number:6
Issue Number:12
Column Tag:Programmer's Forum

Related Info: Quickdraw

QuickDraw-safe Dissolve

By Mike Morton, Honolulu, HI

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

A QuickDraw-safe Dissolve

I have sinned against you.

It was a long time ago. It was a brief dalliance. But it’s time to set things right.

On a hot August night in 1984, I was sitting in a basement with a 128K Mac and a Lisa running the Workshop development system. I had read Inside Macintosh about as far as the QuickDraw section on bitmaps and then bogged down. I didn’t want to learn about DITLs or the segment loader or any of that high-level junk. I was impatient and wanted some instant gratification. It seemed like you could get neat effects by directly manipulating screen memory, bypassing QuickDraw for considerable gains in speed.

So I wrote a subroutine called “DissBits”, modeled on the QuickDraw “CopyBits” call. It copied one bit image to another, moving the pixels one at a time in pseudo-random order. The resulting effect was a smooth dissolve, a “fade” in video lingo.

Persistence of vision

DissBits has popped up here and there over the years, which is pleasing and embarrassing. It’s embarrassing because Apple has been telling people from the outset not to assume things about the depth of the screen, and DissBits does that -- it won’t work in color, or with multiple monitors. I’ve even had it crash in the middle of a job interview.

The subroutine stubbornly tries to evolve with the times: John Love’s MacTutor series on graphics includes an updated version which handles multi-bit pixels -- but still has problems when the target spans multiple monitors. MacroMind has apparently also produced a color version, though they haven’t been very forthcoming about how they did it. Someone (I have no idea who) has produced a version for some IBM monitors. And in more general form, the algorithm is included in the recent compendium Graphics Gems (ed. Andrew Glassner, Academic Press, 1990).

Cleanliness is next to impossible?

Can you get the esthetics of a smooth dissolve without sneaking behind QuickDraw’s back and breaking all the compatibility rules? Well, to some degree, yes. This article presents a set of subroutines collectively called DissMask. This approach to dissolving images onto the screen directly manipulates an offscreen bitmap, but operates on the visible screen using only QuickDraw. While Apple can continue to define new layouts for screens, the structure of a one-deep bitmap is unlikely to change.

This technique isn’t good for fading large areas -- you can adjust the speed to some degree, but you’ll rarely want to use this for a full-screen fade. Still, it’s an instructive look at how closely the speed of a purist solution can approach that of a trickier, hardware-specific solution. It’s also immensely simpler than the original code, since it’s largely coded in C (the original was in assembler), and it solves a fundamentally smaller problem.

Through a mask, darkly

The new method copies the source image to the screen with CopyMask. (CopyMask was introduced with the Mac Plus ROM, so you’ll need to test that it’s present if you want your application to run on very old machines.) CopyMask transfers a selected portion of a source image to a destination image, using a “mask” bitmap to control which pixels are transferred. The dissolve is accomplished by doing a series of CopyMask calls, with more and more black pixels set in the mask. The final CopyMask is with a 100%-black mask (which, come to think of it, could be replaced by a CopyBits call).

The part of the code which most closely resembles the original dissolve is a function called dissMaskNext, which adds more black pixels to the mask bitmap. It’s much simpler than the dissolve code, though, since it only sets bits and doesn’t copy them. In addition, it works on a bitmap whose bounds are powers of two, and that reduces clipping done in the loop. In fact, the loop is just eight instructions per pixel for small images, but after each new round of adding black pixels, the CopyMask call consumes a lot of time, so in most cases the time for this “original” code is negligible.

How many pixels do you add to the mask between each CopyMask? That’s up to you. Adding too few pixels between copies will make the dissolve too slow and (if your image is large enough) may contribute to flicker. Adding too many pixels between copies will keep the dissolve from being smooth, since too many pixels will appear at a time. For large images, there may be no happy medium between these two, especially if other things slow down the CopyMask call: stretching, a target which spans multiple monitors, or a slow CPU.

That ol’ black (and white) magic

What are those magic constants in the array in dissMask.c? The heart of the dissolve is a strange algorithm which produces all integers from 1 through 2n-1 in pseudorandom order. Here’s a glimpse of how it works. (If you want a more detailed discussion, see the December 1985 MacTutor [reprinted in Best of MacTutor, Vol. 1], the November 1986 Dr. Dobb’s Journal, or the above-mentioned Graphics Gems.)

Consider this strange little loop:

/* 1 */

int value = 1;
do
{ if (value & 1)
    value = (value >> 1) ^ MASK;
  else value = (value >> 1);
} while (value != 1);

Each iteration throws the lowest bit off the right end by shifting, but also XORs in a magic MASK constant if the disappearing bit was ‘1’. Look at some values for the constant MASK, and the sequence of values produced for each one.

MASK Sequence produced

0x0003 1 3 2

0x0006 1 6 3 7 5 4 2

0x000C 1 12 6 3 13 10 5 14 7 15 11 9 8 4 2

Each of these masks randomly produces 1 through 2n-1. For every 2n-1, there’s at least one mask to produce a sequence of this length. One list is given in the seqMasks[] array in dissMask.c; verifying it is left as an exercise for the truly bored reader.

The algorithm for DissMask works only with a bitmap whose extents are both powers of two (the mask for CopyMask can be larger than the source and destination). So the total number of pixels in the mask bitmap is always a power of two. The pixels can be numbered 0 to 2n-1, so the loop goes through the random sequence values 1..2n-1 and sets the bit for each value. Bit 0 has to be done as a special case.

If the mask is less than 64K pixels, the loop in dissMaskNext() does several things for each iteration: the first four instructions map the sequence value to a bit address and set the bit. The next three instructions generate the next sequence element. The DBRA at the end of loop just limits the number of sequence values used up per call, since the mask is supposed to get only a little bit darker for each call, not chase through the whole sequence and become completely black.

Using DissMask

Dissolving uses several steps. (Sample code to do this is in the “dissolve” function in main.c, the example program.) You should #include “dissMask.h” to define the types and functions you need. Declare a variable of type “dissMaskInfo”, which is used for both internal purposes by the routines and to return some information to you.

When you have the image you want to copy, call dissMaskInit, passing it the bounds rectangle of the source image and a pointer to the dissMaskInfo structure. This will initialize everything and fill in the structure. It may fail (by running out of memory, for example), in which case it’ll return FALSE. If this happens, you should just call CopyBits and give up.

The initialization code will allocate a mask bitmap and store a pointer for it into the info structure. Your code will use this bitmap in calls to CopyMask. It will also store “pixLeft”, a count of the number of black pixels left to set in the mask bitmap. Your code will watch this count, which decreases with each call to dissMaskNext, and stop looping after it reaches zero.

Before beginning the main loop, you’ll usually want to hide the cursor to speed things up. The main loop is just:

/* 2 */

while (info.pixLeft)
{ dissMaskNext (& info, STEPS);
  CopyMask (srcBits, & info.maskMap, dstBits,
           srcRect, & info.maskRect, dstRect);
}

The value of STEPS is up to you -- it can be a constant, a function of the size of the bitmap (as given by the original value of info.pixLeft), or whatever. One approach would be to time the first couple of iterations and adjust the pixel-steps per iteration to try to calibrate the total time for the dissolve. I haven’t tried this kind of mid-course correction -- my lazy approach was to just use “steps = (info.pixLeft/20)” to get a constant number of loops (20, in this case).

When you’re done call ShowCursor if you hid it before the loop, and call dissMaskFinish to deallocate the bitmap.

Summary

The big advantage of this revised approach is the generality: there’s no intimate knowledge of the layout of the screen, and QuickDraw can begin supporting chunky/planar, smooth or even puréed pixels without breaking this code.

The big disadvantage is the time to dissolve large images. It’s up to you to decide how much flicker is acceptable before you switch to some other effect. Remember that you should try your application on different CPUs and monitors unless you have clever timing code to make sure the speed is right.

Optimizing CopyMask might be one way to help the speed -- does aligning the two images and the mask help? What else affects the speed of CopyMask? (I don’t know anyone want to research this?)

You may also want to synchronize CopyMask calls with the monitor’s vertical refresh to reduce flicker. For a large image, the copy may take longer than the sweep down the screen, so this can be difficult.

There are also some interesting variations that wouldn’t work with the original dissolve. Starting with the Mac II ROMs, CopyMask can stretch images, so this code can, too. If CopyMask is extended to do transfer modes, this code will too. [But if the transfer modes are additive or have some other side effect, the mask bitmap would have to be erased between iterations.] You can also do some tricks with using dissMaskNext() to create and store several masks, and use them non-sequentially, allowing an image to fade in and out (“Beam me up, Scotty!”).

But the big lesson is that there are penalties for playing by the rules, typically in speed and esthetics, and that there are compatibility penalties for end-running the system. The brave new world of Color QuickDraw has broken a lot of applications, and each new version of the system software may to do the same. I feel strongly that compatibility and playing by Apple’s rules are important, but I’m glad I didn’t feel that way in 1984. It sure was fun.

Acknowledgements

Many thanks to Ken Winograd, Rich Siegel, Martin Minow, and David Dunham for their advice and comments.

Listing:  dissMask.h

/*
 dissMask.h -- Copyright © 1990 by Michael S. Morton.  All rights reserved.
 dissMask is a set of functions which allow you to perform a digital 
“dissolve” using a series of calls to QuickDraw’s CopyMask() function. 
 These functions don’t do anything graphical directly; they just enable 
you to do so by rapidly generating a sequence of masks.
 Advantages of this scheme include:
 • It’s completely hardware-independent.  Because QuickDraw does the 
actual graphics work, the only low-level work is done on an old-fashioned 
bitmap, the format of which is stable.
 • This means (same advantage, continued) that it works at any bit depth 
and with multiple-monitor targets.
 • Because the client gets to choose how many black pixels are added 
to the mask in between copies, they can to some degree control the speed 
of the dissolve.  The client can empirically measure the time for the 
first copy, and do “mid-course correction” to get the desired speed.
 • On Mac II ROMs and later, stretching works.
 Disadvantages include:
 • Low memory may prevent allocating the bitmap.
 • The maximum speed can be obtained only by reducing the number of CopyMask 
calls, making the appearance “chunky”.
 • Large areas dissolve slowly and with a lot of flashing.
*/

#include “MacTypes.h”/* for Rect type */
#include “QuickDraw.h”  /* for BitMap type */

typedef struct { 
 /*PUBLIC section: these vars are read-only for the client */
 BitMap maskMap;
 /* mask bitmap for client to pass to CopyMask */
 Rect maskRect; 
 /* mask rectangle for client to pass to CopyMask */
 unsigned long pixLeft;  
 /* number of bits remaining to copy */

 /*PRIVATE section: */
 unsigned long seqElement; /* current element of sequence */
 unsigned long seqMask;  /* mask used to generate sequence */
} dissMaskInfo;   /* define this type */

/* dissMaskInit -- Initialize a “dissMaskInfo” structure, based solely 
on the bounds of the source rectangle.  This is the same rectangle passed 
to CopyMask() as the “srcRect” parameter.
 There will be a slight increase in performance if the srcRect’s dimensions 
are each near or equal to (but not over) a power of two.  This increase 
will be more noticeable if there are fewer CopyMask() calls.
 Under certain conditions, the function may fail, in which case it returns 
FALSE. These include running out of memory and the case where the source 
rectangle is ridiculously small.  The client should just do a vanilla 
CopyBits() call if a failure is reported.
 In addition to filling in the dissMaskInfo structure with the BitMap 
and Rect for use with CopyMask(), the “pixLeft” field is set up.  This 
is the count of pixels left to turn black in the mask.  It MAY be more 
than the number of pixels in the specified rectangle.  The client should 
advance the mask until this field is zero. */
extern Boolean dissMaskInit (Rect *srcRect, dissMaskInfo *info);

/* dissMaskNext -- “Advance” the mask bitmap by the specified number 
of pixels. Advancing in small steps will cause a slower, smoother dissolve. 
 Advancing in large steps will cause a faster, less smooth effect.
 You should hide, or at least obscure, the cursor before entering the 
loop with the CopyMask() calls.
*/
extern void dissMaskNext (dissMaskInfo *info, unsigned long steps);

/* dissMaskFinish -- Clean up the internals of the information struct. 
 Always call this when the client is done. */
extern void dissMaskFinish (dissMaskInfo *info);
Listing:  dissMask.c

/* dissMask.c -- Copyright © 1990 by Michael S. Morton.  All rights reserved.
 History:
 23-Aug-90- MM - First public version.
 Enhancements needed:
 • Can CopyMask be used with transfer modes with side effects (e.g., 
additive)?
 If so, we should erase the bitmap before setting each new set of bits. 
 */
#include “dissMask.h”

/* Internal prototypes: */
static void round2 (short *i);

/* Masks to generate the pseudo-random sequence.  The table runs 0 32, 
but only elements 2 32 are valid. */
static unsigned long seqMasks [ /* 0 32 */ ] =
{0x0, 0x0, 0x03, 0x06, 0x0C, 0x14, 0x30, 0x60, 0xB8, 0x0110, 0x0240, 
0x0500, 0x0CA0, 0x1B00, 0x3500, 0x6000, 0xB400, 0x00012000, 0x00020400, 
0x00072000, 0x00090000, 0x00140000, 0x00300000, 0x00400000, 0x00D80000, 
0x01200000, 0x03880000, 0x07200000, 0x09000000, 0x14000000, 0x32800000, 
0x48000000, 0xA3000000
};

extern Boolean dissMaskInit (srcRect, info)
 Rect *srcRect; /* INPUT: bounds of source rectangle */
 register dissMaskInfo *info; 
 /* OUTPUT: state-of-the-world for mask */
{
 /*Copy the client’s source rectangle, then normalize it to (0,0) for 
simplicity. */
 info->maskRect = *srcRect; /* copy it  */
 OffsetRect (& info->maskRect,/*  and normalize it  */
 -info->maskRect.left, -info->maskRect.top); 
 /*  to (0,0) at the top left */

 /*Round it up to a power of two in each dimension for the bitmap’s bounds. 
 This speeds up the dissolve considerably by removing bounds checking. 
 Also, ensure that the width of the bitmap is a multiple of two bytes, 
or 16 bits. */
 info->maskMap.bounds = info->maskRect;
 /* start by copying the client’s bounds */
 round2 (& info->maskMap.bounds.bottom); 
 /* now round both extents  */
 round2 (& info->maskMap.bounds.right); 
 /*  up to powers of two */
 if (info->maskMap.bounds.right < 16)
 /* too small to be a bitmap? */
 info->maskMap.bounds.right = 16;  /* yep: round it up */

 /*Compute total number of pixels in the mask bitmap; initialize the 
countdown counter. */
 info->pixLeft = info->maskMap.bounds.bottom * (long) info->maskMap.bounds.right;
 /*Figure magic mask to be used in dissMaskNext() loop: */
 { register short log2 = 0; /* log base-two of pixel count */
 register unsigned long ct; 
 /* working copy of pixel count */

 ct = info->pixLeft;
 while (ct > 1)   /* until log2(ct) == 0 */
 { ct >>= 1; ++log2; }/*  shift down one; bump log2 */

 /*Actually, I don’t think either of these (<2 or >32) can happen  */
 if ((log2 < 2) || (log2 > 32))  
 /* outside of table bounds? */
 return FALSE;
 /* can’t do this; client should CopyBits() */
 info->seqMask = seqMasks [log2];  
 /* set up mask which generates cycle of len 2**log2 */
 }

 /*Because we count iterations, we needn’t watch the sequence element: 
it can start anywhere. */
 info->seqElement = 1;
 /* init sequence element to any nonzero value */

 /*Finish filling in pixmap; handle allocation failure. */
 info->maskMap.rowBytes = info->maskMap.bounds.right / 8;
 info->maskMap.baseAddr = NewPtrClear (info->pixLeft / 8); 
 /* allocate data for bitmap */
 if (! info->maskMap.baseAddr) /* allocation failed? */
 return FALSE; /* tell client[should we clear MemErr?] */

 --info->pixLeft; /* kludge: one element done outside loop */
 return TRUE; /* client can continue */
} /* end of dissMaskInit () */

extern void dissMaskNext (info, steps)
 register dissMaskInfo *info; 
 /* UPDATE: state-of-the-world for mask */
 register unsigned long steps;
 /* INPUT: number of steps to take */
{register unsigned long element, mask; /* for use in asm{} */
 register void *baseAddr; /* for use in asm{} */

 if (steps == 0) steps = 1; /* keep things sane */
 if (steps > info->pixLeft) /* more steps than we need? */
 steps = info->pixLeft;   /* yes: just go ’til the end */
 info->pixLeft -= steps;
 /* debit this before we trash “steps” */

 element = info->seqElement;/* move these  */
 mask = info->seqMask;    /*  memory-based variables  */
 baseAddr = info->maskMap.baseAddr;
 /*  into registers for asm {} */

 --steps; 
 /* set up counter to run out at -1, not 0, for DBRA rules */

 /*If all the arithmetic can be done in 16 bits, we do so: */
 if ((info->seqMask & 0xffff) == info->seqMask)
 asm
 { /* Sixteen-bit case: “.w” operands and a simple DBRA to wind it up. 
*/
 @loopStart16:
 /*Set the bit for the current sequence element: */
 move.w element, D0/* copy bit number  */
 move.b D0, D1   /* and make a copy for numbering within a byte */
 lsr.w  #3, D0 /* convert bit number to byte number */
 bset   D1, 0(baseAddr, D0.w) 
 /* set D1’st bit in D0’th byte of contiguous bitmap */

 /*Advance to the next sequence element.  If this element was 1, we’re 
all done. */
 lsr.w  #1, element /* throw out a bit  */
 bcc.s  @skipXOR16  
 /*  if it’s only a zero, don’t XOR */
 eor.w  mask, element 
 /* if a one-bit fell off, flip mask-bits */
 @skipXOR16:
 dbra   steps, @loopStart16 /* count down steps */
 }

 else asm
 { /* Thirty-two-bit case: “.l” operands and a SUB.L to follow up the 
DBRA: */
 @loopStart32:
 /*Set the bit for the current sequence element: */
 move.l element, D0/* copy bit number  */
 move.b D0, D1 
 /* and make a copy for numbering within a byte */
 lsr.l  #3, D0   
 /* convert bit number to byte number */
 bset   D1, 0(baseAddr, D0.l) 
 /* set D1’st bit in D0’th byte of contiguous bitmap */

 /*Advance to the next sequence element.  If this element was 1, we’re 
all done. */
 lsr.l  #1, element/* throw out a bit  */
 bcc.s  @skipXOR32 
 /*  if it’s only a zero, don’t XOR */
 eor.l  mask, element
 /* if a one-bit fell off, flip mask-bits */
 @skipXOR32:
 dbra   steps, @loopStart32 
 /* count down low word of steps */
 sub.l  #0x00010000, steps
 /* low word ran out: check high word */
 bpl.s  @loopStart32 
 /* still   0: loop some more */
 }

 info->seqElement = element;
 /* update sequence element from asm{}’s changes */

 if (! info->pixLeft) /* all general pixels copied? */
 asm    /* yes: there’s a special case */
 { bset #0, (baseAddr)
 /* element 0 never comes up, so set bit #0 in byte #0 */
 }
} /* end of dissMaskNext () */

extern void dissMaskFinish (info)
 register dissMaskInfo *info; 
 /* UPDATE: struct to clean up */
{DisposPtr (info->maskMap.baseAddr);
 info->maskMap.baseAddr = 0L; /* lights on for safety */
} /* end of dissMaskFinish () */

/* round2 -- Round a value up to the next power of two. */
static void round2 (i)
 register short *i;
{register short result;

 result = 1;
 while (result < *i)
 result <<= 1;
 *i = result;
} /* end of round2 () */
Listing:  main.c

/* Quick and dirty demo application for dissMask routines.
 Written August 1990 by Mike Morton for MacTutor. */
#include “dissMask.h”

/* “dissolve” is just a part of the driver; you’ll probably want your 
own code to call the dissMask____ functions(), although your code will 
look a lot like “dissolve”. */
static void dissolve (BitMap *srcBits, BitMap *dstBits, Rect *srcRect, 
Rect *dstRect, unsigned short steps);

void main (void)
{Rect winBounds;
 WindowRecord theWindow;
 Handle scrapHandle;
 long scrapResult;
 long scrapOffset;
 char windowTitle [100];
 BitMap offScreen, winBits;
 short rows, cols;
 EventRecord evt;
 long dummy;
 short clipCopies, clipCount;
 PicHandle thePict;
 short picWidth, picHeight;
 Rect target;

 /*Standard Mac init, skipping menus & TE & dialogs: */
 InitGraf (& thePort);
 InitFonts ();
 FlushEvents (everyEvent, 0);
 InitWindows ();
 InitCursor ();

 /*We prefer to be run with graphics on the clipboard,
 but protest only feebly if there’s no PICT: */
 strcpy (windowTitle, “Dissolve demo using CopyMask”);
 scrapHandle = NewHandle (0L);
 scrapResult = GetScrap (scrapHandle, ‘PICT’, & scrapOffset);
 if (scrapResult < 0) /* no PICT available? */
 strcat (windowTitle, “ (NO PICTURE ON CLIPBOARD)”);
 CtoPstr (windowTitle);

 /*Steal main screen, inset a bit, and avoid menu bar. */
 winBounds = screenBits.bounds;
 InsetRect (& winBounds, 8, 8);
 winBounds.top += 20 + MBarHeight;

 /*Make up a new window: */
 NewWindow (& theWindow, & winBounds, windowTitle,
 true, /*visible at first*/ noGrowDocProc,
 -1L, /*frontmost*/ false, /*no go-away box*/
 0L); /*no refcon*/
 SetPort ((GrafPtr) & theWindow);
 winBits = thePort->portBits; 
 /* remember where onscreen bit image is */

 rows = thePort->portRect.bottom - thePort->portRect.top;
 cols = thePort->portRect.right - thePort->portRect.left;

 /*Make up a bitmap with the same bounds as the window. */
 offScreen.bounds = thePort->portRect;
 offScreen.rowBytes = (cols + 7) / 8;
 if (offScreen.rowBytes & 1)
 ++offScreen.rowBytes;
 offScreen.baseAddr =
 NewPtrClear (rows * (long) offScreen.rowBytes);
 if (offScreen.baseAddr == 0) /* out of memory? */
 { SysBeep (10); /* be uninformative */
 ExitToShell ();
 }

 /*Fill up the offscreen bitmap.  If we have a clipboard PICT, tile the 
offscreen bitmap with it; else fill the bitmap with black. */
 SetPortBits (& offScreen);
 if (scrapResult >= 0)
 { thePict = (PicHandle) scrapHandle;
 target = (**thePict).picFrame;
 picWidth = target.right - target.left;
 picHeight = target.bottom - target.top;

 /*Tile the offscreen image with copies of the PICT. */
 clipCopies = 0;
 target.top = 0;
 target.bottom = picHeight;
 while (target.top < thePort->portRect.bottom)
 { target.left = 0;
 target.right = picWidth;
 while (target.left < thePort->portRect.right)
 { DrawPicture (thePict, & target);
 OffsetRect (& target, picWidth, 0);
 ++clipCopies;
 }
 OffsetRect (& target, 0, picHeight);
 }
 }
 else /* no PICT? */
 FillRect (& thePort->portRect, black); 
 /* paint it black, you devil */
 SetPortBits (& winBits);

 /*Bring in ALL this to show the speed of a nearly-full-screen dissolve. 
*/
 dissolve (& offScreen, & theWindow.port.portBits,
 & thePort->portRect, & thePort->portRect, 10);
 Delay (60L, & dummy);
 EraseRect (& thePort->portRect);

 /*If we have a clipboard PICT, dissolve these things in at
 varying speeds -- note the last parameter to dissolve(). */
 if (scrapResult >= 0)
 { clipCount = 1;
 target.top = 0;
 target.bottom = picHeight;
 while (target.top < thePort->portRect.bottom)
 { target.left = 0;
 target.right = picWidth;
 while (target.left < thePort->portRect.right)
 { /* The first image dissolves in 20 steps; the last
 one in fewer. */
 dissolve (&offScreen, &theWindow.port.portBits, &target, &target, 20 
* (clipCopies - clipCount) / clipCopies);
 OffsetRect (& target, picWidth, 0);
 ++clipCount;
 }
 OffsetRect (& target, 0, picHeight);
 }
 Delay (60L, & dummy);
 EraseRect (& thePort->portRect);
 }

 /*Let ’em draw selections to be dissolved in. */
 SetWTitle (& theWindow, “\pClick and drag to dissolve   press a key 
to exit”);
 do
 { GetNextEvent (everyEvent, & evt);
 if (evt.what == mouseDown)
 { GlobalToLocal (& evt.where);
 if (PtInRect (evt.where, & thePort->portRect))
 { Point startPt, endPt, curPt;
 Rect frame;

 PenPat (gray); PenSize (1, 1); PenMode (patXor);
 startPt = evt.where;
 endPt = evt.where;
 Pt2Rect (startPt, endPt, & frame);
 FrameRect (& frame);
 while (StillDown ())
 { GetMouse (& curPt);
 if (curPt.v < 0) curPt.v = 0; 
 /* hack to avoid mysterious bugs */
 if (! EqualPt (curPt, endPt))
 { FrameRect (& frame);
 endPt = curPt;
 Pt2Rect (startPt, endPt, & frame);
 FrameRect (& frame);
 }
 }
 FrameRect (& frame);
 dissolve (& offScreen, & theWindow.port.portBits,
 & frame, & frame, 20);
 }
 else SysBeep (2); /* click outside window */
 } /* end of handling mousedown */
 } while (evt.what != keyDown);
} /* end of main () */

/* dissolve -- quick driver for dissMask routines.  It sets up the dissolve 
and does it in specified number of iterations. */
static void dissolve (srcBits, dstBits, srcRect, dstRect, steps)
 BitMap *srcBits, *dstBits;
 Rect *srcRect, *dstRect;
 unsigned short steps;
{dissMaskInfo info;
 unsigned long pixPerStep;

/* Initialize for dissolve; if it fails, just copy outright: */
 if (! dissMaskInit (srcRect, & info))
 { CopyBits (srcBits, dstBits, srcRect, dstRect, srcCopy, 0L);
 return;
 }

 if (steps == 0) steps = 1;
 pixPerStep = (info.pixLeft / steps) + 1;

 /*Main dissolve loop: repeatedly darken the mask
 bitmap and CopyMask through it. */
 HideCursor ();
 while (info.pixLeft)
 { dissMaskNext (& info, pixPerStep);
 CopyMask (srcBits, & info.maskMap, dstBits,
 srcRect, & info.maskRect, dstRect);
 }
 /*Clean up: */
 ShowCursor ();
 dissMaskFinish (& info);
} /* end of dissolve () */

 
AAPL
$103.30
Apple Inc.
+0.80
MSFT
$45.09
Microsoft Corpora
-0.34
GOOG
$577.33
Google Inc.
+5.73

MacTech Search:
Community Search:

Software Updates via MacUpdate

TextSoap 7.4.0 - Flexible text editing u...
TextSoap is for people who work with text. TextSoap effortlessly cleans up text from endlessly different formats. Wash away unwanted characters, spaces, tabs. Fix paragraphs with hard returns at the... Read more
NetShade 6.0.2 - Browse privately using...
NetShade is an Internet security tool that conceals your IP address on the web. NetShade routes your Web connection through either a public anonymous proxy server, or one of NetShade's own dedicated... Read more
Mac DVDRipper Pro 5.0 - Copy, backup, an...
Mac DVDRipper Pro is the DVD backup solution that lets you protect your DVDs from scratches, save your batteries by reading your movies from your hard disk, manage your collection with just a few... Read more
pwSafe 3.1 - Secure password management...
pwSafe provides simple and secure password management across devices and computers. pwSafe uses iCloud to keep your password databases backed-up and synced between Macs and iOS devices. It is... Read more
StatsBar 1.8 - Monitor system processes...
StatsBar gives you a comprehensive and detailed analysis of the following areas of your Mac: CPU usage Memory usage Disk usage Network and bandwidth usage Battery power and health (MacBooks only)... Read more
Path Finder 6.5.5 - Powerful, award-winn...
Path Finder is a file browser that combines the familiar Finder interface with the powerful utilities and innovative features. Just a small selection of the Path Finder 6 feature set: Dual pane... Read more
QuarkXPress 10.2.1 - Desktop publishing...
With QuarkXPress, you can communicate in all the ways you need to -- and always look professional -- in print and digital media, all in a single tool. Features include: Easy to Use -- QuarkXPress is... Read more
Skype 6.19.0.450 - Voice-over-internet p...
Skype allows you to talk to friends, family and co-workers across the Internet without the inconvenience of long distance telephone charges. Using peer-to-peer data transmission technology, Skype... Read more
VueScan 9.4.41 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
Cloud 3.0.0 - File sharing from your men...
Cloud is simple file sharing for the Mac. Drag a file from your Mac to the CloudApp icon in the menubar and we take care of the rest. A link to the file will automatically be copied to your clipboard... Read more

Latest Forum Discussions

See All

Modern Combat 5 Gets a Major Multiplayer...
Modern Combat 5 Gets a Major Multiplayer Update Posted by Jessica Fisher on September 2nd, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Alien Creeps TD Review
Alien Creeps TD Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: EXPENSIVE DEFENSESUniversal App - Designed for iPhone and iPad Alien Creeps TD would be a fun if unremarkable Tower Defense game, but its heavy focus on... | Read more »
The Journey Down: Chapter Two Review
The Journey Down: Chapter Two Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: DARK YET ENTICINGUniversal App - Designed for iPhone and iPad It’s a little dark, in every sense of the word, but The Journey Down:... | Read more »
Function Space, a Social Network App for...
Function Space, a Social Network App for Science, Launches on iOS Posted by Ellis Spice on September 2nd, 2014 [ permalink ] | Read more »
Stupidfast – How Taylor Martinez Switche...
How do you make an Endless Running game more than just another Endless Running game? By adding real life prizes to it, of course! That’s the thinking behind StupidFast: a game designed for football enthusiasts, and the brainchild of former college... | Read more »
Little Raiders: Robin’s Revenge Review
Little Raiders: Robin’s Revenge Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: CASUAL RAIDINGUniversal App - Designed for iPhone and iPad Combining simple combat with village building is a potent combination for... | Read more »
Treasure Tombs: Ra Deal Coming from Bulk...
Treasure Tombs: Ra Deal Coming from Bulkypix and Dark Tonic This Fall Posted by Jessica Fisher on September 2nd, 2014 [ permalink ] Dark Tonic and | Read more »
Pirate Bash Review
Pirate Bash Review By Nadia Oxford on September 2nd, 2014 Our Rating: :: BAD PIRATES, GOOD TIMESUniversal App - Designed for iPhone and iPad Pirate Bash’s turn-based battles add an intriguing twist to a typical physics game.   | Read more »
Tiny Tower Vegas Review
Tiny Tower Vegas Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: STEADY DEVELOPMENTUniversal App - Designed for iPhone and iPad Build a huge tower again but Vegas-style in Tiny Tower Vegas.   | Read more »
The Manhattan Project Review
The Manhattan Project Review By Andrew Fisher on September 2nd, 2014 Our Rating: :: ROCKET SCIENCEUniversal App - Designed for iPhone and iPad The Manhattan Project offers a great Euro-style gameplay experience, but it is totally... | Read more »

Price Scanner via MacPrices.net

Apple refurbished iPads available for up to $...
Apple is offering Certified Refurbished iPad Airs for up to $140 off MSRP. Apple’s one-year warranty is included with each model, and shipping is free. Stock tends to come and go with some of these... Read more
Are We Now In The Post-Post-PC Era?
A longtime and thoroughgoing laptop aficionado, I was more than a little dismayed by Steve Jobs’s declaration back in 2010 when he sprang the iPad on an unsuspecting world. that we’d entered a “post-... Read more
PC Outlook Improves, But 2014 Shipments Still...
According to the International Data Corporation (IDC) Worldwide Quarterly PC Tracker, worldwide PC shipments are expected to fall by -3.7 percent in 2014. To hat’s actually an improvement from the... Read more
IDC Lowers Tablet Sales Projections for 2014...
Following a second consecutive quarter of softer than expected demand, International Data Corporation (IDC) has lowered its worldwide tablet plus 2-in-1 forecast for 2014 to 233.1 million units. The... Read more
Apple now offering refurbished 21-inch 1.4GHz...
The Apple Store is now offering Apple Certified Refurbished 21″ 1.4GHz iMacs for $929 including free shipping plus Apple’s standard one-year warranty. Their price is $170 off the cost of new models,... Read more
Save $50 on the 2.5GHz Mac mini, on sale for...
B&H Photo has the 2.5GHz Mac mini on sale for $549.99 including free shipping. That’s $50 off MSRP, and B&H will also include a free copy of Parallels Desktop software. NY sales tax only. Read more
Save up to $300 on an iMac with Apple refurbi...
The Apple Store has Apple Certified Refurbished iMacs available for up to $300 off the cost of new models. Apple’s one-year warranty is standard, and shipping is free. These are the best prices on... Read more
The Rise of Phablets
Carlisle & Gallagher Consulting Group, a businesses and technology consulting firm focused solely on the financial services industry, has released an infographic depicting the convergence of... Read more
Bad Driver Database App Allows Good Drivers t...
Bad Driver Database 1.4 by Facile Group is a new iOS and Android app that lets users instantly input and see how many times a careless, reckless or just plain stupid driver has been added to the... Read more
Eddy – Cloud Music Player for iPhone/iPad Fre...
Ukraine based CapableBits announces the release of Eddy, its tiny, but smart and powerful cloud music player for iPhone and iPad that allows users to stream or download music directly from cloud... Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.