Skip to content
colors

rgbToXyz

The `rgbToXyz` function converts RGB values into the CIE XYZ color space using the D65 reference white. This is an intermediate step for converting to perceptual color spaces like Lab.

1 min read139 words

Function Signature

js

rgbToXyz(r: number, g: number, b: number): { X: number, Y: number, Z: number }

Parameters

  • r (number): Red channel value (0–255).
  • g (number): Green channel value (0–255).
  • b (number): Blue channel value (0–255).

Return Value

An object containing the XYZ tristimulus values, scaled to the D65 reference white:

js

{ X: number, Y: number, Z: number }

Examples

js

rgbToXyz(255, 102, 0);
// { X: ~48.4, Y: ~30.3, Z: ~4.0 }

rgbToXyz(0, 170, 255);
// { X: ~35.8, Y: ~41.4, Z: ~98.5 }

rgbToXyz(255, 255, 255);
// { X: ~95.0, Y: 100.0, Z: ~108.9 }

rgbToXyz(0, 0, 0);
// { X: 0, Y: 0, Z: 0 }

Conversion Details

  • Uses the sRGB color space as input with gamma correction (srgbToLinear).
  • Conversion is performed relative to the D65 reference white (Xn=95.047, Yn=100.0, Zn=108.883).
  • Output values are scaled by 100 for compatibility with Lab conversion.

Usage Notes

  • Often used internally by rgbToLab before conversion to the Lab color space.
  • XYZ is device-independent and serves as a standardized color reference.
  • Output values may include decimals and are not clamped to integers.

Previous

hslToRgb

Next

xyzToLab


Top tools

WorkspaceLinksySEO AnalyzerChromoQR Code Generator

ReadyTools

CareersContactTools
Pricing7 days free
SupportSecurityGuidesDocsBlogUpdatesLaraVault

Select Language

Set theme

ReadyTools

© 2026 ReadyTools. All rights reserved.