Display P3 color space conversions and utilities.
Display P3 is a wide-gamut RGB color space used by Apple devices and
increasingly supported in modern web browsers.
Display P3 uses DCI-P3 primaries adapted to D65 white point.
This implementation follows the CSS Color Module Level 4 specification.
Methods
(static) benefitsFromDisplayP3(srgbColor) → {boolean}
Check if an sRGB color utilizes the extended Display P3 gamut
Parameters:
Name | Type | Description |
---|---|---|
srgbColor |
SrgbColor | sRGB color to check |
- Source:
Returns:
True if converting to P3 provides a wider gamut representation
- Type
- boolean
(static) displayP3ToLinearDisplayP3(p3Color) → {LinearDisplayP3Color}
Convert Display P3 to linear Display P3
Parameters:
Name | Type | Description |
---|---|---|
p3Color |
DisplayP3Color | Display P3 color with gamma correction |
- Source:
Returns:
Linear Display P3 color
- Type
- LinearDisplayP3Color
(static) displayP3ToSrgb(p3Color) → {SrgbColor}
Convert Display P3 to sRGB
Note: Display P3 has a wider gamut than sRGB, so colors may be clipped
Parameters:
Name | Type | Description |
---|---|---|
p3Color |
DisplayP3Color | Display P3 color |
- Source:
Returns:
sRGB color (may be clipped if out of gamut)
- Type
- SrgbColor
(static) formatDisplayP3ForCSS(p3Color, precisionopt) → {string}
Format a Display P3 color for CSS Color Module Level 4
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
p3Color |
DisplayP3Color | Display P3 color | ||
precision |
number |
<optional> |
4 | Decimal precision |
- Source:
Returns:
CSS color() function string
- Type
- string
Example
formatDisplayP3ForCSS({ r: 0.9175, g: 0.2003, b: 0.1386 })
// Returns: "color(display-p3 0.9175 0.2003 0.1386)"
(static) isDisplayP3InSrgbGamut(p3Color) → {boolean}
Check if a Display P3 color is within sRGB gamut
Parameters:
Name | Type | Description |
---|---|---|
p3Color |
DisplayP3Color | Display P3 color to check |
- Source:
Returns:
True if the color can be represented in sRGB
- Type
- boolean
(static) linearDisplayP3ToDisplayP3(linearP3Color) → {DisplayP3Color}
Convert linear Display P3 to Display P3 with gamma correction
Parameters:
Name | Type | Description |
---|---|---|
linearP3Color |
LinearDisplayP3Color | Linear Display P3 color |
- Source:
Returns:
Display P3 color with gamma correction
- Type
- DisplayP3Color
(static) linearDisplayP3ToXyz(linearP3Color) → {Object}
Convert linear Display P3 to XYZ (D65)
Parameters:
Name | Type | Description |
---|---|---|
linearP3Color |
LinearDisplayP3Color | Linear Display P3 color |
- Source:
Returns:
XYZ color
- Type
- Object
(static) parseDisplayP3FromCSS(cssString) → {DisplayP3Color|null}
Parse a CSS Color Module Level 4 display-p3 color
Parameters:
Name | Type | Description |
---|---|---|
cssString |
string | CSS color() function string |
- Source:
Returns:
Display P3 color or null if invalid
- Type
- DisplayP3Color | null
Example
parseDisplayP3FromCSS("color(display-p3 0.9175 0.2003 0.1386)")
// Returns: { r: 0.9175, g: 0.2003, b: 0.1386 }
(static) srgbToDisplayP3(srgbColor) → {DisplayP3Color}
Convert sRGB to Display P3
Parameters:
Name | Type | Description |
---|---|---|
srgbColor |
SrgbColor | sRGB color |
- Source:
Returns:
Display P3 color
- Type
- DisplayP3Color
Example
// Convert pure red from sRGB to Display P3
const p3Red = srgbToDisplayP3({ r: 1, g: 0, b: 0 });
// Result: { r: 0.9175, g: 0.2003, b: 0.1386 }
(static) xyzToLinearDisplayP3(xyzColor) → {LinearDisplayP3Color}
Convert XYZ (D65) to linear Display P3
Parameters:
Name | Type | Description |
---|---|---|
xyzColor |
Object | XYZ color |
- Source:
Returns:
Linear Display P3 color
- Type
- LinearDisplayP3Color
Type Definitions
DisplayP3Color
Type:
- Object
- Source:
LinearDisplayP3Color
Type:
- Object
- Source: