Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Imaging With QuickDraw /
Chapter 4 - Color QuickDraw


Summary of Color QuickDraw

Pascal Summary

Constants

CONST
   {checking for Color QuickDraw and its features}
   gestaltQuickdrawVersion = 'qd  ';   {Gestalt selector for Color QuickDraw}
   gestalt8BitQD     = $100;  {8-bit Color QD}
   gestalt32BitQD    = $200;  {32-bit Color QD}
   gestalt32BitQD11  = $210;  {32-bit Color QDv1.1}
   gestalt32BitQD12  = $220;  {32-bit Color QDv1.2}
   gestalt32BitQD13  = $230;  {System 7: 32-bit Color QDv1.3}
   gestaltQuickdrawFeatures   = 'qdrw';   {Gestalt selector for Color }
                                          { QuickDraw features}
   gestaltHasColor         = 0;  {Color QuickDraw is present}
   gestaltHasDeepGWorlds   = 1;  {GWorlds deeper than 1 bit}
   gestaltHasDirectPixMaps = 2;  {PixMaps can be direct--16 or 32 bit}
   gestaltHasGrayishTextOr = 3;  {supports text mode grayishTextOr}
                  {source modes for color graphics ports}
   srcCopy     = 0;  {determine how close the color of the source pixel is }
                     { to black, and assign this relative amount of }
                     { foreground color to the destination pixel; determine }
                     { how close the color of the source pixel is to white, }
                     { and assign this relative amount of background }
                     { color to the destination pixel}
   srcOr       = 1;  {determine how close the color of the source pixel is }
                     { to black, and assign this relative amount of }
                     { foreground color to the destination pixel}
   srcXor      = 2;  {where source pixel is black, invert the destination }
                     { pixel--for a colored destination pixel, use the }
                     { complement of its color if the pixel is direct, }
                     { invert its index if the pixel is indexed}
   srcBic      = 3;  {determine how close the color of the source pixel is }
                     { to black, and assign this relative amount of }
                     { background color to the destination pixel}

   notSrcCopy  = 4;  {determine how close the color of the source pixel is }
                     { to black, and assign this relative amount of }
                     { background color to the destination pixel; determine }
                     { how close the color of the source pixel is to white, }
                     { and assign this relative amount of foreground color }
                     { to the destination pixel}
   notSrcOr    = 5;  {determine how close the color of the source pixel is }
                     { to white, and assign this relative amount of }
                     { foreground color to the destination pixel}
   notSrcXor   = 6;  {where source pixel is white, invert the destination }
                     { pixel--for a colored destination pixel, use the }
                     { complement of its color if the pixel is direct, }
                     { invert its index if the pixel is indexed}
   notSrcBic   = 7;  {determine how close the color of the source pixel is }
                     { to white, and assign this relative amount of }
                     { background color to the destination pixel}
{special text transfer mode}
   grayishTextOr = 49;
{arithmetic transfer modes available in Color QuickDraw}
   blend       = 32; {replace destination pixel with a blend of the source }
                     { and destination pixel colors; if the destination is }
                     { a bitmap or 1-bit pixel map, revert to srcCopy mode}
   addPin      = 33; {replace destination pixel with the sum of the source }
                     { and destination pixel colors--up to a maximum }
                     { allowable value; if the destination is a bitmap or }
                     { 1-bit pixel map, revert to srcBic mode}
   addOver     = 34; {replace destination pixel with the sum of the source }
                     { and destination pixel colors--but if the value of }
                     { the red, green, or blue component exceeds 65,536, }
                     { then subtract 65,536 from that value; if the }
                     { destination is a bitmap or 1-bit pixel map, revert }
                     { to srcXor mode}
   subPin      = 35; {replace destination pixel with the difference of the }
                     { source and destination pixel colors--but not less }
                     { than a minimum allowable value; if the destination }
                     { is a bitmap or 1-bit pixel map, revert to srcOr mode}
   addMax      = 37; {compare the source and destination pixels, and }
                     { replace the destination pixel with the color }
                     { containing the greater saturation of each of the RGB }
                     { components; if the destination is a bitmap or }
                     { 1-bit pixel map, revert to srcBic mode}

   subOver     = 38; {replace destination pixel with the difference of the }
                     { source and destination pixel colors--but if the }
                     { value of the red, green, or blue component is less }
                     { than 0, add the negative result to 65,536; if the }
                     { destination is a bitmap or 1-bit pixel map, revert }
                     { to srcXor mode}
   adMin       = 39; {compare the source and destination pixels, and }
                     { replace the destination pixel with the color }
                     { containing the lesser saturation of each of the RGB }
                     { components; if the destination is a bitmap or }
                     { 1-bit pixel map, revert to srcOr mode}
{transparent mode constant}
   transparent = 36; {replace the destination pixel with the source pixel }
                     { if the source pixel isn't equal to the background }
                     { color}
hilite      = 50; {add to source or pattern mode for highlighting}
   hiliteBit   = 7;  {flag bit in HiliteMode (lowMem flag)}
   pHiliteBit  = 0;  {flag bit in HiliteMode used with BitClr procedure}
defQDColors = 127;   {resource ID of 'clut' for default QDColors}
{pixel type}
   RGBDirect = 16;      {16 & 32 bits per pixel pixelType value}
{pmVersion values}
   baseAddr32 = 4;    {pixmap base address is 32-bit address}

Data Types

TYPE  PixMap      = 
RECORD
   baseAddr:      Ptr;        {pixel image}
   rowBytes:      Integer;    {flags, and row width}
   bounds:        Rect;       {boundary rectangle}
   pmVersion:     Integer;    {PixMap record version number}
   packType:      Integer;    {packing format}
   packSize:      LongInt;    {size of data in packed state}
   hRes:          Fixed;      {horizontal resolution (dpi)}
   vRes:          Fixed;      {vertical resolution (dpi)}
   pixelType:     Integer;    {format of pixel image}
   pixelSize:     Integer;    {physical bits per pixel}
   cmpCount:      Integer;    {logical components per pixel}
   cmpSize:       Integer;    {logical bits per component}
   planeBytes:    LongInt;    {offset to next plane}
   pmTable:       CTabHandle; {handle to color table for this image}
   pmReserved:    LongInt;    {reserved for future expansion}
END;
CGrafPtr       =\xDD^CGrafPort;
CGrafPort      = 
RECORD
   device:        Integer;       {device ID for font selection}
   portPixMap:    PixMapHandle;  {handle to PixMap record}
   portVersion:   Integer;       {highest 2 bits always set}
   grafVars:      Handle;        {handle to GrafVars record}
   chExtra:       Integer;       {added width for nonspace characters}
   pnLocHFrac:    Integer;       {pen fraction}
   portRect:      Rect;          {port rectangle}
   visRgn:        RgnHandle;     {visible region}
   clipRgn:       RgnHandle;     {clipping region}
   bkPixPat:      PixPatHandle;  {background pattern}
   rgbFgColor:    RGBColor;      {requested foreground color}
   rgbBkColor:    RGBColor;      {requested background color}
   pnLoc:         Point;         {pen location}
   pnSize:        Point;         {pen size}
   pnMode:        Integer;       {pattern mode}
   pnPixPat:      PixPatHandle;  {pen pattern}
   fillPixPat:    PixPatHandle;  {fill pattern}
   pnVis:         Integer;       {pen visibility}
   txFont:        Integer;       {font number for text}
   txFace:        Style;         {text's font style}
   txMode:        Integer;       {source mode for text}
   txSize:        Integer;       {font size for text}
   spExtra:       Fixed;         {added width for space characters}
   fgColor:       LongInt;       {actual foreground color}
   bkColor:       LongInt;       {actual background color}
   colrBit:       Integer;       {plane being drawn}
   patStretch:    Integer;       {used internally}
   picSave:       Handle;        {picture being saved, used internally}
   rgnSave:       Handle;        {region being saved, used internally}
   polySave:      Handle;        {polygon being saved, used internally}
   grafProcs:     CQDProcsPtr;   {low-level drawing routines}
END;
RGBColor       = 
RECORD
   red:     Integer;    {red\xDDcomponent}
   green:   Integer;    {green\xDDcomponent}
   blue:    Integer;    {blue\xDDcomponent}
END;
ColorSpec      = 
RECORD
   value:   Integer;    {index or other value}
   rgb:     RGBColor;   {true color}
END;
cSpecArray : ARRAY[0..0] OF ColorSpec;
CTabHandle     =\xDD^CTabPtr;
CTabPtr        =\xDD^ColorTable;
ColorTable     =\xDD
RECORD
   ctSeed:  LongInt;    {unique identifier from table}
   ctFlags: Integer;    {contains flags describing the ctTable field; }
                        { clear for a PixMap record}
   ctSize:\xDD Integer;    {number\xDDof\xDDentries\xDDin\xDDthe next field minus 1}
   ctTable: cSpecArray; {an array of ColorSpec records}
END;
MatchRec       = 
RECORD
   red:        Integer; {red component of seed}
   green:      Integer; {green component of seed}
   blue:       Integer; {blue component of seed}
   matchData:  LongInt; {value in matchData parameter of }
                        { SeedCFill or CalcCMask}
END;
PixPatHandle   = ^PixPatPtr;
PixPatPtr      = ^PixPat;
PixPat         = 
RECORD
   patType:    Integer;       {pattern type}
   patMap:     PixMapHandle;  {PixMap record for pattern}
   patData:    Handle;        {pixel image defining pattern}
   patXData:   Handle;        {expanded pixel image}
   patXValid:  Integer;       {flags for expanded pattern data}
   patXMap:    Handle;        {handle to expanded pattern data}
   pat1Data:   Pattern;       {bit pattern for a GrafPort record}
END;
CQDProcsPtr       = ^CQDProcs
CQDProcs          = 
RECORD
   textProc:      Ptr;  {text drawing}
   lineProc:      Ptr;  {line drawing}
   rectProc:      Ptr;  {rectangle drawing}
   rRectProc:     Ptr;  {rounded rectangle drawing}
   ovalProc:      Ptr;  {oval drawing}
   arcProc:       Ptr;  {arc and wedge drawing}
   polyProc:      Ptr;  {polygon drawing}
   rgnProc:       Ptr;  {region drawing}
   bitsProc:      Ptr;  {bit transfer}
   commentProc:   Ptr;  {picture comment processing}
   txMeasProc:    Ptr;  {text width measurement}
   getPicProc:    Ptr;  {picture retrieval}
   putPicProc:    Ptr;  {picture saving}
   opcodeProc:    Ptr;  {reserved for future use}
   newProc1:      Ptr;  {reserved for future use}
   newProc2:      Ptr;  {reserved for future use}
   newProc3:      Ptr;  {reserved for future use}
   newProc4:      Ptr;  {reserved for future use}
   newProc5:      Ptr;  {reserved for future use}
   newProc6:      Ptr;  {reserved for future use}
END;
GrafVars       = 
RECORD
   rgbOpColor:       RGBColor;   {color for addPin, subPin, and blend}
   rgbHiliteColor:   RGBColor;   {color for highlighting}
   pmFgColor:        Handle;     {palette handle for foreground color}
   pmFgIndex:        Integer;    {index value for foreground}
   pmBkColor:        Handle;     {palette handle for background color}
   pmBkIndex:        Integer;    {index value for background}
   pmFlags:          Integer;    {flags for Palette Manager}
END;

Color QuickDraw Routines

Opening and Closing Color Graphics Ports

PROCEDURE OpenCPort        (port: CGrafPtr);
PROCEDURE InitCPort        (port: CGrafPtr); 
PROCEDURE CloseCPort       (port: CGrafPtr); 

Managing a Color Graphics Pen

PROCEDURE PenPixPat        (ppat: PixPatHandle);

Changing the Background Pixel Pattern

PROCEDURE BackPixPat       (ppat: PixPatHandle);

Drawing With Color QuickDraw Colors

PROCEDURE RGBForeColor     (color: RGBColor);
PROCEDURE RGBBackColor     (color: RGBColor);
PROCEDURE SetCPixel        (h,v: Integer; cPix: RGBColor);
PROCEDURE FillCRect        (r: Rect; ppat: PixPatHandle);
PROCEDURE FillCRoundRect   (r: Rect; ovalWidth,ovalHeight: Integer; 
                            ppat: PixPatHandle);
PROCEDURE FillCOval        (r: Rect; ppat: PixPatHandle);
PROCEDURE FillCArc         (r: Rect; startAngle,arcAngle: Integer; 
                            ppat: PixPatHandle);
PROCEDURE FillCPoly        (poly: PolyHandle; ppat: PixPatHandle);
PROCEDURE FillCRgn         (rgn: RgnHandle; ppat: PixPatHandle);
PROCEDURE OpColor          (color: RGBColor);
PROCEDURE HiliteColor      (color: RGBColor);

Determining Current Colors and Best Intermediate Colors

PROCEDURE GetForeColor     (VAR color: RGBColor);
PROCEDURE GetBackColor     (VAR color: RGBColor);
PROCEDURE GetCPixel        (h,v: Integer; VAR cPix: RGBColor);
FUNCTION GetGray           (device: GDHandle; backGround: RGBColor; 
                            VAR foreGround: RGBColor): Boolean;

Calculating Color Fills

PROCEDURE SeedCFill        (srcBits,dstBits: BitMap; 
                            srcRect,dstRect: Rect; seedH,seedV: Integer; 
                            matchProc: ProcPtr; matchData: LongInt);
PROCEDURE CalcCMask        (srcBits,dstBits: BitMap; 
                            srcRect,dstRect: Rect; seedRGB: RGBColor; 
                            matchProc: ProcPtr; matchData: LongInt);

Creating, Setting, and Disposing of Pixel Maps

{DisposePixMap is also spelled as DisposPixMap}
FUNCTION NewPixMap : PixMapHandle;
PROCEDURE CopyPixMap       (srcPM,dstPM: PixMapHandle);
PROCEDURE SetPortPix       (pm: PixMapHandle);
PROCEDURE DisposePixMap    (pm: PixMapHandle);

Creating and Disposing of Pixel Patterns

{DisposePixPat is also spelled as DisposPixPat}
FUNCTION GetPixPat         (patID: Integer): PixPatHandle;
                            FUNCTION NewPixPat : PixPatHandle;
PROCEDURE CopyPixPat       (srcPP,dstPP: PixPatHandle);
PROCEDURE MakeRGBPat       (ppat: PixPatHandle; myColor: RGBColor);
PROCEDURE DisposePixPat    (ppat: PixPatHandle);

Creating and Disposing of Color Tables

{DisposeCTable is also spelled as DisposCTable}
FUNCTION GetCTable         (ctID: Integer): CTabHandle;
PROCEDURE DisposeCTable    (cTable: CTabHandle);

Retrieving Color QuickDraw Result Codes

FUNCTION QDError: Integer;

Customizing Color QuickDraw Operations

PROCEDURE SetStdCProcs     (VAR cProcs: CQDProcs);

Reporting Data Structure Changes to QuickDraw

PROCEDURE CTabChanged      (ctab: CTabHandle);
PROCEDURE PixPatChanged    (ppat: PixPatHandle);
PROCEDURE PortChanged      (port: GrafPtr);
PROCEDURE GDeviceChanged   (gdh: GDHandle);

Application-Defined Routine

FUNCTION MyColorSearch     (rgb: RGBColor; position: LongInt): Boolean;

C Summary

Constants

enum {
   /* checking for Color QuickDraw and its features */
   gestaltQuickdrawVersion = 'qd  ',   /* Gestalt selector for Color
                                          QuickDraw */
   gestalt8BitQD     = 0x100, /* 8-bit Color QD */
   gestalt32BitQD    = 0x200, /* 32-bit Color QD */
   gestalt32BitQD11  = 0x210, /* 32-bit Color QDv1.1 */
   gestalt32BitQD12  = 0x220, /* 32-bit Color QDv1.2 */
   gestalt32BitQD13  = 0x230, /* System 7: 32-bit Color QDv1.3 */
   gestaltQuickdrawFeatures
                     = 'qdrw',   /* Gestalt selector for Color QuickDraw 
                                    features */
   gestaltHasColor         = 0,  /* Color QuickDraw is present */
   gestaltHasDeepGWorlds   = 1,  /* GWorlds deeper than 1 bit */
   gestaltHasDirectPixMaps = 2,  /* PixMaps can be direct--16 or 32 bit */
   gestaltHasGrayishTextOr = 3,  /* supports text mode grayishTextOr */

   /* source modes for color graphics ports */
   srcCopy     = 0,  /* determine how close the color of the source pixel is
                        to black, and assign this relative amount of
                        foreground color to the destination pixel; determine
                        how close the color of the source pixel is to white, 
                        and assign this relative amount of background color
                        to the destination pixel */
   srcOr       = 1,  /* determine how close the color of the source pixel is
                        to black, and assign this relative amount of
                        foreground color to the destination pixel */
   srcXor      = 2,  /* where source pixel is black, invert the destination
                        pixel--for a colored destination pixel, use the 
                        complement of its color if the pixel is direct,
                        invert its index if the pixel is indexed */
   srcBic      = 3,  /* determine how close the color of the source pixel is
                        to black, and assign this relative amount of
                        background color to the destination pixel */
   notSrcCopy  = 4,  /* determine how close the color of the source pixel is
                        to black, and assign this relative amount of
                        background color to the destination pixel; determine
                        how close the color of the source pixel is to white,
                        and assign this relative amount of foreground color
                        to the destination pixel */
   notSrcOr    = 5,  /* determine how close the color of the source pixel is
                        to white, and assign this relative amount of
                        foreground color to the destination pixel */
   notSrcXor   = 6,  /* where source pixel is white, invert destination
                        pixel--for a colored destination pixel, use the 
                        complement of its color if the pixel is direct, 
                        invert its index if the pixel is indexed */
   notSrcBic   = 7,  /* determine how close the color of the source pixel is
                        to white, and assign this relative amount of
                        background color to the destination pixel */

   /* special text transfer mode */
   grayishTextOr  = 49,
/* arithmetic transfer modes available in Color QuickDraw */
   blend       = 32, /* replace destination pixel with a blend of the source
                        and destination pixel colors; if the destination is a
                        bitmap or 1-bit pixel map, revert to srcCopy mode */
   addPin      = 33, /* replace destination pixel with the sum of the source
                        and destination pixel colors--up to a maximum
                        allowable value; if the destination is a bitmap or 
                        1-bit pixel map, revert to srcBic mode */
   addOver     = 34, /* replace destination pixel with the sum of the source
                        and destination pixel colors--but if the value of
                        the red, green, or blue component exceeds 65,536, 
                        subtract 65,536 from that value; if the destination
                        is a bitmap or 1-bit pixel map, revert to srcXor
                        mode */
   subPin      = 35, /* replace destination pixel with the difference of the
                        source and destination pixel colors--but not less
                        than a minimum allowable value; if the destination is
                        a bitmap or 1-bit pixel map, revert to srcOr mode */
   addMax      = 37, /* compare the source and destination pixels, and
                        replace the destination pixel with the color 
                        containing the greater saturation of each of the RGB
                        components; if the destination is a bitmap or 1-bit 
                        pixel map, revert to srcBic mode */
   subOver     = 38, /* replace destination pixel with the difference of the
                        source and destination pixel colors--but if the value
                        of the red, green, or blue component is less than 0,
                        add the negative result to 65,536; if the destination
                        is a bitmap or 1-bit pixel map, revert to 
                        srcXor mode */
   adMin       = 39, /* compare the source and destination pixels, and 
                        replace the destination pixel with the color 
                        containing the lesser saturation of each of the RGB 
                        components; if the destination is a bitmap or 1-bit 
                        pixel map, revert to srcOr mode */
/* transparent mode constant */
   transparent = 36, /* replace the destination pixel with the source pixel 
                        if the source pixel isn't equal to the background
                        color */
hilite      = 50, /* add to source or pattern mode for highlighting */
   hiliteBit   = 7,  /* flag bit in highlight mode (lowMem flag) */
   pHiliteBit  = 0,  /* flag bit in highlight mode used with BitClr
                        procedure */
defQDColors    = 127,   /* resource ID of 'clut' for default QDColors */
/* pixel type */
   RGBDirect = 16,          /* 16 & 32 bits/pixel pixelType value */
/* pmVersion values */
   baseAddr32 = 4,         /* pixel map base address is 32-bit address */
};

Data Types

struct PixMap {
   Ptr         baseAddr;      /* pixel image */
   short       rowBytes;      /* flags, and row width */
   Rect        bounds;        /* boundary rectangle */
   short       pmVersion;     /* PixMap version number */
   short       packType;      /* packing format */
   long        packSize;      /* size of data in packed state */
   Fixed       hRes;          /* horizontal resolution (dpi) */
   Fixed       vRes;          /* vertical resolution (dpi) */
   short       pixelType;     /* format of pixel image */
   short       pixelSize;     /* physical bits per pixel */
   short       cmpCount;      /* logical components per pixel */
   short       cmpSize;       /* logical bits per component */
   long        planeBytes;    /* offset to next plane */
   CTabHandle  pmTable;       /* handle to the ColorTable struct */
   long        pmReserved;    /* reserved for future expansion; must be 0 */
};
typedef struct PixMap PixMap;
typedef PixMap *PixMapPtr, **PixMapHandle;
typedef unsigned char PixelType;
struct CGrafPort {
   short          device;     /* device ID for font selection */
   PixMapHandle   portPixMap; /* handle to PixMap struct */
   short          portVersion;/* highest 2 bits always set */
   Handle         grafVars;   /* handle to a GrafVars struct */
   short          chExtra;    /* added width for nonspace characters */
   short          pnLocHFrac; /* pen fraction */
   Rect           portRect;   /* port rectangle */
   RgnHandle      visRgn;     /* visible region */
   RgnHandle      clipRgn;    /* clipping region */
   PixPatHandle   bkPixPat;   /* background pattern */
   RGBColor       rgbFgColor; /* requested foreground color */
   RGBColor       rgbBkColor; /* requested background color */
   Point          pnLoc;      /* pen location */
   Point          pnSize;     /* pen size */
   short          pnMode;     /* pattern mode */
   PixPatHandle   pnPixPat;   /* pen pattern */
   PixPatHandle   fillPixPat; /* fill pattern */
   short          pnVis;      /* pen visibility */
   short          txFont;     /* font number for text */
   Style          txFace;     /* text's font style */
   char           filler;     
   short          txMode;     /* source mode for text */
   short          txSize;     /* font size for text */
   Fixed          spExtra;    /* added width for space characters */
   long           fgColor;    /* actual foreground color */
   long           bkColor;    /* actual background color */
   short          colrBit;    /* plane being drawn */
   short          patStretch; /* used internally */
   Handle         picSave;    /* picture being saved, used internally */
   Handle         rgnSave;    /* region being saved, used internally */
   Handle         polySave;   /* polygon being saved, used internally */
   CQDProcsPtr    grafProcs;  /* low-level drawing routines */
};
typedef struct CGrafPort CGrafPort;
typedef CGrafPort *CGrafPtr;
typedef CGrafPtr CWindowPtr;
struct RGBColor {
   unsigned short red;     /* magnitude of red component */
   unsigned short green;   /* magnitude of green component */
   unsigned short blue;    /* magnitude of blue component */
};
typedef struct RGBColor RGBColor;
struct ColorSpec {
   short       value;   /* index or other value */
   RGBColor    rgb;     /* true color */
};
typedef struct ColorSpec ColorSpec;
typedef ColorSpec *ColorSpecPtr;
typedef ColorSpec CSpecArray[1];
struct ColorTable {
   long        ctSeed;     /* unique identifier for table */
   short       ctFlags;    /* high bit: 0 = PixMap; 1 = device */
   short       ctSize;     /* number of entries in next field */
   CSpecArray  ctTable;    /* array[0..0] of ColorSpec records */
};
typedef struct ColorTable ColorTable;
typedef ColorTable *CTabPtr, **CTabHandle;
struct MatchRec {
   unsigned short red;        /* red component of seed */
   unsigned short green;      /* green component of seed */
   unsigned short blue;       /* blue component of seed */
   long matchData;            /* value in matchData parameter of 
                                 SeedCFill or CalcCMask */
};
typedef struct MatchRec MatchRec;
struct PixPat {
   short          patType;    /* pattern type */
   PixMapHandle   patMap;     /* PixMap structure for pattern */
   Handle         patData;    /* pixel-image defining pattern */
   Handle         patXData;   /* expanded pattern image */
   short          patXValid;  /* for expanded pattern data */
   Handle         patXMap;    /* handle to expanded pattern data */
   Pattern        pat1Data;   /* a bit pattern for a GrafPort structure */
};
typedef struct PixPat PixPat;
typedef PixPat *PixPatPtr, **PixPatHandle;
struct CQDProcs {
   Ptr textProc;     /* text drawing */
   Ptr lineProc;     /* line drawing */
   Ptr rectProc;     /* rectangle drawing */
   Ptr rRectProc;    /* rounded rectangle drawing */
   Ptr ovalProc;     /* oval drawing */
   Ptr arcProc;      /* arc/wedge drawing */
   Ptr polyProc;     /* polygon drawing */
   Ptr rgnProc;      /* region drawing */
   Ptr bitsProc;     /* bit transfer */
   Ptr commentProc;  /* picture comment processing */
   Ptr txMeasProc;   /* text width measurement */
   Ptr getPicProc;   /* picture retrieval */
   Ptr putPicProc;   /* picture saving */
   Ptr opcodeProc;   /* reserved for future use */
   Ptr newProc1;     /* reserved for future use */
   Ptr newProc2;     /* reserved for future use */
   Ptr newProc3;     /* reserved for future use */
   Ptr newProc4;     /* reserved for future use */
   Ptr newProc5;     /* reserved for future use */
   Ptr newProc6;     /* reserved for future use */
};
typedef struct CQDProcs CQDProcs;
typedef CQDProcs *CQDProcsPtr;
struct GrafVars {
   RGBColor    rgbOpColor;       /* color for addPin,subPin,and blend */
   RGBColor    rgbHiliteColor;   /* color for highlighting */
   Handle      pmFgColor;        /* palette handle for foreground color */
   short       pmFgIndex;        /* index value for foreground */
   Handle      pmBkColor;        /* palette handle for background color */
   short       pmBkIndex;        /* index value for background */
   short       pmFlags;          /* flags for Palette Manager */
};
typedef struct GrafVars GrafVars;
typedef GrafVars *GVarPtr, **GVarHandle;

Color QuickDraw Functions

Opening and Closing Color Graphics Ports

pascal void OpenCPort       (CGrafPtr port); 
pascal void InitCPort       (CGrafPtr port); 
pascal void CloseCPort      (CGrafPtr port); 

Managing a Color Graphics Pen

pascal void PenPixPat       (PixPatHandle pp); 

Changing the Background Pixel Pattern

pascal void BackPixPat      (PixPatHandle pp); 

Drawing With Color QuickDraw Colors

pascal void RGBForeColor    (const RGBColor *color); 
pascal void RGBBackColor    (const RGBColor *color); 
pascal void SetCPixel       (short h, short v, const RGBColor *cPix); 
pascal void FillCRect       (const Rect *r, PixPatHandle pp); 
pascal void FillCRoundRect  (const Rect *r, short ovalWidth, 
                             short ovalHeight, PixPatHandle pp); 
pascal void FillCOval       (const Rect *r, PixPatHandle pp); 
pascal void FillCArc        (const Rect *r, short startAngle,
                             short arcAngle, PixPatHandle pp); 
pascal void FillCPoly       (PolyHandle poly, PixPatHandle pp); 
pascal void FillCRgn        (RgnHandle rgn, PixPatHandle pp); 
pascal void OpColor         (const RGBColor *color); 
pascal void HiliteColor     (const RGBColor *color); 

Determining Current Colors and Best Intermediate Colors

pascal void GetForeColor    (RGBColor *color); 
pascal void GetBackColor    (RGBColor *color); 
pascal void GetCPixel       (short h, short v, RGBColor *cPix);
pascal Boolean GetGray      (GDHandle device, const RGBColor *backGround, 
                             RGBColor *foreGround); 

Calculating Color Fills

pascal void SeedCFill       (const BitMap *srcBits, const BitMap *dstBits, 
                             const Rect *srcRect, const Rect *dstRect, 
                             short seedH, short seedV, 
                             ColorSearchProcPtr matchProc, long matchData); 
pascal void CalcCMask       (const BitMap *srcBits, const BitMap *dstBits, 
                             const Rect *srcRect, const Rect *dstRect, 
                             const RGBColor *seedRGB, 
                             ColorSearchProcPtr matchProc, long matchData); 

Creating, Setting, and Disposing of Pixel Maps

/* DisposePixMap is also spelled as DisposPixMap */
pascal PixMapHandle NewPixMap
                            (void); 
pascal void CopyPixMap      (PixMapHandle srcPM, PixMapHandle dstPM); 
pascal void SetPortPix      (PixMapHandle pm); 
pascal void DisposePixMap   (PixMapHandle pm); 

Creating and Disposing of Pixel Patterns

/* DisposePixPat is also spelled as DisposPixPat */
pascal PixPatHandle GetPixPat
                            (short patID); 
pascal PixPatHandle NewPixPat
                            (void);
pascal void CopyPixPat      (PixPatHandle srcPP, PixPatHandle dstPP); 
pascal void MakeRGBPat      (PixPatHandle pp, const RGBColor *myColor); 
pascal void DisposePixPat   (PixPatHandle pp); 

Creating and Disposing of Color Tables

/* DisposeCTable is also spelled as DisposCTable */
pascal CTabHandle GetCTable
                            (short ctID); 
pascal void DisposeCTable   (CTabHandle cTable); 

Retrieving Color QuickDraw Result Codes

pascal short QDError        (void);

Customizing Color QuickDraw Operations

pascal void SetStdCProcs    (CQDProcs *procs); 

Reporting Data Structure Changes to QuickDraw

pascal void CTabChanged     (CTabHandle ctab);
pascal void PixPatChanged   (PixPatHandle ppat);
pascal void PortChanged     (GrafPtr port);
pascal void GDeviceChanged  (GDHandle gdh);

Application-Defined Function

pascal Boolean MyColorSearch(rgb RGBColor, position LongInt);

Assembly-Language Summary

Data Structures

PixMap Data Structure
0pmBaseAddrlongpixel image
4pmRowByteswordflags, and row width
6pmBounds8 bytesboundary rectangle
14pmVersionwordPixMap version number
16pmPackTypewordpacking format
18pmPackSizelongsize of data in packed state
22pmHReslonghorizontal resolution (dpi)
26pmVReslongvertical resolution (dpi)
30pmPixelTypewordformat of pixel image
32pmPixelSizewordphysical bits per pixel
34pmCmpCountwordlogical components per pixel
36pmCmpSizewordlogical bits per component
38pmPlaneByteslongoffset to next plane
42pmTablelonghandle to next ColorTable record
46pmReservedlongreserved; must be 0

CGrafPort Data Structure
0deviceshortdevice ID for font selection
2portPixMaplonghandle to PixMap record
6portVersionshorthighest 2 bits always set
8grafVarslonghandle to GrafVars record
12chExtrashortadded width for nonspace characters
14pnLocHFracshortpen fraction
16portRect8 bytesport rectangle
24visRgnlongvisible region
28clipRgnlongclipping region
32bkPixPatlongbackground pattern
36rgbForeColor6 bytesrequested foreground color
42rgbBackColor6 bytesrequested background color
48pnLoclongpen location
52pnSizelongpen size
56pnModewordpattern mode
58pnPixPatlongpen pattern
62fillPixPatlongfill pattern
66pnViswordpen visibility
68txFontwordfont number for text
70txFacewordtext's font style
72txModewordsource mode for text
74txSizewordfont size for text
76spExtralongadded width for space characters
80fgColorlongactual foreground color
84bkColorlongactual background color
88colrBitwordplane being drawn
90patStretchwordused internally
92picSavelongpicture being saved, used internally
96rgnSavelongregion being saved, used internally
100polySavelongpolygon being saved, used internally
104grafProcslonglow-level drawing routines

Relative Offsets of Additional Fields in a CGrafPort Record
portBitsportPixMaplonghandle to PixMap record
portPixMap+4portVersionwordhighest 2 bits always set
portVersion+2grafVarslonghandle to a GrafVars record
grafVars+4chExtrawordadded width for nonspace characters
chExtra+2pnLocHFracwordpen fraction
bkPatbkPixPatlongbackground pattern
bkPixPat+4rgbFgColor6 bytesrequested foreground color
rgbFgColor+6rgbBkColor6 bytesrequested background color
pnPatpnPixPatlongpen pattern
pnPixPat+4fillPixPatlongfill pattern

RGBColor Data Structure
0redshortmagnitude of red component
2greenshortmagnitude of green component
4blueshortmagnitude of blue component

ColorSpec Data Structure
0valueshortindex or other value
2rgb6 bytestrue color

ColorTable Data Structure
0ctSeedlongunique identifier for table
4transIndexwordindex of transparent pixel (obsolete)
8ctFlagswordhigh bit: 0 = pixel map; 1 = device
10ctSizewordnumber of entries in next field
12ctTablevariablearray of ColorSpec records

MatchRec Data Structure
0redwordred component of seed
2greenwordgreen component of seed
4bluewordblue component of seed
6matchDatalongvalue in matchData parameter of SeedCFill or CalcCMask

PixPat Data Structure
0patTypewordpattern type
2patMaplonghandle to PixMap record for pattern
6patDatalongpixel-image defining pattern
10patXDatalongexpanded pattern data
14patXValidwordfor expanded pattern data
16patXMaplonghandle to expanded pattern data
20pat1Data8 bytesa bit pattern for a GrafPort record
    

CQDProcs Data Structure
0textProclongpointer to text-drawing routine
4lineProclongpointer to line-drawing routine
8rectProclongpointer to rectangle-drawing routine
12rRectProclongpointer to rounded rectangle-drawing routine
16ovalProclongpointer to oval-drawing routine
20arcProclongpointer to arc/wedge-drawing routine
24polyProclongpointer to polygon-drawing routine
28rgnProclongpointer to region-drawing routine
32bitsProclongpointer to bit transfer routine
36commentProclongpointer to picture comment-processing routine
40txMeasProclongpointer to text-width measurement routine
44getPicProclongpointer to picture retrieval routine
48putPicProclongpointer to picture-saving routine
52opcodeProclongreserved for future use
56newProc1longreserved for future use
60newProc2longreserved for future use
64newProc3longreserved for future use
68newProc4longreserved for future use
72newProc5longreserved for future use
76newProc6longreserved for future use

GrafVars Data Structure
0rgbOpColor6 bytescolor for addPin, subPin, and blend
6rgbHiliteColor6 bytescolor for highlighting
12pmFgColorlongpalette handle for foreground color
16pmFgIndexshortindex value for foreground color
18pmBkColorlongpalette handle for background color
22pmBkIndexshortindex value for background color
24pmFlagsshortflags for Palette Manager

Trap Macros Requiring Routine Selectors

_QDExtensions
SelectorRoutine
$00040007CTabChanged
$00040008PixPatChanged
$00040009PortChanged
$0004000AGDeviceChanged

Result Codes
noErr0No error
paramErr-50Illegal parameter to NewGWorld
 -143CopyBits couldn't allocate required temporary memory
 -144Ran out of stack space while drawing polygon
noMemForPictPlaybackErr-145Insufficient memory for drawing the picture
regionTooBigError-147Region too big or complex
pixmapTooDeepErr-148Pixel map is deeper than 1 bit per pixel
nsStackErr-149Insufficient stack
cMatchErr-150Color2Index failed to find an index
cTempMemErr-151Failed to allocate memory for temporary structures
cNoMemErr-152Failed to allocate memory for structure
cRangeErr-153Range error on color table request
cProtectErr-154ColorTable record entry protection violation
cDevErr-155Invalid type of graphics device
cResErr-156Invalid resolution for MakeITable
cDepthErr-157Invalid pixel depth specified to NewGWorld
rgnTooBigErr-500Bitmap would convert to a region greater than 64 KB


Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996