TweetFollow Us on Twitter

Volume Number:2
Issue Number:4
Column Tag:Toolbox Notes

On the nature of Pictures

By Chris Derossi, Chief Wizard, MacTutor Contributing Editor

A Quick Note on Pictures

This article has two puposes. The first is to more fully explain the information contained in Macintosh Technical Note #21; that is, the QuickDraw internal encoded picture format. The second bit of information concerns two problems which I have found relating to QuickDraw pictures.

To begin, let's go over the process of creating a picture. When you call OpenPicture, QuickDraw allocates a new handle, stores some initial data there, sets the picSave field for the current port, calls HidePen, and returns the new handle. The initial data consists of the length, rectangle, version, and clipping region of the picture.

When you then proceed to draw, calling QuickDraw with various artistic requests, QuickDraw notes that there is an open picture because of the valid picSave handle. Because of this, QuickDraw translates your request into its own picture shorthand, and appends this information to the picture data. The length information at the beginning of the picture data is increased to reflect the new data. Since HidePen had been called, none of this shows up on the screen. (Unless, of course, you have called ShowPen without a balancing call to HidePen.)

Finally, you call ClosePicture which calls ShowPen, places an end-of-picture marker in the picture data, and sets the picSave field to NIL.

Now, let's go through some picture data byte by byte. The first two bytes of information are the length, which represent the length of ALL of the data, including the length bytes themselves. Next are eight bytes (4 words/Integers) of rectangle information (top, left, bottom, right). This is the rectangle which was passed as the parameter to OpenPicture. Following this are the picture opcodes and their data.

A picture opcode is a single byte which tells QuickDraw to do something, or how to interpret some amount of additional data. The length and composition of the data following the opcode depends on the opcode itself. The first opcode in a picture is always $11 which represents "Version". This opcode has one byte of data which represents the version number. Whenever QuickDraw encounters $11, it knows to treat the next byte as the version number, and to skip over it to get to the next opcode. Opcodes and their data are packed together. That is, immediately following an opcode and its data is the next opcode.

