TweetFollow Us on Twitter




[IMAGE Othmer_text_html1.GIF]

With System 7.0 comes a major revision of QuickDraw. The CopyBits procedure, QuickDraw's image-processing workhorse, has had some bugs fixed and some features added. This article gives a brief overview of changes to QuickDraw and then brings you up to speed on changes to CopyBits.

We're seeing some impressive examples of computer image processing at the movies these days. Special effects in movies such as Star Trek III , Willow , Back to the Future , Arachnophobia , Ghost , and The Abyss were either assisted or completely generated by computer. While QuickDraw TM does not have the built-in ability to perform the highly specialized image processing necessary to produce the types of effects seen in those movies, producing such effects is not beyond the capability of the Macintosh. You can write custom routines to perform such operations as rotation, warping, and advanced filtering.

Before you get to that advanced stuff, though, you need to be familiar with QuickDraw's basic image-processing capabilities, which provide the starting point for an effects toolbox. With QuickDraw's CopyBits procedure, you can perform several standard image-processing operations, such as resizing (by stretching, shrinking, or clipping the image), colorizing, or changing the pixel depth.

CopyBits is better than ever in System 7.0. Improvements to transfer operations and colorizing mean enhanced results. And it's now easier to use a search procedure to alter colors. We'll look at these improvements in detail and will see samples of CopyBits in action after a brief overview of how QuickDraw has evolved.


There have been a number of QuickDraw versions since the introduction of the Macintosh in 1984. Table 1 summarizes the major QuickDraw versions. Many minor revisions and bug fixes have also occurred along the way, of course.

Table 1 A Summary of Major QuickDraw Versions

DateVersionWhere Documented
January 1984Original B&W QuickDraw Inside Macintosh
(Macintosh 128K)Volume I
January 1986B&W QuickDraw Inside Macintosh
(Macintosh Plus)Volume IV
March 1987Color QuickDraw Inside Macintosh
B&W QuickDrawVolume V
(Macintosh II)
May 198932-Bit QuickDraw v. 1.0 Inside Macintosh
Volume VI
September 198932-Bit QuickDraw v. 1.1 Inside Macintosh
(System 6.0.4,Macintosh Volume VI
IIci, IIfx, IIsi, and LC)
March 199032-Bit QuickDraw v. 1.2 Inside Macintosh
(System 6.0.5)Volume VI
April 1991Color QuickDraw Inside Macintosh
B&W QuickDrawQuickDraw Volume VI
(System 7.0)

Note: QuickDraw is revised for system releases and, in the past, major revisions have coincided with hardware releases. In the future, it's likely that major system releases will be independent of hardware releases.

The version of black-and-white QuickDraw that accompanied the Macintosh Plus system added the SeedFill, CalcMask, and CopyMask calls. The Macintosh II revision introduced Color QuickDraw (which supported indexed devices only) and revised the existing black-and-white QuickDraw (which is still used on 68000-based machines) to display pictures (data of type 'PICT') created in the color version.

Version 1.0 of 32-Bit QuickDraw, released as an INIT at the Developers Conference in 1989, added direct-color capability to QuickDraw. No black-and-white QuickDraw update was provided. Version 1.1 of 32-Bit QuickDraw is in ROM on the Macintosh IIci, IIfx, IIsi, and LC. Version 1.2 of 32-Bit QuickDraw, released as an INIT with System 6.0.5 and patched by the system on machines that have version 1.1 in ROM, added the OpenCPicture call and the capability of recording font names into pictures.

The System 7.0 version of Color QuickDraw integrates the functionality of 32-Bit QuickDraw into all Color QuickDraw machines and adds a variety of new features and bug fixes. In addition, System 7.0 has a new version of black-and-white QuickDraw that includes some of Color QuickDraw's functionality. (See "QuickDraw Features New in System 7.0" on the next page for more information.)


The CopyBits procedure, along with the CopyMask and CopyDeepMask calls, is the core of QuickDraw's image-processing capability. CopyBits transfers a bit image from one bitmap to another and clips the result to a specified area. With CopyBits you can perform such image- processing operations as resizing (by stretching, shrinking, or clipping the image), colorizing, and changing the pixel depth. You can use it to display on-screen the contents of an off-screen buffer.

In the System 7.0 version of QuickDraw, as in previous versions, the CopyBits procedure is defined as

PROCEDURE CopyBits (srcBits,dstBits: BitMap;srcRect,dstRect: Rect;
      mode: INTEGER; maskRgn: RgnHandle);

In the original black-and-white QuickDraw, CopyBits used six explicit parameters (srcBits, dstBits,srcRect, dstRect, mode, and maskRgn) and one global variable (thePort). The introduction of Color QuickDraw required an additional global variable, theGDevice, which is used to determine color information for the destination.

Although the number of variables used by CopyBits hasn't changed from earlier QuickDraw versions, several things have changed:

  • The way transfer operations specified by the mode parameter are performed has changed to make their results predictable regardless of whether the destination device uses indexed or direct color.
  • The way the notCopy transfer operation is performed has changed to improve the quality of color inversions.
  • Dithering has been extended to improve the quality of images resulting from depth conversion, color mapping, or resizing.
  • The way colorizing is performed has changed to make the results predictable for all pixel depths.
  • The use of search procedures has been extended and now provides an easier mechanism for altering colors.

In the following sections we'll take a closer look at each of these improvements. We'll then watch CopyBits in action as we stretch and colorize a gray ramp, and perform RGB and CMY color separations.


