Chapter 7: Color tables and color mapping systems

Previous Chapter          LLUs Home         Next Chapter          Index
A color table is a table that associates color values, such as cyan or yellow, with nonnegative integer indices. This chapter describes how to define color tables in NCAR Graphics and how the associated color indices are used to assign colors to graphics primitives like polylines, polymarkers, text, and filled areas.

In this chapter you will also see how to convert from one "color space" to another.

A color space, or color model, is a three-dimensional coordinate system where coordinates in that system represent colors. There are many popular color spaces; some of them are more suitable for hardware and others are more suitable for human conceptualizing. Two of the more common color models used by hardware are the RGB (red, green, blue) model used by most workstations and the YIQ model used by broadcast TV. Two of the more popular models for human conceptualizing are the HLS (hue, lightness, saturation) and HSV (hue, saturation, value) models.

This chapter describes utilities for converting between the RGB, HLS, HSV, and YIQ models. For a complete description of these models consult the book Computer Graphics by James D. Foley, Andries van Dam, Steven K. Feiner, and John F. Hughes, (Addison-Wesley, 1990).

To provide sample graphics plots for the functions in this chapter would require the use of color; for this reason such plots have not been provided.

This chapter uses the notation [x,y), where x and y are real numbers, to mean the set of real numbers between x and y, including x, but not including y.

Table of color table and color mapping user entry points

This chapter lists entry points for setting up color tables and for converting between several systems for representing color values. The table also lists entry points for assigning colors to the GKS primitives of polyline, polymarker, text and filled area.

Color tables

GSCR
Sets color representation. Used to set up color tables.

Assigning colors to GKS primitives

GSPLCI
Sets polyline color index. Specifies a color index to be used for GKS polylines.

GSPMCI
Sets polymarker color index. Specifies a color index to be used for GKS polymarkers.

GSTXCI
Sets text color index. Specifies a color index to be used for GKS text.

GSFACI
Sets fill area color index. Specifies a color index to be used for GKS filled areas.

Converting between color systems

HLSRGB
Converts from the hue, lightness, saturation color model to the red, green, blue color model.

RGBHLS
Converts from the red, green, blue color model to the hue, lightness, saturation model.

HSVRGB
Converts from the hue, saturation, value color model to the red, green, blue model.

RGBHSV
Converts from the red, green, blue color model to the hue, saturation, value model.

YIQRGB
Converts from the YIQ color model to the red, green, blue model.

RGBYIQ
Converts from the red, green, blue color model to the YIQ model.

Color tables

Color in NCAR Graphics uses an indexing scheme. A table is set up to associate actual color values with indices, and the indices are used to tell NCAR Graphics what color value to use. The GKS function "Set Color Representation," GSCR, is used to set up the color tables. There are various ways to specify color information in specific situations, but all ways ultimately will use color indices as set up in a color table. In some situations, a given function will inherit its color from the underlying GKS specifications. For example, when drawing lines with LINE, the lines will be drawn using the current GKS line color. This module shows how to specify colors for the basic GKS primitives of polylines (GSPLCI), filled areas (GSFACI), text (GSTXCI), and polymarkers (GSPMCI). For specifying colors in other situations, consult the documentation on color in the appropriate chapter.

Code segment from fcce01.f

1       CALL GSCR(IWK, 0, 0.0, 0.0, 0.0)
2       CALL GSCR(IWK, 1, 1.0, 1.0, 1.0)
3       CALL GSCR(IWK, 2, 1.0, 0.0, 0.0)
4       CALL GSCR(IWK, 3, 0.0, 1.0, 0.0)
5       CALL GSCR(IWK, 4, 1.0, 1.0, 0.0)
6       CALL GSCR(IWK, 5, 0.0, 1.0, 1.0)
7       CALL GSPLCI(3)
8       CALL GPL(5,X1,Y)
9       CALL GSMKSC(4.)
10      CALL GPM(1,.5,.25)
11      CALL GSTXCI(4)
12      CALL GTX(0.5,0.5,'Text')
13      CALL GSFACI(5)
14      CALL GSFAIS(1)
15      CALL GFA(5,X2,Y)
16      CALL GSPMCI(2)
17      CALL GPM(1,.5,.75)

