All Manuals > CAPI User Guide and Reference Manual > 15 The Color System

NextPrevUpTopContentsIndex

15.1 Color specs

A color spec is an object which numerically defines a color in some color-model. For example the object returned by the call:

(color:make-rgb 0.0 1.0 0.0) =>
#(:RGB 0.0 1.0 0.0) 

defines the color green in the RGB color model. Generally short-floats are used; this results in the most efficient color conversion process. However, any float type can be used.

To find out what color-spec is associated with a color name, use the function get-color-spec. It returns the color-spec associated with a symbol. If there is no color-spec associated with color-name , this function returns nil. If color-name is the name of a color alias, the color alias is dereferenced until a color-spec is found.

Color-specs are made using standard functions make-rgb, make-hsv and make-gray. For example:

(make-rgb 0.0s0 1.0s0 0.0s0)
(make-hsv 1.2s0 0.5s0 0.9s0)
(make-gray 0.66667s0)

To create a color spec with an alpha component using the above constructors, pass an extra optional argument. For example this specifies green with 40% transparency:

(make-rgb 0.0s0 1.0s0 0.0s0 0.6s0)

You can also make a transparent color using color-with-alpha:

(color-with-alpha color-spec 0.8s0)

Note that the alpha component is not supported on Motif.

The function color-model returns the model in which a color-spec object has been defined.

The components of color specs can be accessed using the following functions:

RGB model

color-red, color-green, color-blue.

HSV model

color-hue, color-saturation, color-value.

Gray model

color-level.

When these readers are supplied a color spec of their model, they just return the corresponding component. If they are supplied a color spec of another model, they compute the component.

The function color-alpha can be used to access the alpha value of a color (its opacity). If the color does not have an alpha, color-alpha returns 1.0.


CAPI User Guide and Reference Manual (Unix version) - 3 Aug 2017

NextPrevUpTopContentsIndex