TweetFollow Us on Twitter

Convert Pict2Rgn
Volume Number:5
Issue Number:6
Column Tag:Assembly Lab

Related Info: Quickdraw Window Manager

Convert PICTs to Regions

By Ted Cohn, San Jose, CA

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

[Ted Cohn has been a long-time Mac enthusiast and used to be an Apple ][ hacker. He wrote a professional 6502 debugger for the Apple ][ called Bugbyter which Apple sold with its ProDOS assembly package. He graduated from UC Berkeley with a B.A. in Computer Science. Since then he has been working at Radius Inc., where he designed and wrote Tear-off Menus and a real-time magnifier for the Radius Two Page Display.]

Quickdraw Regions What’s This All About?

Have you ever used a region? If so, have you ever tried creating irregularly-shaped ones? A year ago I wanted to write a desk accessory that would require several strangely-shaped regions. Unfortunately, I found no simple way to create them with the routines Quickdraw provides. Creating a region in Quickdraw is procedural: You must call OpenRgn, draw lines, rectangles, ovals, etc., and then call CloseRgn to define a region’s boundary. This can be a tedious, almost unbearable process if you want to create bizarre regions by having to combine simple geometric shapes. My goal was to find a way to create regions in a non-procedural manner by drawing them with a standard paint program. Although Quickdraw does provide some useful functions like UnionRgn, DiffRgn, SectRgn and XorRgn, it does not provide a routine to convert a bitmap into a region - a routine I believe should be standard Quickdraw equipment.

The question arose: how do I turn a bitmap into a region? One could develop an algorithm to trace the edges of the bitmap and use Quickdraw to add each point individually to the region’s boundary, but that seemed a bit primitive. The only way to find an efficient algorithm was to first understand the region structure itself. And as many already know, Apple has never divulged the region’s structure - certainly cause for some fun detective work. I became sidetracked by this fascinating data structure.

The following explains the region format and my solution to the problem of region creation. Listed afterwards is MakeRgn, an assembly function to convert a bitmap into a Quickdraw region, and Pict2Rgn, an MPW tool which utilizes MakeRgn to convert ‘PICT’ resources to ‘RGN ’ resources.

Let There Be Light!

This is what Apple thinks we ought to know about regions:

rgnSize:  Integer;
rgnBBox:  Rect;
rgnData:  Mystery;

Inside Mac, page I-141, states, “A region can be concave or convex, can consist of one area or many disjoint areas, and can even have ‘holes’ in the middle.” A region specifies exactly which pixels lie inside and outside of a closed boundary. So, how does a region represent this boundary? Inside Mac describes only the header of the region structure, rgnSize and rgnBBox, which are not very interesting. RgnSize specifies the total number of bytes in the region data structure while rgnBBox contains the region’s bounding rectangle. This is the smallest rectangle that will completely enclose the region, that is, each edge of the rectangle will touch at least one point of the region’s boundary. It seems, however, that rgnData was left as an exercise to the developer - a complete mystery and a nagging curiosity.

Now let’s get technical. It turns out that the rgnData structure is not as complex as it might seem. A region is like a bitmap in that it is arranged into scanlines and is read from left to right, top to bottom. This makes sense since regions are used to “mask” bitmaps which are also read from left to right, top to bottom. But instead of containing pixel data, the region need only contain boundary information.

Figure 1a is a doughnut-shaped picture we would like to convert into a region. Let’s step through the conversion process. If we restrict ourselves to the horizontal dimension for the moment, we can isolate the boundary pixels of this bitmap by taking the exclusive-OR of itself with its right-shifted copy. Figure 1b is the result of this process. Notice that pixels which begin a horizontal line segment remain (pixel [5,0] for instance). The remaining pixels of each line segment are lost, but we gain an extra pixel at the end of the line segment. This additional pixel appears because of the XOR function and signifies the end of the segment. Therefore, in the horizontal dimension, two pixels are used to define the line segment.

Now we could use horizontal information alone to define the boundary, but we would have to store every scanline of the region. This would be extremely wasteful in cases where many contiguous lines are the same (as with large rectangular windows). Notice in Figure 1b that lines three and four are equal, lines six through eight are equal, and lines ten through eleven are equal.

Redundant information in the vertical dimension is eliminated by taking an additional XOR of the bitmap in Figure 1b, except, we take the XOR of the bitmap with its down-shifted copy. Each scanline is replaced by an XOR of itself with the previous line. Figure 1c shows the result of this second XOR. Notice that lines four, seven, eight and eleven are now blank. This means that only the first line of a run of equal lines is necessary to define them all.

