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
$105.22
Apple Inc.
+0.39
MSFT
$46.13
Microsoft Corpora
+1.11
GOOG
$539.78
Google Inc.
-4.20

MacTech Search:
Community Search:

Software Updates via MacUpdate

Tonality Pro 1.1.2 - Professional-grade...
Tonality Pro gives you the power to create stunning and dramatic black & white images. This is a complete monochrome image editor with more than 150 one-click style presets, totally unique... Read more
VueScan 9.4.49 - 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
OS X Server 4.0 - For OS X 10.10 Yosemit...
Designed for OS X and iOS devices, OS X Server makes it easy to share files, schedule meetings, synchronize contacts, develop software, host your own website, publish wikis, configure Mac, iPhone,... Read more
TotalFinder 1.6.12 - Adds tabs, hotkeys,...
TotalFinder is a universally acclaimed navigational companion for your Mac. Enhance your Mac's Finder with features so smart and convenient, you won't believe you ever lived without them. Tab-based... Read more
BusyCal 2.6.3 - Powerful calendar app wi...
BusyCal is an award-winning desktop calendar that combines personal productivity features for individuals with powerful calendar sharing capabilities for families and workgroups. BusyCal's unique... Read more
calibre 2.7 - Complete e-library managem...
Calibre is a complete e-book library manager. Organize your collection, convert your books to multiple formats, and sync with all of your devices. Let Calibre be your multi-tasking digital... Read more
Skitch 2.7.3 - Take screenshots, annotat...
With Skitch, taking, annotating, and sharing screenshots or images is as fun as it is simple.Communicate and collaborate with images using Skitch and its intuitive, engaging drawing and annotating... Read more
Delicious Library 3.3.2 - Import, browse...
Delicious Library allows you to import, browse, and share all your books, movies, music, and video games with Delicious Library. Run your very own library from your home or office using our... Read more
Art Text 2.4.8 - Create high quality hea...
Art Text is an OS X application for creating high quality textual graphics, headings, logos, icons, Web site elements, and buttons. Thanks to multi-layer support, creating complex graphics is no... Read more
Live Interior 3D Pro 2.9.6 - Powerful an...
Live Interior 3D Pro is a powerful yet very intuitive interior designing application. View Video Tutorials It has every feature of Live Interior 3D Standard, plus some exclusive ones: Create multi... Read more

Latest Forum Discussions

See All

Rami Ismail Opens Up distribute​() for D...
Rami Ismail Opens Up distribute​() for Developers Posted by Jessica Fisher on October 24th, 2014 [ permalink ] Rami Ismail, Chief Executive of Business and Development at indie game studio | Read more »
Great Hitman GO Goes on Sale and Gets Ne...
Great Hitman GO Goes on Sale and Gets New Update – Say That Three Times Fast Posted by Jessica Fisher on October 24th, 2014 [ permalink ] | Read more »
Rival Stars Basketball Review
Rival Stars Basketball Review By Jennifer Allen on October 24th, 2014 Our Rating: :: RESTRICTIVE BUT FUNUniversal App - Designed for iPhone and iPad Rival Stars Basketball is a fun mixture of basketball and card collecting but its... | Read more »
Rubicon Development Makes Over a Dozen o...
Rubicon Development Makes Over a Dozen of Their Games Free For This Weekend Only Posted by Jessica Fisher on October 24th, 2014 [ permalink ] | Read more »
I Am Dolphin Review
I Am Dolphin Review By Jennifer Allen on October 24th, 2014 Our Rating: :: NEARLY FIN-TASTICUniversal App - Designed for iPhone and iPad Swim around and eat nearly everything that moves in I Am Dolphin, a fun Ecco-ish kind of game... | Read more »
nPlayer looks to be the ultimate choice...
Developed by Newin Inc, nPlayer may seem like your standard video player – but is aiming to be the best in its field by providing high quality video play performance and support for a huge number of video formats and codecs. User reviews include... | Read more »
Fighting Fantasy: Caverns of the Snow Wi...
Fighting Fantasy: Caverns of the Snow Witch Review By Jennifer Allen on October 24th, 2014 Our Rating: :: CLASSY STORYTELLINGUniversal App - Designed for iPhone and iPad Fighting Fantasy: Caverns of the Snow Witch is a sterling... | Read more »
A Few Days Left (Games)
A Few Days Left 1.01 Device: iOS Universal Category: Games Price: $3.99, Version: 1.01 (iTunes) Description: Screenshots are in compliance to App Store's 4+ age rating! Please see App Preview for real game play! **Important: Make... | Read more »
Toca Boo (Education)
Toca Boo 1.0.2 Device: iOS Universal Category: Education Price: $2.99, Version: 1.0.2 (iTunes) Description: BOO! Did I scare you!? My name is Bonnie and my family loves to spook! Do you want to scare them back? Follow me and I'll... | Read more »
Intuon (Games)
Intuon 1.1 Device: iOS Universal Category: Games Price: $.99, Version: 1.1 (iTunes) Description: Join the battle with your intuition in a new hardcore game Intuon! How well do you trust your intuition? Can you find a needle in a... | Read more »

