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