The Quickdraw region is basically a list of the points (represented by black pixels) in Figure 1c. These points are called “inversion points.” Why? Well, if we were to read a scanline from left to right, they would essentially invert the state of being inside or outside of the region. Unfortunately, this definition is not completely accurate. There is a little more to inversion points than meets the eye. One must realize that no single line of inversion points (except for the first line) can reliably specify which pixels lie inside or outside of a particular line’s boundary. Because the region is not a random access data structure like a bitmap, it must be “played back,” line by line, starting from the top. The first line of inversion points defines the line segment(s) of the top line, but inversion points of successive lines do not directly inform us of the region’s boundary. Boundary information provided by inversion points trickles down each line as the region is processed. This boundary information comes in the form of horizontal “markings” which are set and cleared by inversion points. An inversion point on one line can cancel out a mark made by an inversion point from a previous line.

To illustrate, let’s unravel the boundary of the second line of Figure 1c. The line segment defined on the first line is assumed to be the same for the second line, so marks [5] and [10], which were set, carried through. The second line contains four inversion points: [3,1], [5,1], [10,1] and [12,1]. Inversion point [3,1] defines the new starting point of the line segment. Point [5,1] cancels mark [5] made by the previous inversion point [5,0] so the line segment will not end at point [5,1]. The line segment might also have ended at point [10,1] if it were not for the inversion point [10,1] telling us to cancel mark [10]. The line segment then ends at point [12,1]. For line three, only two marks carry through: [3] and [12]. The other two were canceled out.

During runtime, these marks are stored in the form of an internalized bitmapped line. The bitmapped line is modified from the inversion points that are read in and can be conveniently used to plot the bits of the region on the screen or mask a bitmap in CopyBits.

At this point, let me spell out the rgnData structure in detail. RgnData is a list of two or more scanlines. Each scanline begins with its vertical coordinate. (Every coordinate in the structure is a word in length.) Inversion points are then listed from left to right by entering their horizontal coordinates one after another. Note that there are always an even number of inversion points per scanline because the region is closed. An end mark, $7FFF, terminates the scanline. The remaining scanlines come one after another, each starting with its vertical coordinate. When there are no more scanlines remaining, a final end mark, $7FFF, terminates the rgnData structure. Figure 2 shows the entire Quickdraw region data corresponding to the inversion points of Figure 1c.

MakeRgn Joins the Quickdraw Family

Since it is desirable to draw a region with a paint program, we define the region in bitmap form such that all black pixels in a bitmap are logically included in the region and all white pixels are logically excluded. MakeRgn (Listing 1) follows the process outlined above in converting this bitmap to Quickdraw region format. MakeRgn first does a horizontal XOR with its righted shifted copy and then does a vertical XOR with its down-shifted copy. We could take the vertical XOR first; the order doesn’t matter. This produces a bitmap with inversion points whose coordinates are entered into the rgnData structure. MakeRgn will create and return the region handle, so don’t call NewRgn first. If MakeRgn is provided with an empty bitmap, it will return an empty region. It does not handle Memory Manager errors. If you are concerned about heap space, you can test to see if there exists a free block which is about one hundred bytes larger than your source bitmap. The rgnSize and rgnBBox fields will be calculated and filled in too. The coordinates of the rgnBBox will reflect the bitmap’s bounds rectangle and the location of the region within it.

Tools of the Trade

Pict2Rgn, an MPW Tool shown in Listing 2, lets one convert ‘PICT’ resources into ‘RGN ’ resources. Listing 3 is the make file associated with Pict2Rgn. To use it, place ‘PICT’ resources into a resource file and execute Pict2Rgn with that file name. It will convert each picture and add its corresponding ‘RGN ’ resource to that file with the same ID and name as the source ‘PICT’. The program does not check to see if the resource file already contains regions with the same ID’s, so make sure it is clear of ‘RGN ’ resources before converting pictures. Pict2Rgn demonstrates how to open a GrafPort and draw a picture into that port. Once drawn, the conversion to region format is done by calling MakeRgn with a pointer to the GrafPort’s bitmap.

A nice extension to this tool might be a Region Editor that would allow one to graphically manipulate regions and apply Quickdraw functions to them. Another would be a Control Editor to let one create interesting new controls for dialog boxes. The basic method outlined in Pict2Rgn should be helpful in writing your own utility or package to use MakeRgn.

A Tidbit: What a Drag

