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 fontFeatures, which is used to describe the features for a font. 237 * 238 * @since 20 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 Enumerates storage formats of bitmap pixels. 326 * 327 * @since 8 328 * @version 1.0 329 */ 330 typedef enum { 331 /** Unknown format. */ 332 COLOR_FORMAT_UNKNOWN, 333 /** Each pixel is represented by 8 bits, which together indicate alpha. */ 334 COLOR_FORMAT_ALPHA_8, 335 /** 336 * Each pixel is represented by 16 bits. From the most significant bit to the least significant bit, 337 * the first 5 bits indicate red, the subsequent 6 bits indicate green, and the last 5 bits indicate blue. 338 */ 339 COLOR_FORMAT_RGB_565, 340 /** 341 * Each pixel is represented by 16 bits. From the most significant bit to the least significant bit, 342 * every 4 bits indicate alpha, red, green, and blue, respectively. 343 */ 344 COLOR_FORMAT_ARGB_4444, 345 /** 346 * Each pixel is represented by 32 bits. From the most significant bit to the least significant bit, 347 * every 8 bits indicate alpha, red, green, and blue, respectively. 348 */ 349 COLOR_FORMAT_RGBA_8888, 350 /** 351 * Each pixel is represented by 32 bits. From the most significant bit to the least significant bit, 352 * every 8 bits indicate blue, green, red, and alpha, respectively. 353 */ 354 COLOR_FORMAT_BGRA_8888 355 } OH_Drawing_ColorFormat; 356 357 /** 358 * @brief Enumerates alpha formats of bitmap pixels. 359 * 360 * @since 8 361 * @version 1.0 362 */ 363 typedef enum { 364 /** Unknown format. */ 365 ALPHA_FORMAT_UNKNOWN, 366 /** The bitmap does not have the alpha component. */ 367 ALPHA_FORMAT_OPAQUE, 368 /** The color component of each pixel is premultiplied by the alpha component. */ 369 ALPHA_FORMAT_PREMUL, 370 /** The color component of each pixel is not premultiplied by the alpha component. */ 371 ALPHA_FORMAT_UNPREMUL 372 } OH_Drawing_AlphaFormat; 373 374 /** 375 * @brief The blending operation generates a new color for the two colors (source, destination). 376 * These operations are the same on the 4 color channels: red, green, blue, alpha. 377 * For these, we use alpha channel as an example, rather than naming each channel individually. 378 * 379 * For brevity, we use the following abbreviations. 380 * s : source 381 * d : destination 382 * sa : source alpha 383 * da : destination alpha 384 * 385 * Results are abbreviated 386 * r : if all 4 channels are computed in the same manner 387 * ra : result alpha channel 388 * rc : result "color": red, green, blue channels 389 * 390 * @since 11 391 * @version 1.0 392 */ 393 typedef enum { 394 /** r = 0. */ 395 BLEND_MODE_CLEAR, 396 /** r = s. */ 397 BLEND_MODE_SRC, 398 /** r = d. */ 399 BLEND_MODE_DST, 400 /** r = s + (1-sa)*d. */ 401 BLEND_MODE_SRC_OVER, 402 /** r = d + (1-da)*s. */ 403 BLEND_MODE_DST_OVER, 404 /** r = s * da. */ 405 BLEND_MODE_SRC_IN, 406 /** r = d * sa. */ 407 BLEND_MODE_DST_IN, 408 /** r = s * (1-da). */ 409 BLEND_MODE_SRC_OUT, 410 /** r = d * (1-sa). */ 411 BLEND_MODE_DST_OUT, 412 /** r = s*da + d*(1-sa). */ 413 BLEND_MODE_SRC_ATOP, 414 /** r = d*sa + s*(1-da). */ 415 BLEND_MODE_DST_ATOP, 416 /** r = s*(1-da) + d*(1-sa). */ 417 BLEND_MODE_XOR, 418 /** r = min(s + d, 1). */ 419 BLEND_MODE_PLUS, 420 /** r = s*d. */ 421 BLEND_MODE_MODULATE, 422 /** r = s + d - s*d. */ 423 BLEND_MODE_SCREEN, 424 /** multiply or screen, depending on destination. */ 425 BLEND_MODE_OVERLAY, 426 /** rc = s + d - max(s*da, d*sa), ra = s + (1-sa)*d. */ 427 BLEND_MODE_DARKEN, 428 /** rc = s + d - min(s*da, d*sa), ra = s + (1-sa)*d. */ 429 BLEND_MODE_LIGHTEN, 430 /** brighten destination to reflect source. */ 431 BLEND_MODE_COLOR_DODGE, 432 /** darken destination to reflect source. */ 433 BLEND_MODE_COLOR_BURN, 434 /** multiply or screen, depending on source. */ 435 BLEND_MODE_HARD_LIGHT, 436 /** lighten or darken, depending on source. */ 437 BLEND_MODE_SOFT_LIGHT, 438 /** rc = s + d - 2*(min(s*da, d*sa)), ra = s + (1-sa)*d. */ 439 BLEND_MODE_DIFFERENCE, 440 /** rc = s + d - two(s*d), ra = s + (1-sa)*d. */ 441 BLEND_MODE_EXCLUSION, 442 /** r = s*(1-da) + d*(1-sa) + s*d. */ 443 BLEND_MODE_MULTIPLY, 444 /** hue of source with saturation and luminosity of destination. */ 445 BLEND_MODE_HUE, 446 /** saturation of source with hue and luminosity of destination. */ 447 BLEND_MODE_SATURATION, 448 /** hue and saturation of source with luminosity of destination. */ 449 BLEND_MODE_COLOR, 450 /** luminosity of source with hue and saturation of destination. */ 451 BLEND_MODE_LUMINOSITY, 452 } OH_Drawing_BlendMode; 453 454 /** 455 * @brief Defines image info struct. 456 * 457 * @since 12 458 * @version 1.0 459 */ 460 typedef struct { 461 /** storage for width of image */ 462 int32_t width; 463 /** storage for height of image */ 464 int32_t height; 465 /** storage for color formats */ 466 OH_Drawing_ColorFormat colorType; 467 /** storage for alpha formats */ 468 OH_Drawing_AlphaFormat alphaType; 469 } OH_Drawing_Image_Info; 470 471 /** 472 * @brief Defines rectstyle info struct. 473 * 474 * @since 12 475 * @version 1.0 476 */ 477 typedef struct { 478 /** color of rectstyle */ 479 uint32_t color; 480 /** radius in left top of rectstyle */ 481 double leftTopRadius; 482 /** radius in right top of rectstyle */ 483 double rightTopRadius; 484 /** radius in right bottom of rectstyle */ 485 double rightBottomRadius; 486 /** radius in left bottom of rectstyle */ 487 double leftBottomRadius; 488 } OH_Drawing_RectStyle_Info; 489 490 /** 491 * @brief Defines the string information struct. 492 * 493 * @since 14 494 * @version 1.0 495 */ 496 typedef struct { 497 /** A pointer to a byte string containing UTF-16 encoded entities */ 498 uint8_t* strData; 499 /** The length of `strData` in bytes */ 500 uint32_t strLen; 501 } OH_Drawing_String; 502 503 /** 504 * @brief Enumerates text encoding types. 505 * @since 12 506 * @version 1.0 507 */ 508 typedef enum { 509 /** uses bytes to represent UTF-8 or ASCII */ 510 TEXT_ENCODING_UTF8, 511 /** uses two byte words to represent most of Unicode */ 512 TEXT_ENCODING_UTF16, 513 /** uses four byte words to represent all of Unicode */ 514 TEXT_ENCODING_UTF32, 515 /** uses two byte words to represent glyph indices */ 516 TEXT_ENCODING_GLYPH_ID, 517 } OH_Drawing_TextEncoding; 518 519 /** 520 * @brief Defines a OH_Drawing_FontMgr, which is used to manage font family. 521 * 522 * @since 12 523 * @version 1.0 524 */ 525 typedef struct OH_Drawing_FontMgr OH_Drawing_FontMgr; 526 527 /** 528 * @brief Defines a OH_Drawing_FontStyleSet, which is used to manage font style. 529 * 530 * @since 12 531 * @version 1.0 532 */ 533 typedef struct OH_Drawing_FontStyleSet OH_Drawing_FontStyleSet; 534 535 /** 536 * @brief Define OH_Drawing_RecordCmdUtils, which is used to generate drawing commands tool. 537 * 538 * @since 13 539 * @version 1.0 540 */ 541 typedef struct OH_Drawing_RecordCmdUtils OH_Drawing_RecordCmdUtils; 542 543 /** 544 * @brief Define OH_Drawing_RecordCmd, which is used to replay drawing commands. 545 * 546 * @since 13 547 * @version 1.0 548 */ 549 typedef struct OH_Drawing_RecordCmd OH_Drawing_RecordCmd; 550 551 /** 552 * @brief Defines an array object, which is used to store multiple NDK object. 553 * 554 * @since 14 555 * @version 1.0 556 */ 557 typedef struct OH_Drawing_Array OH_Drawing_Array; 558 #ifdef __cplusplus 559 } 560 #endif 561 /** @} */ 562 #endif 563