After the version, there may be any number of QuickDraw opcodes. The last opcode in a picture is always $FF which stands for "End-of-Picture". Data after this opcode is ignored. (Under normal circumstances, there won't be any further data.)

If the picture was created in the usual manner (i.e. with OpenPicture instead of generating the picture data some other way) then the next opcode is $01 which is "ClipRgn". The data following this opcode is a region, the first word of which is the length of the region. Normally, it will look something like the data in Figure 1. When you call OpenPicture, the region is copied from the current port's clipping region.

Most of the opcodes are pretty straightforward. Some, however, could use a little explanation. Most of the verb-object calls have a corresponding verbSameobject call. The latter simply uses the last explicit data (be it a Rect, RRect, etc) from a prior call for its own argument. For example, if you wanted to do a paintRect (opcode $31) on a rectangle with coordinates (0, 0, 45, 45) and then invertRect the same rectangle, the resultant picture data would look like that in Figure 2.

Instead of passing the fill pattern as an argument each time as in the QuickDraw call, pictures use the concept of a 'current' fill pattern which the TechNote calls "thePat". (This is analagous to the current pen pattern.) To fill several Rects with the same pattern, there would be one opcode to set thePat ($0A), and then several fillRect opcodes and their respective rectangles. (Figure 3).

Because simple lines and text are so common, there are several versions of each so that QuickDraw can use the version that takes the least amount of space. Lines come in two sizes: regular and short. Short lines have vertical and horizontal lengths which can be represented by a single byte (-128 to 127). The horizontal and vertical lengths are then used instead of the line endpoint. Both line and short line (opcodes $20 and $22) also include the starting endpoint. The remaining two line opcodes ($21 and $23) start the line from the current pen location, which could have been set by previous line or text drawing.

If text is to be drawn only a short distance from the current pen location, QuickDraw uses opcodes $29, $2A, or $2B to move the pen horizontally, vertically, or both before drawing the text. If the starting location for the text is too distant to represent with single byte offsets, opcode $28 is used, and the actual point at which to draw the text is specified.

The last 'gotcha', and the first problem I'd like to discuss both concern the SetOrigin call, which is opcode $0C. This opcode takes four bytes (two words/Integers) as arguments. BUT, the two words do not represent the actual origin that you specified with the SetOrigin call; Instead, they are the offset from the current origin to the new one.

For example, if you were at origin (0,0) and you made a SetOrigin(15,10) call, the picture data would be $0C $00 $0F $00 $0A. More importantly, if you were in a situation where the origin was unknown, you might be inclined to call SetOrigin(0, 0) before performing any drawing. This can have some unexpected side effects. Consider the following scenario:

Your code does not know where the origin is, so it calls SetOrigin(0, 0). Let us say that the origin was in fact at (15, 10). QuickDraw would record an origin change of -15, -10 ($0C $FF $F1 $FF $F6). Then you do your drawing and close the picture.

Now, since you didn't make any more SetOrigin calls, you know that the origin is at (0, 0), which is where you want it to be. So you call DrawPicture. QuickDraw would then come across the $0C opcode and changes the origin to (-15, -10), and your drawing would be in the wrong place! The way to avoid this problem is to call SetOrigin before you open the picture, and again before you draw the picture.

The technique of changing picture origins has a use, for example, in printing, when you want to draw a very large picture. You can simply originate different areas of the picture over the 'printer paper' port and draw the picture. In this way, you can print your large picture on several pieces of paper. Moving pictures around is also a nice way to show different parts of a picture in response to a scroll bar; You only have to generate the display once, and just draw the picture with offsets based on the scroll bar values.

But a common occurrance while doing this is to have the picture vanish when it is drawn at any location other than the one where it was created. The reason for this is simple but elusive.

Recall that when you call OpenPicture, QuickDraw copies the clipping region of the port into the picture data. Well, a newly created port has a very large clipping region, specifically, a rectangle with coordinates (-32767, -32767, 32767, 32767). In hexadecimal, those coordinates translate to ($8001, $8001, $7FFF, $7FFF).

If you offset the picture rectangle just one pixel to the right, QuickDraw re-calculates all of the coordinates in the picture data, including those of the clipping region. But, if you add 1 to $8001, you get $8002 (which is -32766) and 1 + $7FFF is $8000 (decimal -32768). This leaves you with coordinates of (-32767, -32766, 32767, -32768) for the clipping rectangle. This is an empty rectangle because the right side is less than the left side. The whole picture gets clipped!

The solution to this problem is as easy as the solution to the last one: Set your clipping region before you open your picture. You can keep the clipping region very large, but stay away from the values that come close to hex $8000. Such is life with finite mathematics.

I hope this has helped to shed some light on your use of pictures. Used intelligently, they can save you from redrawing the same things again and again. As a side note, if you are interested in pictures and the LaserWriter, you should see TechNote #27: The MacDraw Picture Format.



Macintosh Technical Notes

#21: Quickdraw's Internal Picture Definition

See also: QuickDraw

Programming in Assembly Language

Written by: Ginger Jernigan April 24, 1985


This technote describes the internal format of the QuickDraw picture data structure.


This technote describes the long awaited internal definition of the QuickDraw picture. The information given here is meant for DEBUGGING PURPOSES ONLY. It is NOT useful in writing your own picture bottleneck procedures. The reason is that if we add new objects to the picture definition, your program will not be able to operate on pictures created using standard QuickDraw. Your program will not know the size of the new objects and will, therefore, not be able to proceed past the new objects. (What this ultimately means is that pictures will not be downward compatible; you can't process a new picture with a old bottleneck proc.)

Before listing the opcodes a little information is in order. An "opcode" is a number that DrawPicture, for example, uses to determine how to draw that particular object in the picture, and how much data is associated with it. The following list gives the opcode, the name of the object, the associated data, and the total size, in bytes, of the opcode and associated data. To better interpret the sizes, please refer to page 4 in Programming in Assembly Language. For types not described there, here is a quick list:

opcode 1 byte

point long

0..255 1 byte

-128..127 1 byte

rect 8 bytes

poly 11+ bytes

region 10+ bytes

fixed point number long

pattern 8 bytes

Each picture definition begins with a picsize (word), then a picframe (rect), and then the picture definition, which consists of a combination of the following opcodes:

Opcode Name Additional Data Total Size (bytes)

00 NOP none 1

01 clipRgn rgn 1+rgn

02 bkPat pattern 9

03 txFont font (word) 3

04 txFace face (byte) 2

05 txMode mode (word) 3

06 spExtra extra (fixed point) 5

07 pnSize pnSize (point) 5

08 pnMode mode (word) 3

09 pnPat pattern 9

0A thePat pattern 9

0B ovSize point 5

0C origin dh, dv (word) 5

0D txSize size (word) 3

0E fgColor color (long) 5

0F bkColor color (long) 5

10 txRatio numer (point), denom (point) 9

11 picVersion version (byte) 2

20 line pnLoc ( point ), newPt ( point ) 9

21 line from newPt ( point ) 5

22 short line pnLoc ( point ), dh, dv (-128..127) 7

23 short line from dh, dv (-128..127) 3

28 long text txLoc ( point ), count (0..255), text 6+text

29 DH text dh (0..255), count (0..255), text 3+text

2A DV text dv (0..255), count (0..255), text 3+text

2B DHDV text dh, dv (0..255), count (0..255), text 4+text

30 frameRect rect 9

31 paintRect rect 9

32 eraseRect rect 9

33 invertRect rect 9

34 fillRect rect 9

38 frameSameRect rect 1

39 paintSameRect rect 1

3A eraseSameRect rect 1

3B invertSameRect rect 1

3C fillSameRect rect 1

40 frameRRect rect 9

41 paintRRect rect 9

42 eraseRRect rect 9

43 invertRRect rect 9

44 fillRRect rect 9

48 frameSameRRect rect 1

49 paintSameRRect rect 1

4A eraseSameRRect rect 1

4B invertSameRRect rect 1

4C fillSameRRect rect 1

50 frameOval rect 9

51 paintOval rect 9

52 eraseOval rect 9

53 invertOval rect 9

54 fillOval rect 9

58 frameSameOval rect 1

59 paintSameOval rect 1

5A eraseSameOval rect 1

5B invertSameOval rect 1

5C fillSameOval rect 1

60 frameArc rect 9

61 paintArc rect 9

62 eraseArc rect 9

63 invertArc rect 9

64 fillArc rect 9

68 frameSameArc rect 1

69 paintSameArc rect 1

6A eraseSameArc rect 1

6B invertSameArc rect 1

6C fillSameArc rect 1

70 framePoly poly 1+poly

71 paintPoly poly 1+poly

72 erasePoly poly 1+poly

73 invertPoly poly 1+poly

74 fillPoly poly 1+poly

78 frameSamePoly (not yet implemented) 1

79 paintSamePoly (not yet implemented) 1

7A eraseSamePoly (not yet implemented) 1

7B invertSamePoly (not yet implemented) 1

7C fillSamePoly (not yet implemented) 1

80 frameRgn rgn 1+rgn

81 paintRgn rgn 1+rgn

82 eraseRgn rgn 1+rgn

83 invertRgn rgn 1+rgn

84 fillRgn rgn 1+rgn

88 frameSameRgn (not yet implemented) 1

89 paintSameRgn (not yet implemented) 1

8A eraseSameRgn (not yet implemented) 1

8B invertSameRgn (not yet implemented) 1

8C fillSameRgn (not yet implemented) 1

90 BitsRect rowBytes, bounds, srcRect, dstRect, mode, 30+unpacked

byteCount, unpacked bitData bitData

91 BitsRgn rowBytes, bounds, srcRect, dstRect, mode, 30+rgn+

maskRgn, byteCount, unpacked bitData bitData

98 PackBitsRect rowBytes, bounds, srcRect, dstRect, mode, 30+packed

byteCount, packed bitData bitData

99 PackBitsRgn rowBytes, bounds, srcRect, dstRect, mode, 30+rgn+

maskRgn, byteCount, packed bitData packed bitData

A0 shortComment kind(word) 3

A1 longComment kind(word), size(word), data 5+data

FF EndOfPicture none 1


Community Search:
MacTech Search:

Software Updates via MacUpdate

CleanMyMac X 4.4.4 - Delete files that w...
CleanMyMac makes space for the things you love. Sporting a range of ingenious new features, CleanMyMac lets you safely and intelligently scan and clean your entire system, delete large, unused files... Read more
TeamViewer 14.4.2669 - Establish remote...
TeamViewer gives you remote control of any computer or Mac over the Internet within seconds or can be used for online meetings. Find out why more than 200 million users trust TeamViewer! Free for non... Read more
Paperless 3.0.6 - $69.95
Paperless is a digital documents manager. Remember when everyone talked about how we would soon be a paperless society? Now it seems like we use paper more than ever. Let's face it - we need and we... Read more
BetterTouchTool 3.141 - Customize multi-...
BetterTouchTool adds many new, fully customizable gestures to the Magic Mouse, Multi-Touch MacBook trackpad, and Magic Trackpad. These gestures are customizable: Magic Mouse: Pinch in / out (zoom)... Read more
TextMate 2.0.rc.29 - Code/markup editor...
TextMate is a versatile plain text editor with a unique and innovative feature set which caused it to win an Apple Design Award for Best Mac OS X Developer Tool in August 2006 A rapidly growing... Read more
Little Snitch 4.4.1 - Alerts you about o...
Little Snitch gives you control over your private outgoing data. Track background activity As soon as your computer connects to the Internet, applications often have permission to send any... Read more
Little Snitch 4.4 - Alerts you about out...
Little Snitch gives you control over your private outgoing data. Track background activity As soon as your computer connects to the Internet, applications often have permission to send any... Read more
MPlayer OSX Extended 16 - Multimedia pla...
MPlayer OSX Extended is the future of MPlayer OSX. Leveraging the power of the MPlayer and FFmpeg open source projects, MPlayer OSX Extended aims to deliver a powerful, functional and no frills video... Read more
Google Chrome 75.0.3770.142 - Modern and...
Google Chrome is a Web browser by Google, created to be a modern platform for Web pages and applications. It utilizes very fast loading of Web pages and has a V8 engine, which is a custom built... Read more
Notability 4.0.4 - Note-taking and annot...
Notability is a powerful note-taker to annotate documents, sketch ideas, record lectures, take notes and more. It combines, typing, handwriting, audio recording, and photos so you can create notes... Read more

Latest Forum Discussions

See All

TEPPEN guide - Tips and tricks for new p...
TEPPEN is a wild game that nobody asked for, but I’m sure glad it exists. Who would’ve thought that a CCG featuring Capcom characters could be so cool and weird? In case you’re not completely sure what TEPPEN is, make sure to check out our review... | Read more »
Dr. Mario World guide - Other games that...
We now live in a post-Dr. Mario World world, and I gotta say, things don’t feel too different. Nintendo continues to squirt out bad games on phones, causing all but the most stalwart fans of mobile games to question why they even bother... | Read more »
Strategy RPG Brown Dust introduces its b...
Epic turn-based RPG Brown Dust is set to turn 500 days old next week, and to celebrate, Neowiz has just unveiled its biggest and most exciting update yet, offering a host of new rewards, increased gacha rates, and a brand new feature that will... | Read more »
Dr. Mario World is yet another disappoin...
As soon as I booted up Dr. Mario World, I knew I wasn’t going to have fun with it. Nintendo’s record on phones thus far has been pretty spotty, with things trending downward as of late. [Read more] | Read more »
Retro Space Shooter P.3 is now available...
Shoot-em-ups tend to be a dime a dozen on the App Store, but every so often you come across one gem that aims to shake up the genre in a unique way. Developer Devjgame’s P.3 is the latest game seeking to do so this, working as a love letter to the... | Read more »
Void Tyrant guide - Guildins guide
I’ve still been putting a lot of time into Void Tyrant since it officially released last week, and it’s surprising how much stuff there is to uncover in such a simple-looking game. Just toray, I finished spending my Guildins on all available... | Read more »
Tactical RPG Brown Dust celebrates the s...
Neowiz is set to celebrate the summer by launching a 2-month long festival in its smash-hit RPG Brown Dust. The event kicks off today, and it’s divided into 4 parts, each of which will last two weeks. Brown Dust is all about collecting, upgrading,... | Read more »
Flappy Royale is an incredibly clever ta...
I spent the better part of my weekend playing Flappy Royale. I didn’t necessarily want to. I just felt like I had to. It’s a hypnotic experience that’s way too easy to just keep playing. | Read more »
Void Tyrant guide - General tips and tri...
Void Tyrant is a card-based dungeon-crawler that doesn’t fit in the mold of other games in the genre. Between the Blackjack-style combat and strange gear system alone, you’re left to your own devices to figure out how best to use everything to your... | Read more »
Webzen’s latest RPG First Hero is offici...
You might be busy sending your hulking Dark Knight into the midst of battle in Webzen’s other recent release: the long-anticipated MU Origin 2. But for something a little different, the South Korean publisher has launched First Hero. Released today... | Read more »

Price Scanner via

Amazon drops prices, now offers clearance 13″...
Amazon has new dropped prices on clearance 13″ 2.3GHz Dual-Core non-Touch Bar MacBook Pros by $200 off Apple’s original MSRP, with prices now available starting at $1099. Shipping is free. Be sure to... Read more
2018 15″ MacBook Pros now on sale for $500 of...
Amazon has dropped prices on select clearance 2018 15″ 6-Core MacBook Pros to $500 off Apple’s original MSRP. Prices now start at $1899 shipped: – 2018 15″ 2.2GHz Touch Bar MacBook Pro Silver: $1899.... Read more
Price drop! Clearance 12″ 1.2GHz Silver MacBo...
Amazon has dropped their price on the recently-discontinued 12″ 1.2GHz Silver MacBook to $849.99 shipped. That’s $450 off Apple’s original MSRP for this model, and it’s the cheapest price available... Read more
Apple’s 21″ 3.0GHz 4K iMac drops to only $936...
Abt Electronics has dropped their price on clearance, previous-generation 21″ 3.0GHz 4K iMacs to only $936 shipped. That’s $363 off Apple’s original MSRP, and it’s the cheapest price we’ve seen so... Read more
Amazon’s Prime Day savings on Apple 11″ iPad...
Amazon has new 2018 Apple 11″ iPad Pros in stock today and on sale for up to $250 off Apple’s MSRP as part of their Prime Day sale (but Prime membership is NOT required for these savings). These are... Read more
Prime Day Apple iPhone deal: $100 off all iPh...
Boost Mobile is offering Apple’s new 2018 iPhone Xr, iPhone Xs, and Xs Max for $100 off MSRP. Their discount reduces the cost of an Xs to $899 for the 64GB models and $999 for the 64GB Xs Max. Price... Read more
Clearance 13″ 2.3GHz Dual-Core MacBook Pros a...
Focus Camera has clearance 2017 13″ 2.3GHz/128GB non-Touch Bar Dual-Core MacBook Pros on sale for $169 off Apple’s original MSRP. Shipping is free. Focus charges sales tax for NY & NJ residents... Read more
Amazon Prime Day deal: 9.7″ Apple iPads for $...
Amazon is offering new 9.7″ WiFi iPads with Apple Pencil support for $80-$100 off MSRP as part of their Prime Day sale, starting at only $249. These are the same iPads found in Apple’s retail and... Read more
Amazon Prime Day deal: 10% (up to $20) off Ap...
Amazon is offering discounts on new 2019 Apple AirPods ranging up to $20 (10%) off MSRP as part of their Prime Day sales. Shipping is free: – AirPods with Charging Case: $144.99 $15 off MSRP –... Read more
Amazon Prime Day deal: $50-$80 off Apple Watc...
Amazon has Apple Watch Series 4 and Series 3 models on sale for $50-$80 off Apple’s MSRP as part of their Prime Day deals with prices starting at only $199. Choose Amazon as the seller rather than a... Read more

Jobs Board

*Apple* Graders/Inspectors (Seasonal/Hourly/...
…requirements. #COVAentryleveljobs ## Minimum Qualifications Some knowledge of agricultural and/or the apple industry is helpful as well as the ability to comprehend, Read more
Best Buy *Apple* Computing Master - Best Bu...
**710003BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Store Associates **Location Number:** 000171-Winchester Road-Store **Job Description:** Read more
Best Buy *Apple* Computing Master - Best Bu...
**709786BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Sales **Location Number:** 000430-Orange Park-Store **Job Description:** **What does a Read more
Geek Squad *Apple* Master Consultation Agen...
**709918BR** **Job Title:** Geek Squad Apple Master Consultation Agent **Job Category:** Services/Installation/Repair **Location Number:** 000106-Palmdale-Store Read more
*Apple* Systems Architect/Engineer, Vice Pre...
…its vision to be the world's most trusted financial group. **Summary:** Apple Systems Architect/Engineer with strong knowledge of products and services related to Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.