The RGB-XYZ Matrix Calculator
updated 9/16/2022
The World Wide Web Consortium has published standards for several alternatives to the sRGB color space for use in cascading style sheets. Two of these spaces (Display P3 and Rec. 2020) are relatively new, and RGB-XYZ conversion matrices are not readily available on the web. Below is a script that calculates matrices from the primaries and reference white of any RGB color space.
Enter x, y chromaticity coordinates for the primary colors of a color space (six or nine values in the form 0.6400, with or without Y values), and x, y or X, Y, Z coordinates for the reference white (two or three values). Separate the values with spaces or line breaks.
The ICC specification for connection space white is 0.9642 1.0 0.8249 (D50), and the recommended chromatic adaptation transform is Bradford.
Then click calculate to generate the RGB-XYZ matrices for the color space. The chromatic adaptation matrices between the source and destination reference whites, the adapted RGB-XYZ matrices, and the adapted primaries are also displayed.
primaries: xr yr [Yr] xg yg [Yg] xb yb [Yb]
reference white: xw yw or Xw Yw Zw
connection space white: xw yw or Xw Yw Zw
chromatic adaptation transform:
rx gx bx ry gy by rz gz bz
RGB–XYZ:
XYZ–RGB:
source–destination whites:
destination–source whites:
adapted RGB–XYZ:
adapted XYZ–RGB:
adapted primaries, xy[Y]
convert chromaticity coordinates xw yw to a tristimulus reference white Xw Yw Zw, or vice versa (leave one blank):
0 K clear
Color space specifications and implementation are somewhat disturbingly inexact. Published sources differ; and on inspection, .icc profiles have something of a “duct tape and baling wire” quality to them. A number of different P3 profiles are already available, made to different specifications. And the ProPhoto transfer function often seems to get lost in the shuffle. The W3C standards may provide uniformity for html-and-css-based applications and displays; but many other color spaces are widely used, especially for printed media, with a variety of published specifications. Here is a summary of data from the W3C, ICC, CIE, and brucelindbloom.com. With the calculator above, you can now use whatever specifications you want! And if you use Raw Therapee, you can even make your own .icc profiles!
The W3C specifications (see below for transfer functions):
Illuminant | x | y |
---|---|---|
D50 | 0.345704 | 0.358540 |
D65 | 0.3127 | 0.3290 |
Color Space | Transfer Function |
Reference White |
Red Primary | Green Primary | Blue Primary | |||
---|---|---|---|---|---|---|---|---|
x | y | x | y | x | y | |||
a98-rgb | 563/256 | D65 | 0.6400 | 0.3300 | 0.2100 | 0.7100 | 0.1500 | 0.0600 |
display-p3 | (sRGB) | D65 | 0.680 | 0.320 | 0.265 | 0.690 | 0.150 | 0.060 |
prophoto-rgb | (ProPhoto RGB) | D50 | 0.734699 | 0.265301 | 0.159597 | 0.840403 | 0.036598 | 0.000105 |
rec2020 | (Rec. 2020) | D65 | 0.708 | 0.292 | 0.170 | 0.797 | 0.131 | 0.046 |
srgb | (sRGB) | D65 | 0.640 | 0.330 | 0.300 | 0.600 | 0.150 | 0.060 |
ICC and CIE values:
Illuminant | X | Y | Z |
---|---|---|---|
D50 | 0.9642 | 1.0000 | 0.8249 |
D65 | 0.9504 | 1.0000 | 1.0889 |
Bruce Lindbloom:
Illuminant | X | Y | Z |
---|---|---|---|
A | 1.09850 | 1.00000 | 0.35585 |
B | 0.99072 | 1.00000 | 0.85223 |
C | 0.98074 | 1.00000 | 1.18232 |
D50 | 0.96422 | 1.00000 | 0.82521 |
D55 | 0.95682 | 1.00000 | 0.92149 |
D65 | 0.95047 | 1.00000 | 1.08883 |
D75 | 0.94972 | 1.00000 | 1.22638 |
E | 1.00000 | 1.00000 | 1.00000 |
F2 | 0.99186 | 1.00000 | 0.67393 |
F7 | 0.95041 | 1.00000 | 1.08747 |
F11 | 1.00962 | 1.00000 | 0.64350 |
Color Space | Transfer Function |
Reference White |
Red Primary | Green Primary | Blue Primary | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|
x | y | Y | x | y | Y | x | y | Y | |||
Adobe RGB (1998) | 2.2 | D65 | 0.6400 | 0.3300 | 0.297361 | 0.2100 | 0.7100 | 0.627355 | 0.1500 | 0.0600 | 0.075285 |
Apple RGB | 1.8 | D65 | 0.6250 | 0.3400 | 0.244634 | 0.2800 | 0.5950 | 0.672034 | 0.1550 | 0.0700 | 0.083332 |
Best RGB | 2.2 | D50 | 0.7347 | 0.2653 | 0.228457 | 0.2150 | 0.7750 | 0.737352 | 0.1300 | 0.0350 | 0.034191 |
Beta RGB | 2.2 | D50 | 0.6888 | 0.3112 | 0.303273 | 0.1986 | 0.7551 | 0.663786 | 0.1265 | 0.0352 | 0.032941 |
Bruce RGB | 2.2 | D65 | 0.6400 | 0.3300 | 0.240995 | 0.2800 | 0.6500 | 0.683554 | 0.1500 | 0.0600 | 0.075452 |
CIE RGB | 2.2 | E | 0.7350 | 0.2650 | 0.176204 | 0.2740 | 0.7170 | 0.812985 | 0.1670 | 0.0090 | 0.010811 |
ColorMatch RGB | 1.8 | D50 | 0.6300 | 0.3400 | 0.274884 | 0.2950 | 0.6050 | 0.658132 | 0.1500 | 0.0750 | 0.066985 |
Don RGB 4 | 2.2 | D50 | 0.6960 | 0.3000 | 0.278350 | 0.2150 | 0.7650 | 0.687970 | 0.1300 | 0.0350 | 0.033680 |
ECI RGB v2 | L* | D50 | 0.6700 | 0.3300 | 0.320250 | 0.2100 | 0.7100 | 0.602071 | 0.1400 | 0.0800 | 0.077679 |
Ekta Space PS5 | 2.2 | D50 | 0.6950 | 0.3050 | 0.260629 | 0.2600 | 0.7000 | 0.734946 | 0.1100 | 0.0050 | 0.004425 |
NTSC RGB | 2.2 | C | 0.6700 | 0.3300 | 0.298839 | 0.2100 | 0.7100 | 0.586811 | 0.1400 | 0.0800 | 0.114350 |
PAL/SECAM RGB | 2.2 | D65 | 0.6400 | 0.3300 | 0.222021 | 0.2900 | 0.6000 | 0.706645 | 0.1500 | 0.0600 | 0.071334 |
ProPhoto RGB | 1.8 | D50 | 0.7347 | 0.2653 | 0.288040 | 0.1596 | 0.8404 | 0.711874 | 0.0366 | 0.0001 | 0.000086 |
SMPTE-C RGB | 2.2 | D65 | 0.6300 | 0.3400 | 0.212395 | 0.3100 | 0.5950 | 0.701049 | 0.1550 | 0.0700 | 0.086556 |
sRGB | ≈2.2 | D65 | 0.6400 | 0.3300 | 0.212656 | 0.3000 | 0.6000 | 0.715158 | 0.1500 | 0.0600 | 0.072186 |
Wide Gamut RGB | 2.2 | D50 | 0.7350 | 0.2650 | 0.258187 | 0.1150 | 0.8260 | 0.724938 | 0.1570 | 0.0180 | 0.016875 |
Chromatic Adaptation Transforms:
Method | Transform |
---|---|
Bradford | 0.8951 0.2664 -0.1614 -0.7502 1.7135 0.0367 0.0389 -0.0685 1.0296 |
CMCCAT2000 | 0.7982 0.3389 -0.1371 -0.5918 1.5512 0.0406 0.0008 0.0239 0.9753 |
CIECAT02 | 0.7328 0.4296 -0.1624 -0.7036 1.6975 0.0061 0.0030 0.0136 0.9834 |
Sharp | 1.2694 -0.0988 -0.1706 -0.8364 1.8006 0.0357 0.0297 -0.0315 1.0018 |
Hunt–Pointer–Estevez | 0.38971 0.68898 -0.07868 -0.22981 1.18340 0.04641 0.00000 0.00000 1.00000 |
Von Kries | 0.40024 0.70760 -0.08081 -0.22630 1.16532 0.04570 0.00000 0.00000 0.91822 |
XYZ Scaling | 1.0000 0.0000 0.0000 0.0000 1.0000 0.0000 0.0000 0.0000 1.0000 |
Transfer functions, RGB-XYZ and XYZ-RGB (from the W3C and Bruce Lindbloom):
gamma only
c = Math.pow(c, gamma); c = Math.pow(c, 1/gamma);
sRGB
if (c <= 0.04045) c = c/12.92; else c = Math.pow((c + 0.055)/1.055, 2.4); if (c <= 0.0031308) c = 12.92 * c; else c = 1.055 * Math.pow(c, 1/2.4) - 0.055;
ProPhoto RGB
if (c <= 16*e) c = c/16; else c = Math.pow(c, 1.8); if (c <= e) c = 16 * c; else c = Math.pow(c, 1/1.8); e = 0.001953 // actual Kodak standard 1/512 // intent of the Kodak standard
Rec. 2020
abs = Math.abs(c); if (abs < beta * 4.5) c = c / 4.5; else c = (Math.pow((abs + alpha - 1) / alpha, 1/0.45)); if (c < beta) c = 4.5 * c; else c = alpha * Math.pow(c, 0.45) - (alpha - 1); alpha = 1.09929682680944 // 10 * Math.pow(beta, 0.55) beta = 0.018053968510807
L*
if (c <= 0.08) c = (100*c)/k; else c = Math.pow((c + 0.16)/1.16, 3); if (c <= e) c = (c*k)/100; else c = 1.16 * Math.pow(c, 1/3) - 0.16; e = 0.008856 // actual CIE standard 216/24389 // intent of the CIE standard k = 903.3 // actual CIE standard 24389/27 // intent of the CIE standard
The D50-adapted matrices for sRGB and Display P3, based on the W3C specifications for sRGB and Display P3, and the ICC specification for the D50 connection space:
sRGB
adapted RGB–XYZ: 0.4360413 0.3851129 0.1430458 0.2224845 0.7169051 0.0606104 0.0139202 0.0970672 0.7139126 adapted XYZ–RGB: 3.1341864 -1.6172090 -0.4906941 -0.9787485 1.9161301 0.0334334 0.0719639 -0.2289939 1.4057537
Display P3
adapted RGB–XYZ: 0.5151187 0.2919778 0.1571035 0.2411892 0.6922441 0.0665668 -0.0010505 0.0418791 0.7840713 adapted XYZ–RGB: 2.4039840 -0.9899069 -0.3976415 -0.8422229 1.7988437 0.0160354 0.0482059 -0.0974068 1.2740049
References:
https://www.w3.org/TR/css-color-4/#predefined
http://www.color.org/ICC1V42.pdf
http://www.color.org/chadtag.xalter
http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
http://www.brucelindbloom.com/index.html?WorkingSpaceInfo.html
http://www.brucelindbloom.com/index.html?Eqn_ChromAdapt.html
http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html
http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_RGB.html
https://developer.apple.com/documentation/coregraphics/cgcolorspace/1408916-displayp3
http://www.color.org/chardata/rgb/DCIP3.xalter
http://www.color.org/chardata/rgb/srgb.pdf
https://www.kodak.com/global/plugins/acrobat/en/professional/products/software/colorFlow/romm_rgb.pdf
https://acescentral.com/aces-documentation/
https://ninedegreesbelow.com/photography/well-behaved-profiles-quest.html