If you are interested in dragging outlines of regions, there is a faster way than calling FrameRgn continuously. First, make a copy of the region, then InsetRgn(theRgnCopy, 1, 1) and DiffRgn(theRgn, theRgnCopy, theRgn) to create a region outline. Then call PaintRgn(theRgn) to drag the region outline around. FrameRgn is slow because it performs this same process every time it is called.

Any Alternatives?

Not surprisingly, bitmaps can be used to represent boundaries too. Like our definition above, we can say that black pixels in a bitmap represent the interior of the boundary. Depending on the complexity of the boundary, a bitmap can be considerably smaller in size than its equivalent Quickdraw region. The region data in Figure 2 is 156 bytes long, whereas the bitmap in Figure 1 is only 30 bytes long! This is because each inversion point requires entire word of storage. If there is more than approximately one inversion point per word of pixel data, then it is more space efficient to use a bitmap to represent the region. Still, Quickdraw regions are perfect for use by the Window Manager because the regions manipulated are usually rectangular and generally large requiring at most several hundred bytes. (Imagine Quickdraw using entire bitmaps just for region manipulation!) Thus, the larger, less complex the region, the more space efficient it is compared to its bitmap equivalent. On an historical note, region data was originally compressed by Quickdraw. Regions were generally around one third the size they would be today, but region manipulation was slower because of the on-the-fly compression/decompression. Region compression was removed before shipping the 128K Mac. While I don’t prefer a larger region structure, I think Apple was wise in opting for speed in the windowing environment - especially now that we have megabyte systems instead of 128K Macs to contend with.

Region Wrap-up

I hope this utility helps promote the creation of regions for new controls and windows. While user interface standards are important, I think a little variation wouldn’t hurt. As to Apple’s changing the region format in the future, I have this to say: It is easier to design regions non-procedurally than procedurally. If the format changes, another routine can be easily created to convert a bitmap into a region. In the future, I hope Apple will add a similar conversion routine to its graphics repertoire. If you use MakeRgn, I would be most interested in hearing about it. My AppleLink address is D0959. Happy Macing!

Listing 1. MakeRgn assembly code.

;Written by Ted Cohn, March 1987.
;Copyright 1988 By Ted Cohn.
;MakeRgn converts a bitmap image into a Quickdraw region.
;Black pixels are logically included in the resultant region whereas
;white pixels are not included.  No special conditions required
;of the bitmap - it may be arbitrarily complex.  Empty bitmap will
;simply yield an empty region. rgnBBox of resultant rgn may
;be smaller than initial bitmap bounds if image does not use
;full extent of the bitmap.  rgnBBox will be smallest rect
;enclosing the resultant region.
;Algorithm Summary:
;The idea behind the conversion is simple.  The key is in finding 
;inversion points of the picture which define the region.  A 
;source bitmap is first XOR’d with its right-shifted copy.  
;resultant bitmap is then XOR’d with its down-shifted copy.  
;produces a set of inversion points which define the region 
;boundary.  next step is to take these points within final 
;bitmap and convert them to Quickdraw region format.
;  FUNCTION  MakeRgn(srcMap: Bitmap): RgnHandle;
;Modification History:
;  25 Mar 87    New Today.
;  26 Mar 87    Ironed out those bugs!
;  30 Mar 87    Changed to a Pascal function.
;  28 Mar 88    Optimized and reduced code.


ENDMARK EQU $7FFF; end of rgn/line mark [word].

; MakeRgn’s stack frame:

dstRgn  DS.L1  ; output region [RgnHandle].
srcMap  DS.L1  ; source bitmap [Ptr].
Return  DS.L1  ; return address [Ptr].
A6Link  DS.L1  ; old A6 value [long].
srcRect DS.B8  ; temporary [Rect].
dstRect DS.B8  ; temporary [Rect].
rgnMap  DS.B14 ; temp bitmap [BitMap].
VarSize EQU *  ; size of local variables.

 LINK A6,#VarSize; create local stack frame.
 MOVEM.LA1-A3/D0-D7,-(SP) ; save working registers.
 MOVE.L srcMap(A6),A3; load ptr to source bitmap.
 MOVEQ  #0,D0  ; clear for multiplying.
 MOVEQ  #0,D4  ; use D4 for faster clears.
 MOVE.W rowBytes(A3),D7 ; load srcMap rowBytes.
; Find number of lines in source bitmap.  The rgnMap will have
; the same number of lines plus one and two more rowbytes.
 MOVE.W bounds+bottom(A3),D0; load srcMap bottom.
 SUB.W  bounds+top(A3),D0 ; height = bottom-top.
 ADDQ.W #1,D0  ; height++.
 ADDQ.W #2,D7  ; rowBytes += 2.
