Learn R Programming

colorSpec (version 0.5-2)

standardRGB: Convert from XYZ to some standard RGB spaces

Description

To display an XYZ value, it typically must be converted to a standard RGB space. This is the function to do it.

Usage

RGBfromXYZ( XYZ, space )

Arguments

XYZ
a 3-vector, or a matrix with 3 columns with XYZs in the rows
space
the name of the RGB space - either 'sRGB' or 'Adobe RGB'. The match is case-insensitive, and spaces in the string are ignored.

Value

  • An Mx3 matrix where M is the number of rows in XYZ, or M=1 if XYZ is a 3-vector. Each row of the returned matrix is filled with linear RGB in the appropriate RGB space. Values outside the unit cube are not clipped. To compute non-linear display RGB, see DisplayRGBfromLinearRGB. In case of error the function returns NULL.

source

Lindbloom, Bruce. RGB/XYZ Matrices. http://brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html Wikipedia. sRGB. http://en.wikipedia.org/wiki/SRGB Wikipedia. Adobe RGB. http://en.wikipedia.org/wiki/Adobe_RGB_color_space

Details

The input XYZ is multiplied by the appropriate 3x3 conversion matrix (for sRGB or Adobe RGB). These matrices are taken from Lindbloom and not from the corresponding Wikipedia articles; for the reason see Note.

See Also

D65, officialXYZ, DisplayRGBfromLinearRGB

Examples

Run this code
RGBfromXYZ( officialXYZ('D65'), 'sRGB' )
#      R G B
# [1,] 1 1 1    # not really 1s, but difference < 1.e-7

RGBfromXYZ( c(.3127,0.3290,0.3583)/0.3290, 'sRGB' )
#              R        G       B
# [1,] 0.9998409 1.000023 1.00024    difference > 1.e-5

Run the code above in your browser using DataLab