• 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 #ifndef C_INCLUDE_DRAWING_TYPES_H
17 #define C_INCLUDE_DRAWING_TYPES_H
18 
19 /**
20  * @addtogroup Drawing
21  * @{
22  *
23  * @brief Provides functions such as 2D graphics rendering, text drawing, and image display.
24  *
25  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
26  *
27  * @since 8
28  * @version 1.0
29  */
30 
31 /**
32  * @file drawing_types.h
33  *
34  * @brief Declares the data types for drawing 2D graphics, including the canvas, brush, pen, bitmap, and path.
35  *
36  * @kit ArkGraphics2D
37  * @library libnative_drawing.so
38  * @syscap SystemCapability.Graphic.Graphic2D.NativeDrawing
39  * @since 8
40  * @version 1.0
41  */
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 Define color space to determine color information.
110  *
111  * @since 12
112  * @version 1.0
113  */
114 typedef struct OH_Drawing_ColorSpace OH_Drawing_ColorSpace;
115 
116 /**
117  * @brief Defines a pixelmap, which is used to wrap real pixelmap supported by image framework.
118  *
119  * @since 12
120  * @version 1.0
121  */
122 typedef struct OH_Drawing_PixelMap OH_Drawing_PixelMap;
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 font, which is used to describe the font.
237  *
238  * @since 11
239  * @version 1.0
240  */
241 typedef struct OH_Drawing_FontFeatures OH_Drawing_FontFeatures;
242 
243 /**
244  * @brief Defines a memoryStream, which is used to describe the memory stream.
245  *
246  * @since 12
247  * @version 1.0
248  */
249 typedef struct OH_Drawing_MemoryStream OH_Drawing_MemoryStream;
250 
251 /**
252  * @brief Defines fontArguments, which is used to describe the arguments for a font.
253  *
254  * @since 13
255  * @version 1.0
256  */
257 typedef struct OH_Drawing_FontArguments OH_Drawing_FontArguments;
258 
259 /**
260  * @brief Defines a typeface, which is used to describe the typeface.
261  *
262  * @since 11
263  * @version 1.0
264  */
265 typedef struct OH_Drawing_Typeface OH_Drawing_Typeface;
266 
267 /**
268  * @brief Defines a textBlob, which combines multiple text runs into an immutable container.
269  * Each text run consists of glyphs and positions.
270  *
271  * @since 11
272  * @version 1.0
273  */
274 typedef struct OH_Drawing_TextBlob OH_Drawing_TextBlob;
275 
276 /**
277  * @brief Defines a image, which is used to describe a two dimensional array of pixels to draw.
278  *
279  * @since 12
280  * @version 1.0
281  */
282 typedef struct OH_Drawing_Image OH_Drawing_Image;
283 
284 /**
285  * @brief Defines a image filter, which is used to operate on all the color bits of pixels that make up an image.
286  *
287  * @since 12
288  * @version 1.0
289  */
290 typedef struct OH_Drawing_ImageFilter OH_Drawing_ImageFilter;
291 
292 /**
293  * @brief Defines a sampling options, which is used to describe the sampling mode.
294  *
295  * @since 12
296  * @version 1.0
297  */
298 typedef struct OH_Drawing_SamplingOptions OH_Drawing_SamplingOptions;
299 
300 /**
301  * @brief Defines a textBlobBuilder, which is used to build the textBlob.
302  *
303  * @since 11
304  * @version 1.0
305  */
306 typedef struct OH_Drawing_TextBlobBuilder OH_Drawing_TextBlobBuilder;
307 
308 /**
309  * @brief Defines a GPU context, which is used to describe the GPU backend context.
310  *
311  * @since 12
312  * @version 1.0
313  */
314 typedef struct OH_Drawing_GpuContext OH_Drawing_GpuContext;
315 
316 /**
317  * @brief Defines a surface, which is used to manage the pixels that a canvas draws into.
318  *
319  * @since 12
320  * @version 1.0
321  */
322 typedef struct OH_Drawing_Surface OH_Drawing_Surface;
323 
324 /**
325  * @brief Defines a array object, which is used to store multiple object.
326  *
327  * @since 14
328  * @version 1.0
329  */
330 typedef struct OH_Drawing_Array OH_Drawing_Array;
331 
332 /**
333  * @brief Enumerates storage formats of bitmap pixels.
334  *
335  * @since 8
336  * @version 1.0
337  */
338 typedef enum {
339     /** Unknown format. */
340     COLOR_FORMAT_UNKNOWN,
341     /** Each pixel is represented by 8 bits, which together indicate alpha. */
342     COLOR_FORMAT_ALPHA_8,
343     /**
344      * Each pixel is represented by 16 bits. From the most significant bit to the least significant bit,
345      * the first 5 bits indicate red, the subsequent 6 bits indicate green, and the last 5 bits indicate blue.
346      */
347     COLOR_FORMAT_RGB_565,
348     /**
349      * Each pixel is represented by 16 bits. From the most significant bit to the least significant bit,
350      * every 4 bits indicate alpha, red, green, and blue, respectively.
351      */
352     COLOR_FORMAT_ARGB_4444,
353     /**
354      * Each pixel is represented by 32 bits. From the most significant bit to the least significant bit,
355      * every 8 bits indicate alpha, red, green, and blue, respectively.
356      */
357     COLOR_FORMAT_RGBA_8888,
358     /**
359      * Each pixel is represented by 32 bits. From the most significant bit to the least significant bit,
360      * every 8 bits indicate blue, green, red, and alpha, respectively.
361      */
362     COLOR_FORMAT_BGRA_8888
363 } OH_Drawing_ColorFormat;
364 
365 /**
366  * @brief Enumerates alpha formats of bitmap pixels.
367  *
368  * @since 8
369  * @version 1.0
370  */
371 typedef enum {
372     /** Unknown format. */
373     ALPHA_FORMAT_UNKNOWN,
374     /** The bitmap does not have the alpha component. */
375     ALPHA_FORMAT_OPAQUE,
376     /** The color component of each pixel is premultiplied by the alpha component. */
377     ALPHA_FORMAT_PREMUL,
378     /** The color component of each pixel is not premultiplied by the alpha component. */
379     ALPHA_FORMAT_UNPREMUL
380 } OH_Drawing_AlphaFormat;
381 
382 /**
383  * @brief The blending operation generates a new color for the two colors (source, destination).
384  * These operations are the same on the 4 color channels: red, green, blue, alpha.
385  * For these, we use alpha channel as an example, rather than naming each channel individually.
386  *
387  * For brevity, we use the following abbreviations.
388  * s  : source
389  * d  : destination
390  * sa : source alpha
391  * da : destination alpha
392  *
393  * Results are abbreviated
394  * r  : if all 4 channels are computed in the same manner
395  * ra : result alpha channel
396  * rc : result "color": red, green, blue channels
397  *
398  * @since 11
399  * @version 1.0
400  */
401 typedef enum {
402     /** r = 0. */
403     BLEND_MODE_CLEAR,
404     /** r = s. */
405     BLEND_MODE_SRC,
406     /** r = d. */
407     BLEND_MODE_DST,
408     /** r = s + (1-sa)*d. */
409     BLEND_MODE_SRC_OVER,
410     /** r = d + (1-da)*s. */
411     BLEND_MODE_DST_OVER,
412     /** r = s * da. */
413     BLEND_MODE_SRC_IN,
414     /** r = d * sa. */
415     BLEND_MODE_DST_IN,
416     /** r = s * (1-da). */
417     BLEND_MODE_SRC_OUT,
418     /** r = d * (1-sa). */
419     BLEND_MODE_DST_OUT,
420     /** r = s*da + d*(1-sa). */
421     BLEND_MODE_SRC_ATOP,
422     /** r = d*sa + s*(1-da). */
423     BLEND_MODE_DST_ATOP,
424     /** r = s*(1-da) + d*(1-sa). */
425     BLEND_MODE_XOR,
426     /** r = min(s + d, 1). */
427     BLEND_MODE_PLUS,
428     /** r = s*d. */
429     BLEND_MODE_MODULATE,
430     /** r = s + d - s*d. */
431     BLEND_MODE_SCREEN,
432     /** multiply or screen, depending on destination. */
433     BLEND_MODE_OVERLAY,
434     /** rc = s + d - max(s*da, d*sa), ra = s + (1-sa)*d. */
435     BLEND_MODE_DARKEN,
436     /** rc = s + d - min(s*da, d*sa), ra = s + (1-sa)*d. */
437     BLEND_MODE_LIGHTEN,
438     /** brighten destination to reflect source. */
439     BLEND_MODE_COLOR_DODGE,
440     /** darken destination to reflect source. */
441     BLEND_MODE_COLOR_BURN,
442     /** multiply or screen, depending on source. */
443     BLEND_MODE_HARD_LIGHT,
444     /** lighten or darken, depending on source. */
445     BLEND_MODE_SOFT_LIGHT,
446     /** rc = s + d - 2*(min(s*da, d*sa)), ra = s + (1-sa)*d. */
447     BLEND_MODE_DIFFERENCE,
448     /** rc = s + d - two(s*d), ra = s + (1-sa)*d. */
449     BLEND_MODE_EXCLUSION,
450     /** r = s*(1-da) + d*(1-sa) + s*d. */
451     BLEND_MODE_MULTIPLY,
452     /** hue of source with saturation and luminosity of destination. */
453     BLEND_MODE_HUE,
454     /** saturation of source with hue and luminosity of destination. */
455     BLEND_MODE_SATURATION,
456     /** hue and saturation of source with luminosity of destination. */
457     BLEND_MODE_COLOR,
458     /** luminosity of source with hue and saturation of destination. */
459     BLEND_MODE_LUMINOSITY,
460 } OH_Drawing_BlendMode;
461 
462 /**
463  * @brief Defines image info struct.
464  *
465  * @since 12
466  * @version 1.0
467  */
468 typedef struct {
469     /** storage for width of image */
470     int32_t width;
471     /** storage for height of image */
472     int32_t height;
473     /** storage for color formats */
474     OH_Drawing_ColorFormat colorType;
475     /** storage for alpha formats */
476     OH_Drawing_AlphaFormat alphaType;
477 } OH_Drawing_Image_Info;
478 
479 /**
480  * @brief Defines rectstyle info struct.
481  *
482  * @since 12
483  * @version 1.0
484  */
485 typedef struct {
486     /** color of rectstyle */
487     uint32_t color;
488     /** radius in left top of rectstyle */
489     double leftTopRadius;
490     /** radius in right top of rectstyle */
491     double rightTopRadius;
492     /** radius in right bottom of rectstyle */
493     double rightBottomRadius;
494     /** radius in left bottom of rectstyle */
495     double leftBottomRadius;
496 } OH_Drawing_RectStyle_Info;
497 
498 /**
499  * @brief Defines the string information struct.
500  *
501  * @since 14
502  * @version 1.0
503  */
504 typedef struct {
505     /** A pointer to a byte string containing UTF-16 encoded entities */
506     uint8_t* strData;
507     /** The length of `strData` in bytes */
508     uint32_t strLen;
509 } OH_Drawing_String;
510 
511 /**
512  * @brief Enumerates text encoding types.
513  * @since 12
514  * @version 1.0
515  */
516 typedef enum {
517     /** uses bytes to represent UTF-8 or ASCII */
518     TEXT_ENCODING_UTF8,
519     /** uses two byte words to represent most of Unicode */
520     TEXT_ENCODING_UTF16,
521     /** uses four byte words to represent all of Unicode */
522     TEXT_ENCODING_UTF32,
523     /** uses two byte words to represent glyph indices */
524     TEXT_ENCODING_GLYPH_ID,
525 } OH_Drawing_TextEncoding;
526 
527 /**
528  * @brief Defines a OH_Drawing_FontMgr, which is used to manage font family.
529  *
530  * @since 12
531  * @version 1.0
532  */
533 typedef struct OH_Drawing_FontMgr OH_Drawing_FontMgr;
534 
535 /**
536  * @brief Defines a OH_Drawing_FontStyleSet, which is used to manage font style.
537  *
538  * @since 12
539  * @version 1.0
540  */
541 typedef struct OH_Drawing_FontStyleSet OH_Drawing_FontStyleSet;
542 
543 /**
544  * @brief Define OH_Drawing_RecordCmdUtils, which is used to generate drawing commands tool.
545  *
546  * @since 13
547  * @version 1.0
548  */
549 typedef struct OH_Drawing_RecordCmdUtils OH_Drawing_RecordCmdUtils;
550 
551 /**
552  * @brief Define OH_Drawing_RecordCmd, which is used to replay drawing commands.
553  *
554  * @since 13
555  * @version 1.0
556  */
557 typedef struct OH_Drawing_RecordCmd OH_Drawing_RecordCmd;
558 
559 #ifdef __cplusplus
560 }
561 #endif
562 /** @} */
563 #endif
564