Previous Chapter LLUs Home Next Chapter IndexA 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.

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

**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.

**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.

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)

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

**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.].

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