How to Convert LCH to HEX
Converting LCH (Lightness, Chroma, Hue) to a HEX code requires translating a perceptually uniform, wide-gamut color space into the standard, sRGB-bound format used by legacy web browsers.
The Gamut Clipping Problem
LCH is capable of describing any color the human eye can see. HEX codes are strictly tied to the sRGB color space, which is much smaller. If you have a highly vibrant LCH color (like a neon green with a high Chroma value), it physically cannot be represented as a HEX code.
During the conversion process, if the LCH color falls outside the sRGB gamut, the algorithm must "clamp" or map the color to the closest available sRGB value. This means the resulting HEX code will look slightly less vibrant than the original LCH color.
The Conversion Pipeline
To get from LCH to HEX, the color must pass through several intermediate spaces:
- LCH to Lab: Trigonometry is used to convert the Chroma and Hue angle back into the
aandbCartesian coordinates of CIELAB. - Lab to XYZ: The Lab values are transformed into the CIE XYZ reference space.
- XYZ to Linear RGB: Matrix multiplication converts the XYZ coordinates into linear red, green, and blue light.
- Gamma Correction: The linear RGB values are passed through the sRGB gamma curve.
- RGB to HEX: The final RGB decimals (0-255) are converted into base-16 hexadecimal strings and combined.