If you sample a wall color from a room photograph—say #DCE3E6 —and search a database of 15,000 commercial paint swatches using standard RGB Euclidean distance, the top result frequently looks visibly purple or green once rolled onto drywall.
1. Non-Linearity of sRGB Gamma Encoding
Standard hex codes live in gamma-compressed sRGB space rather than linear light intensity. Before comparing two colors, each channel C_srgb in [0, 1] must be linearized:
const linearize = ( c ) => ( c <= 0.04045 ? c / 12.92 : Math . pow ( ( c + 0.055 ) / 1.055 , 2.4 ) ) ;
Enter fullscreen mode
Exit fullscreen mode
Once linearized, the relative luminance Y = 0.2126 * R + 0.7152 * G + 0.0722 * B maps directly to the paint industry's Light Reflectance Value (LRV, 0–100) printed on the back of fan decks from Sherwin-Williams, Benjamin Moore, and Behr.
2.…