• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup Drawing
18  * @{
19  *
20  * @brief Provides functions such as 2D graphics rendering, text drawing, and image display.
21  *
22  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
23  *
24  * @since 8
25  * @version 1.0
26  */
27 
28 /**
29  * @file drawing_types.h
30  *
31  * @brief Declares the data types for drawing 2D graphics, including the canvas, brush, pen, bitmap, and path.
32  *
33  * @kit ArkGraphics2D
34  * @library libnative_drawing.so
35  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
36  * @since 8
37  * @version 1.0
38  */
39 
40 #ifndef C_INCLUDE_DRAWING_TYPES_H
41 #define C_INCLUDE_DRAWING_TYPES_H
42 
43 #include <stdbool.h>
44 #include <stddef.h>
45 #include <stdint.h>
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 /**
52  * @brief Defines a rectangular canvas on which various shapes, images,
53  * and texts can be drawn by using the brush and pen.
54  *
55  * @since 8
56  * @version 1.0
57  */
58 typedef struct OH_Drawing_Canvas OH_Drawing_Canvas;
59 
60 /**
61  * @brief Defines a pen, which is used to describe the style and color to outline a shape.
62  *
63  * @since 8
64  * @version 1.0
65  */
66 typedef struct OH_Drawing_Pen OH_Drawing_Pen;
67 
68 /**
69  * @brief Defines a region, which is used to represent an enclosed area on the canvas layer.
70  *
71  * @since 12
72  * @version 1.0
73  */
74 typedef struct OH_Drawing_Region OH_Drawing_Region;
75 
76 /**
77  * @brief Defines as a brush, which is used to describe the style and color to fill in a shape.
78  *
79  * @since 8
80  * @version 1.0
81  */
82 typedef struct OH_Drawing_Brush OH_Drawing_Brush;
83 
84 /**
85  * @brief Defines a path, which is used to customize various shapes.
86  *
87  * @since 8
88  * @version 1.0
89  */
90 typedef struct OH_Drawing_Path OH_Drawing_Path;
91 
92 /**
93  * @brief Defines a bitmap, which is a memory that contains the pixel data of a shape.
94  *
95  * @since 8
96  * @version 1.0
97  */
98 typedef struct OH_Drawing_Bitmap OH_Drawing_Bitmap;
99 
100 /**
101  * @brief Defines a point, which is used to describe the coordinate point.
102  *
103  * @since 11
104  * @version 1.0
105  */
106 typedef struct OH_Drawing_Point OH_Drawing_Point;
107 
108 /**
109  * @brief Defines a pixelmap, which is used to wrap real pixelmap supported by image framework.
110  *
111  * @since 12
112  * @version 1.0
113  */
114 typedef struct OH_Drawing_PixelMap OH_Drawing_PixelMap;
115 
116 /**
117  * @brief Define color space to determine color information.
118  *
119  * @since 12
120  * @version 1.0
121  */
122 typedef struct OH_Drawing_ColorSpace OH_Drawing_ColorSpace;
123 
124 /**
125  * @brief Defines a point of 2d.
126  *
127  * @since 12
128  * @version 1.0
129  */
130 typedef struct {
131     float x;
132     float y;
133 } OH_Drawing_Point2D;
134 
135 /**
136  * @brief Defines a corner radii, which is on x-axis and y-axis.
137  *
138  * @since 12
139  * @version 1.0
140  */
141 typedef OH_Drawing_Point2D OH_Drawing_Corner_Radii;
142 
143 /**
144  * @brief Defines a point of 3d, which is used to describe the coordinate point.
145  *
146  * @since 12
147  * @version 1.0
148  */
149 typedef struct {
150     float x;
151     float y;
152     float z;
153 } OH_Drawing_Point3D;
154 
155 /**
156  * @brief Defines a pathEffect, which is used to affects stroked paths.
157  *
158  * @since 12
159  * @version 1.0
160  */
161 typedef struct OH_Drawing_PathEffect OH_Drawing_PathEffect;
162 
163 /**
164  * @brief Defines a rect, which is used to describe the rectangle.
165  *
166  * @since 11
167  * @version 1.0
168  */
169 typedef struct OH_Drawing_Rect OH_Drawing_Rect;
170 
171 /**
172  * @brief Defines a roundRect, which is used to describe the round rectangle.
173  *
174  * @since 11
175  * @version 1.0
176  */
177 typedef struct OH_Drawing_RoundRect OH_Drawing_RoundRect;
178 
179 /**
180  * @brief Defines a matrix, which is used to describe the transforming coordinates.
181  *
182  * @since 11
183  * @version 1.0
184  */
185 typedef struct OH_Drawing_Matrix OH_Drawing_Matrix;
186 
187 /**
188  * @brief Defines a shaderEffect, which is used to describe the source color(s) for what is being drawn.
189  *
190  * @since 11
191  * @version 1.0
192  */
193 typedef struct OH_Drawing_ShaderEffect OH_Drawing_ShaderEffect;
194 
195 /**
196  * @brief Defines a shadowLayer, which is used to draw shaded parts.
197  *
198  * @since 12
199  * @version 1.0
200  */
201 typedef struct OH_Drawing_ShadowLayer OH_Drawing_ShadowLayer;
202 
203 /**
204  * @brief Defines a filter, which is used to store maskFilter, colorFilter and imageFilter.
205  *
206  * @since 11
207  * @version 1.0
208  */
209 typedef struct OH_Drawing_Filter OH_Drawing_Filter;
210 
211 /**
212  * @brief Defines a maskFilter, which is used to perform transformations on the mask before drawing it.
213  *
214  * @since 11
215  * @version 1.0
216  */
217 typedef struct OH_Drawing_MaskFilter OH_Drawing_MaskFilter;
218 
219 /**
220  * @brief Defines a colorFilter, which is called a color and returns a new color.
221  *
222  * @since 11
223  * @version 1.0
224  */
225 typedef struct OH_Drawing_ColorFilter OH_Drawing_ColorFilter;
226 
227 /**
228  * @brief Defines a font, which is used to describe the font.
229  *
230  * @since 11
231  * @version 1.0
232  */
233 typedef struct OH_Drawing_Font OH_Drawing_Font;
234 
235 /**
236  * @brief Defines a memoryStream, which is used to describe the memory stream.
237  *
238  * @since 12
239  * @version 1.0
240  */
241 typedef struct OH_Drawing_MemoryStream OH_Drawing_MemoryStream;
242 
243 /**
244  * @brief Defines fontArguments, which is used to describe the arguments for a font.
245  *
246  * @since 13
247  * @version 1.0
248  */
249 typedef struct OH_Drawing_FontArguments OH_Drawing_FontArguments;
250 
251 /**
252  * @brief Defines a typeface, which is used to describe the typeface.
253  *
254  * @since 11
255  * @version 1.0
256  */
257 typedef struct OH_Drawing_Typeface OH_Drawing_Typeface;
258 
259 /**
260  * @brief Defines a textBlob, which combines multiple text runs into an immutable container.
261  * Each text run consists of glyphs and positions.
262  *
263  * @since 11
264  * @version 1.0
265  */
266 typedef struct OH_Drawing_TextBlob OH_Drawing_TextBlob;
267 
268 /**
269  * @brief Defines a image, which is used to describe a two dimensional array of pixels to draw.
270  *
271  * @since 12
272  * @version 1.0
273  */
274 typedef struct OH_Drawing_Image OH_Drawing_Image;
275 
276 /**
277  * @brief Defines a image filter, which is used to operate on all the color bits of pixels that make up an image.
278  *
279  * @since 12
280  * @version 1.0
281  */
282 typedef struct OH_Drawing_ImageFilter OH_Drawing_ImageFilter;
283 
284 /**
285  * @brief Defines a sampling options, which is used to describe the sampling mode.
286  *
287  * @since 12
288  * @version 1.0
289  */
290 typedef struct OH_Drawing_SamplingOptions OH_Drawing_SamplingOptions;
291 
292 /**
293  * @brief Defines a textBlobBuilder, which is used to build the textBlob.
294  *
295  * @since 11
296  * @version 1.0
297  */
298 typedef struct OH_Drawing_TextBlobBuilder OH_Drawing_TextBlobBuilder;
299 
300 /**
301  * @brief Defines a GPU context, which is used to describe the GPU backend context.
302  *
303  * @since 12
304  * @version 1.0
305  */
306 typedef struct OH_Drawing_GpuContext OH_Drawing_GpuContext;
307 
308 /**
309  * @brief Defines a surface, which is used to manage the pixels that a canvas draws into.
310  *
311  * @since 12
312  * @version 1.0
313  */
314 typedef struct OH_Drawing_Surface OH_Drawing_Surface;
315 
316 /**
317  * @brief Enumerates storage formats of bitmap pixels.
318  *
319  * @since 8
320  * @version 1.0
321  */
322 typedef enum {
323     /** Unknown format. */
324     COLOR_FORMAT_UNKNOWN,
325     /** Each pixel is represented by 8 bits, which together indicate alpha. */
326     COLOR_FORMAT_ALPHA_8,
327     /**
328      * Each pixel is represented by 16 bits. From the most significant bit to the least significant bit,
329      * the first 5 bits indicate red, the subsequent 6 bits indicate green, and the last 5 bits indicate blue.
330      */
331     COLOR_FORMAT_RGB_565,
332     /**
333      * Each pixel is represented by 16 bits. From the most significant bit to the least significant bit,
334      * every 4 bits indicate alpha, red, green, and blue, respectively.
335      */
336     COLOR_FORMAT_ARGB_4444,
337     /**
338      * Each pixel is represented by 32 bits. From the most significant bit to the least significant bit,
339      * every 8 bits indicate alpha, red, green, and blue, respectively.
340      */
341     COLOR_FORMAT_RGBA_8888,
342     /**
343      * Each pixel is represented by 32 bits. From the most significant bit to the least significant bit,
344      * every 8 bits indicate blue, green, red, and alpha, respectively.
345      */
346     COLOR_FORMAT_BGRA_8888
347 } OH_Drawing_ColorFormat;
348 
349 /**
350  * @brief Enumerates alpha formats of bitmap pixels.
351  *
352  * @since 8
353  * @version 1.0
354  */
355 typedef enum {
356     /** Unknown format. */
357     ALPHA_FORMAT_UNKNOWN,
358     /** The bitmap does not have the alpha component. */
359     ALPHA_FORMAT_OPAQUE,
360     /** The color component of each pixel is premultiplied by the alpha component. */
361     ALPHA_FORMAT_PREMUL,
362     /** The color component of each pixel is not premultiplied by the alpha component. */
363     ALPHA_FORMAT_UNPREMUL
364 } OH_Drawing_AlphaFormat;
365 
366 /**
367  * @brief The blending operation generates a new color for the two colors (source, destination).
368  * These operations are the same on the 4 color channels: red, green, blue, alpha.
369  * For these, we use alpha channel as an example, rather than naming each channel individually.
370  *
371  * For brevity, we use the following abbreviations.
372  * s  : source
373  * d  : destination
374  * sa : source alpha
375  * da : destination alpha
376  *
377  * Results are abbreviated
378  * r  : if all 4 channels are computed in the same manner
379  * ra : result alpha channel
380  * rc : result "color": red, green, blue channels
381  *
382  * @since 11
383  * @version 1.0
384  */
385 typedef enum {
386     /** r = 0. */
387     BLEND_MODE_CLEAR,
388     /** r = s. */
389     BLEND_MODE_SRC,
390     /** r = d. */
391     BLEND_MODE_DST,
392     /** r = s + (1-sa)*d. */
393     BLEND_MODE_SRC_OVER,
394     /** r = d + (1-da)*s. */
395     BLEND_MODE_DST_OVER,
396     /** r = s * da. */
397     BLEND_MODE_SRC_IN,
398     /** r = d * sa. */
399     BLEND_MODE_DST_IN,
400     /** r = s * (1-da). */
401     BLEND_MODE_SRC_OUT,
402     /** r = d * (1-sa). */
403     BLEND_MODE_DST_OUT,
404     /** r = s*da + d*(1-sa). */
405     BLEND_MODE_SRC_ATOP,
406     /** r = d*sa + s*(1-da). */
407     BLEND_MODE_DST_ATOP,
408     /** r = s*(1-da) + d*(1-sa). */
409     BLEND_MODE_XOR,
410     /** r = min(s + d, 1). */
411     BLEND_MODE_PLUS,
412     /** r = s*d. */
413     BLEND_MODE_MODULATE,
414     /** r = s + d - s*d. */
415     BLEND_MODE_SCREEN,
416     /** multiply or screen, depending on destination. */
417     BLEND_MODE_OVERLAY,
418     /** rc = s + d - max(s*da, d*sa), ra = s + (1-sa)*d. */
419     BLEND_MODE_DARKEN,
420     /** rc = s + d - min(s*da, d*sa), ra = s + (1-sa)*d. */
421     BLEND_MODE_LIGHTEN,
422     /** brighten destination to reflect source. */
423     BLEND_MODE_COLOR_DODGE,
424     /** darken destination to reflect source. */
425     BLEND_MODE_COLOR_BURN,
426     /** multiply or screen, depending on source. */
427     BLEND_MODE_HARD_LIGHT,
428     /** lighten or darken, depending on source. */
429     BLEND_MODE_SOFT_LIGHT,
430     /** rc = s + d - 2*(min(s*da, d*sa)), ra = s + (1-sa)*d. */
431     BLEND_MODE_DIFFERENCE,
432     /** rc = s + d - two(s*d), ra = s + (1-sa)*d. */
433     BLEND_MODE_EXCLUSION,
434     /** r = s*(1-da) + d*(1-sa) + s*d. */
435     BLEND_MODE_MULTIPLY,
436     /** hue of source with saturation and luminosity of destination. */
437     BLEND_MODE_HUE,
438     /** saturation of source with hue and luminosity of destination. */
439     BLEND_MODE_SATURATION,
440     /** hue and saturation of source with luminosity of destination. */
441     BLEND_MODE_COLOR,
442     /** luminosity of source with hue and saturation of destination. */
443     BLEND_MODE_LUMINOSITY,
444 } OH_Drawing_BlendMode;
445 
446 /**
447  * @brief Defines image info struct.
448  *
449  * @since 12
450  * @version 1.0
451  */
452 typedef struct {
453     /** storage for width of image */
454     int32_t width;
455     /** storage for height of image */
456     int32_t height;
457     /** storage for color formats */
458     OH_Drawing_ColorFormat colorType;
459     /** storage for alpha formats */
460     OH_Drawing_AlphaFormat alphaType;
461 } OH_Drawing_Image_Info;
462 
463 /**
464  * @brief Defines rectstyle info struct.
465  *
466  * @since 12
467  * @version 1.0
468  */
469 typedef struct {
470     /** color of rectstyle */
471     uint32_t color;
472     /** radius in left top of rectstyle */
473     double leftTopRadius;
474     /** radius in right top of rectstyle */
475     double rightTopRadius;
476     /** radius in right bottom of rectstyle */
477     double rightBottomRadius;
478     /** radius in left bottom of rectstyle */
479     double leftBottomRadius;
480 } OH_Drawing_RectStyle_Info;
481 
482 /**
483  * @brief Defines the string information struct.
484  *
485  * @since 14
486  * @version 1.0
487  */
488 typedef struct {
489     /** A pointer to a byte string containing UTF-16 encoded entities */
490     uint8_t* strData;
491     /** The length of `strData` in bytes */
492     uint32_t strLen;
493 } OH_Drawing_String;
494 
495 /**
496  * @brief Enumerates text encoding types.
497  * @since 12
498  * @version 1.0
499  */
500 typedef enum {
501     /** uses bytes to represent UTF-8 or ASCII */
502     TEXT_ENCODING_UTF8,
503     /** uses two byte words to represent most of Unicode */
504     TEXT_ENCODING_UTF16,
505     /** uses four byte words to represent all of Unicode */
506     TEXT_ENCODING_UTF32,
507     /** uses two byte words to represent glyph indices */
508     TEXT_ENCODING_GLYPH_ID,
509 } OH_Drawing_TextEncoding;
510 
511 /**
512  * @brief Defines a OH_Drawing_FontMgr, which is used to manage font family.
513  *
514  * @since 12
515  * @version 1.0
516  */
517 typedef struct OH_Drawing_FontMgr OH_Drawing_FontMgr;
518 
519 /**
520  * @brief Defines a OH_Drawing_FontStyleSet, which is used to manage font style.
521  *
522  * @since 12
523  * @version 1.0
524  */
525 typedef struct OH_Drawing_FontStyleSet OH_Drawing_FontStyleSet;
526 
527 /**
528  * @brief Define OH_Drawing_RecordCmdUtils, which is used to generate drawing commands tool.
529  *
530  * @since 13
531  * @version 1.0
532  */
533 typedef struct OH_Drawing_RecordCmdUtils OH_Drawing_RecordCmdUtils;
534 
535 /**
536  * @brief Define OH_Drawing_RecordCmd, which is used to replay drawing commands.
537  *
538  * @since 13
539  * @version 1.0
540  */
541 typedef struct OH_Drawing_RecordCmd OH_Drawing_RecordCmd;
542 
543 /**
544  * @brief Defines an array object, which is used to store multiple NDK object.
545  *
546  * @since 14
547  * @version 1.0
548  */
549 typedef struct OH_Drawing_Array OH_Drawing_Array;
550 #ifdef __cplusplus
551 }
552 #endif
553 /** @} */
554 #endif
555