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