JavaScript EditorFree JavaScript Editor     Ajax Editor 



Main Page
Previous Page
Next Page

19.4. Color Space Conversions

A variety of color space conversions can be implemented in OpenGL shaders. In this section, we look at converting CIE colors to RGB, and vice versa. Conversions between other color spaces can be done similarly.

The CIE system was defined in 1931 by the Committee Internationale de L'Éclairage (CIE). It defines a device-independent color space based on the characteristics of human color perception. The CIE set up a hypothetical set of primaries, XYZ, that correspond to the way the eye's retina behaves. After experiments based on color matching by human observers, the CIE defined the primaries so that all visible light maps into a positive mixture of X, Y, and Z and so that Y correlates approximately to the apparent lightness of a color. The CIE system precisely defines any color. With this as a standard reference, colors can be transformed from the native (device-dependent) color space of one device to the native color space of another device.

A matrix formulation is convenient for performing such conversions. The HDTV standard as defined in ITU-R Recommendation BT.709 (1990) has the following CIE XYZ primaries and uses the D65 (natural sunlight) white point:

 

R

G

B

white

x

0.640

0.300

0.150

0.3127

y

0.330

0.600

0.060

0.3290

z

0.030

0.100

0.790

0.3582


Listing 19.1 shows the OpenGL shader code that transforms CIE color values to HDTV standard RGB values by using the D65 white point, and Listing 19.2 shows the reverse transformation. The matrices look like they are transposed compared to the colorimetry literature because in the OpenGL Shading Language, matrix values are provided in column major order.

Listing 19.1. OpenGL shader code to transform CIE values to RGB

const mat3 CIEtoRGBmat = mat3(3.240479, -0.969256,  0.055648,
                             -1.537150,  1.875992, -0.204043,
                             -0.498535,  0.041556,  1.057311);

vec3 rgbColor = cieColor * CIEtoRGBmat;

Listing 19.2. OpenGL shader code to transform RGB values to CIE

const mat3 RGBtoCIEmat = mat3(0.412453, 0.212671, 0.019334,
                              0.357580, 0.715160, 0.119193,
                              0.180423, 0.072169, 0.950227);

vec3 cieColor = rgbColor * RGBtoCIEmat;


Previous Page
Next Page




JavaScript EditorAjax Editor     JavaScript Editor