The appearance of the result of the CopyBits procedure is determined by the mode parameter. This parameter specifies which source transfer mode is to be used and whether or not dithering should occur during transfer operations. Improvements to CopyBits in System 7.0 make the results of transfer operations independent of whether the destination device uses indexed or direct color. The new CopyBits also improves the results of color inversions and extends the use of dithering.

Before System 7.0, the transfer mode specified in CopyBits' mode parameter was implemented directly by one of eight transfer operations: Copy, Or, Xor, Bic, notCopy, notOr, notXor, and notBic. For each bit in the source bitmap to be drawn, QuickDraw found the corresponding bit in the destination bitmap, performed the transfer operation on the pair of bits, and stored the resulting bit into the bit image.

This method extended naturally to the use of indexed devices in Color QuickDraw. But with the introduction of 32-Bit QuickDraw, which supported both indexed and direct-color devices, the results of the Or, Bic, and Xor transfer operations became dependent on the type of destination device. Using the Or operation with direct color--where 0 represents black and $FF represents white--resulted in pixels that went toward white, while using the Or operation on indexed pixels-- where indexes typically range from 0 (white) to $FF (black)--had a result that went toward black. Bic and Xor had similar problems.

For example, many applications use the srcXor transfer mode--defined in Inside Macintosh Volume I as inverting destination pixels that are black in the source--when dragging a selection. In the original Color QuickDraw, this operation was performed correctly. In 32-Bit QuickDraw, on the other hand, destination pixels that were white in the source were inverted on direct-color devices.

In the new Color QuickDraw, the transfer modes srcOr, srcBic, and srcXor are still undefined for color pixel values, but behave correctly--that is, as documented in Inside Macintosh Volume I--with respect to black and white regardless of whether the destination device uses indexed or direct color. The way these modes work now as compared to the way they worked in 32-Bit QuickDraw version 1.0 for direct sources copied to a direct-color device is shown in Figure 1.

[IMAGE Othmer_text_html2.GIF]

Figure 1 Results of Transfer Modes for Direct Source to Direct Destination

For all devices now, the srcOr transfer mode produces a black result where the source is black. The srcXor transfer mode inverts destination pixels where the source is black. And srcBic (which stands for "bit clear" but may be easier to remember as "black is changed") produces a white result where the source is black. All three modes leave the destination pixels under the white part of the source unchanged. (Note that using these transfer modes for colored sources, while legal, does not always produce well-defined results.)

Before System 7.0, notCopy was performed by inverting source index values. In System 7.0, the inversion takes place in color space, giving a much more pleasing result. Note that the trade-off for higher quality in this case is reduced speed: this operation is somewhat slower than in previous versions.

Using notSrcCopy mode to highlight items when they've been selected produces good results on screens of all depths, although it suffers from gray mapping to gray.

Figure 2 shows a button ("Squishy") highlighted using notSrcCopy mode.

[IMAGE Othmer_text_html3.GIF]

Figure 2 Button Highlighted Using notSrcCopy Mode


32-Bit QuickDraw version 1.0 introduced the dither flag. In that version of QuickDraw, setting the dither flag (bit 6 of the mode, called ditherCopy) caused dithering to occur when direct pixMaps were copied to indexed destinations.

In System 7.0, setting the dither flag in QuickDraw causes dithering to occur during any depth conversion or color mapping. For example, you can get a dither when converting an 8-bit image to a 4-bit image or a 1-bit image, or when copying between two 4-bit pixMaps that have different color tables. Figure 3 shows the effect of dithering when depth conversion occurs.

[IMAGE Othmer_text_html4.GIF]

Figure 3 Depth Conversion With and Without Dithering

In addition, setting the dither flag now affects how images are resized. In 32-Bit QuickDraw, only 32-bit pixMaps used a technique of pixel averaging in RGB space when they were shrunk. All other pixMaps were shrunk using a technique that maximizes pixel value and tends to turn shrunk pixMaps to black. In System 7.0, setting the dither flag causes pixMaps of all depths to be averaged when shrunk. Figure 4 shows the effect of dithering when shrinking a 1-bit image and an 8-bit image. Notice that the dithered result for the 1-bit image includes shades of gray as well as black and white.

Because dithering is a relatively slow process, setting the dither flag tells CopyBits that quality is more important than speed. Note, however, that direct pixMaps are always averaged when shrunk, regardless of the state of the dither flag.


When CopyBits transfers an image from one bitmap to another, it refers to the foreground and background color fields of the global variable thePort. The foreground color specified there is applied to black pixels in the source and the background color is applied to white pixels. This is known as colorizing .

Before System 7.0, colorizing with CopyBits was performed on the indexes of the colors rather than on the color values. This meant that the results depended on the organization of the color look-up table (CLUT) of the destination GDevice. Thus, the results for multicolor images were unpredictable. This problem is illustrated in Figure 5. This was the basis for the common knowledge that the foreground and background color in the current grafPort must be set to black and white respectively or unpredictable results would occur when using CopyBits. In System 7.0, colorizing occurs in color space, not index space. Thus, colorizing now works as predictably for deep source pixMaps as it always has for 1-bit source pixMaps.

[IMAGE Othmer_text_html5.GIF]

Figure 4 Resizing With and Without Dithering

[IMAGE Othmer_text_html5a.GIF]

Figure 5 Colorizing

