1 /* 2 * Copyright (c) 2021-2023 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 * @since 8 37 * @version 1.0 38 */ 39 40 #include <stdint.h> 41 #include <stddef.h> 42 43 #ifdef __cplusplus 44 extern "C" { 45 #endif 46 47 /** 48 * @brief Defines a rectangular canvas on which various shapes, images, 49 * and texts can be drawn by using the brush and pen. 50 * 51 * @since 8 52 * @version 1.0 53 */ 54 typedef struct OH_Drawing_Canvas OH_Drawing_Canvas; 55 56 /** 57 * @brief Defines a pen, which is used to describe the style and color to outline a shape. 58 * 59 * @since 8 60 * @version 1.0 61 */ 62 typedef struct OH_Drawing_Pen OH_Drawing_Pen; 63 64 /** 65 * @brief Defines as a brush, which is used to describe the style and color to fill in a shape. 66 * 67 * @since 8 68 * @version 1.0 69 */ 70 typedef struct OH_Drawing_Brush OH_Drawing_Brush; 71 72 /** 73 * @brief Defines a path, which is used to customize various shapes. 74 * 75 * @since 8 76 * @version 1.0 77 */ 78 typedef struct OH_Drawing_Path OH_Drawing_Path; 79 80 /** 81 * @brief Defines a bitmap, which is a memory that contains the pixel data of a shape. 82 * 83 * @since 8 84 * @version 1.0 85 */ 86 typedef struct OH_Drawing_Bitmap OH_Drawing_Bitmap; 87 88 /** 89 * @brief Defines a point, which is used to describe the coordinate point. 90 * 91 * @since 11 92 * @version 1.0 93 */ 94 typedef struct OH_Drawing_Point OH_Drawing_Point; 95 96 /** 97 * @brief Defines a point of 3x3, which is used to describe the coordinate point. 98 * 99 * @since 12 100 * @version 1.0 101 */ 102 typedef struct OH_Drawing_Point3 OH_Drawing_Point3; 103 104 /** 105 * @brief Defines a pathEffect, which is used to affects stroked paths. 106 * 107 * @since 12 108 * @version 1.0 109 */ 110 typedef struct OH_Drawing_PathEffect OH_Drawing_PathEffect; 111 112 /** 113 * @brief Defines a rect, which is used to describe the rectangle. 114 * 115 * @since 11 116 * @version 1.0 117 */ 118 typedef struct OH_Drawing_Rect OH_Drawing_Rect; 119 120 /** 121 * @brief Defines a roundRect, which is used to describe the round rectangle. 122 * 123 * @since 11 124 * @version 1.0 125 */ 126 typedef struct OH_Drawing_RoundRect OH_Drawing_RoundRect; 127 128 /** 129 * @brief Defines a matrix, which is used to describe the transforming coordinates. 130 * 131 * @since 11 132 * @version 1.0 133 */ 134 typedef struct OH_Drawing_Matrix OH_Drawing_Matrix; 135 136 /** 137 * @brief Defines a shaderEffect, which is used to describe the source color(s) for what is being drawn. 138 * 139 * @since 11 140 * @version 1.0 141 */ 142 typedef struct OH_Drawing_ShaderEffect OH_Drawing_ShaderEffect; 143 144 /** 145 * @brief Defines a filter, which is used to store maskFilter and colorFilter. 146 * 147 * @since 11 148 * @version 1.0 149 */ 150 typedef struct OH_Drawing_Filter OH_Drawing_Filter; 151 152 /** 153 * @brief Defines a maskFilter, which is used to perform transformations on the mask before drawing it. 154 * 155 * @since 11 156 * @version 1.0 157 */ 158 typedef struct OH_Drawing_MaskFilter OH_Drawing_MaskFilter; 159 160 /** 161 * @brief Defines a colorFilter, which is called a color and returns a new color. 162 * 163 * @since 11 164 * @version 1.0 165 */ 166 typedef struct OH_Drawing_ColorFilter OH_Drawing_ColorFilter; 167 168 /** 169 * @brief Defines a font, which is used to describe the font. 170 * 171 * @since 11 172 * @version 1.0 173 */ 174 typedef struct OH_Drawing_Font OH_Drawing_Font; 175 176 /** 177 * @brief Defines a memoryStream, which is used to describe the memory stream. 178 * 179 * @since 12 180 * @version 1.0 181 */ 182 typedef struct OH_Drawing_MemoryStream OH_Drawing_MemoryStream; 183 184 /** 185 * @brief Defines a typeface, which is used to describe the typeface. 186 * 187 * @since 11 188 * @version 1.0 189 */ 190 typedef struct OH_Drawing_Typeface OH_Drawing_Typeface; 191 192 /** 193 * @brief Defines a textBlob, which combines multiple text runs into an immutable container. 194 * Each text run consists of glyphs and positions. 195 * 196 * @since 11 197 * @version 1.0 198 */ 199 typedef struct OH_Drawing_TextBlob OH_Drawing_TextBlob; 200 201 /** 202 * @brief Defines a image, which is used to describe a two dimensional array of pixels to draw. 203 * 204 * @since 12 205 * @version 1.0 206 */ 207 typedef struct OH_Drawing_Image OH_Drawing_Image; 208 209 /** 210 * @brief Defines a sampling options, which is used to describe the sampling mode. 211 * 212 * @since 12 213 * @version 1.0 214 */ 215 typedef struct OH_Drawing_SamplingOptions OH_Drawing_SamplingOptions; 216 217 /** 218 * @brief Defines a textBlobBuilder, which is used to build the textBlob. 219 * 220 * @since 11 221 * @version 1.0 222 */ 223 typedef struct OH_Drawing_TextBlobBuilder OH_Drawing_TextBlobBuilder; 224 225 /** 226 * @brief Enumerates storage formats of bitmap pixels. 227 * 228 * @since 8 229 * @version 1.0 230 */ 231 typedef enum { 232 /** Unknown format. */ 233 COLOR_FORMAT_UNKNOWN, 234 /** Each pixel is represented by 8 bits, which together indicate alpha. */ 235 COLOR_FORMAT_ALPHA_8, 236 /** 237 * Each pixel is represented by 16 bits. From the most significant bit to the least significant bit, 238 * the first 5 bits indicate red, the subsequent 6 bits indicate green, and the last 5 bits indicate blue. 239 */ 240 COLOR_FORMAT_RGB_565, 241 /** 242 * Each pixel is represented by 16 bits. From the most significant bit to the least significant bit, 243 * every 4 bits indicate alpha, red, green, and blue, respectively. 244 */ 245 COLOR_FORMAT_ARGB_4444, 246 /** 247 * Each pixel is represented by 32 bits. From the most significant bit to the least significant bit, 248 * every 8 bits indicate alpha, red, green, and blue, respectively. 249 */ 250 COLOR_FORMAT_RGBA_8888, 251 /** 252 * Each pixel is represented by 32 bits. From the most significant bit to the least significant bit, 253 * every 8 bits indicate blue, green, red, and alpha, respectively. 254 */ 255 COLOR_FORMAT_BGRA_8888 256 } OH_Drawing_ColorFormat; 257 258 /** 259 * @brief Enumerates alpha formats of bitmap pixels. 260 * 261 * @since 8 262 * @version 1.0 263 */ 264 typedef enum { 265 /** Unknown format. */ 266 ALPHA_FORMAT_UNKNOWN, 267 /** The bitmap does not have the alpha component. */ 268 ALPHA_FORMAT_OPAQUE, 269 /** The color component of each pixel is premultiplied by the alpha component. */ 270 ALPHA_FORMAT_PREMUL, 271 /** The color component of each pixel is not premultiplied by the alpha component. */ 272 ALPHA_FORMAT_UNPREMUL 273 } OH_Drawing_AlphaFormat; 274 275 /** 276 * @brief The blending operation generates a new color for the two colors (source, destination). 277 * These operations are the same on the 4 color channels: red, green, blue, alpha. 278 * For these, we use alpha channel as an example, rather than naming each channel individually. 279 * 280 * For brevity, we use the following abbreviations. 281 * s : source 282 * d : destination 283 * sa : source alpha 284 * da : destination alpha 285 * 286 * Results are abbreviated 287 * r : if all 4 channels are computed in the same manner 288 * ra : result alpha channel 289 * rc : result "color": red, green, blue channels 290 * 291 * @since 11 292 * @version 1.0 293 */ 294 typedef enum { 295 /** r = 0. */ 296 BLEND_MODE_CLEAR, 297 /** r = s. */ 298 BLEND_MODE_SRC, 299 /** r = d. */ 300 BLEND_MODE_DST, 301 /** r = s + (1-sa)*d. */ 302 BLEND_MODE_SRC_OVER, 303 /** r = d + (1-da)*s. */ 304 BLEND_MODE_DST_OVER, 305 /** r = s * da. */ 306 BLEND_MODE_SRC_IN, 307 /** r = d * sa. */ 308 BLEND_MODE_DST_IN, 309 /** r = s * (1-da). */ 310 BLEND_MODE_SRC_OUT, 311 /** r = d * (1-sa). */ 312 BLEND_MODE_DST_OUT, 313 /** r = s*da + d*(1-sa). */ 314 BLEND_MODE_SRC_ATOP, 315 /** r = d*sa + s*(1-da). */ 316 BLEND_MODE_DST_ATOP, 317 /** r = s*(1-da) + d*(1-sa). */ 318 BLEND_MODE_XOR, 319 /** r = min(s + d, 1). */ 320 BLEND_MODE_PLUS, 321 /** r = s*d. */ 322 BLEND_MODE_MODULATE, 323 /** r = s + d - s*d. */ 324 BLEND_MODE_SCREEN, 325 /** multiply or screen, depending on destination. */ 326 BLEND_MODE_OVERLAY, 327 /** rc = s + d - max(s*da, d*sa), ra = s + (1-sa)*d. */ 328 BLEND_MODE_DARKEN, 329 /** rc = s + d - min(s*da, d*sa), ra = s + (1-sa)*d. */ 330 BLEND_MODE_LIGHTEN, 331 /** brighten destination to reflect source. */ 332 BLEND_MODE_COLOR_DODGE, 333 /** darken destination to reflect source. */ 334 BLEND_MODE_COLOR_BURN, 335 /** multiply or screen, depending on source. */ 336 BLEND_MODE_HARD_LIGHT, 337 /** lighten or darken, depending on source. */ 338 BLEND_MODE_SOFT_LIGHT, 339 /** rc = s + d - 2*(min(s*da, d*sa)), ra = s + (1-sa)*d. */ 340 BLEND_MODE_DIFFERENCE, 341 /** rc = s + d - two(s*d), ra = s + (1-sa)*d. */ 342 BLEND_MODE_EXCLUSION, 343 /** r = s*(1-da) + d*(1-sa) + s*d. */ 344 BLEND_MODE_MULTIPLY, 345 /** hue of source with saturation and luminosity of destination. */ 346 BLEND_MODE_HUE, 347 /** saturation of source with hue and luminosity of destination. */ 348 BLEND_MODE_SATURATION, 349 /** hue and saturation of source with luminosity of destination. */ 350 BLEND_MODE_COLOR, 351 /** luminosity of source with hue and saturation of destination. */ 352 BLEND_MODE_LUMINOSITY, 353 } OH_Drawing_BlendMode; 354 355 /** 356 * @brief Defines image info struct. 357 * 358 * @since 12 359 * @version 1.0 360 */ 361 typedef struct { 362 /** storage for width of image */ 363 int32_t width; 364 /** storage for height of image */ 365 int32_t height; 366 /** storage for color formats */ 367 OH_Drawing_ColorFormat colorType; 368 /** storage for alpha formats */ 369 OH_Drawing_AlphaFormat alphaType; 370 } OH_Drawing_Image_Info; 371 372 #ifdef __cplusplus 373 } 374 #endif 375 /** @} */ 376 #endif 377