Price Scanner via MacPrices.net

Weekend sale: 13-inch 128GB MacBook Air for $...
Best Buy has the 2014 13-inch 1.4GHz 128GB MacBook Air on sale for $849.99, or $150 off MSRP, on their online store. Choose free home shipping or free local store pickup (if available). Price valid... Read more
Nimbus Note Cross=Platform Notes Utility
Nimbus Note will make sure you never forget or lose your valuable data again. Create and edit notes, save web pages, screenshots and any other type of data – and share it all with your friends and... Read more
NewerTech’s Snuglet Makes MagSafe 2 Power Con...
NewerTech has introduced the Snuglet, a precision-manufactured ring designed to sit inside your MagSafe 2 connector port, providing a more snug fit to prevent your power cable from unintentional... Read more
Apple Planning To Sacrifice Gross Margins To...
Digitimes Research’s Jim Hsiao says its analysts believe Apple is planning to sacrifice its gross margins to save its tablet business, which has recently fallen into decline. They project that Apple’... Read more
Who’s On Now? – First Instant-Connect Search...
It’s nighttime and your car has broken down on the side of the highway. You need a tow truck right away, so you open an app on your iPhone, search for the closest tow truck and send an instant... Read more
13-inch 2.5GHz MacBook Pro on sale for $949,...
Best Buy has the 13″ 2.5GHz MacBook Pro available for $949.99 on their online store. Choose free shipping or free instant local store pickup (if available). Their price is $150 off MSRP. Price is... Read more
Save up to $125 on Retina MacBook Pros
B&H Photo has the new 2014 13″ and 15″ Retina MacBook Pros on sale for up to $125 off MSRP. Shipping is free, and B&H charges NY sales tax only. They’ll also include free copies of Parallels... Read more
Apple refurbished Time Capsules available sta...
The Apple Store has certified refurbished Time Capsules available for up to $60 off MSRP. Apple’s one-year warranty is included with each Time Capsule, and shipping is free: - 2TB Time Capsule: $255... Read more
Textilus New Word, Notes and PDF Processor fo...
Textilus is new word-crunching, notes, and PDF processor designed exclusively for the iPad. I haven’t had time to thoroughly check it out yet, but it looks great and early reviews are positive.... Read more
WD My Passport Pro Bus-Powered Thunderbolt RA...
WD’s My Passport Pro RAID solution is powered by an integrated Thunderbolt cable for true portability and speeds as high as 233 MB/s. HighlightsOverviewSpecifications Transfer, Back Up And Edit In... Read more

Jobs Board

*Apple* Solutions Consultant - Apple Inc. (U...
…important role that the ASC serves is that of providing an excellent Apple Customer Experience. Responsibilities include: * Promoting Apple products and solutions 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
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.