Colorizing is logically the last step in the CopyBits procedure. It modifies the destination pixel color as follows: all bits that are off in the source pixel are given the value of the corresponding bit in the foreground color, and all bits that are on are given the value of the corresponding bit in the background color. This is illustrated for a 16-bit pixel in Figure 6. For a foreground color of black 6 (all components 0) and a background color of white (all components $FFFF) this operation does not change the pixel color value. The formula that performs this operation (in color space) is

result = (src AND bkColor) OR ((not src) AND fgColor)

f15 f14 f13 f12 f11 f10 f9 f8 f7 f6 f5 f4 f3 f2 f1 f0 fgColor
b15b14b13b12b11b10b9b8b7b6b5b4b3 b2b1b0bkColor
1010111100001100 source
b15f14b13f12b11b10b9b8f7f6f5 f4b3b2f1f0result

Figure 6 How Colorizing Works in System 7.0

This operation may seem convoluted at first, but it turns out to be quite useful. For example, you can invert an image by changing the foreground color to white and the background color to black. Figure 7 shows some of the variations on one image that can be obtained simply by changing the foreground and background colors. The code samples later in this article use CopyBits colorizing to perform CMY and RGB color separation.

[IMAGE Othmer_text_html6.GIF]

Figure 7 Colorized Versions of the 32-Bit QuickDraw Icon


In Color QuickDraw, destination color information comes from the current GDevice. You can attach a search procedure to a GDevice to determine how colors will appear on that device.

Before System 7.0, search procedures were used only when the source and destination pixMaps had different depths or color tables. In System 7.0, search procedures can be used in any case--for example, to alter the colors of a pixMap. In addition, the RGBColor parameter that the search procedure receives is now always a VAR parameter. (This was not true in 32-Bit QuickDraw for direct-color destinations.)

In System 7.0, a search procedure is defined as

FUNCTION SearchProc(VAR rgb: RGBColor; VAR position: LongInt)
         : Boolean;

On entry, the RGBColor parameter contains the color QuickDraw is trying to represent on the current device. The search procedure can do one of three things:

  • It can return the index or the direct-color value (depending on the device) in the position parameter and a result of TRUE. In this case, QuickDraw draws using the color returned in the position parameter.
  • It can modify the RGBColor parameter and return a result of FALSE. In this case, QuickDraw ignores the position parameter and uses its default color look-up mechanism on the returned color to find the value to draw with. For indexed devices, QuickDraw uses an inverse look-up table (ILUT) to determine which index to represent a given color with. For direct-color devices, QuickDraw merely truncates each component of the RGBColor parameter to the desired size: 5 bits for 16-bit color, 8 bits for 32-bit color.
  • It can leave the RGBColor parameter unchanged, return FALSE, and still let QuickDraw do the job using the default algorithm above.

Using a search procedure in this way provides an easy mechanism for altering colors. For example, to darken an image you simply attach a search procedure that reduces the RGBColor parameter to a GDevice and then call CopyBits with that device as the current GDevice.


The following code samples show how to do some useful things with the improved CopyBits found in Color QuickDraw in System 7.0. Example 1 shows how to stretch and colorize a gray ramp. Although the example is trivial, a number of pitfalls associated with directly accessing a GWorld's pixMap are addressed.

Example 2 shows how to do RGB and CMY color separation with CopyBits, and how to expand the source picture by a factor of 1.5. It's fairly easy to do RGB and CMY color separation using CopyBits with the correct foreground and background colors. Note that CMYK color separation (which removes gray components before separating the cyan, magenta, and yellow) is generally more useful than the simple CMY separation performed here. CMYK color separation is usually accomplished by using a search procedure.

The goal in this first example is to produce a red-scale ramp that fills the current window. The code merely allocates a one-pixel-wide gray-scale line and then uses CopyBits colorizing to stretch this line to the size of the window.

The first thing the code does is allocate a 32-bit off-screen GWorld to hold the one-pixel- wide line. If the allocation fails, the routine does nothing.Next, GetGWorldPixMap is used to get a handle to the GWorld's pixMap. Note that this call did not work in pre-System 7.0 versions of QuickDraw. In those versions you could get the pixMap handle directly from the GWorld. On black-and-white QuickDraw machines, you must use GetGWorldPixMap. Note that on these machines you get the functional equivalent of a pixMap as far as GWorlds are concerned, but you do not get a true PixMapHandle.

The code then locks the pixels. This is necessary since CopyBits can move memory. Here's what we've got so far:

    Rect            srcRect;
    long            * bitsPtr;
    short           iii;
    long            jjj;
    RGBColor        myrgb, savergb;
    GDHandle        oldGD;
    GWorldPtr       oldGW;
    GWorldPtr       myOffGWorld;
    PixMapHandle    myPixMapHandle;
    unsigned short  myRowBytes;
    char    mode;

    SetRect( &srcRect, 0, 0, 1, 256 );  
                                    /* Left, top, right, bottom. */
    if( NewGWorld( &myOffGWorld, 32, &srcRect, 0, 0, 0 ) == noErr)
        myPixMapHandle = GetGWorldPixMap( myOffGWorld );  
                                                     /* 7.0 only. */
/*      myPixMapHandle = myOffGWorld->portPixMap;     pre-7.0. */
        LockPixels( myPixMapHandle );

