Windows in X on a color display always have an associated colormap, a collection of color cells (i.e. triples of R, G and B values).
On some high end displays it may be possible to interpret the contents of
the colormap in more than one way. These `ways' are called Visual
s.
The possible classes of visual are:-
Direct Color
:- A pixel value is separated into 3 fields, each used for
indexing separate R,G,B arrays.True color
:- Like DirectColor, except that colormap has predefined
read-only, server-dependent, values.PseudoColor
:- The pixel value indexes the colormap (an array of triples)
to produce RGB values.Static Color
:- read-only PseudoColor.GrayScale
:- A degenerate case of PseudoColor, when within a triple,
R=G=B.StaticGray
:- read-only GrayScale.
Visual XDefaultVisual(display,screen)to find the default
Visual
and use that, you can't go far wrong. Use
Colormap XDefaultColorMap(display,screen)to get the default colormap. Colormaps are local to a particular screen and if read-only, may be shared among multiple applications.
Much hardware built today have a single color map, so the primitives are written to encourage sharing of color map entries between applications. If there is not sufficient colormap resources in the display, then some windows may not be displayed in their true colors. If you ask for colors that are named then you're more likely to be able to share an already used colorcell.
Colors can be specified by RGB values or by name. Color information is held in the following structure.
typedef struct /* the colour structure is used to set */ { /* colour cell mappings for the screen */ unsigned long pixel; /* pixel value */ unsigned long red,green,blue; /* intensity (0 to 65535) */ char flags; /* DoRed, DoGreen, DoBlue */ char pad; } XColor;