@ohos.graphics.colorSpaceManager (Color Space Management)
The colorSpaceManager module provides APIs for creating and managing color space objects and obtaining basic color space attributes.
NOTE
The initial APIs of this module are supported since API version 9. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Modules to Import
import colorSpaceManager from '@ohos.graphics.colorSpaceManager';
ColorSpace
Enumerates the color space types.
System capability: SystemCapability.Graphic.Graphic2D.ColorManager.Core
Name | Value | Description |
---|---|---|
UNKNOWN | 0 | Unknown type. |
ADOBE_RGB_1998 | 1 | Adobe RGB (1998). The conversion function is of the Adobe RGB (1998) type. The encoding range is of the Full type. |
DCI_P3 | 2 | DCI-P3. The conversion function is of the Gamma 2.6 type. The encoding range is of the Full type. |
DISPLAY_P3 | 3 | Display P3. The conversion function is of the SRGB type. The encoding range is of the Full type. |
SRGB | 4 | SRGB. The conversion function is of the SRGB type. The encoding range is of the Full type. This is the default color space type. |
CUSTOM | 5 | Custom type. |
BT70911+ | 6 | BT709. The conversion function is of the BT709 type. The encoding range is of the Full type. |
BT601_EBU11+ | 7 | BT601_P. The conversion function is of the BT709 type. The encoding range is of the Full type. |
BT601_SMPTE_C11+ | 8 | BT601_N. The conversion function is of the BT709 type. The encoding range is of the Full type. |
BT2020_HLG11+ | 9 | BT2020. The conversion function is of the HLG type. The encoding range is of the Full type. |
BT2020_PQ11+ | 10 | BT2020. The conversion function is of the PQ type. The encoding range is of the Full type. |
P3_HLG11+ | 11 | Display P3. The conversion function is of the HLG type. The encoding range is of the Full type. |
P3_PQ11+ | 12 | Display P3. The conversion function is of the PQ type. The encoding range is of the Full type. |
ADOBE_RGB_1998_LIMIT11+ | 13 | Adobe RGB (1998). The conversion function is of the Adobe RGB (1998) type. The encoding range is of the Limit type. |
DISPLAY_P3_LIMIT11+ | 14 | Display P3. The conversion function is of the SRGB type. The encoding range is of the Limit type. |
SRGB_LIMIT11+ | 15 | SRGB. The conversion function is of the SRGB type. The encoding range is of the Limit type. |
BT709_LIMIT11+ | 16 | BT709. The conversion function is of the BT709 type. The encoding range is of the Limit type. |
BT601_EBU_LIMIT11+ | 17 | BT601_P. The conversion function is of the BT709 type. The encoding range is of the Limit type. |
BT601_SMPTE_C_LIMIT11+ | 18 | BT601_N. The conversion function is of the BT709 type. The encoding range is of the Limit type. |
BT2020_HLG_LIMIT11+ | 19 | BT2020. The conversion function is of the HLG type. The encoding range is of the Limit type. |
BT2020_PQ_LIMIT11+ | 20 | BT2020. The conversion function is of the PQ type. The encoding range is of the Limit type. |
P3_HLG_LIMIT11+ | 21 | Display P3. The conversion function is of the HLG type. The encoding range is of the Limit type. |
P3_PQ_LIMIT11+ | 22 | Display P3. The conversion function is of the PQ type. The encoding range is of the Limit type. |
LINEAR_P311+ | 23 | Display P3. The conversion function is of the Linear type. |
LINEAR_SRGB11+ | 24 | SRGB. The conversion function is of the Linear type. |
LINEAR_BT70911+ | 24 | Same as that of LINEAR_SRGB. BT709. The conversion function is of the Linear type. |
LINEAR_BT202011+ | 25 | BT2020. The conversion function is of the Linear type. |
DISPLAY_SRGB11+ | 4 | Same as that of SRGB. SRGB. The conversion function is of the SRGB type. The encoding range is of the Full type. |
DISPLAY_P3_SRGB11+ | 3 | Same as that of DISPLAY_P3. Display P3. The conversion function is of the SRGB type. The encoding range is of the Full type. |
DISPLAY_P3_HLG11+ | 11 | Same as that of P3_HLG. Display P3. The conversion function is of the HLG type. The encoding range is of the Full type. |
DISPLAY_P3_PQ11+ | 12 | Same as that of P3_PQ. Display P3. The conversion function is of the PQ type. The encoding range is of the Full type. |
ColorSpacePrimaries
Defines the color space primaries. A color space is defined by chromaticity coordinates of the red, green, and blue additive primaries, the white point, and the gamma.
System capability: SystemCapability.Graphic.Graphic2D.ColorManager.Core
Name | Type | Readable | Writable | Description |
---|---|---|---|---|
redX | number | Yes | Yes | X coordinate of the red color in the color space. |
redY | number | Yes | Yes | Y coordinate of the red color in the color space. |
greenX | number | Yes | Yes | X coordinate of the green color in the color space. |
greenY | number | Yes | Yes | Y coordinate of the green color in the color space. |
blueX | number | Yes | Yes | X coordinate of the blue color in the color space. |
blueY | number | Yes | Yes | Y coordinate of the blue color in the color space. |
whitePointX | number | Yes | Yes | X coordinate of the white point in the color space. |
whitePointY | number | Yes | Yes | Y coordinate of the white point in the color space. |
colorSpaceManager.create
create(colorSpaceName: ColorSpace): ColorSpaceManager
Creates a standard color space object.
System capability: SystemCapability.Graphic.Graphic2D.ColorManager.Core
Parameters
Parameter | Type | Mandatory | Description |
---|---|---|---|
colorSpaceName | ColorSpace | Yes | Type of the color space. UNKNOWN and CUSTOM cannot be used when creating standard color space objects. |
Return value
Type | Description |
---|---|
ColorSpaceManager | Color space object created. |
Error codes
For details about the error codes, see colorSpaceManager Error Codes.
ID | Error Message |
---|---|
18600001 | Parameter value is abnormal. |
Example
let colorSpace: colorSpaceManager.ColorSpaceManager;
try {
colorSpace = colorSpaceManager.create(colorSpaceManager.ColorSpace.SRGB);
} catch (err) {
console.log(`Failed to create SRGB colorSpace. Cause: ` + JSON.stringify(err));
}
colorSpaceManager.create
create(primaries: ColorSpacePrimaries, gamma: number): ColorSpaceManager
Creates a custom color space object.
System capability: SystemCapability.Graphic.Graphic2D.ColorManager.Core
Parameters
Parameter | Type | Mandatory | Description |
---|---|---|---|
primaries | ColorSpacePrimaries | Yes | Primaries of the color space. |
gamma | number | Yes | Gamma of the color space. |
Return value
Type | Description |
---|---|
ColorSpaceManager | Color space object created. The color space type is CUSTOM of ColorSpace. |
Error codes
For details about the error codes, see colorSpaceManager Error Codes.
ID | Error Message |
---|---|
18600001 | Parameter value is abnormal. |
Example
let colorSpace: colorSpaceManager.ColorSpaceManager;
try {
let primaries: colorSpaceManager.ColorSpacePrimaries = {
redX: 0.1,
redY: 0.1,
greenX: 0.2,
greenY: 0.2,
blueX: 0.3,
blueY: 0.3,
whitePointX: 0.4,
whitePointY: 0.4
};
let gamma = 2.2;
colorSpace = colorSpaceManager.create(primaries, gamma);
} catch (err) {
console.log(`Failed to create colorSpace with customized primaries and gamma. Cause: ` + JSON.stringify(err));
}
ColorSpaceManager
Implements management of color space objects.
Before calling any of the following APIs, you must use create() to create a color space manager.
getColorSpaceName
getColorSpaceName(): ColorSpace
Obtains the color space type.
System capability: SystemCapability.Graphic.Graphic2D.ColorManager.Core
Return value
Type | Description |
---|---|
ColorSpace | Color space type. |
Error codes
For details about the error codes, see colorSpaceManager Error Codes.
ID | Error Message |
---|---|
18600001 | Parameter value is abnormal. |
Example
try {
colorSpace.getColorSpaceName();
} catch (err) {
console.log(`Fail to get colorSpace's name. Cause: ` + JSON.stringify(err));
}
getWhitePoint
getWhitePoint(): Array<number>
Obtains the coordinates of the white point in the color space.
System capability: SystemCapability.Graphic.Graphic2D.ColorManager.Core
Return value
Type | Description |
---|---|
Array<number> | Coordinates [x, y] of the white point. |
Error codes
For details about the error codes, see colorSpaceManager Error Codes.
ID | Error Message |
---|---|
18600001 | Parameter value is abnormal. |
Example
try {
colorSpace.getWhitePoint();
} catch (err) {
console.log(`Failed to get white point. Cause: ` + JSON.stringify(err));
}
getGamma
getGamma(): number
Obtains the gamma of the color space.
System capability: SystemCapability.Graphic.Graphic2D.ColorManager.Core
Return value
Type | Description |
---|---|
number | Gamma of the color space. |
Error codes
For details about the error codes, see colorSpaceManager Error Codes.
ID | Error Message |
---|---|
18600001 | Parameter value is abnormal. |
Example
try {
colorSpace.getGamma();
} catch (err) {
console.log(`Failed to get gamma. Cause: ` + JSON.stringify(err));
}