COLOUR(7P) — SUNPHIGS LIBRARY
NAME
COLOUR − introduction to using colour in the SunPHIGS graphics library
DESCRIPTION
This page provides an overview of using the capabilities of a colour system from SunPHIGS. The topics covered are:
• Colour Frame Buffers
• Standard PHIGS: Indexed Colour
• PHIGS+: General Colour
• A Workstation’s Default Colour Table
• Setting a Workstation’s Colour Table
• Sizing a Workstation’s Colour Table
• Colormap Double Buffering
• Naming and Sharing a Colormap Segment
• Other Colour Attributes
Colour Frame Buffers
SunPHIGS supports several different colour frame buffers which have different colour capabilities. All of Sun’s current frame buffers display pixels by specifying the red, green, and blue (RGB) components of the colour for each pixel. This specification can be done in two different ways, indexed and true colour.
Indexed frame buffers have a hardware colour table, also known as a colormap, which holds colour definitions. Each pixel in the frame buffer holds a colour index which selects a colour definition from this colormap. The pixels are converted from an indices to RGB colours each time the monitor is refreshed from the frame buffer (many times a second). The colour table holds 24-bit RGB values, so that each entry choses a colour from a 16 million colour palette. This is close to the limit of human perception. Each pixel holds an 8-bit index into the colormap, so that each pixel can select one of the 256 entries in the colormap. This means that there can be a maximum of 256 different colours on an indexed frame buffer at a time, and that each of those colours can be chosen from a 16 million colour palette. Since the conversion from index to RGB colour is done each time the monitor is refreshed, changes to the colormap appear almost instantaneously. SunView arbitrates the use of the hardware colormap among all the windows that want to display different sets of colours. This is described in the Sizing a Workstation’s Colour Table section of this manpage.
Sun’s true colour frame buffers store 24-bit RGB values for each pixel. This means that each pixel can take any of 16 million colours. Since each pixel specifies a RGB colour, there is no need for a colormap.
SunPHIGS uses the colour mode workstation configuration attribute to indicate whether a workstation is open on an indexed or true colour frame buffer. The attribute is called PHIGS_COLOUR_MODE in C (with values PHIGS_INDEX_COLOUR and PHIGS_TRUE_COLOUR) and PHIGSCLRMODE in FORTRAN (with values PHIGSINDEXCOLOUR and PHIGSTRUECOLOUR). The default value is indexed colour on indexed colour frame buffers and true colour on true colour frame buffers. If the colour mode is indexed, then the workstation is called an indexed workstation, if it is true colour, the workstation is called a true colour workstation. SunPHIGS can simulate a true colour frame buffer on an indexed frame buffer; this is enabled by setting the colour mode to true colour on an indexed frame buffer. This simulation may be slower than a normal indexed or true colour workstation, and the appearance of primitives may be different. See WORKSTATION TYPE SET (3P).
Standard PHIGS: Indexed Colour
Standard PHIGS supports only indexed colour. Structure elements select a colour for a primitive by using an integer colour index, such as that selected by SET POLYLINE COLOUR INDEX(3P). When a primitive is displayed on a workstation, the colour index is used to select a colour value (called a colour representation) from the workstation’s colour table. The colour representation is what is actually seen by the observer. The default colour index for all primitives is 1.
PHIGS+: General Colour
SunPHIGS extensions based on PHIGS+ allow the specification of colour either as indexed colours, or as RGB colours directly. When a colour is specified as an index, it is called indirect colour, since the colours are indirectly specified through the workstation colour table. When a colour is specified as an RGB triple, it is called direct colour. General colour is an abstraction that allows colour or direct colour to be specified as a single aspect. A general colour consists of a type and a value. If the type is indirect, then the value is interpreted as an index into the workstation colour table. If the type RGB, then the value is interpreted as an RGB value.
Using the SunPHIGS extension primitives and attributes, the colour for a primitive can be set using either attribute elements, such as SET POLYLINE COLOUR (3P+), or primitives with one or more colour as part of the primitive, such as POLYLINE SET 3 WITH DATA (3P+). In either case, the colour is specified as a general colour, so that an index or direct colour can be used. This functionality superseds the standard PHIGS functionality. Standard PHIGS primitives will be rendered using the PHIGS+ attributes, and standard PHIGS attributes affect PHIGS+ primitives. For example, SET POLYLINE COLOUR INDEX(3P) is equivalent to calling SET POLYLINE COLOUR(3P+) with the type set to indirect, both elements set the same attribute. The default colour for all primitives is indirect colour, index 1. If a primitive or attribute specifies direct colour on an indexed colour workstation indirect colour, index 1 will be used instead.
A Workstation’s Default Colour Table
The size of the colour table is workstation-dependent, but entries 0 and 1 are always defined. SunPHIGS predefines the colour table for all workstation’s to be:
| Index | Colour | Red | Green | Blue |
| 0 | black | 0.0 | 0.0 | 0.0 |
| 1 | white | 1.0 | 1.0 | 1.0 |
| 2 | red | 1.0 | 0.0 | 0.0 |
| 3 | green | 0.0 | 1.0 | 0.0 |
| 4 | blue | 0.0 | 0.0 | 1.0 |
| 5 | yellow | 1.0 | 1.0 | 0.0 |
| 6 | cyan | 0.0 | 1.0 | 1.0 |
| 7 | magenta | 1.0 | 0.0 | 1.0 |
| ≥8 | white | 1.0 | 1.0 | 1.0 |
Colour 0 is considered the background colour: PHIGS clears the display surface to this colour index as the first step in regenerating an image. The last colour in the colour table is considered the foreground colour by SunView on indexed colour or monochrome workstations. If the foreground and background colour indices are assigned the same colour representation, SunView will override the colormap values, substituting the Sun Tools foreground and background colours.
Setting a Workstation’s Colour Table
In PHIGS, an application can use the function SET COLOUR REPRESENTATION to specify a colour representation by a triple of real values whose meaning depends on the current colour model. SunPHIGS supports only the RGB colour model. The colour coordinate space is [0,1] in all three dimensions. No intensity is 0.0 and is mapped to SunView colour value 0. Maximum intensity is 1.0 and is mapped to SunView colour value 255. The RGB values for the default colour definitions are given above.
A true colour workstation has a workstation colour table and supports indirect colour.
A change to a colour representation will show up immediately on an indexed colour workstation and during the next regeneration on a true colour workstation.
A PHIGS application can inquire for any colour index, either the value it sets into the workstation’s colour table or the values that will be Realized on the display, after mapping to available SunView colour values. See INQUIRE COLOUR REPRESENTATION (3P).
Other colour models PHIGS defines are CIE (Commission Internationale de l’Eclairage’s universal colour definition system), HSV (Hue, Saturation, and Value), and HLS (Hue, Lightness, and Saturation).
Colour representations 0 and 1 can be set on a monochrome workstation, to produce either normal or inverse video.
Sizing a Workstation’s Colour Table
In PHIGS, a workstation’s colour table has a fixed size. SunPHIGS allows the size to be selected from any power of 2 up to and including 256. The default is 32 entries. Before opening the workstation, an application may select the size, using the workstation attribute PHIGS_COLOUR_TABLE_SIZE in C or PHIGSCLRTBLSIZE in FORTRAN. See WORKSTATION TYPE SET(3P).
On indexed colour workstations, SunView arbitrates the use of the hardware colormap among windows, by allocating to each window a logical colormap, called a colormap segment. Each colormap segment has a size that is some power of two, up to the total size of the hardware colormap. Because the hardware colormap has a fixed size, it should be considered a scarce resource.
When the total number of colour entries used by all the colormap segments of all the windows on the display (including SunPHIGS workstations) exceeds the total number of colour entries provided by the hardware, SunView loads the hardware colour table entries of the window under the mouse cursor. Other windows may display incorrect colours until the cursor enters them.
When SunPHIGS simulates a true colour workstation on a indexed colour frame buffer, SunPHIGS uses a special colormap that uses all 256 entries in the hardware colormap. This means that the mouse must be in a true colour workstation’s window for the proper colours to appear.
Colormap Double Buffering
On index colour workstations, setting the colours in the colormap is much faster than redrawing many thousands of pixels with a new value, therefore, colormap manipulation is the basis of many animation techniques. Colormap double buffering is one such technique. It is described in Double Buffering, Section 7.5 of the SunView Programmer’s Guide.
Double buffering is conceptually simple: first the complete picture is prepared, then the complete picture is displayed. This produces a smoother switch from one frame to the next. The viewer will not see the drawing of the new frame. When a double buffered workstation traverses the posted structures, they are rendered into the undisplayed buffer. When the traversal is done and the image in the undisplayed buffer is complete, the undisplayed buffer and displayed buffer are swapped. Quick update methods, the simulations permitted via SET DISPLAY UPDATE STATE(3P), are not double buffered by SunPHIGS.
SunPHIGS applications control double buffering using the workstation attribute PHIGS_DOUBLE_BUFFER in C (values are PHIGS_DBL_NONE, PHIGS_DBL_CMAP, and PHIGS_DBL_HW) and PHIGSDBLBUFFER in FORTRAN (values are PHIGSDBLNONE, PHIGSDBLCMAP, and PHIGSDBLHW). These values request no, colormap, and hardware double buffering alternatives, respectively. The default is no double buffering. See WORKSTATION TYPE SET (3P).
Colormap double buffering uses the colormap (a SunView colormap segment) and the frame buffer write-enable mask to treat a single frame buffer as two virtual buffers. SunPHIGS applications need not understand the details of implementation, except that the actual number of colormap segment entries required by the window is the square of the number of entries in the PHIGS colour table. (The size of the PHIGS colour table is the number of entries in one of the virtual buffers.)
A SunPHIGS workstation with an 8-entry colour table (3 bits) with colormap double buffering really uses 64 colours (6 bits) in its SunView colormap segment. A 16-entry (4-bit) colour table with colormap double buffering uses 256 colours (all 8 bits) of the frame buffer. The colormap will be swapped in and out as the cursor moves in and out of the window. A SunPHIGS workstation with a 32-entry colour table (which is the default) cannot use colormap double buffering. No window sharing a colormap segment (see below) can use colormap double buffering.
True colour workstations do not support colormap double buffering.
Hardware double buffering is an alternative technique that does not require extra colormap resources. It uses two physical frame buffers, only one of which is displayed. This allows double buffering of colour tables with up to 256 entries, on both indexed colour and true colour workstations. The extra frame buffer required is presently a CG5 graphics controller board. See CG5(4S) and Double Buffering Support in the SunView documentation. Hardware double buffering is also available on the CG9 true colour frame buffer. See CG9(4S).
Naming and Sharing a Colormap Segment
On indexed colour workstations, SunView allows multiple windows to share a single colormap segment, leaving more of the hardware colormap for other windows. If the colour values are to be loaded once and never changed, and another window can use the same colour table definitions, the colormap is a good candidate for sharing. On the other hand, colour tables used for animation, or for which colormap double buffering is enabled, should not be shared.
All windows that share a colormap segment must use the same name, which is simply a character string. SunPHIGS workstations can set the colormap segment name using the workstation attribute PHIGS_COLOURMAP_NAME in C or PHIGSCMAPNAME in FORTRAN. (See WORKSTATION TYPE SET (3P).) Other applications that wish to share the colormap segment can set the colormap segment name using pw_setcmsname. (See Sharing Colormap Segments, Section 7.5 of the SunView Programmer’s Guide)
If this workstation attribute is not used, SunPHIGS will assign the workstation a unique colormap segment name when it is opened. The workstation’s colormap segment name can be inquired using INQUIRE WORKSTATION CONNECTION AND TYPE (3P) to get the specific workstation type, and then WORKSTATION TYPE GET (3P).
True colour workstations on indexed colour frame buffers all share the same special colormap.
If a colormap segment is shared among windows, setting a colour representation will affect all windows sharing the same colormap segment. If a SunPHIGS workstation colormap is changed by another window’s action, the change is not reflected in the inquiry of its Realized colour representation.
Other Colour Attributes
SunPHIGS offers a Generalized Structure Element(GSE) for setting the highlight colour index entry in the PHIGS traversal state list. This entry will be used when highlighting subsequent output primitives. The default is the last colour in the colour table. A direct colour cannot be specified for highlighting.
Additional workstation attributes provide control over the cursor colour, and the border and banner colours of a Sun Tool workstation. Double buffering and the cursor’s raster operation also affect the observed cursor colour of a Sun Tool or Sun Canvas workstation. See WORKSTATION TYPE SET (3P).
SEE ALSO
INQUIRE COLOUR FACILITIES (3P)
INQUIRE COLOUR MODEL FACILITIES (3P)
INQUIRE DIRECT COLOUR MODEL FACILITIES (3P+)
SET COLOUR MODEL (3P)
SET COLOUR REPRESENTATION (3P)
INQUIRE COLOUR REPRESENTATION (3P)
INQUIRE PREDEFINED COLOUR REPRESENTATION (3P)
SET POLYLINE COLOUR INDEX (3P)
SET POLYLINE COLOUR (3P+)
SunPHIGS Release 1.1 — Last change: 10 July 1989