Depth Manipulation in Pascal
Bill Catambay, Pascal Developer



Getting and setting the depth information for monitors on the Macintosh is a relatively simple task. The basic toolbox routines used are HasDepth, SetDepth, SetGDevice and TestDeviceAttribute. To determine the current depth setting of a specific device, examine the pixelSize field of the device record. For example, to determine the current depth setting for device aDevice, examine aDevice^^.gdPMap^^.pixelSize.

Library routines for getting and setting the color depth for monitors have already been available in C and C++. On this page they are available in Pascal. Included with the library routines are a couple of sample programs utilizing the routine calls. First, here are some brief descriptions of the four basic toolbox routines used in the depth library (fully documented in Inside Macintosh: Imaging with QuickDraw).

HasDepth - determines whether a video device supports a specific pixel depth

Function HasDepth (aDevice: GDHandle;     { handle to a GDevice record }
                   depth: Integer;        { pixel depth to test }
                   whichFlags: Integer;   { gdDevType constant }
                   flags: Integer)        { 0 = test for b&w, 1 = test for color }
                   : Integer;   

Returns 0 if depth is not supported; otherwise, returns mode ID.

SetDepth - change the pixel depth of a video device

Function SetDepth (aDevice: GDHandle;     { handle to a GDevice record }
                   depth: Integer;        { desired pixel depth }
                   whichFlags: Integer;   { gdDevType constant }
                   flags: Integer)        { 0 = change to b&w, 1 = change to color }
                   : OSErr;

Returns 0 if successful; otherwise, an error code.

SetGDevice - set a GDevice record as the current device

Procedure SetGDevice (aDevice: GDHandle);   { handle to a GDevice record }

TestDeviceAttribute - determines whether the flag bit for an attribute has been set in the gdFlags field of a GDevice record

Function TestDeviceAttribute (aDevice: GDHandle;   { handle to a GDevice record }
										                    attribute: Integer)  { a gdFlags bit constant }
                              : Boolean;

Returns TRUE if the device attribute is set to 1; otherwise, returns FALSE.

All of the above routines are described in greater detail in Inside Macintosh: Imaging with Quickdraw.

Sample Code

Sample Depth HTML - This is webified source code. This program displays a dialog box of supported screen depths and modes, and allows the user to change the settings.

Sample Depth - The same as above, except it is a binhexed download. It includes a CodeWarrior project file, source code files, resource file and running application.

Color Check - This is another binhexed project. This program performs a generic check for 256 colors, and provides dialogs for switching to and from 256 color mode. It includes a CodeWarrior project file, source code files, resource file and running application.

Depth-Lib 1.1p - This is an FTP binhexed depth-lib project for both Think Pascal and CodeWarrior Pascal (thanks to Ingemar Ragnemalm).


Copyright © 1996 Bill Catambay. All Rights Reserved.