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