Next the code gets the base address of the pixels using the GetPixBaseAddr call. This call returns a base address that's good in 32-bit addressing mode, so the code saves the current mode and switches to 32-bit addressing mode. This is necessary to support accelerators that might keep the GWorld data cached on a card requiring 32-bit addressing. See "About 32- Bit Addressing" on the next page for more information.

/* Get baseAddr good in 32-bit mode. */
        bitsPtr = (long *) GetPixBaseAddr( myPixMapHandle );    
        myRowBytes = (**myPixMapHandle).rowBytes & 0x3fff;
        mode = true32b;     /* Switch to 32-bit mode. */

/* Go to 32-bit addressing mode to access pixels. */
        SwapMMUMode( &mode );

Then the code fills the GWorld with a gray ramp. Note that you cannot make other system calls after you switch the addressing mode, since system calls expect to be made in the addressing mode the machine was booted in.

        for( jjj = 256-1; jjj >= 0; jjj-- )
            *bitsPtr = jjj | (jjj<<8) | (jjj<<16);
            bitsPtr = (long *)((char *)bitsPtr + myRowBytes);

Next the code switches back to the prior addressing mode, sets the foreground color to red, and uses CopyBits to stretch the line to the size of the current port and colorize it to red. Finally, the foreground color is restored and the GWorld is disposed of.

/* Back to old addressing. */
        SwapMMUMode( &mode );
        GetForeColor( &savergb ); = 0xFFFF; = 0; = 0;
        RGBForeColor( &myrgb ); 
        CopyBits( *myPixMapHandle, &thePort->portBits, &srcRect,
            &thePort->portRect, srcCopy, 0 );
        RGBForeColor( &savergb );
        UnlockPixels( myPixMapHandle );
        DisposeGWorld( myOffGWorld );

In addition to doing RGB and CMY color separation, the following code expands the source picture by a factor of 1.5. When QuickDraw stretches an image, it simply replicates pixel values. Thus, if you scale an image up by a factor of 3 in both the horizontal and vertical dimensions, each pixel appears in nine places in the result. But if you scale an image by a factor of 1.5, only every other pixel is repeated, so source pixels do not contribute equally to the result.

Fortunately, this problem is easy to rectify. Since CopyBits averages when shrinking with the ditherCopy flag set, you can first scale the image up by a factor of 3 and then shrink it by a factor of 2. It's easiest to visualize this process by thinking of the horizontal and vertical dimensions independently. In the vertical direction, each source pixel is first expanded to three destination pixels. Then, when the image is shrunk by a factor of 2, CopyBits averages two scanlines to produce each pixel of the result. The outcome is that each source pixel contributes equally to the result.

