Three color models are defined by default: RGB, HSV and GRAY. RGB and HSV allow specification of any color within conventional color space using three orthogonal coordinate axes, while gray restricts colors to one hue between white and black.
The Hue value in HSV is mathematically in the open interval [0.0 6.0). All values must be specified in floating point values.
You can convert color-specs between models using the available ensure-functions
. For example:
(setf green (make-rgb 0.0 1.0 0.0)
=> #(:RGB 0.0 1.0 0.0))
(eq green (ensure-rgb green)) => T
(ensure-hsv green) => #(:HSV 3.0 0.0 1.0)
(eq green (ensure-hsv green) => NIL
(ensure-rgb (ensure-hsv green)) => #(:RGB 0.0 1.0 0.0)
(eq green (ensure-rgb (ensure-hsv green))) => NIL
Of course, information can be lost when converting to GRAY:
(make-rgb 0.3 0.4 0.5) => #(:RGB 0.3 0.4 0.5)
(ensure-gray (make-rgb 0.3 0.4 0.5))
=> #(:GRAY 0.39999965)
(ensure-rgb (ensure-gray
(make-rgb 0.3 0.4 0.5)))
=> #(:RGB 0.39999965 0.39999965 0.39999965)
There is also ensure-color
which takes two color-spec arguments. It converts if necessary the first argument to the same model as the second. For example:
(ensure-color (make-gray 0.3) green)
=> #(:RGB 0.3 0.3 0.3)
ensure-model-color
takes a model as the second argument. For example:
(ensure-model-color (make-gray 0.3) :hsv)
=> #(:HSV 0 1.0 0.3)
The following function compares two color-spec objects for color equality.
colors= color1 color2 &optional ( tolerance 0.001s0)
colors=
returns t
if the two colors are equal to the given tolerance.
Conversion to pixel values used by CLX is done by convert-color
.
convert-color port color &key ( errorp t)
This returns the representation of color on the given Graphics Port port . In CLX, this is the "pixel" value, which corresponds to an index into the default colormap. It is more efficient to use the result of convert-color
in place of its argument in drawing function calls, but the penalty is the risk of erroneous colors being displayed should the colormap or the colormap entry be changed.