TweetFollow Us on Twitter

Screen Dump
Volume Number:4
Issue Number:2
Column Tag:Macintosh II

Screen Dump FKEY for Color Picts

By Steven C. Sheets, Chicago, IL

In our first article, we saw how to create a plot in PICT format, complete with the old style Quickdraw color. But, since our program did not include an open command, how can we view the plot in color once it is made? If we try to snapshot the color screen, we get a beep! What we need is a way to snapshot and view our plot without having to turn off the color. Steve Sheets, from Apple’s Chicago technical support office, shows us how to capture the screen on a Mac II with the color enabled.And best of all, the picture is not rotated! Once we capture our plot, we want to view it. Steve again comes to our rescue with a companion viewer DA for color PICTs.

Color Images: Saving and Loading

Since this column has given some examples of how to draw in Color on the Mac //, now would be a good time to describe how to save and load color pictures. While a specific file format can always be defined for an application, it is convenient to be able to read generic file formats, so that various applications can share and port data. When discussing graphics, the two generic file formats have always been MacPaint file format and PICT file format. MacPaint format has always been considered the generic Bitmap method of saving Mac graphics, while PICT format is the associated with object oriented graphics programs (ie. MacDraw).

With the introduction of Color Quickdraw and the Mac //, things have changed slightly. Unfortunately MacPaint file format can not be expanded to cover PixMap graphics (ie. multiple colors per pixel). Nor is there any other PixMap file format that has been widely accepted by developers (though there is a need). On the other hand, PICT file format is nothing but an extension of a Quickdraw Picture Handle. With the introduction of the Mac //, Quickdraw Pictures have been expanded to support color. This article will talk about the new Color Quickdraw Picture format, the PICT file format, and will touch briefly on using the Palette Manager to display a Picture in the Color needed. The example sources, ColorImage DA and ColorImage FKEY, will demonstrate how to save and read PICT file.

Quickdraw Picture Format

A Quickdraw Picture is a data structure that contains a sequence of Quickdraw commands. To create a Picture, a program defines a Picture Frame (ie, a rectangle and data structure) with the OpenPicture function. OpenPicture returns a handle to the Picture data structure being created. At this point, the program can call any Quickdraw command. Instead of being drawn on the current grafport, the command is stored in the Picture for later use. A ClosePicture command needs to be issued to tell Quickdraw to stop saving the commands into the Picture Handle. Once the program has a Picture, it can display it using the DrawPicture call. This will draw the Picture (ie. all the Quickdraw commands saved in the Picture) into a destination rectangle. If the destination rectangle is not the same size as the picture frame, the picture will be expanded or reduced to fit the destination rectangle. The Plotter program in this issue illustrates this traditional use of the Quickdraw picture.

The Picture handle points to a data structure which contains the Picture Size (Integer picSize), the Picture Frame (Rect picFrame) and various Opcodes describing the Quickdraw calls. Always ignore picSize. With the expansion of the Memory Manager so that it can handle sizes beyond 32K, picSize is now ignored by Quickdraw. Instead, the picture is played out until the end. If the Picture size is needed, call GetHandleSize. Generally beyond picSize and picFrame, a program should not read the data structures directly. The internal structures beyond this point are documented in Inside Macintosh, Vol 5 and the various tech notes cited in the Pascal column.

An image stored and drawn as a Picture (using DrawPicture) is much more compressed than the same image drawn using individual Quickdraw commands in the code. Also the program can pass a Picture through the clipboard and Scrapbook to other Applications. Notice while the Picture is considered an Object Graphic type of data structure, one of the commands it stores is CopyBits. A Picture can thus have BitMapped graphics in it.

Version 1 vs Version 2 Format

With the introduction of the Mac //, the Picture Format has been extended. The old Picture format (called Version 1 Format) contains only the non-Color Quickdraw commands. The newer Picture format (called Version 2 Format) contains all the Color Quickdraw commands. On a Mac //, which Format is created with an OpenPicture call depends on the current GrafPort. If an OpenPicture call is made when the current GrafPort is a Color GrafPort, the Picture created is a Version 2 format. If a call is made on a normal GrafPort, a Version 1 Picture is created. Obviously non-Mac // computers can not create a Version 2 Picture. However, due to a patch in System 4.1 and later, an Enhanced Mac 512K, a MacPlus or a Mac SE can display a Version 2 Picture (not in color, of course).

While checking the Opcodes (Quickdraw picture commands) directly is not a good idea, a program can identify which version of Picture it has by checking the first integer past the picSize and picFrame. If this integer is 4353 ($1101), the Picture is Version 1. If the integer is 17 ($0011), the Picture is Version 2.

Just as a Version 1 Picture can have bitmap graphics in it, a Version 2 Picture can have a PixMap in it. Any CopyBits calls made following an OpenPicture, but before a ClosePicture call, will store the data into the Picture. If the source was a PixMap instead of a BitMap, the Picture handle will have both the bit data (compressed format) and a color table (Color Look Up Table or CLUT) describing the colors used in the PixMap.

PICT File Format

Knowing the Picture format, the PICT File Format is simple. A PICT file (ie. one that has the Filetype ‘PICT’) consists of a data fork with a 512 byte header followed by a picture data structure. The header is usually specific to the application that made it (most programs ignore it). After the header, the picture data contains picSize, picFrame and then the variable length Opcodes. As stated above, do not use picSize to determine how much data follows. Instead, check the size of the file with a File I/O call. Subtract 512 and that should be the size of the handle that the data should be read into.

ColorImage FKEY Code

The ColorImage FKEY was designed to save the current screen to file, similar to the Screen Save FKEY (Command-Shift-3). Instead of a MacPaint file being created, a PICT file is created instead. A CopyBits call on the current screen is used when creating the picture handle, which is then saved to the file.