; Fill in rgnMap rowBytes and baseAddr fields.  Allocate
; memory for the temporary rgnMap image buffer.
 MOVE.W D7,rgnMap+rowBytes(A6); store new rowBytes.
 MULU D7,D0 ; calculate bitmap size.
 _NewPtr ,clear  ; create rgnMap image buffer.
 MOVE.L A0,rgnMap+baseAddr(A6); store start of buffer.
; rgnMap’s bounds will be one pixel larger to the right and bottom.
 MOVE.L bounds+topLeft(A3),D0 ; get original bitmap bounds.
 MOVE.L bounds+botRight(A3),D1
 ADDQ.W #1,D1  ; right++.
 MOVE.L D0,rgnMap+bounds+topLeft(A6)
 MOVE.L D1,rgnMap+bounds+botRight(A6)
 ADDQ.W #1,rgnMap+bounds+bottom(A6)
; Now make right-shifted copy in rgnMap.
 ADDQ.W #1,D0  ; left++.
 MOVE.L D0,dstRect+topLeft(A6); dstRect is right-shifted one.
 MOVE.L D1,dstRect+botRight(A6)
 MOVE.L A3,-(SP) ; srcBits = srcMap.
 PEA  rgnMap(A6) ; dstBits = rgnMap.
 PEA  bounds(A3) ; srcRect = srcMap.bounds.
 PEA  dstRect(A6); dstRect.
 MOVE.W D4,-(SP) ; srcCopy mode.
 MOVE.L D4,-(SP) ; no maskRgn.
; XOR srcMap with right-shifted copy rgnMap & store in rgnMap.
 MOVE.L A3,-(SP) ; srcBits = srcMap.
 PEA  rgnMap(A6) ; dstBits = rgnMap.
 PEA  bounds(A3) ; srcRect = srcMap.bounds.
 PEA  bounds(A3) ; dstRect = srcMap.bounds.
 MOVE.W #srcXor,-(SP); srcXor mode.
 MOVE.L D4,-(SP) ; no maskRgn.
; XOR rgnMap with down-shifted copy of rgnMap.
 MOVE.L rgnMap+bounds+topLeft(A6),srcRect+topLeft(A6)
 MOVE.L rgnMap+bounds+botRight(A6),srcRect+botRight(A6)
 MOVE.L srcRect+topLeft(A6),dstRect+topLeft(A6)
 MOVE.L srcRect+botRight(A6),dstRect+botRight(A6)
 SUBQ.W #1,srcRect+bottom(A6)
 ADDQ.W #1,dstRect+top(A6)
 PEA  rgnMap(A6) ; srcBits = rgnMap.
 PEA  rgnMap(A6) ; dstBits = rgnMap.
 PEA  srcRect(A6); srcRect = top rectangle.
 PEA  dstRect(A6); dstRect = down-shift one.
 MOVE.W #srcXor,-(SP); srcCopy mode.
 MOVE.L D4,-(SP) ; no maskRgn.
; We’ve exposed the inversion points of the picture.  Time to
; count the number of rows and black pixels in the rgnMap to determine
; the size of the RgnHandle we will soon fill in.
 MOVE.L rgnMap+baseAddr(A6),A0; start at topLeft of bitmap.
 LSR.W  #1,D7  ; rowWords = rowBytes/2.
 SUBQ.W #1,D7  ; loop rowWords times.
 MOVE.W rgnMap+bounds+top(A6),D1 ; current Y coordinate.
 MOVE.W rgnMap+bounds+bottom(A6),A1; last Y coord. for end test.
 MOVEQ  #0,D5  ; row count = 0.
 MOVE.W D7,D6  ; x loop on rowWords.
 MOVEQ  #0,D3  ; clear line flag.
 MOVE.W (A0)+,D0 ; load next rgnMap word.
 BEQ.S  @2; skip blank words.
 TST.B  D3; is line flag already set?
 BNE.S  @1; yes --> skip.
 STD3 ; no --> set line flag.
 ADDQ.W #1,D5  ; row count++.
 ADDQ.W #1,D4  ; add number of bits
 MOVE.W D0,D2  ; in rgnMap word to
 SUBQ.W #1,D2  ; total bit count.
 AND.W  D2,D0
 BNE.S  @1
 DBRA D6,@0 ; loop if more words to read.
 ADDQ.W #1,D1  ; y++.
 CMP.W  D1,A1  ; y <= bottom?
 BGT.S  Count  ; yes --> loop.
