This page documents the scientific methods, algorithms, and constants used in hexcode.info for color calculations and simulations.
\[ \begin{bmatrix} X \\ Y \\ Z \end{bmatrix} = \begin{bmatrix} 0.4124564 & 0.3575761 & 0.1804375 \\ 0.2126729 & 0.7151522 & 0.0721750 \\ 0.0193339 & 0.1191920 & 0.9503041 \end{bmatrix} \begin{bmatrix} R \\ G \\ B \end{bmatrix} \]
Standard sRGB to CIE XYZ transformation matrix using D65 standard illuminant (6504K). Input RGB values are linearized using sRGB gamma correction before transformation.
\[ \operatorname{Linear}(u) = \begin{cases} \dfrac{u}{12.92}, & u \le 0.04045 \\ \left(\dfrac{u + 0.055}{1.055}\right)^{2.4}, & u > 0.04045 \end{cases} \]
\[ \operatorname{sRGB}(u) = \begin{cases} 12.92u, & u \le 0.0031308 \\ 1.055u^{1/2.4} - 0.055, & u > 0.0031308 \end{cases} \]
Standard sRGB gamma correction functions for linearization and encoding.
OKLab is a perceptually uniform color space designed for image processing applications. Our implementation follows the original specification by Björn Ottosson.
src/utils/oklab.tsIndustry-standard color difference calculation using the CIEDE2000 formula. Provides perceptually uniform color difference measurements.
src/utils/colorMath.ts:315Physiologically accurate color vision deficiency simulation using LMS cone response matrices. Supports protanopia, deuteranopia, tritanopia, and their anomalous variants.
src/utils/colorMath.ts:437Standard WCAG contrast calculation using relative luminance (Y component in XYZ).
src/utils/colorMath.ts:389Modern perceptual contrast algorithm designed for digital displays. Provides more accurate readability predictions than WCAG contrast ratios.
src/utils/apca.tsAll calculations are implemented in TypeScript with comprehensive test coverage. The source code is available in the following modules:
src/utils/colorMath.ts - Core color space conversions and calculationssrc/utils/oklab.ts - OKLab color space implementationsrc/utils/apca.ts - APCA contrast calculationssrc/__tests__/colorMath.spec.ts - Comprehensive test suiteAll color calculations are validated against reference implementations and established test datasets. The test suite includes round-trip conversions, edge cases, and comparison with industry standards.