Gamut Mapping
Color Gamut Mapping
The process of converting colors from one color space to another while handling out-of-gamut colors gracefully.
Техническая деталь
A gamut mapping defines a gamut — the total range of reproducible colors. sRGB covers approximately 35% of the visible spectrum and is the web standard. Display P3 (used by Apple devices) covers ~25% more than sRGB. Adobe RGB targets professional photography and print workflows. CMYK (Cyan/Magenta/Yellow/Key) is subtractive and used for print, while RGB is additive and used for screens. Converting between color spaces can cause gamut clipping where out-of-range colors snap to their nearest representable value.
Пример
```javascript
// Convert RGB to HSL
function rgbToHsl(r, g, b) {
r /= 255; g /= 255; b /= 255;
const max = Math.max(r, g, b), min = Math.min(r, g, b);
const l = (max + min) / 2;
let h = 0, s = 0;
if (max !== min) {
const d = max - min;
s = l > 0.5 ? d/(2-max-min) : d/(max+min);
}
return [h, s, l];
}
```