1# @ohos.graphics.colorSpaceManager (Color Space Management) 2 3The **colorSpaceManager** module provides APIs for creating and managing color space objects and obtaining basic color space attributes. 4 5> **NOTE** 6> 7> 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. 8 9## Modules to Import 10 11```js 12import colorSpaceManager from '@ohos.graphics.colorSpaceManager'; 13``` 14 15## ColorSpace 16 17Enumerates the color space types. 18 19**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core 20 21| Name | Value | Description | 22| --------------------------- | ------ | ----------------------- | 23| UNKNOWN | 0 | Unknown type.| 24| ADOBE_RGB_1998 | 1 | Adobe RGB (1998).| 25| DCI_P3 | 2 | DCI-P3.| 26| DISPLAY_P3 | 3 | Display P3.| 27| SRGB | 4 | SRGB.<br>This is the default color space type.| 28| CUSTOM | 5 | Custom type.| 29 30## ColorSpacePrimaries 31 32Defines 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. 33 34**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core 35 36| Name | Type| Readable| Writable| Description | 37| ---------------------------- | -------- | ---- | ---- | ----------------------------------------------------- | 38| redX | number | Yes | Yes | X coordinate of the red color in the color space.| 39| redY | number | Yes | Yes | Y coordinate of the red color in the color space.| 40| greenX | number | Yes | Yes | X coordinate of the green color in the color space.| 41| greenY | number | Yes | Yes | Y coordinate of the green color in the color space.| 42| blueX | number | Yes | Yes | X coordinate of the blue color in the color space.| 43| blueY | number | Yes | Yes | Y coordinate of the blue color in the color space.| 44| whitePointX | number | Yes | Yes | X coordinate of the white point in the color space.| 45| whitePointY | number | Yes | Yes | Y coordinate of the white point in the color space.| 46 47## colorSpaceManager.create 48 49create(colorSpaceName: ColorSpace): ColorSpaceManager 50 51Creates a standard color space object. 52 53**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core 54 55**Parameters** 56 57| Parameter | Type | Mandatory| Description | 58| --------------- | ------------------------ | ---- | -----------------------------| 59| colorSpaceName | [ColorSpace](#colorspace)| Yes | Type of the color space.<br>**UNKNOWN** and **CUSTOM** cannot be used when creating standard color space objects. | 60 61**Return value** 62 63| Type | Description | 64| ------------------ | ------------------------ | 65| [ColorSpaceManager](#colorspacemanager) | Color space object created. | 66 67**Error codes** 68 69For details about the error codes, see [colorSpaceManager Error Codes](../errorcodes/errorcode-colorspace-manager.md). 70 71| ID| Error Message| 72| ------- | ----------------------- | 73| 18600001 | Parameter value is abnormal. | 74 75**Example** 76 77```js 78let colorSpace = null; 79try { 80 colorSpace = colorSpaceManager.create(colorSpaceManager.ColorSpace.SRGB); 81} catch (err) { 82 console.log(`Failed to create SRGB colorSpace. Cause: ` + JSON.stringify(err)); 83} 84``` 85 86## colorSpaceManager.create 87 88create(primaries: ColorSpacePrimaries, gamma: number): ColorSpaceManager 89 90Creates a custom color space object. 91 92**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core 93 94**Parameters** 95 96| Parameter | Type | Mandatory| Description | 97| --------------- | ------------------------------------------ | ---- | -----------------------------| 98| primaries | [ColorSpacePrimaries](#colorspaceprimaries)| Yes | Primaries of the color space. | 99| gamma | number | Yes | Gamma of the color space. | 100 101**Return value** 102 103| Type | Description | 104| ------------------ | ------------------------ | 105| [ColorSpaceManager](#colorspacemanager) | Color space object created.<br>The color space type is **CUSTOM** of [ColorSpace](#colorspace).| 106 107**Error codes** 108 109For details about the error codes, see [colorSpaceManager Error Codes](../errorcodes/errorcode-colorspace-manager.md). 110 111| ID| Error Message| 112| ------- | ----------------------- | 113| 18600001 | Parameter value is abnormal. | 114 115**Example** 116 117```js 118let colorSpace = null; 119try { 120 let primaries = { 121 redX: 0.1, 122 redY: 0.1, 123 greenX: 0.2, 124 greenY: 0.2, 125 blueX: 0.3, 126 blueY: 0.3, 127 whitePointX: 0.4, 128 whitePointY: 0.4 129 }; 130 let gamma = 2.2; 131 colorSpace = colorSpaceManager.create(primaries, gamma); 132} catch (err) { 133 console.log(`Failed to create colorSpace with customized primaries and gamma. Cause: ` + JSON.stringify(err)); 134} 135``` 136 137## ColorSpaceManager 138 139Implements management of color space objects. 140 141Before calling any of the following APIs, you must use [create()](#colorspacemanagercreate) to create a color space object. 142 143### getColorSpaceName 144 145getColorSpaceName(): ColorSpace 146 147Obtains the color space type. 148 149**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core 150 151**Return value** 152 153| Type | Description | 154| ------------------ | ------------------------ | 155| [ColorSpace](#colorspace) | Color space type.| 156 157**Error codes** 158 159For details about the error codes, see [colorSpaceManager Error Codes](../errorcodes/errorcode-colorspace-manager.md). 160 161| ID| Error Message| 162| ------- | ----------------------- | 163| 18600001 | Parameter value is abnormal. | 164 165**Example** 166 167```js 168try { 169 colorSpace.getColorSpaceName(); 170} catch (err) { 171 console.log(`Fail to get colorSpace's name. Cause: ` + JSON.stringify(err)); 172} 173``` 174 175### getWhitePoint 176 177getWhitePoint(): Array\<number\> 178 179Obtains the coordinates of the white point of the color space. 180 181**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core 182 183**Return value** 184 185| Type | Description | 186| ------------------ | ------------------------ | 187| Array\<number\> | Coordinates [x, y] of the white point.| 188 189**Error codes** 190 191For details about the error codes, see [colorSpaceManager Error Codes](../errorcodes/errorcode-colorspace-manager.md). 192 193| ID| Error Message| 194| ------- | ----------------------- | 195| 18600001 | Parameter value is abnormal. | 196 197**Example** 198 199```js 200try { 201 colorSpace.getWhitePoint(); 202} catch (err) { 203 console.log(`Failed to get white point. Cause: ` + JSON.stringify(err)); 204} 205``` 206 207### getGamma 208 209getGamma(): number 210 211Obtains the gamma of the color space. 212 213**System capability**: SystemCapability.Graphic.Graphic2D.ColorManager.Core 214 215**Return value** 216 217| Type | Description | 218| ------------------ | ------------------------ | 219| number | Gamma of the color space.| 220 221**Error codes** 222 223For details about the error codes, see [colorSpaceManager Error Codes](../errorcodes/errorcode-colorspace-manager.md). 224 225| ID| Error Message| 226| ------- | ----------------------- | 227| 18600001 | Parameter value is abnormal. | 228 229**Example** 230 231```js 232try { 233 colorSpace.getGamma(); 234} catch (err) { 235 console.log(`Failed to get gamma. Cause: ` + JSON.stringify(err)); 236} 237``` 238