TweetFollow Us on Twitter

June 93 - GRAPHICAL TRUFFLES

GRAPHICAL TRUFFLES

FOUR COMMON GRAPHICS ANSWERS

BILL GUSCHWAN

[IMAGE 054-057_Graphics_col._re1.GIF]

QuickDraw regions were almost lost when Bill Atkinson crashed his car and nearly killed himself. Considering that Steve Wozniak also crashed his airplane, crashing must be a hallmark of Apple genius. I'm no Macintosh wizard, though I did crash my car once. To aid and abet other non- wizards, I'll divulge four cool answers that apply to nearly any QuickDraw question:

  • Check the graphics state.
  • Check the QuickDraw version.
  • Do it off-screen.
  • Use the bottlenecks.

They may not answer your questions completely, but they'll probably get you partway there.

CHECK THE GRAPHICS STATE
Whenever you call a QuickDraw routine, its behavior depends heavily on the state of the machine at the time of the call: things like the pen size, transfer mode, and color environment all affect the drawing. Most of the state information QuickDraw depends on can be found in two handy locations -- the current grafPort and the current GDevice.

The grafPort maintains state information for the pen, the text, and the bitmap (or pixel map) to draw into. The GDevice defines the color environment, among other things. This information is accessed by many QuickDraw routines. For example, the LineTo routine draws a line from the current pen location to the point you pass to the routine, using the current pen size, pattern, and transfer mode; all these values are fields of the current grafPort. Because most QuickDraw routines use these "implied" parameters, you can't fully understand the behavior of a QuickDraw routine without knowing about them.

