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