Technical Authority•Core Calculation Engine

Color Calculation & Accessibility Methodology

A technical reference detailing the mathematical models, color space transformations, WCAG 2.2 algorithms, and gamut-mapping strategies implemented across the Palettekey platform.

1. Deterministic Client-Side Architecture

Palettekey executes all color space conversions, contrast audits, and color vision deficiency simulations client-side within the browser’s JavaScript runtime engine. Calculations use standard floating-point precision and fixed matrix transforms without reliance on remote web APIs.

This architectural choice ensures zero network latency, instant user feedback during dynamic slider adjustments, and absolute data privacy: no user-inputted hex codes, brand palettes, or uploaded images leave your local device.

2. Color Representation & Conversion Models

Palettekey supports transformations between device-dependent (sRGB, HEX, HSL, HSV, CMYK) and device-independent, perceptually uniform color spaces (CIE XYZ, CIELAB, CIELCH, OKLAB, OKLCH).

sRGB & HEX

Standard 8-bit per channel RGB space (0 to 255) used by modern displays. Hexadecimal notations map directly to 24-bit sRGB values.

HSL & HSV / HSB

Cylindrical transformations of sRGB. While useful for intuitive manual adjustments, they are non-perceptually uniform (e.g., pure yellow and pure blue both have HSL lightness of 50%, despite yellow appearing vastly brighter to human eyes).

CIELAB & CIELCH

CIE 1976 Lab space measures lightness (L*), green-red axis (a*), and blue-yellow axis (b*). CIELCH represents CIELAB in cylindrical coordinates (Lightness L*, Chroma C*, Hue h).

OKLab & OKLCH

Developed by Björn Ottosson in 2020. OKLCH provides superior perceptual uniformity compared to CIELAB, preventing hue shifts when modifying lightness and chroma. Used natively in modern CSS (CSS Color Module Level 4).

* Note on CMYK: Conversions between sRGB and CMYK in web environments are mathematical approximations intended for general design utility. Accurate prepress printing requires specialized ICC profile color management engines.

3. sRGB Linearization & D65 Illuminant

Before converting sRGB channels (8-bit Red, Green, Blue) to physical CIE XYZ coordinates or calculating relative luminance, 8-bit values are normalized (c = C / 255) and linearized using the standard sRGB piecewise transfer function:

c_linear = (c <= 0.04045) ? (c / 12.92) : Math.pow((c + 0.055) / 1.055, 2.4)

Linear RGB components are transformed into CIE XYZ coordinates using the D65 standard illuminant reference white point (Xn = 95.047, Yn = 100.000, Zn = 108.883), corresponding to daylight viewing conditions (6504 K).

4. WCAG 2.2 Relative Luminance & Contrast Ratios

Relative luminance (L) measures the visual brightness of a point in a color space normalized from 0.0 (pure black) to 1.0 (pure white). In accordance with W3C WCAG 2.2 guidelines, relative luminance is calculated using linearized sRGB components:

L = 0.2126 * R_linear + 0.7152 * G_linear + 0.0722 * B_linear

The contrast ratio between two colors is determined by:

Contrast Ratio = (L1 + 0.05) / (L2 + 0.05) [where L1 > L2]
StandardContextMin Contrast Ratio
WCAG AANormal Body Text (< 18pt / 24px)4.5 : 1
WCAG AALarge Text (≥ 18pt / 24px or bold 14pt)3.0 : 1
WCAG AAUI Components & Graphic Objects3.0 : 1
WCAG AAANormal Body Text (< 18pt)7.0 : 1
WCAG AAALarge Text (≥ 18pt)4.5 : 1

* Compliance Disclaimer: Passing a pairwise color contrast check is a critical component of digital accessibility, but does not guarantee that an entire web application is compliant with all WCAG success criteria (such as focus management, screen reader navigation, or structure).

5. Automated Accessible Color Solver Algorithm

When using Palettekey’s Accessible Color Generator, the system automatically calculates the nearest passing foreground or background color that meets a specified contrast target (e.g., 4.5:1 or 7.0:1) while minimizing perceptual color shift.

The algorithm operates as follows:

  1. Perceptual Space Initialization: Converts the target color into OKLCH space (Lightness L, Chroma C, Hue h) to isolate lightness while locking hue.
  2. Dual Direction Binary Search: Performs a binary search along both darker (L towards 0) and lighter (L towards 1) bounds for 24 iterations.
  3. sRGB Gamut Mapping: During each iteration, candidate OKLCH values are mapped back to standard sRGB bounds via chroma reduction if out-of-gamut.
  4. Revalidation & Delta E 2000 Minimization: Evaluates contrast ratio against the fixed background. The passing candidate that minimizes CIEDE2000 (Delta E 2000) perceptual difference from the original color is selected.

6. Color Vision Deficiency (CVD) Simulation

Palettekey simulates color blindness types using the LMS cone response transformation models established by Machado et al. Inputs in linearized sRGB space are transformed into Long (L), Medium (M), and Short (S) cone responses, modified according to specific deficiency matrices, and converted back to RGB space:

  • • Protanopia (Red-Blind): Simulates loss of L-cone sensitivity (~1.0% of males).
  • • Deuteranopia (Green-Blind): Simulates loss of M-cone sensitivity (~1.2% of males).
  • • Tritanopia (Blue-Blind): Simulates loss of S-cone sensitivity (~0.008% of population).
  • • Achromatopsia (Monochromacy): Maps color directly to relative luminance values (~0.003% of population).

* Disclaimer: CVD simulations are design evaluation tools and do not constitute clinical or diagnostic eye examinations.

Technical Standards & Formal References

  • • W3C Web Content Accessibility Guidelines (WCAG) 2.2 Specification (2023)
  • • W3C CSS Color Module Level 4 & 5 Candidate Recommendation
  • • Ottosson, B. (2020) "A perceptual color space for image processing" (OKLab specification)
  • • Sharma, G., Wu, W., and Dalal, E. N. (2005) "The CIEDE2000 color-difference formula: Implementation notes, supplementary test data, and mathematical observations"
  • • Machado, G. M., Oliveira, M. M., and Fernandes, L. A. (2009) "A Physiologically-based Model for Simulation of Color Vision Deficiency"