The current grafPort also defines where your drawing will occur. Even though you call a routine, it may not draw, because QuickDraw applies a rectangle -- the portRect -- and two regions -- the visRgn and clipRgn -- to your drawing. No drawing will occur outside the intersection of these areas. QuickDraw places control of the clipRgn in your hands, first initializing it to be wide open (a rectangular region that covers the entire QuickDraw coordinate space). If your grafPort is in a window, control of the visRgn is placed in the hands of the Window Manager. (A region is a truly marvelous concept, a compact description of strange shapes that can be extended and changed dynamically. It's a good thing Bill Atkinson survived his crash.)

Let's try applying this first answer to a common QuickDraw question: Why can't you nest calls to OpenPicture? Well, as you may know, when you call OpenPicture to begin saving picture data, a handle is created to store the picture information until the corresponding ClosePicture call. This handle is kept in the picSave field of the current grafPort. If you nest a second OpenPicture call, where in the grafPort will you store the newly created handle? Answer: There is no place, so you can't nest OpenPicture calls. Because so many other Managers rely on QuickDraw, this answer will help with questions about other Managers as a bonus.

CHECK THE QUICKDRAW VERSION
There are currently seven versions of QuickDraw.
You can find out which version is available using Gestalt, and that's usually the most important thing for your code to know about. But many developers also want to know which machine and system software combinations produce which versions of QuickDraw. For example, some developers code for 32-Bit QuickDraw and want to inform their users of the minimum Macintosh machine requirement. The ROM version, extensions, and system software all combine to affect which version of QuickDraw is available.

ROM versions of QuickDraw can be neatly categorized into three classes of machines: black and white, Color QuickDraw, and "ci class." The original Macintosh and the Macintosh 512K, Plus, Portable, SE, and PowerBook 100 are examples of the black-and-white class. The Macintosh II, IIx, IIcx, and SE/30 fall into the Color QuickDraw (256K ROM) class. The Macintosh IIci, IIsi, LC II, IIfx, and later models belong to the ci class (>256K ROM).

Black-and-white class. There are only two common versions of QuickDraw on black-and-white machines today: original black-and-white QuickDraw and System 7 black-and-white QuickDraw. (The uncommon ones are present only with pre-Macintosh Plus ROMs or system versions earlier than 4.2.) When System 7 is installed on a machine of this class, it installs some new routines so that a few Color QuickDraw routines can be used (you get 1-bit GWorlds, you can correctly display pictures containing direct-color information, you can create version 2 pictures, and so on).

Black-and-white QuickDraw is documented inInside MacintoshVolumes I and IV. For a comprehensive list of the routines that System 7 adds to black-and-white QuickDraw, see "QuickDraw's CopyBits Procedure: Better Than Ever in System 7.0" in develop Issue 6.

Color QuickDraw class. This class of machines has 8-bit Color QuickDraw built into ROM, so it will always be there regardless of the system version. When these machines are running system versions earlier than System 7, they can be extended to handle direct color through the use of the 32-Bit QuickDraw INIT. Finally, if they're running System 7, System 7 Color QuickDraw is available.

Inside MacintoshVolume V describes 8-bit Color QuickDraw. For documentation on the various 32- Bit QuickDraw versions, including System 7 Color QuickDraw, the best place to look is Inside Macintosh Volume VI. If you really need to know the differences in capabilities among the versions, 32-Bit QuickDraw v. 1.0 is covered in "Realistic Color for Real-World Applications" in develop Issue 1, and the features added in 32-Bit QuickDraw v. 1.2 are documented in the Tech Note "32-Bit QuickDraw: Version 1.2 Features."

ci class. This class of machines has only three possible QuickDraw versions. The least common version, 32-Bit QuickDraw v. 1.01, is found on a IIci running system software version 6.0.4. The other machines in this class that can run System 6 need at least version 6.0.5, which will patch in 32- Bit QuickDraw v. 1.2. Finally, System 7 provides its own version of Color QuickDraw.

Again, for documentation on the various 32-Bit QuickDraw versions, including System 7 Color QuickDraw, seeInside MacintoshVolume VI.

In the GestaltEqu.h header file, you'll find Gestalt values for six QuickDraw versions:

gestaltOriginalQD =0x000,// 1-bit QD
gestalt8BitQD =  0x100,// 8-bit color QD
gestalt32BitQD = 0x200,// 32-bit v1.0
gestalt32BitQD11 =0x210,// 32-bit v1.1
gestalt32BitQD12 =0x220,// 32-bit v1.2
gestalt32BitQD13 =0x230,// 32-bit v1.3

One of these -- gestalt32BitQD11 -- will never be returned, so this list accounts for only five of the total of seven versions. The sixth is 32-Bit QuickDraw v. 1.01, mentioned above, which returns the Gestalt value 0x201 but doesn't have a gestalt constant defined for it. The seventh is System 7 with a black-and-white machine: You'll need to check for both black-and-white QuickDraw (gestaltOriginalQD) and System 7 (gestaltSystemVersion greater than or equal to $0700). If both are true, you're running System 7 black-and-white QuickDraw. That's the only way to tell.

Table 1 shows all the possible combinations, in one handy location.

Table 1Possible Combinations of ROM Versions and System Software Versions

ROM ClassSystem VersionGestalt Value
Black-and-white classPre-7.0gestaltOriginalQD
7.0 and latergestaltOriginalQD and gestaltSystemVersion = $0700 or greater
Color QuickDraw classPre-7.0, no INITsgestalt8BitQD
6.0.3 or 6.0.4, andgestalt32BitQD
32-Bit QuickDraw INIT v. 1.0
System 6 from 6.0.5 on, andgestalt32BitQD12
32-Bit QuickDraw INIT v. 1.2
7.0 and latergestalt32BitQD13
ci class6.0.4gestalt32BitQD + 1
System 6 from 6.0.5 ongestalt32BitQD12
7.0 and latergestalt32BitQD13

Exactly which permutations you need to code for depends entirely on what you're doing, but typically the major divisions are color versus black-and-white, direct color versus indexed color, and GWorlds versus no GWorlds. Whenever possible, of course, you should make decisions in your code based on the QuickDraw version rather than on the specific machine configuration.

DO IT OFF-SCREEN
Off-screen environments give you explicit and total control over an image. Since the image and its associated data structures are no longer tied to a physical device, many of the complexities and limitations of QuickDraw are reduced, and your hands -- previously tied tightly behind your back -- are now freed. You'll typically manipulate your image off-screen and then use CopyBits to move the image to the screen. The FX snippet on this issue's CD provides a robust demonstration of some snazzy CopyBits effects, and there's a nice overview of how to perform animation using off-screen graphics environments in the Graphical Truffles column ("Animation at a Glance") in develop Issue 12.

Using CopyBits and off-screen environments for speed is covered eloquently in Konstantin Othmer and Mike Reed's article "Drawing in GWorlds for Speed and Versatility" in develop Issue 10, so I won't dwell on it here. Also, the Tech Note "Principia Offscreen Graphics Environments" gives details for creating off-screen environments on machines without 32-Bit QuickDraw (see the discussion above).

The point is this: when faced with a question in the "How do I . . ." category, try this answer on for size first. That may be as far as you need to go.

USE THE BOTTLENECKS
QuickDraw routines are easily customizable, which can be incredibly useful; however, this feature is typically underused. (In fact, most of the Macintosh is customizable. There ought to be a whole chapter in Inside Macintosh on customization; there are so many places in the OS that you can intercept, you could probably patch out the whole OS if you were so inclined.) You can replace QuickDraw's "guts" with viscera of your own design, completely (and reversibly) transforming QuickDraw's functionality.

Here's one example of how this can be useful: Let's say we want to find out the exact colors used in a picture that contains innumerable colors. We'll be drawing the picture to an 8-bit color monitor, and we want to manually select the best 256 colors, replacing the default color table that DrawPicture uses. There are two methods of getting the colors used in a PICT: use the System 7 Picture Utilities Package, or do it yourself. The Picture Utilities Package is available only in System 7, so if we want to run on earlier systems, our only choice is to do it ourselves. We do that by using the bottlenecks.

You can replace all the bottlenecks with no-ops except for a few carefully selected ones, then draw the picture. Your replacement bottlenecks will be able to watch all the picture data go by and can keep track, say, of the colors used in the picture. (Two sample programs on the CD, CollectPictColors and GMundo, demonstrate this technique.) So, for instance, to draw our many- colored picture with a custom-picked set of 256 colors, we actually have to draw the picture twice: the first time, we replace the bottlenecks, allowing us to use -- collect, extract, or read -- the colors in the picture. We can then set up the destination cGrafPort with the colors we want to show, restore the bottlenecks, and draw the picture again, this time to actually image it into the destination cGrafPort.

THAT'S IT FOR NOW When you're faced with a question about QuickDraw, try running through the answers in this column first, to see if any of them fit. Is the state of the machine at the time of the call different than you assumed? Did you check the QuickDraw features and version? Can you do it off-screen? Can you intercept processing at the bottleneck level to customize QuickDraw's routines? It's likely that one of these answers will help.

RELATED READING

  • "Graphical Truffles: Animation at a Glance" by Edgar Lee, develop Issue 12.
  • "Drawing in GWorlds for Speed and Versatility" by Konstantin Othmer and Mike Reed, develop Issue 10.
  • "QuickDraw's CopyBits Procedure: Better Than Ever in System 7.0" by Konstantin Othmer, develop Issue
  • "Realistic Color for Real-World Applications" by Bruce Leak, develop Issue 1.
  • Inside Macintosh Volume VI (Addison-Wesley, 1991), Chapter 17, "Color QuickDraw."
  • Inside Macintosh Volume V (Addison-Wesley, 1988), Chapter 4, "Color QuickDraw."
  • Inside Macintosh Volume IV (Addison-Wesley, 1986), Chapter 4, "QuickDraw."
  • Inside Macintosh Volume I (Addison-Wesley, 1985), Chapter 6, "QuickDraw."
  • Macintosh (Imaging) Technical Notes "Principia Offscreen Graphics Environments" (formerly #120) and "32-Bit QuickDraw: Version 1.2 Features" (formerly #275).

BILL GUSCHWAN (AppleLink ANGUS) asked Howard Roark to dialog with him: "So, Angus, you ditched med school to become a protector of the dogcow? I love you, man." Angus: "Well, Howard, as Tori Amos would say, 'Sometimes I hear my voice and it's been here silent all these years.'" Howard: "You know, I ditched architecture school, not unlike David Byrne. Speaking of Talking Heads, you got kicked out of one of his concerts because you wanted to dance." Angus: "Words are very unnecessary, they can only do harm, so I dance." Howard: "Even your idol Wittgenstein went back to school. What about you?" Angus: "As you know, Howard, even Atlas shrugged." *

Thanks to Edgar Lee, Konstantin Othmer, Brigham Stevens, Forrest Tanaka, and John Wang for reviewing this column. *

 
AAPL
$100.86
Apple Inc.
-0.77
MSFT
$46.76
Microsoft Corpora
+0.52
GOOG
$579.95
Google Inc.
+6.85

MacTech Search:
Community Search:

Software Updates via MacUpdate

Capture One Pro 8.0.0.433 - RAW workflow...
Capture One Pro 8 is a professional RAW converter offering you ultimate image quality with accurate colors and incredible detail from more than 300 high-end cameras -- straight out of the box. It... Read more
Adobe Acrobat Pro 11.0.09 - Powerful PDF...
Adobe Acrobat allows users to communicate and collaborate more effectively and securely. Unify a wide range of content in a single organized PDF Portfolio. Collaborate through electronic document... Read more
Adobe Reader 11.0.09 - View PDF document...
Adobe Reader allows users to view PDF documents. You may not know what a PDF file is, but you've probably come across one at some point. PDF files are used by companies and even the IRS to... Read more
iFFmpeg 4.6.1 - Convert multimedia files...
iFFmpeg is a graphical front-end for FFmpeg, a command-line tool used to convert multimedia files between formats. The command line instructions can be very hard to master/understand, so iFFmpeg does... Read more
NTFS 11.3.62 - Provides full read and wr...
Paragon NTFS breaks down the barriers between Windows and OS X. Paragon NTFS effectively solves the communication problems between the Mac system and NTFS, providing full read and write access to... Read more
OS X Yosemite 10.10 DP8 - Developer Prev...
Note: This is a Developer Preview. You must be a registered Apple Mac Developer to download this update. You can also sign up for the free OS X Beta Program to download and preview public beta... Read more
FotoMagico 4.5 - Powerful slideshow crea...
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
Screenshot Path 1.2.1 - Change the defau...
Screenshot Path lets you change the folder where OS X saves screenshots. Screenshots are saved by default to the user’s desktop. This is handy for the occasional screenshot but those looking to take... Read more
Fantastical 1.3.16 - Create calendar eve...
Fantastical is the Mac calendar you'll actually enjoy using. Creating an event with Fantastical is quick, easy, and fun: Open Fantastical with a single click or keystroke Type in your event details... Read more
GIMP 2.8.14 - Powerful, free image editi...
GIMP is a multi-platform photo manipulation tool. GIMP is an acronym for GNU Image Manipulation Program. The GIMP is suitable for a variety of image manipulation tasks, including photo retouching,... Read more

Latest Forum Discussions

See All

Zynga Unveils First Look at Looney Tunes...
Zynga Unveils First Look at Looney Tunes Dash! Posted by Ellis Spice on September 16th, 2014 [ permalink ] Be vewy, vewy qwiet. I’m hunting wunners featuwing wabbits, and luckily, it’s duck season wunner season. | Read more »
Guardians on the Go – How to Connect to...
At this point I’m relatively certain most of the country is familiar with Destiny. And for those looking to augment their game a bit, Bungie has changed their Bungie Mobile Companion App to Destiny Companion. | Read more »
Kunin Review
Kunin Review By Jordan Minor on September 16th, 2014 Our Rating: :: SHURIKEN DO ITUniversal App - Designed for iPhone and iPad Kunin is a nervous test of ninja reflexes.   Developer: Dodreams Price: FREE Version Reviewed: 1.0.1... | Read more »
4 KEMCO Titles are Just $0.99 for a Limi...
4 KEMCO Titles are Just $0.99 for a Limited Time Posted by Jessica Fisher on September 16th, 2014 [ permalink ] KEMCO RPGs Destiny Fantasia, Infinite Dunamis, Bonds of the Sk | Read more »
Introducing Flash, the Latest Wearable F...
Introducing Flash, the Latest Wearable Fitness Monitor from Misfit Posted by Jessica Fisher on September 16th, 2014 [ permalink ] The Misfit Flash is the newly-released fitness and sleep monitor from | Read more »
Hyper Trip Review
Hyper Trip Review By Jennifer Allen on September 16th, 2014 Our Rating: :: HYPER TWITCHYUniversal App - Designed for iPhone and iPad Tough and unforgiving, Hyper Trip is a bit like Snake – if Snake was really harsh.   | Read more »
Collectible Card Game Earthcore: Shatter...
Collectible Card Game Earthcore: Shattered Elements is Set to Arrive on iOS in 2015 Posted by Ellis Spice on September 16th, 2014 [ permalink ] Polish developers | Read more »
Boogey Boy Review
Boogey Boy Review By Jennifer Allen on September 16th, 2014 Our Rating: :: PRETTY BUT BASICUniversal App - Designed for iPhone and iPad It looks delightful but lack of Game Center support and more variety really affects the fun... | Read more »
Vizzywig 4K (Photography)
Vizzywig 4K 1.0 Device: iOS iPhone Category: Photography Price: $999.99, Version: 1.0 (iTunes) Description: REQUIRES: iOS 7 on iPhone 5S with 32GB or 64GB. (Do not use iOS 8)The world's FIRST mobile 4K video capture, editing and... | Read more »
The Sleeping Prince Review
The Sleeping Prince Review By Jennifer Allen on September 15th, 2014 Our Rating: :: RESTRICTIVE KINGDOM SAVINGUniversal App - Designed for iPhone and iPad The Sleeping Prince looks and feels great to play, but its lack of peril and... | Read more »

Price Scanner via MacPrices.net

Sprint offers 16GB iPad mini for $199.99 with...
Sprint is offering 1st generation 16GB iPad minis for $199.99 with a 2-year service agreement. Standard MSRP for this iPad is $429. Their price is the lowest available for this model. Read more
2.5GHz Mac mini remains on sale for $549, sav...
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
Apple refurbished iMacs available for up to $...
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
13″ 2.5GHz MacBook Pro offered for $100 off M...
B&H Photo has the 13″ 2.5GHz MacBook Pro on sale for $999.99 including free shipping plus NY sales tax only. Their price is $100 off MSRP. Read more
Free GIMP Professional Grade Graphics App Ver...
The latest 2.8.14 version of the oddly-named GIMP (acronym for: GNU Image Manipulation Program) open source, high-end image editing and creation alternative to Adobe’s Photoshop and refuge from... Read more
Apple Announces Record Pre-orders for iPhone...
Apple has released metrics showing a record number of first day pre-orders of iPhone 6 and iPhone 6 Plus, with over four million sold in the first 24 hours. Demand for the new iPhones exceeds the... Read more
10% off iPhone 6 and 6 Plus Otterbox cases
Get 10% off on popular Otterbox iPhone 6 and iPhone 6 Plus cases at MacMall through September 19th. Use code OTTERBOX10 to see the discount. Read more
15-inch MacBook Pros on sale for up to $125 o...
Amazon has the new 2014 15″ Retina MacBook Pros on sale for up to $125 off MSRP including free shipping: - 15″ 2.2GHz Retina MacBook Pro: $1899.99 save $100 - 15″ 2.5GHz Retina MacBook Pro: $2374... Read more
27-inch 3.2GHz iMac on sale for $1698, $101 o...
Abt has the 27″ 3.2GHz iMac on sale for $1698 including free shipping. Their price is $101 off MSRP. Read more
More To Making A Larger iPad Than Expanded Sc...
CNET’s Ross Rubin has posted a thoughtful analysis of prospects for a larger display iPad Pro, noting that Microsoft and Samsung currently have the large-display touchscreen tablet category to... 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
*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
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.