Synopsis

      CALL GSCR (WKID, CI, CR, CG, CB)
      CALL GSPLCI (CI)
      CALL GSTXCI (CI)
      CALL GSFACI (CI)
      CALL GSPMCI (CI)

Arguments

WKID
Integer, Input ---A number assigned to a workstation as an identifier that is to be used in subsequent calls to GKS functions that require a workstation identifier. In NCAR GKS, WKID can be any nonnegative integer.

CI
Integer, Input ---A color index. CI can be any nonnegative integer and can be used in any subsequent calls that require a color index.

CR
Real, Input ---A number between 0. and 1. (inclusive) that gives an intensity for the red component of the color value that is to be associated with the color index CI.

CG
Real, Input ---A number between 0. and 1. (inclusive) that gives an intensity for the green component of the color value that is to be associated with the color index CI.

CB
Real, Input ---A number between 0. and 1. (inclusive) that gives an intensity for the blue component of the color value that is to be associated with the color index CI.

H
Real, Input for HLSRGB; Output for RGBHLS---A value for hue in the HLS color space. H is in the range [0.,360.).

L
Real, Input for HLSRGB; Output for RGBHLS---A value for lightness in the HLS color space. L is in the range [0.,100.].

S
Real, Input for HLSRGB; Output for RGBHLS---A value for saturation in the HLS color space. S is in the range [0.,100.].

R
Real, Input for RGBHLS; Output for HLSRGB---A value for red in the RGB color space. R is in the range [0.,1.].

G
Real, Input for RGBHLS; Output for HLSRGB---A value for green in the RGB color space. G is in the range [0.,1.].

B
Real, Input for RGBHLS; Output for HLSRGB---A value for blue in the RGB color space. B is in the range [0.,1.].

H
Real, Input for HSVRGB; Output for RGBHSV---A value for hue in the HSV color space. H is in the range [0.,360.).

S
Real, Input for HSVRGB; Output for RGBHSV---A value for lightness in the HSV color space. S is in the range [0.,1.].

V
Real, Input for HSVRGB; Output for RGBHSV---A value for the value component in the HSV color space. V is in the range [0.,1.].

R
Real, Input for RGBHSV; Output for HSVRGB ---A value for red in the RGB color space. R is in the range [0.,1.].

G
Real, Input for RGBHSV; Output for HSVRGB ---A value for green in the RGB color space. G is in the range [0.,1.].

B
Real, Input for RGBHSV; Output for HSVRGB ---A value for blue in the RGB color space. B is in the range [0.,1.].

Y
Real, Input for YIQRGB; Output for RGBYIQ---A value for the Y component of the YIQ color space. Y is in the range [0.,1.].

I
Real, Input for YIQRGB; Output for RGBYIQ---A value for the I component of the YIQ color space. I is in the range [-.6,.6].

Q
Real, Input for YIQRGB; Output for RGBYIQ---A value for the Q component of the YIQ color space. Q is in the range [-.52,.52].

R
Real, Input for RGBYIQ; Output for YIQRGB ---A value for red in the RGB color space. R is in the range [0.,1.].

G
Real, Input for RGBYIQ; Output for YIQRGB ---A value for green in the RGB color space. G is in the range [0.,1.].

B
Real, Input for RGBYIQ; Output for YIQRGB ---A value for blue in the RGB color space. B is in the range [0.,1.].

Discussion

Lines 1 through 3 of code segment 3 from fcce02.f assign values to the Y, I, and Q components of the YIQ color space that correspond to red=0., green=1., and blue=0. in the RGB space. The result of the call in line 4 is that R will be returned as 0., G as 1., and B as 0.

Lines 5 through 7 of code segment 3 from fcce02.f assign values to red, green, and blue in the RGB space that correspond to values of Y=1., I=0., and Q=0. in the YIQ space. The result of the call in line 8 is that Y will be returned as 1., RI will be returned as 0., and Q will be returned as 0. Y is the grayscale component of a color TV signal that is shown on black and white TVs.

Previous Chapter          LLUs Home         Next Chapter          Index