; Determine size of new RgnHandle.
 TST.W  D5; was the rgnMap empty?
 BNE.S  BuildRgn ; no --> skip.
 SUBQ.W #4,SP  ; yes --> get new empty region.
 MOVE.L (SP)+,dstRgn(A6)  ; stuff result.
 BRA  Done; exit.
; Calculate number of bytes to allocate for output region handle.
 MOVEQ  #12,D0 ; (12 for header & end mark.)
 ADD.W  D1,D1  ; (4*number of lines in map for
 ADD.W  D1,D1  ; each Y coordinate and
 ADD.W  D1,D0  ; end mark.)
 ADD.W  D4,D4  ; (2*number of inversion
 ADD.W  D4,D0  ; points in the entire map.)
 MOVE.W D0,D4  ; remember the region size.
 _NewHandle ,clear ; allocate a cleared RgnHandle.
 MOVE.L A0,dstRgn(A6); store handle in result.
; Translate rgnMap (containing inversion points) into Quickdraw Region
; format. We do not need to lock block because we will be making no
; trap calls which might rearrange the heap. DstRect will be used to
; help us find smallest enclosing rectangle for the region.
 MOVE.L (A0),A0  ; point to rgn data.
 MOVE.W D4,rgnSize(A0)  ; store region size.
 MOVE.L A0,A2  ; save ptr for the end.
 LEA  rgnData(A0),A0 ; offset ptr to rgnData.
 MOVE.L rgnMap+baseAddr(A6),A1; point to topLeft of bitmap.
 MOVE.W rgnMap+bounds+top(A6),D1 ; y = top.
 MOVE.W D1,dstRect+bottom(A6) ; initialize dstRect...
 MOVE.W rgnMap+bounds+left(A6),dstRect+right(A6)
 MOVE.L rgnMap+bounds+botRight(A6),dstRect+topLeft(A6)
; The line flag tells us if the scanline is not completely blank after
; reading whole line.  If not blank, we add end-of-line mark.
 MOVE.W D7,D6  ; load word count.
 MOVEQ  #0,D5  ; clear line flag.
 MOVE.W rgnMap+bounds+left(A6),D3  ; x = left edge.
 MOVE.W (A1)+,D0 ; load srcMap word.
 BNE.S  @NotEmpty; only process non-zero words.
 ADD.W  #16,D3 ; skip zero words for speed.
 BRA.S  @4
 TST.B  D5; is line flag set?
 BNE.S  @1; yes --> skip.
 STD5 ; no --> set line flag.
 MOVE.W D1,(A0)+ ; store y coord. in structure.
 CMP.W  dstRect+top(A6),D1; now find the topmost
 BGE.S  @MaxBottom ; row of the region.
 MOVE.W D1,dstRect+top(A6); top = min(top,y).
 CMP.W  dstRect+bottom(A6),D1 ; now find the bottommost
 BLE.S  @1; row of the region.
 MOVE.W D1,dstRect+bottom(A6) ; bottom = max(bottom,y).
 OR#$10,CCR ; set the X flag.
 ADDX.W D0,D0  ; shift in end-bit-marker.
 BCC.S  @3; branch if MSB clear.
 MOVE.W D3,(A0)+ ; store x coord. in structure.
 CMP.W  dstRect+left(A6),D3 ; now find the leftmost
 BGE.S  @MaxRight; edge of the region.
 MOVE.W D3,dstRect+left(A6) ; left = min(left,x).
 CMP.W  dstRect+right(A6),D3; now find the rightmost
 BLE.S  @3; edge of the region.
 MOVE.W D3,dstRect+right(A6); right = max(right,x).
 ADDQ.W #1,D3  ; increment the x coordinate.
 ADD.W  D0,D0  ; shift msb bit into carry.
 BNE.S  @2; repeat if more one-bits.
 DBRA D6,@0 ; loop on rowWords-1.
 TST.B  D5; empty line?
 BEQ.S  @5; yes -->
 MOVE.W #ENDMARK,(A0)+  ; no, store end-of-line mark.
 ADDQ.W #1,D1  ; increment the y coordinate.
 CMP.W  rgnMap+bounds+bottom(A6),D1; loop if y <= bottom rgnMap.
 BLT.S  Translate
