TkGS Specification - Internals: Colors

Introduction

From a user's point of view, colors are defined as TkGS_Colors, which are opaque tokens. Internally, colors are defined by the TkGS_Color_ structure (notice the trailing underscore). This structure is a "subclass" (using OOP terminology) of the more generic TkGS_Obj structure.

Structures


TkGS_Color_
Description
This structure is a "subclass" of the TkGS_Obj generic structure. Thus, its first member, header, contains a TkGS_Obj in order for a TkGS_Color_ to be used by generic object code.
It basically stores color information in the form of a RGB triplet.
Status
Internal use only. Likely to change: may take other color representations into account (eg. CMYK, HSB, alpha channel...).
Structure
typedef struct TkGS_Color_ {
    TkGS_Obj	   header;	/* Must be first */

    unsigned short rgb[3];	/* Color RGB values */
} TkGS_Color_;

Accessors


TkGSColor_R
TkGSColor_G
TkGSColor_B
Description
Gives read/write access to the RGB values in the rgb of the TkGS_Color_ structure.
Status
Internal use only. Likely to change (will follow any structural change of TkGS_Color_).
Declaration
#define TkGSColor_R(objPtr) \
    (((TkGS_Color_*)objPtr)->rgb[0])
#define TkGSColor_G(objPtr) \
    (((TkGS_Color_*)objPtr)->rgb[1])
#define TkGSColor_B(objPtr) \
    (((TkGS_Color_*)objPtr)->rgb[2])
Arguments
The object to access.

Functions


TkGSNewColor
Description
Allocate a new TkGS_Color_ given its red, green and blue (RGB) values. These values are represented as unsigned 16-bit integers, although most systems only use 8-bit values.
Status
Internal use only. Unlikely to change except for its name (may be renamed TkGSNewRGBColor).
Declaration
TkGS_Color_ * TkGSNewColor(
    unsigned short red,
    unsigned short green,
    unsigned short blue
);
Arguments
red, green, blue: the values of the 3 primary colors.
Returned value
A pointer to a newly allocated TkGS_Color_.
Side effects
A new object is allocated.

TkGS_GetColorBaseType
Description
Return a pointer to the color object base type. This is intended to be used by device drivers for creating new device-specific color types.
Status
Complete.
Declaration
TkGS_BaseType* TkGS_GetColorBaseType();
Arguments
None.
Returned value
A pointer to the color base type.
Side effects
None.

TODO