The FKEY will work on any Macintosh. If the Macintosh has Color Quickdraw (ie. Macintosh //), the Color Window Manager GrafPort is temporarily set before creating the picture handle. Thus a version 2 PICT file will be created and any color images on the screen will be saved. On a non-Color Quickdraw Macintosh (ie. Mac SE and before), the normal Window Manager Port is used and a version 1 PICT file is created. If the Caps Lock key is pressed, the entire screen is saved to a file. If the Caps Lock key is not pressed and a front window exists, only the current window is saved to a file. The picture is not saved to a set file name like the Screen Save FKEY, instead the user is prompted for the file name. The image is also not rotated on a Mac II monitor. Thus you won’t need to edit your screen dumps before using them in your documentation, nor will you need to turn off your color interface as is the case with the old style shift-cmd-3.

Remember, if the Screen was a PixMap instead of a Bitmap, the CLUT will be saved into the PICT file along with the compressed bit data. Color PICTs are amazingly packed files.

Palette Manager

Reading a PICT file, however, is only half the job of displaying a color image correctly. If the Picture contained Color Quickdraw commands (for example, a Color Window saved with ColorImage FKEY), the user will want to see the Picture drawn again using the original colors. For this, the Palette Manager needs to be used.

The Palette Manager establishes the color environment of the Mac //. It uses the Color Manager (which controls what colors are used) to select the best colors for a given display. The idea is that each window can have a Color Palette associated with it. These are the Colors that the window wants the screen to be showing, in order to view the window at it’s best. Unless there are to many windows needing to many colors, each window gets it’s Palette. If there are not enough colors, highest priority goes to the top most window. Every time the top most window changes (and it has an associated Palette), the colors may change to give the new window it’s best appearance. The Palette Manager will then issue an update event for all Palette windows so that they can be redrawn to their best appearance in the new colors.

While an Application could use the Color Manager directly and bypass the Palette Manager, this is not recommended. Such programming would fall apart in a color Multiple task environment. Remember, Multifinder is not the only such environment. There are also color DAs like ColorImage.

Thus the DA takes the Picture (if it is Version 2), searches for a CLUT, and tries to create a Color Palette from it. The program does all this by temporarily replacing the low-level quickdraw procs (specifically StdBits) with one that checks for a PixMap, then transfers the RGB colors into a temporary buffer. The low-level routines are replaced and the buffer is converted to a Color Palette. Then the Palette is attached to the window so every time that particular window becomes the top most, the screen colors are set to the Palette. This also causes an update of the window so the Picture can be shown in it’s best colors.

ColorImage DA Code

The ColorImage Desk Accessory contains the complementing code to Color FKEY, and more. The DA creates a window (Color Window if the CPU has Color Quickdraw) to display Pictures in. The user can then select a PICT file and have it read into a Picture handle. Since a user may want to know what colors are being used for a specific Picture, the DA allows the users to switch between looking at the Picture or the current Palette.

Think of two ColorImage DA’s that are loaded into the system. Each opens a Picture with a radically different CLUT (one is a 256 color RGB Picture while the other is a 256 shade Gray Scaled one). When the RGB Picture is clicked on, it becomes the front window. The Palette Manager sets the 256 RGB colors (assuming the Color Video Card has 8 Bits per Pixel). Both pictures are completely redrawn using the current screen colors. Notice the Palette Manager caused the update; the program does not have to keep track. The RGB Picture appears perfect, while the Gray Picture (which can be seen behind the front window) appears as best as it can using the current screen colors. Then the user wants to look at the Gray Picture. He clicks on that window. It becomes front window, and the Palette Manager sets the current screen to 256 shades of gray. The windows are redrawn. The Gray Picture appears perfectly, while the RGB one appears as best it can using these new gray tones.

Last Comments

The ColorImage FKEY and Desk Accessory were created with LightSpeed Pascal (LSP). Macintosh Programming Workshop (MPW) has it’s points. It is an extremely powerful development system perfect for large projects. Being from Apple, MPW is the first development system that has any new Trap Listings or new code interfaces. LSP only recently has released the Mac // libraries and interfaces. MPW is also the best Object Pascal system around. However LSP may be the best environment to develop code segments (ie. DA, FKEYs, Window or Control Panel Definition Procedures) for the Macintosh. Both code examples were tested from inside a test program (a simple program that called the FKEY and a modified version of LSP DAShell). This decreases development time since the various codes could be tested without having to insert the DA or FKEY into the System file. The code could even be stepped through one line at a time, perhaps the best feature of LSP!

This program requires the Palette manager. When LS Pascal version 1.11 was released in September, Think did not include the Palette manager, nor the MultiFinder routines. We are still waiting for both Think and Borland to upgrade their products to MPW version 2.0 interfaces. You can add the Palette manager by taking the MPW 2.0 interface and adding it to your project. Remove the USES MemTypes and replace with USES ColorQuickdraw instead. Then add “Implementation” to the end of the file and your in business.

ColorImage DA could be expanded to check not only the PixMap’s CLUT in a Picture, but could check other Color Quickdraw commands. Since the DA was designed to work with the FKEY, checking the CLUT is all that is needed to function. The program could also check for colors that are in the CLUT, but are NOT present in the PixMap. Such colors are not displayed and need not be in the Palette.

Yet to come a full blown explanation of the Palette Manager and Palette Animation!

{ ColorImage DA / FKEY by Steve Sheets 12/87 }
{ Saves the current Screen to a PICT file.  If Cap Lock }
{is down, saves theentire screen.  If the key is not & a}
{ Window exists, saves the window.}

UNIT UColorImageFKEY;

INTERFACE

 PROCEDURE main;

IMPLEMENTATION

{Returns the Color Window Manager Port.  }
 PROCEDURE CGetWMgrPort (VAR CWPort : GrafPtr);
 INLINE
 $AA48;

{Does this CPU have color Quickdraw? }
 FUNCTION ColorQDExists : boolean;
 CONST
 ROM85Loc = $28E;
 TwoHighMask = $C000;
 TYPE
 WordPtr = ^INTEGER;
 VAR
 Wd : WordPtr;
 BEGIN
 Wd := POINTER(ROM85Loc);
 ColorQDExists := (BitAnd(Wd^, TwoHighMask) = 0);
 END;

{Is Cap Lock key down?  }
 FUNCTION CapLockDown : BOOLEAN;
 VAR
 theMap : KeyMap;
 BEGIN
 GetKeys(theMap);
 CapLockDown := BitTst(@theMap[1], 30);
 END;

{Given a flag saying color Quickdraw exists, returns} 
{the Handle of a Picture and a flag saying if the window } 
{was saved or if the entire screen was.}
 PROCEDURE GetPic (VAR thePic : PicHandle;
 VAR IsWindow : BOOLEAN;
 QDExists : BOOLEAN);
 TYPE
 BitMapPtr = ^BitMap;
 BitMapHdl = ^BitMapPtr;
 VAR
 sorcRect, destRect, mapRect : Rect;
 OldPort, WPort : GrafPtr;
 clip, vis : RgnHandle;
 FWin : WindowPtr;
 PixH : BitMapHdl;
 tempMap : BitMap;
 BEGIN
 GetPort(OldPort);

{ If Color Quickdraw exists, use the Color Window Manager 
{ PixMap. Else use the normal Window Manager BitMap. }
 IF QDExists THEN
 BEGIN
 CGetWMgrPort(WPort);
 PixH := BitMapHdl(WPort^.portBits.baseAddr);
 mapRect := PixH^^.bounds;
 END
 ELSE
 BEGIN
 GetWMgrPort(WPort);
 mapRect := WPort^.portBits.bounds;
 END;

{Chose to save the Window or entire Screen.  }
 FWin := FrontWindow;
 IsWindow := (NOT CapLockDown) AND (FWin <> NIL);
 IF IsWindow THEN
 BEGIN
 SetPort(FWin);
 sorcRect := FWin^.portRect;
 LocalToGlobal(sorcRect.topLeft);
 LocalToGlobal(sorcRect.botRight);
 OffSetRect(sorcRect, mapRect.left, mapRect.top);
 END
 ELSE
 sorcRect := mapRect;
 destRect.left := 0;
 destRect.right := sorcRect.right - sorcRect.left;
 destRect.top := 0;
 destRect.bottom := sorcRect.bottom - sorcRect.top;

{Resize the regions so they do not get in the way. }
 SetPort(WPort);
 vis := WPort^.visRgn;
 clip := WPort^.clipRgn;
 WPort^.visRgn := NewRgn;
 WPort^.clipRgn := NewRgn;
 SetRectRgn(WPort^.visRgn, -30000, -30000, 30000, 30000);
 SetRectRgn(WPort^.clipRgn, -30000, -30000, 30000, 30000);

{Create Picture, copy map to it and close the Picture. }
 thePic := OpenPicture(destRect);
 CopyBits(WPort^.portBits, WPort^.portBits, sorcRect, destRect, srcCopy, 
NIL);
 ClosePicture;

{Reset the Regions and Port.}
 DisposeRgn(WPort^.visRgn);
 DisposeRgn(WPort^.clipRgn);
 WPort^.visRgn := vis;
 WPort^.clipRgn := clip;

 SetPort(OldPort);
 END;

{Pick a PICT file to save the Picture into (with correct title line).
 }
 PROCEDURE PickFile (VAR theReply : SFReply;
 IsWindow : BOOLEAN;
 QDExists : BOOLEAN);
 VAR
 Pt : Point;
 S1, S2 : str255;
 BEGIN
 Pt.v := 60;
 Pt.h := 60;
 IF QDExists THEN
 S1 := ‘Save Color ‘
 ELSE
 S1 := ‘Save ‘;
 IF IsWindow THEN
 S2 := ‘Window PICT:’
 ELSE
 S2 := ‘Screen PICT:’;
 SFPutFile(Pt, CONCAT(S1, S2), ‘’, NIL, theReply);
 END;

{Given a Picture handle and a reference to a file, create a PICT file 
and save the Picture into it. }
 PROCEDURE SaveColorImage (thePic : PicHandle;
 theReply : SFReply);
 TYPE
 BufType = PACKED ARRAY[1..128] OF LongInt;
 VAR
 theErr : OSErr;
 OK : BOOLEAN;
 FileRef : INTEGER;
 BufSize : LongInt;
 Buf : BufType;
 count : integer;
 BEGIN
 OK := FALSE;
 FileRef := 0;
 theErr := FSDelete(theReply.fname, theReply.vRefNum);
 IF (theErr = noErr) OR (theErr = fnfErr) THEN
 BEGIN
 theErr := Create(theReply.fname, theReply.vRefNum, ‘MDRW’, ‘PICT’);
 IF (theErr = noErr) THEN
 BEGIN
 theErr := FSOpen(theReply.fname, theReply.vRefNum, FileRef);
 IF (theErr = noErr) THEN
 BEGIN
 FOR count := 1 TO 128 DO
 Buf[count] := 0;
 BufSize := 512;
 theErr := FSWrite(FileRef, BufSize, @Buf);
 IF (theErr = noErr) THEN
 BEGIN
 BufSize := GetHandleSize(Handle(thePic));
 HLock(Handle(thePic));
 theErr := FSWrite(FileRef, BufSize, Ptr(thePic^));
 HUnLock(Handle(thePic));
 IF (theErr = noErr) THEN
 BEGIN
 theErr := FSClose(FileRef);
 FileRef := 0;
 IF (theErr = noErr) THEN
 BEGIN
 theErr := FlushVol(NIL, theReply.vRefNum);
 OK := TRUE;
 END;
 END;
 END;
 END;
 END;
 END;
 IF NOT OK THEN
 SysBeep(60);
 IF (FileRef <> 0) THEN
 theErr := FSClose(FileRef);
 END;

{Main FKEY routine:  Check if this CPU has Color Quickdraw}
{(used by all routines).  Create the Picture Handle and Pick} 
{ a File.  If successful, savethe Picture into the file and}
{ kill the picture.}
 PROCEDURE main;
 VAR
 thePic : PicHandle;
 theReply : SFReply;
 IsWindow : BOOLEAN;
 QDExist : BOOLEAN;
 BEGIN
 QDExist := ColorQDExists;
 GetPic(thePic, IsWindow, QDExist);
 PickFile(theReply, IsWindow, QDExist);
 IF theReply.good THEN
 SaveColorImage(thePic, theReply);
 KillPicture(thePic);
 END;
END.

{ColorImage DA by Steve Sheets 12/87 }

{Displays a PICT file.  Checks if the PICT has a Color}
{ PixMap. If so, use the Palette Manager to display the PICT} 
{ in the correct colors.  }

UNIT xColorImageDA;

INTERFACE

 USES
 ColorQuickDraw, PaletteMgr, ColorWindowMgr;

 FUNCTION Main (theDCE : DCtlPtr;
 IOPB : ParmBlkPtr;
 driveCall : Integer) : OSErr;

IMPLEMENTATION

 CONST
 DriverOpen = 0;
 DriverPrime = 1;
 DriverControl = 2;
 DriverStatus = 3;
 DriverClose = 4;

 MaxPal = 512;

 dCtlEnable = 10;

 kNum = 16;
 kBox = 20;
 kHst = 30;
 kVst = 40;
 kVoff = 40;

 kAbout = 1;
 kLoadPic = 3;
 kShowPic = 5;
 kShowPal = 6;

 TYPE
 BufType = RECORD
 Counter : integer;
 CLUTnum : longint;
 B : ARRAY[1..MaxPal] OF RGBColor;
 END;
 BufPtr = ^BufType;
 BufHdl = ^BufPtr;

 imageData = RECORD
 imagePic : PicHandle;
 imagePal : PaletteHandle;
 imageID : integer;
 imageWindow : WindowPtr;
 imageMenu : MenuHandle;
 picRect, palRect : Rect;
 ColorFlag, ShowPicFlag : boolean;
 numPal : integer;
 noPicstr, nameStr : str255;
 END;
 imagePtr = ^imageData;
 imageHandle = ^imagePtr;

 MyCSpecArray = ARRAY[0..MaxPal] OF ColorSpec;

 MyCTabHandle = ^MyCTabPtr;
 MyCTabPtr = ^MyColorTable;
 MyColorTable = RECORD
 ctSeed : LONGINT;
 transIndex : INTEGER;
 ctSize : INTEGER;
 ctTable : MyCSpecArray;
 END;

{Resize the window W to the size R.  Updates the entire}
{ window (window must be the current Grafport).    }
 PROCEDURE ReSize (W : WindowPtr;
 R : rect);
 BEGIN
 SizeWindow(W, R.right, R.bottom, false);
 InvalRect(R)
 END;

{Low level Quickdraw Proc.  Instead of drawing a} {Bitmap/Pixmap, grabs 
the Color Lookup Table, and passes}
{the RGB colors into the   buffer (stored in the Window}
{Ref Con). }
 PROCEDURE BitInfo (VAR srcBits : PixMap;
 VAR srcRect, dstRect : Rect;
 mode : integer;
 maskRgn : RgnHandle);
 VAR
 tempW : WindowPtr;
 theBuf : BufHdl;
 tempC : MyCTabHandle;
 n, count : integer;
 BEGIN
 GetPort(tempW);
 theBuf := POINTER(GetWRefCon(tempW));
 { Make sure it is a PixMap.}
 IF (srcBits.rowBytes < 0) THEN
 BEGIN
 tempC := POINTER(srcBits.pmTable);
 { Make sure this is a new CLUT.  }
 IF (tempC^^.ctSeed <> theBuf^^.CLUTnum) THEN
 BEGIN
 { Cycle through all colors, stuffing into Buf.}
 theBuf^^.CLUTnum := tempC^^.ctSeed;
 n := theBuf^^.Counter;
 IF tempC^^.ctSize >= 0 THEN
 FOR count := 0 TO tempC^^.ctSize DO
 BEGIN
 IF n < MaxPal THEN
 BEGIN
 n := n + 1;
 theBuf^^.B[n] := tempC^^.ctTable[count].rgb;
 END;
 END;
 theBuf^^.Counter := n;
 END;
 END;
 END;

{Given a window and a Picture Handle, return a}
{ Palette Handle and Palette number of the colors used} 
{ in the Picture Handle.  }
 FUNCTION GetPal (theW : WindowPtr;
 thePic : PicHandle;
 VAR thePal : PaletteHandle;
 VAR theNum : integer) : boolean;
 TYPE
 myPicHdl = ^myPicPtr;
 myPicPtr = ^myPicData;
 myPicData = RECORD
 P : Picture;
 ID   : integer;
 END;
 VAR
 count : integer;
 theBuf : BufHdl;
 tempPtr : myPicHdl;
 tempProc : CQDProcs;
 oldProc : QDProcsPtr;
 oldRef : longint;
 dummy : boolean;
 tempP : GrafPtr;
 BEGIN
 dummy := false;
 { If this is a Handle, }
 IF thePic <> NIL THEN
 BEGIN
 { And if it is a color Picture. }
 tempPtr := POINTER(thePic);
 IF tempPtr^^.ID = $0011 THEN
 BEGIN
 { Create the Buffer.}
 theBuf := POINTER(NewHandle(SizeOf(BufType)));
 IF (theBuf <> NIL) THEN
 BEGIN
 { Clear Buffers counters.}
 theBuf^^.Counter := 0;
 theBuf^^.CLUTnum := -1;

{Save the old Window RefCon, and stuff the Buffer into the RefCon.
 }
 oldRef := GetWRefCon(theW);
 SetWRefCon(theW, ord4(theBuf));
{Save the old low level QD Procs, create new ones (including BitInfo).
 }
 oldProc := POINTER(theW^.grafProcs);
 SetStdCProcs(tempProc);
 tempProc.bitsProc := @BitInfo;
 theW^.grafProcs := @tempProc;

{Draw the Picture (grabing the CLUT and RGB Colors).  }
 GetPort(tempP);
 SetPort(theW);
 DrawPicture(thePic, thePic^^.picFrame);
 SetPort(tempP);

 theW^.grafProcs := POINTER(oldProc);
 SetWRefCon(theW, oldRef);

{If there were any colors, create a Color Palette.}
 IF theBuf^^.Counter > 0 THEN
 BEGIN
 thePal := NewPalette(theBuf^^.Counter, NIL, pmTolerant, 0);
 IF thePal <> NIL THEN
 BEGIN
 dummy := true;
 theNum := theBuf^^.Counter;
 FOR count := 1 TO theNum DO
 SetEntryColor(thePal, count - 1, theBuf^^.B[count]);
 END;
 END
 ELSE
 thePal := NIL;
 DisposHandle(POINTER(theBuf));
 END;
 END;
 END;
 GetPal := dummy;
 END;

{Given references to a PICT file, read the PICT file into a PICT handle.
 }
 FUNCTION GetPic (theReply : SFReply;
 VAR thePic : PicHandle) : BOOLEAN;
 VAR
 OK : BOOLEAN;
 FileRef : INTEGER;
 BufSize : LongInt;
 theE : OSerr;
 tempPic : PicHandle;
 BEGIN
 OK := FALSE;
 FileRef := 0;
 tempPic := NIL;
 theE := FSOpen(theReply.fname, theReply.vRefNum, FileRef);
 IF (theE = noErr) THEN
 BEGIN
 theE := GetEOF(FileRef, BufSize);
 IF (theE = noErr) THEN
 BEGIN
 BufSize := BufSize - 512;
 theE := SetFPos(FileRef, fsFromStart, 512);
 IF (theE = noErr) THEN
 BEGIN
 tempPic := PicHandle(NewHandle(BufSize));
 theE := MemError;
 IF (theE = noErr) THEN
 BEGIN
 HLock(Handle(tempPic));
 theE := FSRead(FileRef, BufSize, POINTER(tempPic^));
 HUnLock(Handle(tempPic));
 OK := (theE = noErr);
 IF OK THEN
 thePic := tempPic;
 END;
 END;
 END;
 END;
 IF (FileRef <> 0) THEN
 FileRef := FSClose(FileRef);

 IF NOT OK THEN
 BEGIN
 SysBeep(1);
 IF tempPic <> NIL THEN
 DisposHandle(Handle(tempPic));
 END;
 GetPic := OK;
 END;

{Load a PICT into the DA. }
 PROCEDURE LoadPic (theDCE : DCtlPtr);
 VAR
 theImage : ImageHandle;
 tempReply : SFReply;
 P : point;
 theList : SFTypeList;
 S : str255;
 BEGIN
 theImage := ImageHandle(theDCE^.dCtlStorage);
 WITH theImage^^ DO
 BEGIN
 { Select a File.}
 P.h := 60;
 P.v := 60;
 theList[0] := ‘PICT’;
 SFGetFile(P, ‘’, NIL, 1, theList, NIL, tempReply);
 IF tempReply.good THEN
 BEGIN
 {If a files is selected, release the old Picture and Palette (if any).}
 IF imagePic <> NIL THEN
 BEGIN
 DisposHandle(Handle(imagePic));
 imagePic := NIL;
 picRect.bottom := kBox * kNum;
 picRect.right := kBox * kNum;
 END;
 IF imagePal <> NIL THEN
 BEGIN
 DisposePalette(imagePal);
 numPal := 0;
 imagePal := NIL;
 END;
 { Prepare to set Windows name to ‘ColorImage’.}
 S := nameStr;

 { Read the Picture. }
 IF GetPic(tempReply, imagePic) THEN
 BEGIN
 { If PICT read correctly, resize the window & set the Window name to 
‘ColorImage : (filename)’.}
 picRect.bottom := imagePic^^.picFrame.bottom - imagePic^^.picFrame.top;
 picRect.right := imagePic^^.picFrame.right - imagePic^^.picFrame.left;

 S := CONCAT(S, ‘: ‘, tempReply.fname);

 {If this is Color Quickdraw CPU.}
 IF ColorFlag THEN
 BEGIN
 { Get Palette from Picture.}
 IF GetPal(imageWindow, imagePic, imagePal, numpal) THEN
 BEGIN
 { If successful, set the Palette to the Image Window & resize the Pal 
rect. }
 SetPalette(imageWindow, imagePal, true);
 IF numPal > kNum THEN
 palRect.right := palRect.left + (kNum * kBox)
 ELSE
 palRect.right := numPal * kBox;
 palRect.bottom := (((numPal - 1) DIV kNum) + 1) * kBox;
 END;
 END;
 END;

{Set the Menu correctly, set so the Picture is displayed first, resize
 the window, and set the Window Title. }
 IF imagePic <> NIL THEN
 EnableItem(imageMenu, kShowPic)
 ELSE
 DisableItem(imageMenu, kShowPic);
 IF imagePal <> NIL THEN
 EnableItem(imageMenu, kShowPal)
 ELSE
 DisableItem(imageMenu, kShowPal);

 ShowPicFlag := true;
 ReSize(imageWindow, picRect);
 SetWTitle(imageWindow, S);
 END;
 END;
 END;

{Does this CPU have color Quickdraw? }
 FUNCTION ColorQDExists : boolean;
 CONST
 ROM85Loc = $28E;
 TwoHighMask = $C000;
 TYPE
 WordPtr = ^INTEGER;
 VAR
 Wd : WordPtr;
 BEGIN
 Wd := POINTER(ROM85Loc);
 ColorQDExists := (BitAnd(Wd^, TwoHighMask) = 0);
 END;

{Open the DA.  Set the data structures, the Menu,  the window,  etc.
 }
 FUNCTION Open (theDCE : DCtlPtr) : OSErr;
 VAR
 tempPort : Grafptr;
 theImage : ImageHandle;
 tmpRect : Rect;
 insideWindow : WindowPeek;
 BEGIN
 getport(tempPort);
 IF theDCE^.dCtlStorage = NIL THEN
 BEGIN
 theDCE^.dCtlStorage := NewHandle(SizeOf(imageData));
 HLock(theDCE^.dCtlStorage);
 theImage := ImageHandle(theDCE^.dCtlStorage);
 WITH theDCE^, theImage^^ DO
 BEGIN
 imageID := dCtlRefNum;
 IF imageID > 0 THEN
 imageID := -imageID;
 imageID := $C000 + 32 * (-1 - imageID);

 imageMenu := GetMenu(imageID);
 IF dCtlRefNum < 0 THEN
 BEGIN
 imageMenu^^.menuID := imageID;
 theDCE^.dctlMenu := imageID;
 END
 ELSE
 BEGIN
 imageMenu^^.menuID := -imageID;
 theDCE^.dctlMenu := -imageID;
 END;

 imagePic := NIL;
 imagePal := NIL;
 numPal := 0;
 DisableItem(imageMenu, kShowPic);
 DisableItem(imageMenu, kShowPal);
 picRect.top := 0;
 picRect.left := 0;
 picRect.bottom := kBox * kNum;
 picRect.right := kBox * kNum;
 palRect := picRect;
 ShowPicFlag := true;
 ColorFlag := ColorQDExists;
 GetIndString(nameStr, imageID, 1);
 GetIndString(nopicStr, imageID, 2);

 tmpRect := picRect;
 OffSetRect(tmpRect, 0, kVoff);
 IF ColorFlag THEN
 imageWindow := NewCWindow(NIL, tmpRect, nameStr, true, rDocProc, Pointer(-1), 
True, 0)
 ELSE
 imageWindow := NewWindow(NIL, tmpRect, nameStr, true, rDocProc, Pointer(-1), 
True, 0);
 SetPort(imageWindow);
 insideWindow := WindowPeek(imageWindow);
 insideWindow^.windowKind := dCtlRefNum;
 dCtlWindow := Ptr(imageWindow);
 END;
 HUnLock(theDCE^.dCtlStorage);
 END
 ELSE
 BEGIN
 SelectWindow(WindowPtr(theDCE^.dCtlWindow));
 SetPort(WindowPtr(theDCE^.dCtlWindow));
 END;
 SetPort(tempPort);
 Open := noErr;
 END;

{Do nothing Prime routine.}
 FUNCTION Prime (theDCE : DCtlPtr;
 IOPB : ParmBlkPtr) : OSErr;
 BEGIN
 Prime := noErr;
 END;

{Do the Control routine (ie. Events, Menus, etc.).}
 FUNCTION Control (theDCE : DCtlPtr;
 IOPB : ParmBlkPtr) : OSErr;
 CONST
 accEvent = 64;
 accMenu = 67;
 accUndo = 68;
 accCut = 70;
 accCopy = 71;
 accPaste = 72;
 accClear = 73;
 VAR
 theEvent : EventRecord;
 theImage : ImageHandle;
 aWindow : WindowPtr;
 tempRect : Rect;
 tempPort : Grafptr;
 count : integer;
 BEGIN
 getport(tempPort);
 HLock(theDCE^.dCtlStorage);
 theImage := ImageHandle(theDCE^.dCtlStorage);
 WITH theImage^^ DO
 BEGIN
 SetPort(imageWindow);
 CASE IOPB^.csCode OF
 accEvent : 
 BEGIN
 BlockMove(IOPB^.ioMisc, @theEvent, SizeOf(theEvent));
 CASE theEvent.what OF
 {Update event:  Show the Picture or the Palette.}
 updateEvt : 
 BEGIN
 BeginUpdate(WindowPtr(theEvent.message));
 SetPort(WindowPtr(theEvent.message));
 
 IF ShowPicFlag THEN
 BEGIN
 EraseRect(picRect);
 IF imagePic <> NIL THEN
 DrawPicture(imagePic, picRect)
 ELSE
 BEGIN
 MoveTo(kHst, kVst);
 DrawString(noPicStr);
 END;
 END
 ELSE IF ColorFlag THEN
 BEGIN
 EraseRect(palRect);
 IF imagePal <> NIL THEN
 FOR count := 0 TO NumPal - 1 DO
 BEGIN
 PmForeColor(count);
 tempRect.top := (count DIV kNum) * kBox;
 tempRect.left := (count MOD kNum) * kBox;
 tempRect.bottom := tempRect.top + kBox;
 tempRect.right := tempRect.left + kBox;
 PaintRect(tempRect);
 END;
 END;
 EndUpdate(WindowPtr(theEvent.message));
 END;
 { Activate Event:  Add or remove the Menu.  }
 activateEvt : 
 IF BitAND(theEvent.modifiers, activeFlag) <> 0 THEN
 BEGIN
 IF Ord(theEvent.message) = Ord(imageWindow) THEN
 BEGIN
 InsertMenu(imageMenu, 0);
 DrawMenuBar;
 END;
 END
 ELSE IF Ord(theEvent.message) = Ord(imageWindow) THEN         
 {De-activate event}
 BEGIN
 DeleteMenu(imageMenu^^.menuID);
 DrawMenuBar;
 END;
 { Mouse Down:  Drag the window.   }
 mouseDown : 
 IF FindWindow(theEvent.where, awindow) IN [inSysWindow, inContent] THEN
 BEGIN
 SetRect(tempRect, -30000, -30000, 30000, 30000);
 DragWindow(awindow, theEvent.where, tempRect);
 END;
 keyDown, autoKey : 
 SysBeep(1);
 OTHERWISE
 END;
 END;
{Menus:  Do the About Alert, Load a Picture or switch between the Picture 
or Palette. }
 accMenu : 
 CASE IOPB^.CSParam[1] OF
 kAbout : 
 count := Alert(imageID, NIL);
 kLoadPic : 
 LoadPic(theDCE);
 kShowPic : 
 IF NOT ShowPicFlag THEN
 BEGIN
 ShowPicFlag := true;
 ReSize(imageWindow, picRect);
 END;
 kShowPal : 
 IF ShowPicFlag THEN
 BEGIN
 ShowPicFlag := false;
 ReSize(imageWindow, palRect);
 END;
 OTHERWISE
 END;
 accUndo, accCut, accCopy, accPaste, accClear : 
 SysBeep(1);
 OTHERWISE
 END;
 END;
 HUnLock(Handle(theImage));
 SetPort(tempPort);
 Control := noErr;
 END;

{Do nothing Status routine. }
 FUNCTION Status (theDCE : DCtlPtr;
 IOPB : ParmBlkPtr) : OSErr;
 BEGIN
 Status := noErr;
 END;

{Close Routine:  Clear the Menu, Window, Palette, Picture and Data Structure. 
 }
 FUNCTION Close (theDCE : DCtlPtr;
 IOPB : ParmBlkPtr) : OSErr;
 VAR
 theImage : ImageHandle;
 BEGIN
 HLock(theDCE^.dCtlStorage);
 theImage := ImageHandle(theDCE^.dCtlStorage);
 WITH theImage^^ DO
 BEGIN
 DeleteMenu(imageMenu^^.menuID);
 ReleaseResource(Handle(imageMenu));
 DrawMenuBar;
 IF imagePal <> NIL THEN
 DisposePalette(imagePal);
 IF imagePic <> NIL THEN
 DisposHandle(Handle(imagePic));
 DisposeWindow(imageWindow);
 END;
 HUnLock(theDCE^.dCtlStorage);

 IF theDCE^.dCtlRefNum < 0 THEN
 HPurge(Handle(theDCE^.dCtlDriver));

 theDCE^.dCtlWindow := NIL;
 DisposHandle(theDCE^.dCtlStorage);
 theDCE^.dCtlStorage := NIL;
 Close := noErr;
 END;

{DAs main routine. }
 FUNCTION Main;
 BEGIN
 CASE driveCall OF
 DriverOpen : 
 Main := Open(theDCE);
 DriverPrime : 
 Main := Prime(theDCE, IOPB);
 DriverControl : 
 BEGIN
 BitClr(@theDCE^.dCtlFlags, 15 - dCtlEnable);
 Main := Control(theDCE, IOPB);
 BitSet(@theDCE^.dCtlFlags, 15 - dCtlEnable);
 END;
 DriverStatus : 
 Main := Status(theDCE, IOPB);
 DriverClose : 
 Main := Close(theDCE, IOPB);
 END;
 END;

END.

*  ColorImageDA.R
*  Resource Source File 
*by Steve Sheets 12/87
* 
ColorImageDA Rsrc

Type MENU
  ,-16000
ColorImage
  About ColorImage...
  (-
  Load Picture
  (-
  Show Picture
  Show Palette

Type STR#
  ,-16000
2
ColorImage
No Picture Available

Type DITL
  ,-16000
5

button
160 170 180 230
OK

staticText
20 95 39 305
ColorImage 1.1 by Steve Sheets

staticText
40 104 59 296
Designed for MacTutor 12/87

staticText
80 40 119 360
DA - Displays a PICT file.  If 
it contains a Color PixMap, 
displays it in the correct Palette.

staticText
120 40 139 360
FKEY - Saves the current screen 
into a PICT file.

Type ALRT
  ,-16000
60 120 260 520
-16000
5555
 
AAPL
$94.72
Apple Inc.
+0.78
MSFT
$44.83
Microsoft Corpora
-0.01
GOOG
$594.74
Google Inc.
+5.27

MacTech Search:
Community Search:

Software Updates via MacUpdate

Airmail 1.4 - Powerful, minimal email cl...
Airmail is a powerful, minimal mail client.It was designed to retain the same experience with a single or multiple accounts and provide a quick, modern and easy-to-use user experience. Airmail... Read more
Macs Fan Control 1.1.12 - Monitor and co...
Macs Fan Control allows you to monitor and control almost any aspect of your computer's fans, with support for controlling fan speed, temperature sensors pane, menu-bar icon, and autostart with... Read more
A Better Finder Rename 9.37 - 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
MacBook Air EFI Firmware Update 2.9 - Fo...
MacBook Air EFI Firmware Update is recommended for MacBook Air (Mid 2011) models. This update addresses an issue where systems may take longer to wake from sleep than expected and fixes a rare issue... Read more
FileZilla 3.9.0.1 - Fast and reliable FT...
FileZilla (ported from Windows) is a fast and reliable FTP client and server with lots of useful features and an intuitive interface.Version 3.9.0.1: MSW: Fix installation issue with locked DLLs... Read more
OS X Yosemite 10.10 DP4 - Developer Prev...
Note: This is a Developer Preview. You must be a registered Apple Mac Developer to download this update. OS X Yosemite is Apple's newest operating system for Mac. An elegant design that feels... Read more
FinderPop 2.5.6 - Classic Mac utility, n...
FinderPop is a Universal preference pane that extends OS X's contextual menus using a FinderPop Items folder much as the Apple Menu Items folder used to do for the Apple menu. It has other features... Read more
SpiderOak 5.1.7 - Secure cloud backup, s...
SpiderOak is a multi-platform secure online backup, storage, access, and sharing solution engineered for the consumer and small businesses. You must first sign up to use SpiderOak. Running natively... Read more
Espionage 3.6 - Simple, state of the art...
Espionage offers state-of-the-art encryption and plausible deniability for your confidential data. Sometimes, encrypting your data isn't enough to protect it. That's why Espionage 3 goes beyond data... Read more
calibre 1.45.0 - Complete e-library mana...
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

Latest Forum Discussions

See All

Celebrate Summer With a Cat in the Hat L...
Celebrate Summer With a Cat in the Hat Learning Library Sale Posted by Ellis Spice on July 22nd, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
MyTaskList Review
MyTaskList Review By Jennifer Allen on July 22nd, 2014 Our Rating: :: EFFECTIVE IF PLAINUniversal App - Designed for iPhone and iPad It’s not the most stylish of task management apps, but MyTaskList has all the features you could... | Read more »
FlyCraft Herbie: Crazy Machines Review
FlyCraft Herbie: Crazy Machines Review By Jennifer Allen on July 22nd, 2014 Our Rating: :: TRICKY FLYINGUniversal App - Designed for iPhone and iPad A tough game of careful thrusting and navigation, FlyCraft Herbie: Crazy Machines... | Read more »
MTN Review
MTN Review By Jessica Fisher on July 22nd, 2014 Our Rating: :: ADORABLE, SERENE, AND AMUSINGUniversal App - Designed for iPhone and iPad MTN is an adorable, talking pet mountain that is less game and more zen garden.   | Read more »
Fly High with Ninja UP! Now Available o...
Fly High with Ninja UP! Now Available on the App Store Posted by Jessica Fisher on July 22nd, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Bio Inc. Review
Bio Inc. Review By Nadia Oxford on July 22nd, 2014 Our Rating: :: SICKENING - IN A COMPELLING WAYUniversal App - Designed for iPhone and iPad Bio Inc is about orchestrating the medical destruction of a single person. If that doesn’... | Read more »
HELMUT Review
HELMUT Review By Andrew Fisher on July 21st, 2014 Our Rating: :: TRUNDLE SIMULATOR 2014Universal App - Designed for iPhone and iPad HELMUT is a fun, fleeting time-sink that offers a momentary distraction and nothing else.   | Read more »
Walkr Review
Walkr Review By Jennifer Allen on July 21st, 2014 Our Rating: :: ORIGINAL WALKINGiPhone App - Designed for the iPhone, compatible with the iPad Walking is a bit more exciting thanks to this planet building/discovering sim reliant... | Read more »
Zombie Commando Review
Zombie Commando Review By Jennifer Allen on July 21st, 2014 Our Rating: :: MINDLESS SLAUGHTERUniversal App - Designed for iPhone and iPad Briefly fun but ultimately forgettable, Zombie Commando will scratch an itch then be... | Read more »
Swords & Poker Adventures Review
Swords & Poker Adventures Review By Jennifer Allen on July 21st, 2014 Our Rating: :: SOULLESS POKER PLAYUniversal App - Designed for iPhone and iPad Swords & Poker Adventures is a mishmash of Poker and RPGing, but it lacks... | Read more »

Price Scanner via MacPrices.net

15-inch 2.0GHz MacBook Pro Retina on sale for...
B&H Photo has the 15″ 2.0GHz Retina MacBook Pro on sale for $1829 including free shipping plus NY sales tax only. Their price is $170 off MSRP. B&H will also include free copies of Parallels... Read more
Apple restocks refurbished Mac minis for up t...
The Apple Store has restocked Apple Certified Refurbished Mac minis for up to $150 off the cost of new models. Apple’s one-year warranty is included with each mini, and shipping is free: - 2.5GHz Mac... Read more
Twelve South HiRise For MacBook – Height-Adju...
If you use your MacBook as a workhorse desktop substitute, as many of us do, a laptop stand combined with an external keyboard and pointing device are pretty much obligatory if you want to avoid... Read more
Why The Mac Was Not Included In The Apple/IBM...
TUAW’s Yoni Heisler cites Fredrick Paul of Network World whoi blogged last week that the Mac’s conspicuous absence from Apple and IBM’s landmark partnership agreement represents a huge squandered... Read more
Save $100 on 13-inch Retina MacBook Pros, plu...
Adorama has 13″ Retina MacBook Pros on sale for $100 off MSRP. Shipping is free, and Adorama charges sales tax in NY & NJ only: - 13″ 2.4GHz/128GB MacBook Pro with Retina Display: $1199 - 13″ 2.... Read more
Blurr it 2.3 for iOS – Quickly Blurs Selected...
Hyderabad, India based TouchLabs has announced a new update of Blurr it 2.3, their photography app for iOS users. Blurr it allows you to blur part of the image to hide potentially sensitive or... Read more
MacBook Airs on sale for $100 off MSRP, start...
Best Buy has the new 2014 MacBook Airs on sale for up to $100 off MSRP on their online store. Choose free home shipping or free local store pickup (if available). Prices valid for online orders only... Read more
Amazon Announces Kindle Unlimited: Unlimited...
Amazon.com has introduced Kindle Unlimited — a new subscription service which allows customers to freely read as much as they want from over 600,000 Kindle books, and listen as much as they want to... Read more
New Linksys Wireless Range Extenders Boost Wi...
Linksys has announced its new lineup of Linksys Wi-Fi Range Extenders. Consumers often experience a weak wireless signal in some parts of their house or apartment caused by blocking elements such as... Read more
MacBook Airs available starting at $719
The Apple Store has Apple Certified Refurbished 2013 & 2012 MacBook Airs in stock today starting at $719. An Apple one-year warranty is included with each MacBook, and shipping is free: 2013... 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
Sr *Apple* Engineer - IT - Requisition #: -...
For more information about TIAA-CREF, visit our website . The Apple Engineer will provide engineering and third-level incident support for 300- 500 MacOS desktop/laptop Read more
*Apple* Systems Administrator - DISH (United...
…satellite service provider, and Dish is currently looking for an experienced Apple /Mac Systems Administrator. Apple systems administrator will be responsible for Read more
*Apple* Systems Administrator - DISH (United...
…satellite service provider, and Dish is currently looking for an experienced Apple /Mac Systems Administrator. Apple systems administrator will be responsible for Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.