; We are finished entering information into the rgnData field.
; Mark the end of the region and fill in the rgnBBox field.
 MOVE.W #ENDMARK,(A0); store end-of-region mark.
 MOVE.L dstRect+topLeft(A6),rgnBBox+topLeft(A2)
 MOVE.L dstRect+botRight(A6),rgnBBox+botRight(A2)
 MOVE.L rgnMap+baseAddr(A6),A0; deallocate temporary bitmap.
 MOVEM.L(SP)+,A1-A3/D0-D7 ; restore working registers.
 UNLK A6; unlink the stack frame.
 MOVE.L (SP)+,A0 ; load return address.
 ADDQ #4,SP ; pop parameter.
 JMP  (A0); return.
Listing 2.  Pict2Rgn.

  Pict2Rgn -- convert PICT resources to Quickdraw region format.
 Pict2Rgn [file] [-v]

 file = any resource file containing PICT resources
 -v= verbose flag
  Converts PICT resources within a file to Quickdraw
  region format.  ID’s of the generated regions will be the
  same as the source PICT’s.  region resource type is ‘RGN ‘.
  Does not check to see if RGN resources are already there.
  Written Ted Cohn, March 1988.
  Copyright Ted Cohn, 1988.

#include <types.h>
#include <stdio.h>
#include <resources.h>
#include <quickdraw.h>
#include <memory.h>

#define RgnType ‘RGN ‘

pascal RgnHandle MakeRgn(srcMap)
 BitMap *srcMap;