The following code sample produces CMY color separations that are scaled by 1.5. The first section of code draws the picture into a GWorld three times the size of the picture's bounding box.

    Rect            dstRect;
    long            * bitsPtr;
    RGBColor        myrgb, savergb;
    GDHandle        oldGD;
    GWorldPtr       oldGW;
    GWorldPtr       myOffGWorld;
    PixMapHandle    myPixMapHandle;

    Rect            bounds;
    PicHandle       myPicHandle;

    #define         PICTResID   1000

    myPicHandle = GetPicture( PICTResID );
    if( !myPicHandle )
        return; /* Failed -> exit. */
    bounds = (*myPicHandle)->picFrame;
    /* Home the rect (top, left at 0, 0). */
    OffsetRect(&bounds, -bounds.left,; 
    dstRect = bounds;
    dstRect.right *=1.5;    
                     /* Final image = 1.5 times size of src image. */
    dstRect.bottom *=1.5;
    OffsetRect( &dstRect, 20, 20 );

    bounds.right *=3;   /* Expand by factor of 3. */
    bounds.bottom *=3;

    if( NewGWorld( &myOffGWorld, 32, &bounds, 0, 0, 0 ) == noErr)
        GetForeColor( &savergb );

        EraseRect( &bounds );       /* Clear the GWorld. */
        myPixMapHandle = GetGWorldPixMap( myOffGWorld );  
                                                       /* 7.0 only*/
/*      myPixMapHandle = myOffGWorld->portPixMap;     pre-7.0. */
        LockPixels( myPixMapHandle );
        DrawPicture( myPicHandle, &bounds );

The GWorld now contains the picture blown up three times in both directions. Next it's copied four times to the window to a dstRect 1.5 times the size of the original picture. The first three times, the GWorld is color-separated to yellow, magenta, and cyan; then the original image is drawn.

       SetGWorld(oldGW,oldGD);     /* Copy to window. */

/* Get the yellow component. */ = 0xFFFF; = 0xFFFF; = 0;
        RGBForeColor( &myrgb ); 
        CopyBits( *myPixMapHandle, &thePort->portBits, &bounds,
            &dstRect, ditherCopy + srcCopy, 0 );
        OffsetRect( &dstRect, 220, 0 );

/* Get the magenta component. */ = 0xFFFF; = 0; = 0xFFFF;
        RGBForeColor( &myrgb ); 
        CopyBits( *myPixMapHandle, &thePort->portBits, &bounds,
            &dstRect, ditherCopy + srcCopy, 0 );
        OffsetRect( &dstRect, -220, 220 );

/* Get the cyan component. */ = 0; = 0xFFFF; = 0xFFFF;
        RGBForeColor( &myrgb ); 
        CopyBits( *myPixMapHandle, &thePort->portBits, &bounds,
            &dstrect, ditherCopy + srcCopy, 0 );
        OffsetRect( &dstRect, 220, 0 );

/* Copy original image. */ = 0; = 0; = 0;
        RGBForeColor( &myrgb ); 
        CopyBits( *myPixMapHandle, &thePort->portBits, &bounds,
            &dstRect, ditherCopy + srcCopy, 0 );
        RGBForeColor( &savergb );
        UnlockPixels( myPixMapHandle );
        DisposeGWorld( myOffGWorld );

Getting the RGB components is similar. Simply replace the previous four CopyBits calls with the following:

/* Get the red component. */ = 0; = 0; = 0;
        RGBForeColor( &myrgb ); = 0xFFFF; = 0; = 0;
        RGBBackColor( &myrgb ); 
        CopyBits( *myPixMapHandle, &thePort->portBits, &bounds,
            &dstRect, ditherCopy + srcCopy, 0 );
        OffsetRect( &dstRect, 220, 0 );

/* Get the green component. */ = 0; = 0xFFFF; = 0;
        RGBBackColor( &myrgb ); 
        CopyBits( *myPixMapHandle, &thePort->portBits, &bounds,
            &dstRect, ditherCopy + srcCopy, 0 );
        OffsetRect( &dstRect, -220, 220 );

/* Get the blue component. */ = 0; = 0; = 0xFFFF;
        RGBBackColor( &myrgb ); 
        CopyBits( *myPixMapHandle, &thePort->portBits, &bounds,
            &dstRect, ditherCopy + srcCopy, 0 );
        OffsetRect( &dstRect, 220, 0 );

/* Original. */ = 0xffff; = 0xffff; = 0xffff;
        RGBBackColor( &myrgb ); 
        CopyBits( *myPixMapHandle, &thePort->portBits, &bounds,
            &dstRect, ditherCopy + srcCopy, 0 );

The result of these color separations is shown in Figure 9.

[IMAGE Othmer_text_html8.GIF]

Figure 9 CMY and RGB Color Separations Generated Using CopyBits


CopyBits is the workhorse at the core of QuickDraw's image-processing capabilities. As you've learned in this article, it's better than ever in System 7.0. CopyBits transfer operations now give higher-quality images and produce reliable results for all pixel depths and regardless of whether the destination device uses indexed or direct color. The GDevice's search procedure provides an easy way to alter colors. Color separations have become fairly easy to do. Can Hollywood-style special effects be far behind?



Custom drawing for specific screen depths. The DeviceLoop call lets applications do custom drawing for specific screen depths rather than having QuickDraw do the color translation. (If QuickDraw does the translation, a picture of a color wheel may turn out solid black when drawn on a black-and-white screen.) With DeviceLoop, you pass a drawing region, flags, and a pointer to a callback procedure that DeviceLoop will call for each different device that intersects the drawing region.

Picture Utilities. The Picture Utilities package ('PACK' 15) provides an easy way to profile the contents of a picture. It can tell you which fonts are used inside a picture so you can warn the user if one of the fonts is not available. It can also calculate the optimal color table or palette (using a predefined color pick method, or you can write your own) for displaying the picture.

Any bit depth for a mask. Before System 7.0, CopyMask's mask parameter could be only 1 bit deep. This caused the mask to be used very much like a region, selecting whether or not to copy a specific source pixel. In 7.0, the mask can be any bit depth. It specifies a blending value for merging the source and destination: black selects the source, white selects the destination, and gray provides a blend between the source and destination. Color masks can be used to blend only specific color components.

New version of the CopyMask call. The new CopyDeepMask call is an extension of CopyMask that includes a mode parameter and a region parameter. CopyDeepMask enables a blend of the source and destination to be applied to the destination using any transfer mode (not just srcCopy). Like previous versions of CopyMask, CopyMask and CopyDeepMask calls are not saved in pictures and do not print in System 7.0. (The resulting image can be printed, of course!) This may change in a future version.


New calls. The calls RGBForeColor, RGBBackColor, GetForeColor, GetBackColor, and QDError are now available in B&W QuickDraw.

Font names in pictures. Font names, rather than just font IDs (which may be different on different machines), are recorded into pictures, as in 32-Bit QuickDraw v. 1.2.

Custom drawing for specific screen depths. The DeviceLoop call, as described for Color QuickDraw, exists on all 7.0 machines, but because B&W QuickDraw supports only one screen device, the call is trivial.

Native resolution. OpenCPicture enables you to specify a picture's native resolution. This makes it easy to create pictures with resolutions other than 72 dpi. This feature was first available in 32-Bit QuickDraw v. 1.2.

Picture Utilities. See description for Color QuickDraw. In B&W QuickDraw, the Picture Utilities will not return a palette when you request color information.

Version 2 pictures. B&W QuickDraw previously could display version 2 pictures created on color machines, but could create only version 1 pictures. In 7.0, pictures created with OpenCPicture are version 2.Display of 16- and 32-bit PICTs. Before System 7.0, B&W QuickDraw could display only PICTs containing indexed pixMap data; in 7.0, it can display pictures containing direct-color data.

1-bit GWorlds. In 7.0, 1-bit GWorlds are available in B&W QuickDraw. You must access the data with GetGWorldPixMap. You cannot dereference the GWorldPtr directly. On black-and-white machines, GetGWorldPixMap returns a handle to an extended bitmap (only 1 bit is supported), rather than a pixMap. You can then call GetPixBaseAddr to access the pixels.


If your application needs to directly access the memory in a GWorld, you need to know some things about 32-bit addressing.

A tour through slot space. Slot space, and thus video memory, is at the top of the memory map, as shown in Figure 8, and sometimes requires 32-bit addressing.

In 24-bit mode, slot space ranges from $900000 to $EFFFFF, with 1 MB per slot ($s00000 to $sFFFFF where s = slot number $9 to $E). In 32-bit mode, slot space ranges from $F9000000 to $FEFFFFFF, with 16 MB per slot ($Fs000000 to $FsFFFFFF where s = $9 to $E). Super slot space, accessible only in 32-bit mode, ranges from $90000000 to $EFFFFFFF, with 256 MB per slot ($s0000000 to $sFFFFFFF where s = $9 to $E).

QuickDraw versions before 32-bit QuickDraw always use 24-bit slot space. But 24-bit slot space doesn't permit access to more than 1 MB of video memory, easily outgrown with 32-bit-per-pixel displays. Thus, video cards with more than 1 MB of video memory must be addressed in 32-bit mode. 32-Bit QuickDraw always accesses the screen in 32-bit mode, using either the 32-bit slot space or the super slot space baseAddr as given by the video ROM.

Let's look at some examples of how cards use slot space if 32-Bit QuickDraw is running:

  • The original Macintosh High-Resolution Video Card uses 24-bit slot space, with a baseAddr of $Fss00000. In 24-bit mode, the stripped address is $s00000, which maps to slot s in 24-bit slot space. That address also works with 32-Bit QuickDraw because if it's used in 32-bit mode, it happens to map to 32-bit slot space as well.
  • The 8*24 card uses $Fs000000 (32-bit slot space) with 32-Bit QuickDraw and $Fss00000 (24-bit slot space) with earlier versions. The 8*24 GC card uses $s0000000 (super slot space!) with 32-Bit QuickDraw and $Fss00000 with earlier versions.

32-Bit QuickDraw correctly handles pixMaps it creates--that is, pixMaps belonging to GDevices in the DeviceList and to GWorlds. However, if you create your own pixMap with your own baseAddr, the address is assumed to be good in 24-bit mode. If you pass QuickDraw a 32-bit base address, you must explicitly indicate that the address is 32-bit by setting bit 2 of the pixMap's pmVersion field.

The plot thickens. The issue of 24-bit versus 32-bit addressing becomes important when you use the GWorld calls to create a GWorld and then access the GWorld's pixels directly. To get the baseAddr of such a pixMap, you should call GetPixBaseAddr. This call returns a baseAddr that's good for certain cards only in 32-bit mode. Thus, you should always assume that the address is 32-bit and that you have to call SwapMMUMode.

If you forget to switch to 32-bit mode by calling SwapMMUMode, you've got problems. But the bug will not appear until you use an 8*24 GC card with a 2 MB DRAM upgrade kit or any other card that implements GWorlds. Thus, to access the data at the address returned by GetPixBaseAddr you must switch to 32-bit mode with SwapMMUMode, call StripAddress on any handle that you dereference, and switch back to the original mode when you've finished accessing the pixels. Example 1 in this article shows how to correctly access a GWorld's pixels. Note that you can't make any other system calls after you've switched from 24- to 32-bit mode, since calls expect to be made in whatever mode the Macintosh was started up in.

The upshot. To access the pixels of an off-screen GWorld in System 7.0, call GetPixBaseAddr and switch to 32-bit mode. And test your application with an accelerator card that implements GWorlds. If you don't want your GWorlds to go out on a card, you can set the keepLocal flag in NewGWorld--but then you won't get the benefits of graphics acceleration.

[IMAGE Othmer_text_html7.GIF]

Figure 8Macintosh II Memory Map in 24-Bit and 32-Bit Mode



As you know, when pixel data is included in a PICT, the data is usually packed. Pixel maps that are 8 or fewer bits deep pack fairly well using straight run-length encoding of bytes (that is, the PackBits routine), but compressing direct pixels using run-length encoding doesn't work very well. Here's what QuickDraw does with direct pixels in PICTs:

If the packType field contains 1, no compression is done at all. The complete pixel image is saved in the PICT. If the packType field contains 2 and the pixel map is 32 bits per pixel, all that's done is that the alpha channel byte is removed. So this


is compressed to this


If the packType field contains 3 and the pixel map is 16 bits per pixel, run-length encoding is done, but not through PackBits. Instead, a run-length encoding algorithm private to QuickDraw is used. This algorithm is very similar to PackBits, but where PackBits compresses runs of bytes, this routine compresses runs of words. The format of the resulting data is exactly the same as described in Technical Note #171, Things You Wanted to Know About _PackBits, but you'll get words instead. For example, let's say the 16-bit pixel image begins with these pixel values:


After being packed by QuickDraw's internal compression routine, this becomes

FEAA AA01 0000 2A2A FDAA AA03 F0F0 0101
*      *            *      *

where the asterisks mark the flag counter bytes. Notice that you can't assume the pixel values are word-aligned. PackBits packs data 127 bytes at a time, for up to 32,767 total bytes; similarly, the internal compression routine packs data 127 words at a time.

If the packType field contains 4 and the pixel map is 32 bits per pixel, run-length encoding via PackBits is done, but only after some preprocessing. QuickDraw first rearranges the color components of the pixels so that each color component of every pixel is consecutive. So the following three pixels

00 FF FF FF 00 FF C0 00 00 FF 80 00
a0 r0 g0 b0 a1 r1 g1 b1 a2 r2 g2 b2
are rearranged to become

FF FF FF FF C0 80 FF 00 00
r0 r1 r2 g0 g1 g2 b0 b1 b2

In the row below the pixel values a = alpha channel, r = red, g = green, b = blue, and the number is the pixel offset. The first three bytes are the red components of the three pixels, the next three bytes indicate the green components of the three pixels, and so on. The alpha channel isn't included unless the cmpCount field contains 4 rather than the normal 3. If cmpCount contains 4, all the alpha channel bytes are placed before the red bytes. Once this is done, PackBits is called to compress the rearranged data.

These are the only four compression schemes (including no compression) that are supported for direct pixel maps in PICTs. As always, reading PICTs yourself puts you in danger of not being able to read PICTs generated by future versions of QuickDraw. However, for compatibility reasons, these compression algorithms as described here probably won't change in the future. It's possible that new values for packType could be implemented, though.

KONSTANTIN OTHMER is a wild man. He whips out books,develop articles, and ski vacations in less time than it takes most of us to find our keys. We're not sure what position he plays on the soccer field--maybe it's "guy with the ball." He is, however, a team player. He works on QuickDraw in the system software group and helps people out all over the place. The kind of music he likes is from famous bands you haven't yet heard of. The baby picture here is just a trade show disguise; if you want a hint about what Konstantin really looks like, check out the Berlin Wall illustration in this article--if you look carefully you'll find him and Bruce Leak peeking out at you. *

FOR MORE INFORMATION The usual sources (Inside Macintosh, Tech Notes) will soon be augmented by a new QuickDraw book by David Surovell, Frederick Hall, and Konstantin Othmer in the Macintosh Inside Out series from Addison-Wesley. Debugging Macintosh Software With Macsbug by Konstantin Othmer and Jim Straus (Addison-Wesley, 1991) contains a great deal of information on debugging QuickDraw-related (as well as other) problems. *

Thanks to Our Technical ReviewersRich Biasi, Jean-Charles Mourey, Guillermo Ortiz, Forrest Tanaka *


Community Search:
MacTech Search:

Software Updates via MacUpdate

FotoMagico 6.2.2 - Powerful slideshow cr...
FotoMagico lets you create professional slideshows from your photos and music with just a few, simple mouse clicks. It sports a very clean and intuitive yet powerful user interface. High image... Read more
Default Folder X 5.7 - Enhances Open and...
Default Folder X attaches a toolbar to the right side of the Open and Save dialogs in any OS X-native application. The toolbar gives you fast access to various folders and commands. You just click on... Read more
f.lux 42.1 - Adjusts the color of your d...
f.lux makes the color of your computer's display adapt to the time of day, warm at night and like sunlight during the day. Ever notice how people texting at night have that eerie blue glow? Or wake... Read more
Spotify - Stream music, creat...
Spotify is a streaming music service that gives you on-demand access to millions of songs. Whether you like driving rock, silky R&B, or grandiose classical music, Spotify's massive catalogue puts... Read more
Vitamin-R 4.15 - Personal productivity t...
Vitamin-R creates the optimal conditions for your brain to work at its best by structuring your work into short bursts of distraction-free, highly focused activity alternating with opportunities for... Read more
OfficeTime 2.0.628 - Easy time and expen...
OfficeTime is time and expense tracking that is easy, elegant and focused. Other time keepers are clumsy or oversimplified. OfficeTime balances features and ease of use, allowing you to easily track... Read more
Slack 4.28.182 - Collaborative communica...
Slack brings team communication and collaboration into one place so you can get more work done, whether you belong to a large enterprise or a small business. Check off your to-do list and move your... Read more
DEVONthink Pro 3.8.6 - Knowledge base, i...
DEVONthink is DEVONtechnologies' document and information management solution. It supports a large variety of file formats and stores them in a database enhanced by artificial intelligence (AI). Many... Read more
FileMaker Pro 19.5.4 - Quickly build cus...
FileMaker Pro is the tool you use to create a custom app. You also use FileMaker Pro to access your app on a computer. Start by importing data from a spreadsheet or using a built-in Starter app to... Read more
Backblaze - Online backup serv...
Backblaze is an online backup service designed from the ground-up for the Mac. With unlimited storage available for $6 per month, as well as a free 15-day trial, peace of mind is within reach with... Read more

Latest Forum Discussions

See All

SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for September 26th, 2022. In today’s article, we kick off the week with a bang. And by “bang", I mean four reviews. Family Man, Radiant Silvergun, The Legend of Heroes: Trails from Zero... | Read more »
‘Romancing SaGa: Minstrel Song Remastere...
Following its showing at TGS 2022, Square Enix has released a new gameplay trailer for the previously announced remaster of the PS2 remake of the Super Famicom original (yes) Romancing SaGa game, Romancing SaGa: Minstrel Song Remastered. | Read more »
Gamabilis reveal release date for realis...
Realistic Sims are very fun experiences and give gamers an excellent chance to experience other walks of life, and Gamabilis has released its hyper-real farm management game Roots of Tomorrow. Whilst the more arcade-type games like Stardew Valley... | Read more »
Best iPhone Game Updates: ‘Streets of Ra...
Hello everyone, and welcome to the week! It’s time once again for our look back at the noteworthy updates of the last seven days. We’ve got a nice mix of Apple Arcade, free-to-play, and even a proper paid game. We don’t see those often! So yes, a... | Read more »
The House of Da Vinci 3 launches on Andr...
Following its earlier release on iOS this year, The House of Da Vinci 3 has also officially launched on Android devices. Blue Brain Games' 3D puzzle adventure boasts an average rating of 4.9/5 and will give players the much-awaited conclusion to... | Read more »
‘Oxenfree: Netflix Edition’ Is Out Now o...
Over the weekend, Netflix and Nightschool Studio announced and released Oxenfree: Netflix Edition (Free) worldwide on iOS and Android. This new version of Oxenfree: Netflix Edition is a separate release, and the prior version that I own, is no... | Read more »
‘Genshin Impact’ Version 3.1 Update Pre-...
Genshin Impact (Free) version 3.1 ‘King Deshret and the Three Magi’ goes live in a few days across iOS, Android, PC, PS5, and PS4. As with prior updates, pre-installation for the upcate has just gone live a few days before release. | Read more »
We’re Digging ‘Shovel Knight Dig’ – The...
We spend the bulk of this week’s podcast talking about the new iPhone 14. Specifically, the iPhone 14 Pro Max which both Eli and myself picked up. The consensus seems to be: They’re great! They’re iPhones! We do lay down our hot takes on all the new... | Read more »
TouchArcade Game of the Week: ‘Loose Noz...
There aren’t a lot of stories like that of the development of Loose Nozzles, and of those games that do have an interesting development story, even fewer are actually decent games to play. Loose Nozzles nails both, though. The way it was created is... | Read more »
SwitchArcade Round-Up: ‘Shovel Knight Di...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for September 23rd, 2022. In today’s article, we’ve got the rest of this week’s releases to look at. There are actually a few big games today, including the hot-hot-hot Shovel Knight Dig... | Read more »

Price Scanner via

13-inch Apple MacBook Airs with M2 processors...
Amazon has 13″ MacBook Airs with M2 CPUs in stock today and on sale for $1099. Shipping is free. Their prices are $100 off Apple’s MSRP, and they are the lowest prices available for M2-powered Macs... Read more
AR Glasses That Work With Apple’s Hardware? T...
NEWS – Lenovo has created quite the spectacle(s) with its latest product. “Apple Glass” — the purported name of Apple’s forthcoming AR glasses — is not expected to be released until 2025 (at the... Read more
New today at Apple: 13-inch M2 MacBook Pros f...
Apple 13″ MacBook Pros with M2 CPUs in stock and available today starting at $1169, Certified Refurbished, and ranging up to $150 off original MSRP. These are the cheapest 13″ M2 MacBook Pros for... Read more
Sunday Sale: 13″ Apple M1 MacBook Air availab...
Amazon has Space Gray Apple 13″ M1 MacBook Airs on sale for $690.95 for an extremely limited time. Other models are on sale for $849. Their price for the Space Gray model is the cheapest we’ve ever... Read more
Use our exclusive Apple Price Trackers to fin...
Our Apple award-winning price trackers are the best place to look for the lowest prices and latest sales on all the latest Apple gear this season. Scan our price trackers for the latest information... Read more
New promo at Verizon: Get Apple Watch Series...
Purchase a new iPhone 14 at Verizon, and get an Apple Watch Series 8 for as low as $5 per month. $120 in promo credits for the Watch are spread over a 36 month term, reducing the price of the Watch... Read more
Visible drops prices on Apple iPhone 13 model...
Verizon’s low-cost wireless cell service, Visible has dropped prices on iPhone 13 models to new low prices starting at $599: – iPhone 13 Pro Max: starting at $980 + free $200 gift card – iPhone 13... Read more
Back in stock! 14″ MacBook Pros with Apple M1...
Amazon has restocked 14″ MacBook Pros M1 Pro CPUs for $400 off MSRP, starting at only $1599. Shipping is free. Be sure to make your purchase from Amazon rather than a third-party seller. Their prices... Read more
This is the final week to take advantage of A...
Apple’s Back to School promotion for 2022 ends on September 26, 2022. As part of this promotion, Apple will include a free $150 Apple Gift Card with the purchase of any MacBook Air, MacBook Pro, or... Read more
Mac Studio with M1 Max CPU back in stock toda...
Apple has the base standard-configuration Mac Studio available again in their Certified Refurbished section for $1799, and it’s in stock today. Each Mac Studio comes with Apple’s one-year warranty,... Read more

Jobs Board

Physician Assistant, Primary Care, *Apple*...
Physician Assistant, Primary Care, Apple Valley (1.07FTE) + Job ID: 65766 + Department: AV Primary Care + City: Apple Valley, MN + Location: HP - Apple Read more
Operations Manager - Mac/ *Apple* Engineerin...
…Responsible for the day-to-day activities relating to the engineering of Apple Macs in a complex, multi-platform environment. Demonstrates strong leadership, Read more
Lead Developer - *Apple* tvOS - Rumble (Uni...
…earnings, and positive sentiment About the role: We are looking for a Lead Apple tvOS Developer to join our application engineering team to expand our video centric Read more
Systems Administrator - *Apple* Devices / J...
…Administration **Duties and Responsibilities** + Configure and maintain the client's Apple Device Management (ADM) solution. The current solution is JAMF supporting Read more
Sr Product Manager, *Apple* TV Platforms -...
…an experienced senior product manager to drive the strategy and requirements for our Apple TV devices, acting as the champion and owner of the holistic experience in Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.