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