main(argc, argv)
char  *argv[];
 Rect   frame; /* picture frame */
 GrafPort gp;  /* offscreen GrafPort pictures are drawn */
 short  index; /* for-loop variable */
 short  refNum;  /* the resource file’s refNum */
 short  pictCount; 
 /* number of picts in resource file to convert */
 Handle pictHandle;/* handle to current picture */
 short  rowWords;/* #of words across picture’s bitmap */
 BitMap srcMap;  /* GrafPort’s bitmap */
 short  theID; /* resource ID from GetResInfo */
 ResTypetheType; /* resource TYPE from GetResInfo */
 RgnHandletheRgn;/* hdle region converted from picture */
 Str255 theName; /* resource NAME from GetResInfo */
 short  verbose; /* boolean signals to print more info */

 verbose = (argc>2); /*boolean more than 2 arguments given */

 /* Must initialize Quickdraw for the conversion process */
 /* if no argument supplied, then print info about tool */
 if (argc<2) {
 fprintf(stderr,”\nUsage:  Pict2Rgn <resource file>”);
 fprintf(stderr,”\n  -Converts all PICT resources to Quickdraw region 
 fprintf(stderr,”\n  -ResType is ‘RGN ‘, ID’s correspond to PICT ID’s.”);
 fprintf(stderr,”\n  -Written by Ted Cohn, March, 1988.\n”);

 /* Try to open resource.  If errors, report and exit. */
 if ((refNum = OpenResFile(argv[1])) == -1) {
 fprintf(stderr, “\nCan’t open the resource file %s.\n”, argv[1]);

 /* Find out how many to convert. Exit if no picts in file.*/
 if ((pictCount = Count1Resources(‘PICT’)) == 0) {
 fprintf(stderr, “\nThere are no PICTs in this file to convert.\n”);

 if (verbose)
  fprintf(stderr, “PICT Count = %d\n”, pictCount);
 /* Now convert each PICT to RGN format */
 for (index = 1; index <= pictCount; index++) {    
 /* Get a picture and lock it down */
 HLock(pictHandle = Get1IndResource(‘PICT’, index));
 /* Must get the picture’s ID */
 GetResInfo(pictHandle, &theID, &theType, &theName);
 /* Get the picture’s frame rectangle */
 frame = *((Rect *) (*pictHandle + 2));
 /* Calculate size of srcMap we need to allocate */
 rowWords = (frame.right-frame.left-1)/16+1;
 srcMap.baseAddr = NewPtr((long) ((*rowWords*2));
 srcMap.rowBytes = rowWords*2;
 srcMap.bounds = frame;

 /* Open offscreen GrafPort and set bitmap to our srcMap */

 RectRgn(gp.clipRgn, &frame);
 RectRgn(gp.visRgn, &frame);
 gp.portRect = frame;
 DrawPicture((PicHandle) pictHandle, &frame);
 /* Now convert the picture from a srcMap to a region */
 theRgn = MakeRgn(&srcMap);
 if (verbose)
 fprintf(stderr, “Converted (%d) PICT ID = %d\n”, index, theID);

 /* Add the new region to the file and dispose of it */
 AddResource(theRgn, RgnType, theID, &theName);
 /* All done, so close the resource file */
Listing 3.  Make file for Pict2Rgn.

#   File: Pict2Rgn.make
#   Target: Pict2Rgn
#   Sources:MakeRgn.a Pict2Rgn.c
#   Created:Sunday, April 3, 1988 11:25:18 AM

MakeRgn.a.o ƒ Pict2Rgn.make MakeRgn.a
 Asm MakeRgn.a
Pict2Rgn.c.o ƒ Pict2Rgn.make Pict2Rgn.c
 C Pict2Rgn.c
Pict2Rgn ƒƒ Pict2Rgn.make MakeRgn.a.o Pict2Rgn.c.o
 Link -t MPST -c ‘MPS ‘ 
 “{CLibraries}”CRuntime.o 
 “{CLibraries}”StdCLib.o 
 “{CLibraries}”CSANELib.o 
 “{CLibraries}”CInterface.o 
 MakeRgn.a.o 
 Pict2Rgn.c.o 
 -o Pict2Rgn


Community Search:
MacTech Search:

Software Updates via MacUpdate

A Better Finder Rename 9.52 - File, phot...
A Better Finder Rename is the most complete renaming solution available on the market today. That's why, since 1996, tens of thousands of hobbyists, professionals and businesses depend on A Better... Read more
OmniFocus 2.2.3 - GTD task manager with...
OmniFocus helps you manage your tasks the way that you want, freeing you to focus your attention on the things that matter to you most. Capturing tasks and ideas is always a keyboard shortcut away in... Read more
TinkerTool 5.4 - Expanded preference set...
TinkerTool is an application that gives you access to additional preference settings Apple has built into Mac OS X. This allows to activate hidden features in the operating system and in some of the... Read more
Tinderbox 6.3.1 - Store and organize you...
Tinderbox is a personal content management assistant. It stores your notes, ideas, and plans. It can help you organize and understand them. And Tinderbox helps you share ideas through Web journals... Read more
Parallels Desktop 10.2.2 - Run Windows a...
Parallels Desktop is simply the world's bestselling, top-rated, and most trusted solution for running Windows applications on your Mac. With Parallels Desktop for Mac, you can seamlessly run both... Read more
Adobe Premiere Pro CC 2015 9.0.1 - Digit...
Premiere Pro CC 2015 is available as part of Adobe Creative Cloud for as little as $19.99/month (or $9.99/month if you're a previous Premiere Pro customer). Premiere Pro CS6 is still available for... Read more
Adobe After Effects CC 2015 13.5.1 - Cre...
After Effects CC 2015 is available as part of Adobe Creative Cloud for as little as $19.99/month (or $9.99/month if you're a previous After Effects customer). After Effects CS6 is still available... Read more
Adobe Creative Cloud - Access...
Adobe Creative Cloud costs $49.99/month (or less if you're a previous Creative Suite customer). Creative Suite 6 is still available for purchase (without a monthly plan) if you prefer. Introducing... Read more
Tower 2.2.3 - Version control with Git m...
Tower is a powerful Git client for OS X that makes using Git easy and more efficient. Users benefit from its elegant and comprehensive interface and a feature set that lets them enjoy the full power... Read more
Apple Java 2015-001 - For OS X 10.7, 10....
Apple Java for OS X 2015-001 installs the legacy Java 6 runtime for OS X 10.11 El Capitan, OS X 10.10 Yosemite, OS X 10.9 Mavericks, OS X 10.8 Mountain Lion, and OS X 10.7 Lion. This package is... Read more

Domino Drop (Games)
Domino Drop 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Domino Drop is a delightful new puzzle game with dominos and gravity!Learn how to play it in a minute, master it day by day.Your... | Read more »
OPERATION DRACULA 1.0.1 Device: iOS Universal Category: Games Price: $5.99, Version: 1.0.1 (iTunes) Description: 25% off launch sale!!! 'Could prove to be one of the most accurate representations of the Japanese bullet hell shmup... | Read more »
Race The Sun (Games)
Race The Sun 1.01 Device: iOS iPhone Category: Games Price: $4.99, Version: 1.01 (iTunes) Description: You are a solar craft. The sun is your death timer. Hurtle towards the sunset at breakneck speed in a futile race against time.... | Read more »
Tap Delay (Music)
Tap Delay 1.0.0 Device: iOS Universal Category: Music Price: $4.99, Version: 1.0.0 (iTunes) Description: Back in the “old days”, producers and engineers created delay and echo effects using tape machines. Tap Delay combines the warm... | Read more »
This Week at 148Apps: July 20-24, 2015
July is Heating Up With 148Apps How do you know what apps are worth your time and money? Just look to the review team at 148Apps. We sort through the chaos and find the apps you're looking for. The ones we love become Editor’s Choice, standing out... | Read more »
Red Game Without A Great Name (Games)
Red Game Without A Great Name 1.0.3 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0.3 (iTunes) Description: The mechanical bird is flying through an unfriendly, Steampunk world. Help it avoid obstacles and deadly... | Read more »
Warhammer: Arcane Magic (Games)
Warhammer: Arcane Magic 1.0.2 Device: iOS Universal Category: Games Price: $9.99, Version: 1.0.2 (iTunes) Description: Engage in epic battles and tactical gameplay that challenge both novice and veteran in Warhammer: Arcane Magic, a... | Read more »
Mazes of Karradash (Games)
Mazes of Karradash 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: The city of Karradash is under attack: the monsters of the Shadow Realms are emerging from the depths.No adventurer is... | Read more »
Battle Golf is the Newest Game from the...
Wrassling was a pretty weird - and equally great - little wressling game. Now the developers, Folmer Kelly and Colin Lane, have turned their attention to a different sport: golfing. This is gonna be weird. [Read more] | Read more »
Qbert Rebooted has the App Store Going...
The weird little orange... whatever... is back, mostly thanks to that movie which shall remain nameless (you know the one). But anyway it's been "rebooted" and now you can play the fancy-looking Qbert Rebooted on iOS devices. [Read more] | Read more »

Price Scanner via

2015 13-inch 2.7GHz Retina MacBook Pro on sal...
B&H Photo has the new 2015 13″ 2.7GHz/128GB Retina MacBook Pro on sale today for $1199 including free shipping plus NY sales tax only. Their price is $100 off MSRP. Read more
2.8GHz Mac mini available for $988, includes...
Adorama has the 2.8GHz Mac mini available for $988, $11 off MSRP, including a free copy of Apple’s 3-Year AppleCare Protection Plan. Shipping is free, and Adorama charges sales tax in NY & NJ... Read more
Updated Mac Price Trackers
We’ve updated our Mac Price Trackers with the latest information on prices, bundles, and availability on systems from Apple’s authorized internet/catalog resellers: - 15″ MacBook Pros - 13″ MacBook... Read more
High-Precision Battery Fuel Gauge IC Extends...
Renesas Electronics Corporation has announced its new lithium-ion (Li-ion) battery fuel gauge IC, the RAJ240500, designed to extend battery life for connected mobile devices such as tablets, notebook... Read more
27-inch 3.3GHz 5K iMac on sale for $1799, $20...
B&H Photo has the 27″ 3.3GHz 5K iMac on sale for $1799 including free shipping plus NY tax only. Their price is $200 off MSRP, and it’s the lowest price available for this model from any Apple... Read more
Twelve South Free Dual Screen Backgrounds Co...
Twelve South has posted a second collection of travel Desktop photos, noting: For the Twelve South team, a vacation is never just a vacation. It’s a time to try out new prototypes on the road, visit... Read more
Apple Refurbished iMacs available for up to $...
The Apple Store has Apple Certified Refurbished iMacs available for up to $380 off the cost of new models. Apple’s one-year warranty is standard, and shipping is free: - 27″ 3.5GHz 5K iMac – $1949 $... Read more
Tablets: Why Microsoft’s Surface Is Soaring W...
In contrast to Apple’s record fiscal third quarter reported this week, Microsoft had a miserable latest quarter with its revenues falling by 5.1 percent, hammered by ongoing weak PC demand, and... Read more
Sale! 13″ 1.6GHz/256GB MacBook Air for $1099,...
B&H Photo has the 13″ 1.6GHz/256GB MacBook Air on sale for $1099 including free shipping plus NY tax only. Their price is $100 off MSRP, and it’s the lowest price available for this model. Read more
iPad mini 4 To Be Upgraded To iPad Air 2 Spec...
There’s a certain inevitability about making Apple product predictions this time of year. Come September, we can pretty reliably count on the release of refreshed iPhones, along with the iOS 9... Read more

Jobs Board

*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
*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
*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
*Apple* Customer Experience (ACE) Leader - A...
…management to deliver on business objectives Training partner store staff on Apple products, services, and merchandising guidelines Coaching partner store staff on Read more
Project Manager - *Apple* Pay Security - Ap...
**Job Summary** The Apple Pay Security team is seeking a highly organized, results-driven Project Manager to drive the development of Apple Pay Security. If you are Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.