The Problem with RGB
If you've ever tried to find the "closest" color from a limited palette, you probably used Euclidean distance in RGB space:
function rgbDistance ( c1 , c2 ) { return Math . sqrt ( ( c1 . r - c2 . r ) ** 2 + ( c1 . g - c2 . g ) ** 2 + ( c1 . b - c2 . b ) ** 2 ); }
Enter fullscreen mode
Exit fullscreen mode
This looks reasonable. It's fast, it's simple, and it's completely wrong.
Why RGB Distance Lies
RGB is not a perceptually uniform color space. A distance of 50 units between two reds looks very different from a distance of 50 units between two blues. The human eye is much more sensitive to green variations than blue variations, but RGB treats them equally.
The result: algorithms that pick "mathematically closest" colors that look obviously wrong to humans. Green skin tones. Muddy hair. Flat shadows.
Enter OKLab
OKLab was created by Björn Ottosson in 2020.…