# Basic sRGB Math

The sRGB color space is based on the monitor characteristics expected in a dimly lit office.  It has been standardized by the International Electrotechnical Commission (IEC) as IEC 61966-2-1.  The official specification should be purchased from the IEC to assure that you have the most recent and correct information.  This information is provided as an informative reference only.

The expected colors of the red, green, and blue monitor phosphors and the white setting of an sRGB monitor are specified in chromaticity values below.  The non-linearity or gamma of the monitor is 2.2.  The formulas used to convert between sRGB and XYZ tristimulus values are also included below.

 CIE chromaticities for ITU-R BT.709 reference primaries and CIE standard illuminant Red Green Blue D65 White Point x 0.6400 0.3000 0.1500 0.3127 y 0.3300 0.6000 0.0600 0.3290 z 0.0300 0.1000 0.7900 0.3583

### Converting XYZ to sRGB

The red, green and blue phosphor chromaticities and D65 white point results in the following relationship between D65 tristimulus values and linear RGB values:

Any values greater than 1.0 or less than 0.0 are clipped to 1.0 and 0.0 respectively.

The linear RGB values are transformed to nonlinear sR'G'B' values as follows:

If  R,G, B 0.0031308

R’sRGB = 12.92 R

G’sRGB = 12.92 G

B’sRGB = 12.92 B

else if  R,G, B > 0.0031308

R’sRGB = 1.055 R(1.0/2.4) – 0.055

G’sRGB = 1.055 G(1.0/2.4) – 0.055

B’sRGB = 1.055 B(1.0/2.4) – 0.055

The nonlinear sR’G’B’ values are then converted into 8 bit integers by:

R8bit = round(255.0 R’sRGB)

G8bit = round(255.0 G’sRGB)

B8bit = round(255.0 B’sRGB)

### Converting sRGB to XYZ

The 8 bit integer sRGB values are converted to floating point non-linear sR'G'B' values as follows:

R’sRGB = R8bit / 255.0

G’sRGB = G8bit / 255.0

B’sRGB = B8bit / 255.0

The nonlinear sR'G'B' values are transformed to linear R,G, B values by:

If  R’sRGB,GsRGB, BsRGB 0.04045

R =  R’sRGB 12.92

G =  GsRGB 12.92

B =  BsRGB 12.92

else if  R’sRGB,GsRGB, BsRGB > 0.04045

R = ((R’sRGB + 0.055) / 1.055)2.4

G = ((G’sRGB + 0.055) / 1.055)2.4

B = ((B’sRGB + 0.055) / 1.055)2.4

Then convert to XYZ by:

 R G B

 *

 sRGB Viewing Environment Summary * Condition sRGB Display Luminance level 80 cd/m2 Display White Point x = 0.3127, y = 0.3290 (D65) Display model offset (R, G and B) 0.0 Display input/output characteristic 2.2 Reference ambient illuminance level 64 lux Reference Ambient White Point x = 0.3457, y = 0.3585 (D50) Reference Veiling Glare 0.2 cd m-2

*Please refer to the official IEC 61966-2-1 specification for more of the viewing environment details and descriptions.