1 /*! 2 * \file thorvg_capi.h 3 * 4 * \brief The module provides C bindings for the ThorVG library. 5 * Please refer to src/examples/Capi.cpp to find the thorvg_capi usage examples. 6 * 7 * The thorvg_capi module allows to implement the ThorVG client and provides 8 * the following functionalities: 9 * - drawing shapes: line, curve, polygon, circle, user-defined, ... 10 * - filling: solid, linear and radial gradient 11 * - scene graph & affine transformation (translation, rotation, scale, ...) 12 * - stroking: width, join, cap, dash 13 * - composition: blending, masking, path clipping 14 * - pictures: SVG, PNG, JPG, bitmap 15 * 16 */ 17 18 #include "../../lv_conf_internal.h" 19 #if LV_USE_THORVG_INTERNAL 20 #define TVG_BUILD 1 21 22 #ifndef __THORVG_CAPI_H__ 23 #define __THORVG_CAPI_H__ 24 25 #include <stdint.h> 26 #include <stdbool.h> 27 28 #ifdef TVG_API 29 #undef TVG_API 30 #endif 31 32 #ifndef TVG_STATIC 33 #ifdef _WIN32 34 #if TVG_BUILD 35 #define TVG_API __declspec(dllexport) 36 #else 37 #define TVG_API __declspec(dllimport) 38 #endif 39 #elif (defined(__SUNPRO_C) || defined(__SUNPRO_CC)) 40 #define TVG_API __global 41 #else 42 #if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__INTEL_COMPILER) 43 #define TVG_API __attribute__ ((visibility("default"))) 44 #else 45 #define TVG_API 46 #endif 47 #endif 48 #else 49 #define TVG_API 50 #endif 51 52 #ifdef TVG_DEPRECATED 53 #undef TVG_DEPRECATED 54 #endif 55 56 #ifdef _WIN32 57 #define TVG_DEPRECATED __declspec(deprecated) 58 #elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1) 59 #define TVG_DEPRECATED __attribute__ ((__deprecated__)) 60 #else 61 #define TVG_DEPRECATED 62 #endif 63 64 #ifdef __cplusplus 65 extern "C" { 66 #endif 67 68 /** 69 * \defgroup ThorVG_CAPI ThorVG_CAPI 70 * \brief ThorVG C language binding APIs. 71 * 72 * \{ 73 */ 74 75 76 /** 77 * \brief A structure responsible for managing and drawing graphical elements. 78 * 79 * It sets up the target buffer, which can be drawn on the screen. It stores the Tvg_Paint objects (Shape, Scene, Picture). 80 */ 81 typedef struct _Tvg_Canvas Tvg_Canvas; 82 83 84 /** 85 * \brief A structure representing a graphical element. 86 * 87 * \warning The TvgPaint objects cannot be shared between Canvases. 88 */ 89 typedef struct _Tvg_Paint Tvg_Paint; 90 91 92 /** 93 * \brief A structure representing a gradient fill of a Tvg_Paint object. 94 */ 95 typedef struct _Tvg_Gradient Tvg_Gradient; 96 97 98 /** 99 * \brief A structure representing an object that enables to save a Tvg_Paint object into a file. 100 */ 101 typedef struct _Tvg_Saver Tvg_Saver; 102 103 /** 104 * \brief A structure representing an animation controller object. 105 */ 106 typedef struct _Tvg_Animation Tvg_Animation; 107 108 109 /** 110 * \brief Enumeration specifying the engine type used for the graphics backend. For multiple backends bitwise operation is allowed. 111 * 112 * \ingroup ThorVGCapi_Initializer 113 */ 114 typedef enum { 115 TVG_ENGINE_SW = (1 << 1), ///< CPU rasterizer. 116 TVG_ENGINE_GL = (1 << 2) ///< OpenGL rasterizer. 117 } Tvg_Engine; 118 119 120 /** 121 * \brief Enumeration specifying the result from the APIs. 122 * 123 * All ThorVG APIs could potentially return one of the values in the list. 124 * Please note that some APIs may additionally specify the reasons that trigger their return values. 125 * 126 */ 127 typedef enum { 128 TVG_RESULT_SUCCESS = 0, ///< The value returned in case of a correct request execution. 129 TVG_RESULT_INVALID_ARGUMENT, ///< The value returned in the event of a problem with the arguments given to the API - e.g. empty paths or null pointers. 130 TVG_RESULT_INSUFFICIENT_CONDITION, ///< The value returned in case the request cannot be processed - e.g. asking for properties of an object, which does not exist. 131 TVG_RESULT_FAILED_ALLOCATION, ///< The value returned in case of unsuccessful memory allocation. 132 TVG_RESULT_MEMORY_CORRUPTION, ///< The value returned in the event of bad memory handling - e.g. failing in pointer releasing or casting 133 TVG_RESULT_NOT_SUPPORTED, ///< The value returned in case of choosing unsupported engine features(options). 134 TVG_RESULT_UNKNOWN ///< The value returned in all other cases. 135 } Tvg_Result; 136 137 138 /** 139 * \brief Enumeration indicating the method used in the composition of two objects - the target and the source. 140 * 141 * \ingroup ThorVGCapi_Paint 142 */ 143 typedef enum { 144 TVG_COMPOSITE_METHOD_NONE = 0, ///< No composition is applied. 145 TVG_COMPOSITE_METHOD_CLIP_PATH, ///< The intersection of the source and the target is determined and only the resulting pixels from the source are rendered. Note that ClipPath only supports the Shape type. @deprecated Use Paint::clip() instead. 146 TVG_COMPOSITE_METHOD_ALPHA_MASK, ///< The pixels of the source and the target are alpha blended. As a result, only the part of the source, which intersects with the target is visible. 147 TVG_COMPOSITE_METHOD_INVERSE_ALPHA_MASK, ///< The pixels of the source and the complement to the target's pixels are alpha blended. As a result, only the part of the source which is not covered by the target is visible. 148 TVG_COMPOSITE_METHOD_LUMA_MASK, ///< The source pixels are converted to grayscale (luma value) and alpha blended with the target. As a result, only the part of the source which intersects with the target is visible. \since 0.9 149 TVG_COMPOSITE_METHOD_INVERSE_LUMA_MASK ///< The source pixels are converted to grayscale (luma value) and complement to the target's pixels are alpha blended. As a result, only the part of the source which is not covered by the target is visible. \since 0.14 150 } Tvg_Composite_Method; 151 152 /** 153 * @brief Enumeration indicates the method used for blending paint. Please refer to the respective formulas for each method. 154 * 155 * \ingroup ThorVGCapi_Paint 156 * 157 * \since 0.15 158 */ 159 typedef enum { 160 TVG_BLEND_METHOD_NORMAL = 0, ///< Perform the alpha blending(default). S if (Sa == 255), otherwise (Sa * S) + (255 - Sa) * D 161 TVG_BLEND_METHOD_MULTIPLY, ///< Takes the RGB channel values from 0 to 255 of each pixel in the top layer and multiples them with the values for the corresponding pixel from the bottom layer. (S * D) 162 TVG_BLEND_METHOD_SCREEN, ///< The values of the pixels in the two layers are inverted, multiplied, and then inverted again. (S + D) - (S * D) 163 TVG_BLEND_METHOD_OVERLAY, ///< Combines Multiply and Screen blend modes. (2 * S * D) if (2 * D < Da), otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D) 164 TVG_BLEND_METHOD_SRCOVER, ///< Replace the bottom layer with the top layer. 165 TVG_BLEND_METHOD_DARKEN, ///< Creates a pixel that retains the smallest components of the top and bottom layer pixels. min(S, D) 166 TVG_BLEND_METHOD_LIGHTEN, ///< Only has the opposite action of Darken Only. max(S, D) 167 TVG_BLEND_METHOD_COLORDODGE, ///< Divides the bottom layer by the inverted top layer. D / (255 - S) 168 TVG_BLEND_METHOD_COLORBURN, ///< Divides the inverted bottom layer by the top layer, and then inverts the result. 255 - (255 - D) / S 169 TVG_BLEND_METHOD_HARDLIGHT, ///< The same as Overlay but with the color roles reversed. (2 * S * D) if (S < Sa), otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D) 170 TVG_BLEND_METHOD_SOFTLIGHT, ///< The same as Overlay but with applying pure black or white does not result in pure black or white. (1 - 2 * S) * (D ^ 2) + (2 * S * D) 171 TVG_BLEND_METHOD_DIFFERENCE, ///< Subtracts the bottom layer from the top layer or the other way around, to always get a non-negative value. (S - D) if (S > D), otherwise (D - S) 172 TVG_BLEND_METHOD_EXCLUSION, ///< The result is twice the product of the top and bottom layers, subtracted from their sum. s + d - (2 * s * d) 173 TVG_BLEND_METHOD_HUE, ///< Reserved. Not supported. 174 TVG_BLEND_METHOD_SATURATION, ///< Reserved. Not supported. 175 TVG_BLEND_METHOD_COLOR, ///< Reserved. Not supported. 176 TVG_BLEND_METHOD_LUMINOSITY, ///< Reserved. Not supported. 177 TVG_BLEND_METHOD_ADD, ///< Simply adds pixel values of one layer with the other. (S + D) 178 TVG_BLEND_METHOD_HARDMIX ///< Reserved. Not supported. 179 } Tvg_Blend_Method; 180 181 182 /** 183 * \see Tvg_Type 184 * \deprecated 185 */ 186 typedef enum { 187 TVG_IDENTIFIER_UNDEF = 0, ///< Undefined type. 188 TVG_IDENTIFIER_SHAPE, ///< A shape type paint. 189 TVG_IDENTIFIER_SCENE, ///< A scene type paint. 190 TVG_IDENTIFIER_PICTURE, ///< A picture type paint. 191 TVG_IDENTIFIER_LINEAR_GRAD, ///< A linear gradient type. 192 TVG_IDENTIFIER_RADIAL_GRAD, ///< A radial gradient type. 193 TVG_IDENTIFIER_TEXT ///< A text type paint. 194 } Tvg_Identifier; 195 196 197 /** 198 * \brief Enumeration indicating the ThorVG object type value. 199 * 200 * ThorVG's drawing objects can return object type values, allowing you to identify the specific type of each object. 201 * 202 * \ingroup ThorVGCapi_Paint 203 * 204 * \see tvg_paint_get_type() 205 * \see tvg_gradient_get_type() 206 * 207 * \note Experimental API 208 */ 209 typedef enum { 210 TVG_TYPE_UNDEF = 0, ///< Undefined type. 211 TVG_TYPE_SHAPE, ///< A shape type paint. 212 TVG_TYPE_SCENE, ///< A scene type paint. 213 TVG_TYPE_PICTURE, ///< A picture type paint. 214 TVG_TYPE_TEXT, ///< A text type paint. 215 TVG_TYPE_LINEAR_GRAD = 10, ///< A linear gradient type. 216 TVG_TYPE_RADIAL_GRAD ///< A radial gradient type. 217 } Tvg_Type; 218 219 220 /** 221 * \addtogroup ThorVGCapi_Shape 222 * \{ 223 */ 224 225 /** 226 * \brief Enumeration specifying the values of the path commands accepted by TVG. 227 * 228 * Not to be confused with the path commands from the svg path element (like M, L, Q, H and many others). 229 * TVG interprets all of them and translates to the ones from the PathCommand values. 230 */ 231 typedef enum { 232 TVG_PATH_COMMAND_CLOSE = 0, ///< Ends the current sub-path and connects it with its initial point - corresponds to Z command in the svg path commands. 233 TVG_PATH_COMMAND_MOVE_TO, ///< Sets a new initial point of the sub-path and a new current point - corresponds to M command in the svg path commands. 234 TVG_PATH_COMMAND_LINE_TO, ///< Draws a line from the current point to the given point and sets a new value of the current point - corresponds to L command in the svg path commands. 235 TVG_PATH_COMMAND_CUBIC_TO ///< Draws a cubic Bezier curve from the current point to the given point using two given control points and sets a new value of the current point - corresponds to C command in the svg path commands. 236 } Tvg_Path_Command; 237 238 239 /** 240 * \brief Enumeration determining the ending type of a stroke in the open sub-paths. 241 */ 242 typedef enum { 243 TVG_STROKE_CAP_SQUARE = 0, ///< The stroke is extended in both endpoints of a sub-path by a rectangle, with the width equal to the stroke width and the length equal to the half of the stroke width. For zero length sub-paths the square is rendered with the size of the stroke width. 244 TVG_STROKE_CAP_ROUND, ///< The stroke is extended in both endpoints of a sub-path by a half circle, with a radius equal to the half of a stroke width. For zero length sub-paths a full circle is rendered. 245 TVG_STROKE_CAP_BUTT ///< The stroke ends exactly at each of the two endpoints of a sub-path. For zero length sub-paths no stroke is rendered. 246 } Tvg_Stroke_Cap; 247 248 249 /** 250 * \brief Enumeration specifying how to fill the area outside the gradient bounds. 251 */ 252 typedef enum { 253 TVG_STROKE_JOIN_BEVEL = 0, ///< The outer corner of the joined path segments is bevelled at the join point. The triangular region of the corner is enclosed by a straight line between the outer corners of each stroke. 254 TVG_STROKE_JOIN_ROUND, ///< The outer corner of the joined path segments is rounded. The circular region is centered at the join point. 255 TVG_STROKE_JOIN_MITER ///< The outer corner of the joined path segments is spiked. The spike is created by extension beyond the join point of the outer edges of the stroke until they intersect. In case the extension goes beyond the limit, the join style is converted to the Bevel style. 256 } Tvg_Stroke_Join; 257 258 259 /** 260 * \brief Enumeration specifying how to fill the area outside the gradient bounds. 261 */ 262 typedef enum { 263 TVG_STROKE_FILL_PAD = 0, ///< The remaining area is filled with the closest stop color. 264 TVG_STROKE_FILL_REFLECT, ///< The gradient pattern is reflected outside the gradient area until the expected region is filled. 265 TVG_STROKE_FILL_REPEAT ///< The gradient pattern is repeated continuously beyond the gradient area until the expected region is filled. 266 } Tvg_Stroke_Fill; 267 268 269 /** 270 * \brief Enumeration specifying the algorithm used to establish which parts of the shape are treated as the inside of the shape. 271 */ 272 typedef enum { 273 TVG_FILL_RULE_WINDING = 0, ///< A line from the point to a location outside the shape is drawn. The intersections of the line with the path segment of the shape are counted. Starting from zero, if the path segment of the shape crosses the line clockwise, one is added, otherwise one is subtracted. If the resulting sum is non zero, the point is inside the shape. 274 TVG_FILL_RULE_EVEN_ODD ///< A line from the point to a location outside the shape is drawn and its intersections with the path segments of the shape are counted. If the number of intersections is an odd number, the point is inside the shape. 275 } Tvg_Fill_Rule; 276 277 /** \} */ // end addtogroup ThorVGCapi_Shape 278 279 280 /*! 281 * \addtogroup ThorVGCapi_Gradient 282 * \{ 283 */ 284 285 /*! 286 * \brief A data structure storing the information about the color and its relative position inside the gradient bounds. 287 */ 288 typedef struct 289 { 290 float offset; /**< The relative position of the color. */ 291 uint8_t r; /**< The red color channel value in the range [0 ~ 255]. */ 292 uint8_t g; /**< The green color channel value in the range [0 ~ 255]. */ 293 uint8_t b; /**< The blue color channel value in the range [0 ~ 255]. */ 294 uint8_t a; /**< The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. */ 295 } Tvg_Color_Stop; 296 297 /** \} */ // end addtogroup ThorVGCapi_Gradient 298 299 300 /** 301 * \brief A data structure representing a point in two-dimensional space. 302 */ 303 typedef struct 304 { 305 float x, y; 306 } Tvg_Point; 307 308 309 /** 310 * \brief A data structure representing a three-dimensional matrix. 311 * 312 * The elements e11, e12, e21 and e22 represent the rotation matrix, including the scaling factor. 313 * The elements e13 and e23 determine the translation of the object along the x and y-axis, respectively. 314 * The elements e31 and e32 are set to 0, e33 is set to 1. 315 */ 316 typedef struct 317 { 318 float e11, e12, e13; 319 float e21, e22, e23; 320 float e31, e32, e33; 321 } Tvg_Matrix; 322 323 324 /** 325 * \defgroup ThorVGCapi_Initializer Initializer 326 * \brief A module enabling initialization and termination of the TVG engines. 327 * 328 * \{ 329 */ 330 331 /************************************************************************/ 332 /* Engine API */ 333 /************************************************************************/ 334 /*! 335 * \brief Initializes TVG engines. 336 * 337 * TVG requires the running-engine environment. 338 * TVG runs its own task-scheduler for parallelizing rendering tasks efficiently. 339 * You can indicate the number of threads, the count of which is designated @p threads. 340 * In the initialization step, TVG will generate/spawn the threads as set by @p threads count. 341 * 342 * \code 343 * tvg_engine_init(TVG_ENGINE_SW, 0); //Initialize software renderer and use the main thread only 344 * \endcode 345 * 346 * \param[in] engine_method The engine types to initialize. This is relative to the Canvas types, in which it will be used. For multiple backends bitwise operation is allowed. 347 * - TVG_ENGINE_SW: CPU rasterizer 348 * - TVG_ENGINE_GL: OpenGL rasterizer (not supported yet) 349 * \param[in] threads The number of additional threads used to perform rendering. Zero indicates only the main thread is to be used. 350 * 351 * \return Tvg_Result enumeration. 352 * \retval TVG_RESULT_INVALID_ARGUMENT Unknown engine type. 353 * \retval TVG_RESULT_NOT_SUPPORTED Unsupported engine type. 354 * 355 * \note The Initializer keeps track of the number of times it was called. Threads count is fixed at the first init() call. 356 * \see tvg_engine_term() 357 * \see Tvg_Engine 358 */ 359 TVG_API Tvg_Result tvg_engine_init(Tvg_Engine engine_method, unsigned threads); 360 361 362 /*! 363 * \brief Terminates TVG engines. 364 * 365 * It should be called in case of termination of the TVG client with the same engine types as were passed when tvg_engine_init() was called. 366 * 367 * \code 368 * tvg_engine_init(TVG_ENGINE_SW, 0); 369 * //define canvas and shapes, update shapes, general rendering calls 370 * tvg_engine_term(TVG_ENGINE_SW); 371 * \endcode 372 * 373 * \param engine_method The engine types to terminate. This is relative to the Canvas types, in which it will be used. For multiple backends bitwise operation is allowed 374 * - TVG_ENGINE_SW: CPU rasterizer 375 * - TVG_ENGINE_GL: OpenGL rasterizer (not supported yet) 376 * 377 * \return Tvg_Result enumeration. 378 * \retval TVG_RESULT_INSUFFICIENT_CONDITION Nothing to be terminated. 379 * \retval TVG_RESULT_INVALID_ARGUMENT Unknown engine type. 380 * \retval TVG_RESULT_NOT_SUPPORTED Unsupported engine type. 381 * 382 * \see tvg_engine_init() 383 * \see Tvg_Engine 384 */ 385 TVG_API Tvg_Result tvg_engine_term(Tvg_Engine engine_method); 386 387 388 /** 389 * \brief Retrieves the version of the TVG engine. 390 * 391 * \param[out] major A major version number. 392 * \param[out] minor A minor version number. 393 * \param[out] micro A micro version number. 394 * \param[out] version The version of the engine in the format major.minor.micro, or a @p nullptr in case of an internal error. 395 * 396 * \return Tvg_Result enumeration. 397 * \retval TVG_RESULT_SUCCESS. 398 * 399 * \since 0.15 400 */ 401 TVG_API Tvg_Result tvg_engine_version(uint32_t* major, uint32_t* minor, uint32_t* micro, const char** version); 402 403 /** \} */ // end defgroup ThorVGCapi_Initializer 404 405 406 /** 407 * \defgroup ThorVGCapi_Canvas Canvas 408 * \brief A module for managing and drawing graphical elements. 409 * 410 * A canvas is an entity responsible for drawing the target. It sets up the drawing engine and the buffer, which can be drawn on the screen. It also manages given Paint objects. 411 * 412 * \note A Canvas behavior depends on the raster engine though the final content of the buffer is expected to be identical. 413 * \warning The Paint objects belonging to one Canvas can't be shared among multiple Canvases. 414 \{ 415 */ 416 417 418 /** 419 * \defgroup ThorVGCapi_SwCanvas SwCanvas 420 * \ingroup ThorVGCapi_Canvas 421 * 422 * \brief A module for rendering the graphical elements using the software engine. 423 * 424 * \{ 425 */ 426 427 /************************************************************************/ 428 /* SwCanvas API */ 429 /************************************************************************/ 430 431 /** 432 * \brief Enumeration specifying the methods of Memory Pool behavior policy. 433 */ 434 typedef enum { 435 TVG_MEMPOOL_POLICY_DEFAULT = 0, ///< Default behavior that ThorVG is designed to. 436 TVG_MEMPOOL_POLICY_SHAREABLE, ///< Memory Pool is shared among canvases. 437 TVG_MEMPOOL_POLICY_INDIVIDUAL ///< Allocate designated memory pool that is used only by the current canvas instance. 438 } Tvg_Mempool_Policy; 439 440 441 /** 442 * \brief Enumeration specifying the methods of combining the 8-bit color channels into 32-bit color. 443 */ 444 typedef enum { 445 TVG_COLORSPACE_ABGR8888 = 0, ///< The channels are joined in the order: alpha, blue, green, red. Colors are alpha-premultiplied. (a << 24 | b << 16 | g << 8 | r) 446 TVG_COLORSPACE_ARGB8888, ///< The channels are joined in the order: alpha, red, green, blue. Colors are alpha-premultiplied. (a << 24 | r << 16 | g << 8 | b) 447 TVG_COLORSPACE_ABGR8888S, ///< The channels are joined in the order: alpha, blue, green, red. Colors are un-alpha-premultiplied. @since 0.13 448 TVG_COLORSPACE_ARGB8888S ///< The channels are joined in the order: alpha, red, green, blue. Colors are un-alpha-premultiplied. @since 0.13 449 } Tvg_Colorspace; 450 451 452 /*! 453 * \brief Creates a Canvas object. 454 * 455 * \code 456 * Tvg_Canvas *canvas = NULL; 457 * 458 * tvg_engine_init(TVG_ENGINE_SW, 4); 459 * canvas = tvg_swcanvas_create(); 460 * 461 * //set up the canvas buffer 462 * uint32_t *buffer = NULL; 463 * buffer = (uint32_t*) malloc(sizeof(uint32_t) * 100 * 100); 464 * if (!buffer) return; 465 * 466 * tvg_swcanvas_set_target(canvas, buffer, 100, 100, 100, TVG_COLORSPACE_ARGB8888); 467 * 468 * //set up paints and add them into the canvas before drawing it 469 * 470 * tvg_canvas_destroy(canvas); 471 * tvg_engine_term(TVG_ENGINE_SW); 472 * \endcode 473 * 474 * \return A new Tvg_Canvas object. 475 */ 476 TVG_API Tvg_Canvas* tvg_swcanvas_create(void); 477 478 479 /*! 480 * \brief Sets the buffer used in the rasterization process and defines the used colorspace. 481 * 482 * For optimisation reasons TVG does not allocate memory for the output buffer on its own. 483 * The buffer of a desirable size should be allocated and owned by the caller. 484 * 485 * \param[in] canvas The Tvg_Canvas object managing the @p buffer. 486 * \param[in] buffer A pointer to the allocated memory block of the size @p stride x @p h. 487 * \param[in] stride The stride of the raster image - in most cases same value as @p w. 488 * \param[in] w The width of the raster image. 489 * \param[in] h The height of the raster image. 490 * \param[in] cs The colorspace value defining the way the 32-bits colors should be read/written. 491 * - TVG_COLORSPACE_ABGR8888 492 * - TVG_COLORSPACE_ARGB8888 493 * 494 * \return Tvg_Result enumeration. 495 * \retval TVG_RESULT_INVALID_ARGUMENTS An invalid canvas or buffer pointer passed or one of the @p stride, @p w or @p h being zero. 496 * \retval TVG_RESULT_INSUFFICIENT_CONDITION if the canvas is performing rendering. Please ensure the canvas is synced. 497 * \retval TVG_RESULT_NOT_SUPPORTED The software engine is not supported. 498 * 499 * \warning Do not access @p buffer during tvg_canvas_draw() - tvg_canvas_sync(). It should not be accessed while the engine is writing on it. 500 * 501 * \see Tvg_Colorspace 502 */ 503 TVG_API Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas* canvas, uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, Tvg_Colorspace cs); 504 505 506 /*! 507 * \brief Sets the software engine memory pool behavior policy. 508 * 509 * ThorVG draws a lot of shapes, it allocates/deallocates a few chunk of memory 510 * while processing rendering. It internally uses one shared memory pool 511 * which can be reused among the canvases in order to avoid memory overhead. 512 * 513 * Thus ThorVG suggests using a memory pool policy to satisfy user demands, 514 * if it needs to guarantee the thread-safety of the internal data access. 515 * 516 * \param[in] canvas The Tvg_Canvas object of which the Memory Pool behavior is to be specified. 517 * \param[in] policy The method specifying the Memory Pool behavior. The default value is @c TVG_MEMPOOL_POLICY_DEFAULT. 518 * 519 * \return Tvg_Result enumeration. 520 * \retval TVG_RESULT_INVALID_ARGUMENTS An invalid canvas pointer passed. 521 * \retval TVG_RESULT_INSUFFICIENT_CONDITION The canvas contains some paints already. 522 * \retval TVG_RESULT_NOT_SUPPORTED The software engine is not supported. 523 * 524 * \note When @c policy is set as @c TVG_MEMPOOL_POLICY_INDIVIDUAL, the current instance of canvas uses its own individual 525 * memory data, which is not shared with others. This is necessary when the canvas is accessed on a worker-thread. 526 * 527 * \warning It's not allowed after pushing any paints. 528 */ 529 TVG_API Tvg_Result tvg_swcanvas_set_mempool(Tvg_Canvas* canvas, Tvg_Mempool_Policy policy); 530 531 /** \} */ // end defgroup ThorVGCapi_SwCanvas 532 533 534 /************************************************************************/ 535 /* Common Canvas API */ 536 /************************************************************************/ 537 /*! 538 * \brief Clears the canvas internal data, releases all paints stored by the canvas and destroys the canvas object itself. 539 * 540 * \code 541 * static Tvg_Canvas *canvas = NULL; 542 * static uint32_t *buffer = NULL; 543 * 544 * static void _init() { 545 * canvas = tvg_swcanvas_create(); 546 * buffer = (uint32_t*) malloc(sizeof(uint32_t) * 100 * 100); 547 * tvg_swcanvas_set_target(canvas, buffer, 100, 100, 100, TVG_COLORSPACE_ARGB8888); 548 * } 549 * 550 * //a task called from main function in a loop 551 * static void _job(const int cmd) { 552 * //define a valid rectangle shape 553 * switch (cmd) { 554 * case CMD_EXIT: return 0; 555 * case CMD_ADD_RECT: 556 * tvg_canvas_push(canvas, rect); 557 * break; 558 * case CMD_DEL_RECT: 559 * tvg_paint_del(rect); 560 * //now to safely delete Tvg_Canvas, tvg_canvas_clear() API have to be used 561 * break; 562 * default: 563 * break; 564 * } 565 * } 566 * 567 * int main(int argc, char **argv) { 568 * int cmd = 0; 569 * int stop = 1; 570 * 571 * tvg_engine_init(TVG_ENGINE_SW, 4); 572 * 573 * while (stop) { 574 * //wait for a command e.g. from a console 575 * stop = _job(cmd); 576 * } 577 * tvg_canvas_clear(canvas, false); 578 * tvg_canvas_destroy(canvas); 579 * tvg_engine_term(TVG_ENGINE_SW); 580 * return 0; 581 * } 582 * 583 * tvg_canvas_destroy(canvas); 584 * tvg_engine_term(TVG_ENGINE_SW) 585 * \endcode 586 * 587 * \param[in] canvas The Tvg_Canvas object to be destroyed. 588 * 589 * \return Tvg_Result enumeration. 590 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer to the Tvg_Canvas object is passed. 591 * 592 * \note If the paints from the canvas should not be released, the tvg_canvas_clear() with a @c free argument value set to @c false should be called. 593 * Please be aware that in such a case TVG is not responsible for the paints release anymore and it has to be done manually in order to avoid memory leaks. 594 * 595 * \see tvg_paint_del(), tvg_canvas_clear() 596 */ 597 TVG_API Tvg_Result tvg_canvas_destroy(Tvg_Canvas* canvas); 598 599 600 /*! 601 * \brief Inserts a drawing element into the canvas using a Tvg_Paint object. 602 * 603 * \param[in] canvas The Tvg_Canvas object managing the @p paint. 604 * \param[in] paint The Tvg_Paint object to be drawn. 605 * 606 * Only the paints pushed into the canvas will be drawing targets. 607 * They are retained by the canvas until you call tvg_canvas_clear(). 608 * 609 * \return Tvg_Result return values: 610 * \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. 611 * \retval TVG_RESULT_INSUFFICIENT_CONDITION An internal error. 612 * 613 * \note The rendering order of the paints is the same as the order as they were pushed. Consider sorting the paints before pushing them if you intend to use layering. 614 * \see tvg_canvas_clear() 615 */ 616 TVG_API Tvg_Result tvg_canvas_push(Tvg_Canvas* canvas, Tvg_Paint* paint); 617 618 619 /*! 620 * \brief Reserves a memory block where the objects pushed into a canvas are stored. 621 * 622 * If the number of Tvg_Paints to be stored in a canvas is known in advance, calling this function reduces the multiple 623 * memory allocations thus improves the performance. 624 * 625 * \code 626 * Tvg_Canvas *canvas = NULL; 627 * 628 * tvg_engine_init(TVG_ENGINE_SW, 4); 629 * canvas = tvg_swcanvas_create(); 630 * 631 * uint32_t *buffer = NULL; 632 * buffer = (uint32_t*) malloc(sizeof(uint32_t) * 100 * 100); 633 * if (!buffer) return; 634 * 635 * tvg_swcanvas_set_target(canvas, buffer, 100, 100, 100, TVG_COLORSPACE_ARGB8888); 636 * 637 * tvg_canvas_destroy(canvas); 638 * tvg_engine_term(TVG_ENGINE_SW) 639 * \endcode 640 * 641 * \param[in] canvas The Tvg_Canvas object managing the reserved memory. 642 * \param[in] n The number of objects for which the memory is to be reserved. 643 * 644 * \return Tvg_Result enumeration. 645 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. 646 */ 647 TVG_DEPRECATED TVG_API Tvg_Result tvg_canvas_reserve(Tvg_Canvas* canvas, uint32_t n); 648 649 650 /*! 651 * \brief Sets the total number of the paints pushed into the canvas to be zero. 652 * Tvg_Paint objects stored in the canvas are released if @p free is set to @c true, otherwise the memory is not deallocated and 653 * all paints should be released manually in order to avoid memory leaks. 654 * 655 * \param[in] canvas The Tvg_Canvas object to be cleared. 656 * \param[in] free If @c true the memory occupied by paints is deallocated, otherwise it is not. 657 * 658 * \return Tvg_Result enumeration. 659 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. 660 * 661 * \see tvg_canvas_destroy() 662 */ 663 TVG_API Tvg_Result tvg_canvas_clear(Tvg_Canvas* canvas, bool free); 664 665 666 /*! 667 * \brief Updates all paints in a canvas. 668 * 669 * Should be called before drawing in order to prepare paints for the rendering. 670 * 671 * \code 672 * //A frame drawing example. Thread safety and events implementation is skipped to show only TVG code. 673 * 674 * static Tvg_Canvas *canvas = NULL; 675 * static Tvg_Paint *rect = NULL; 676 * 677 * int _frame_render(void) { 678 * tvg_canvas_update(canvas); 679 * tvg_canvas_draw(canvas); 680 * tvg_canvas_sync(canvas); 681 * } 682 * 683 * //event handler from your code or third party library 684 * void _event_handler(event *event_data) { 685 * if (!event_data) return NULL; 686 * switch(event_data.type) { 687 * case EVENT_RECT_ADD: 688 * if (!rect) { 689 * tvg_shape_append_rect(rect, 10, 10, 50, 50, 0, 0); 690 * tvg_shape_set_stroke_width(rect, 1.0f); 691 * tvg_shape_set_stroke_color(rect, 255, 0, 0, 255); 692 * tvg_canvas_push(canvas, rect); 693 * } 694 * break; 695 * case EVENT_RECT_MOVE: 696 * if (rect) tvg_paint_translate(rect, 10.0, 10.0); 697 * break; 698 * default: 699 * break; 700 * } 701 * } 702 * 703 * int main(int argc, char **argv) { 704 * //example handler from your code or third party lib 705 * event_handler_add(handler, _event_handler); 706 * 707 * //create frame rendering process which calls _frame_render() function. 708 * app_loop_begin(_frame_render); 709 * app_loop_finish(); 710 * cleanup(); 711 * } 712 * \endcode 713 * 714 * \param[in] canvas The Tvg_Canvas object to be updated. 715 * 716 * \return Tvg_Result enumeration. 717 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. 718 * 719 * \see tvg_canvas_update_paint() 720 */ 721 TVG_API Tvg_Result tvg_canvas_update(Tvg_Canvas* canvas); 722 723 724 /*! 725 * \brief Updates the given Tvg_Paint object from the canvas before the rendering. 726 * 727 * If a client application using the TVG library does not update the entire canvas with tvg_canvas_update() in the frame 728 * rendering process, Tvg_Paint objects previously added to the canvas should be updated manually with this function. 729 * 730 * \param[in] canvas The Tvg_Canvas object to which the @p paint belongs. 731 * \param[in] paint The Tvg_Paint object to be updated. 732 * 733 * \return Tvg_Result enumeration. 734 * \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. 735 * 736 * \see tvg_canvas_update() 737 */ 738 TVG_API Tvg_Result tvg_canvas_update_paint(Tvg_Canvas* canvas, Tvg_Paint* paint); 739 740 741 /*! 742 * \brief Requests the canvas to draw the Tvg_Paint objects. 743 * 744 * All paints from the given canvas will be rasterized to the buffer. 745 * 746 * \param[in] canvas The Tvg_Canvas object containing elements to be drawn. 747 * 748 * \return Tvg_Result enumeration. 749 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. 750 * 751 * \note Drawing can be asynchronous based on the assigned thread number. To guarantee the drawing is done, call tvg_canvas_sync() afterwards. 752 * \see tvg_canvas_sync() 753 */ 754 TVG_API Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas); 755 756 757 /*! 758 * \brief Guarantees that the drawing process is finished. 759 * 760 * Since the canvas rendering can be performed asynchronously, it should be called after the tvg_canvas_draw(). 761 * 762 * \param[in] canvas The Tvg_Canvas object containing elements which were drawn. 763 * 764 * \return Tvg_Result enumeration. 765 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. 766 * \retval TVG_RESULT_INSUFFICIENT_CONDITION @p canvas is either already in sync condition or in a damaged condition (a draw is required before syncing). 767 * 768 * \see tvg_canvas_draw() 769 */ 770 TVG_API Tvg_Result tvg_canvas_sync(Tvg_Canvas* canvas); 771 772 773 /*! 774 * \brief Sets the drawing region in the canvas. 775 * 776 * This function defines the rectangular area of the canvas that will be used for drawing operations. 777 * The specified viewport is used to clip the rendering output to the boundaries of the rectangle. 778 * 779 * \param[in] canvas The Tvg_Canvas object containing elements which were drawn. 780 * \param[in] x The x-coordinate of the upper-left corner of the rectangle. 781 * \param[in] y The y-coordinate of the upper-left corner of the rectangle. 782 * \param[in] w The width of the rectangle. 783 * \param[in] h The height of the rectangle. 784 * 785 * \return Tvg_Result enumeration. 786 * 787 * \warning It's not allowed to change the viewport during tvg_canvas_update() - tvg_canvas_sync() or tvg_canvas_push() - tvg_canvas_sync(). 788 * 789 * \note When resetting the target, the viewport will also be reset to the target size. 790 * \see tvg_swcanvas_set_target() 791 * \since 0.15 792 */ 793 TVG_API Tvg_Result tvg_canvas_set_viewport(Tvg_Canvas* canvas, int32_t x, int32_t y, int32_t w, int32_t h); 794 795 /** \} */ // end defgroup ThorVGCapi_Canvas 796 797 798 /** 799 * \defgroup ThorVGCapi_Paint Paint 800 * \brief A module for managing graphical elements. It enables duplication, transformation and composition. 801 * 802 * \{ 803 */ 804 805 /************************************************************************/ 806 /* Paint API */ 807 /************************************************************************/ 808 /*! 809 * \brief Releases the given Tvg_Paint object. 810 * 811 * \code 812 * //example of cleanup function 813 * Tvg_Paint *rect = NULL; //rectangle shape added in other function 814 * 815 * //rectangle delete API 816 * int rectangle_delete(void) { 817 * if (rect) tvg_paint_del(rect); 818 * rect = NULL; 819 * } 820 * 821 * int cleanup(void) { 822 * tvg_canvas_clear(canvas, false); 823 * tvg_canvas_destroy(canvas); 824 * canvas = NULL; 825 * } 826 * \endcode 827 * 828 * \param[in] paint The Tvg_Paint object to be released. 829 * 830 * \return Tvg_Result enumeration. 831 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 832 * 833 * \warning If this function is used, tvg_canvas_clear() with the @c free argument value set to @c false should be used in order to avoid unexpected behaviours. 834 * 835 * \see tvg_canvas_clear(), tvg_canvas_destroy() 836 */ 837 TVG_API Tvg_Result tvg_paint_del(Tvg_Paint* paint); 838 839 840 /*! 841 * \brief Scales the given Tvg_Paint object by the given factor. 842 * 843 * \param[in] paint The Tvg_Paint object to be scaled. 844 * \param[in] factor The value of the scaling factor. The default value is 1. 845 * 846 * \return Tvg_Result enumeration. 847 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 848 * \retval TVG_RESULT_INSUFFICIENT_CONDITION in case a custom transform is applied. 849 * 850 * \see tvg_paint_set_transform() 851 */ 852 TVG_API Tvg_Result tvg_paint_scale(Tvg_Paint* paint, float factor); 853 854 855 /*! 856 * \brief Rotates the given Tvg_Paint by the given angle. 857 * 858 * The angle in measured clockwise from the horizontal axis. 859 * The rotational axis passes through the point on the object with zero coordinates. 860 * 861 * \param[in] paint The Tvg_Paint object to be rotated. 862 * \param[in] degree The value of the rotation angle in degrees. 863 * 864 * \return Tvg_Result enumeration. 865 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 866 * \retval TVG_RESULT_INSUFFICIENT_CONDITION in case a custom transform is applied. 867 * 868 * \see tvg_paint_set_transform() 869 */ 870 TVG_API Tvg_Result tvg_paint_rotate(Tvg_Paint* paint, float degree); 871 872 873 /*! 874 * \brief Moves the given Tvg_Paint in a two-dimensional space. 875 * 876 * The origin of the coordinate system is in the upper-left corner of the canvas. 877 * The horizontal and vertical axes point to the right and down, respectively. 878 * 879 * \param[in] paint The Tvg_Paint object to be shifted. 880 * \param[in] x The value of the horizontal shift. 881 * \param[in] y The value of the vertical shift. 882 * 883 * \return Tvg_Result enumeration. 884 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 885 * \retval TVG_RESULT_INSUFFICIENT_CONDITION in case a custom transform is applied. 886 * 887 * \see tvg_paint_set_transform() 888 */ 889 TVG_API Tvg_Result tvg_paint_translate(Tvg_Paint* paint, float x, float y); 890 891 892 /*! 893 * \brief Transforms the given Tvg_Paint using the augmented transformation matrix. 894 * 895 * The augmented matrix of the transformation is expected to be given. 896 * 897 * \param[in] paint The Tvg_Paint object to be transformed. 898 * \param[in] m The 3x3 augmented matrix. 899 * 900 * \return Tvg_Result enumeration. 901 * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr is passed as the argument. 902 */ 903 TVG_API Tvg_Result tvg_paint_set_transform(Tvg_Paint* paint, const Tvg_Matrix* m); 904 905 906 /*! 907 * \brief Gets the matrix of the affine transformation of the given Tvg_Paint object. 908 * 909 * In case no transformation was applied, the identity matrix is returned. 910 * 911 * \param[in] paint The Tvg_Paint object of which to get the transformation matrix. 912 * \param[out] m The 3x3 augmented matrix. 913 * 914 * \return Tvg_Result enumeration. 915 * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr is passed as the argument. 916 */ 917 TVG_API Tvg_Result tvg_paint_get_transform(Tvg_Paint* paint, Tvg_Matrix* m); 918 919 920 /*! 921 * \brief Sets the opacity of the given Tvg_Paint. 922 * 923 * \param[in] paint The Tvg_Paint object of which the opacity value is to be set. 924 * \param[in] opacity The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. 925 * 926 * \return Tvg_Result enumeration. 927 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 928 * 929 * \note Setting the opacity with this API may require multiple renderings using a composition. It is recommended to avoid changing the opacity if possible. 930 */ 931 TVG_API Tvg_Result tvg_paint_set_opacity(Tvg_Paint* paint, uint8_t opacity); 932 933 934 /*! 935 * \brief Gets the opacity of the given Tvg_Paint. 936 * 937 * \param[in] paint The Tvg_Paint object of which to get the opacity value. 938 * \param[out] opacity The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. 939 * 940 * \return Tvg_Result enumeration. 941 * \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. 942 */ 943 TVG_API Tvg_Result tvg_paint_get_opacity(const Tvg_Paint* paint, uint8_t* opacity); 944 945 946 /*! 947 * \brief Duplicates the given Tvg_Paint object. 948 * 949 * Creates a new object and sets its all properties as in the original object. 950 * 951 * \param[in] paint The Tvg_Paint object to be copied. 952 * 953 * \return A copied Tvg_Paint object if succeed, @c nullptr otherwise. 954 */ 955 TVG_API Tvg_Paint* tvg_paint_duplicate(Tvg_Paint* paint); 956 957 958 /*! 959 * \brief Gets the axis-aligned bounding box of the Tvg_Paint object. 960 * 961 * \param[in] paint The Tvg_Paint object of which to get the bounds. 962 * \param[out] x The x-coordinate of the upper-left corner of the object. 963 * \param[out] y The y-coordinate of the upper-left corner of the object. 964 * \param[out] w The width of the object. 965 * \param[out] h The height of the object. 966 * \param[in] transformed If @c true, the paint's transformations are taken into account in the scene it belongs to. Otherwise they aren't. 967 * 968 * \return Tvg_Result enumeration. 969 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 970 * 971 * \note This is useful when you need to figure out the bounding box of the paint in the canvas space. 972 * \note The bounding box doesn't indicate the actual drawing region. It's the smallest rectangle that encloses the object. 973 * \note If @p transformed is @c true, the paint needs to be pushed into a canvas and updated before this api is called. 974 * \see tvg_canvas_update_paint() 975 */ 976 TVG_API Tvg_Result tvg_paint_get_bounds(const Tvg_Paint* paint, float* x, float* y, float* w, float* h, bool transformed); 977 978 979 /*! 980 * \brief Sets the composition target object and the composition method. 981 * 982 * \param[in] paint The source object of the composition. 983 * \param[in] target The target object of the composition. 984 * \param[in] method The method used to composite the source object with the target. 985 * 986 * \return Tvg_Result enumeration. 987 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid @p paint or @p target object or the @p method equal to TVG_COMPOSITE_METHOD_NONE. 988 */ 989 TVG_API Tvg_Result tvg_paint_set_composite_method(Tvg_Paint* paint, Tvg_Paint* target, Tvg_Composite_Method method); 990 991 992 /** 993 * \brief Gets the composition target object and the composition method. 994 * 995 * \param[in] paint The source object of the composition. 996 * \param[out] target The target object of the composition. 997 * \param[out] method The method used to composite the source object with the target. 998 * 999 * \return Tvg_Result enumeration. 1000 * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr is passed as the argument. 1001 */ 1002 TVG_API Tvg_Result tvg_paint_get_composite_method(const Tvg_Paint* paint, const Tvg_Paint** target, Tvg_Composite_Method* method); 1003 1004 1005 /*! 1006 * \brief Clip the drawing region of the paint object. 1007 * 1008 * This function restricts the drawing area of the paint object to the specified shape's paths. 1009 * 1010 * \param[in] paint The target object of the clipping. 1011 * \param[in] clipper The shape object as the clipper. 1012 * 1013 * \return Tvg_Result enumeration. 1014 * \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. 1015 * \retval TVG_RESULT_NOT_SUPPORTED If the @p clipper type is not Shape. 1016 * 1017 * \note Experimental API 1018 */ 1019 TVG_API Tvg_Result tvg_paint_set_clip(Tvg_Paint* paint, Tvg_Paint* clipper); 1020 1021 1022 /** 1023 * \brief Gets the unique value of the paint instance indicating the instance type. 1024 * 1025 * \param[in] paint The Tvg_Paint object of which to get the type value. 1026 * \param[out] type The unique type of the paint instance type. 1027 * 1028 * \return Tvg_Result enumeration. 1029 * \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. 1030 * 1031 * \note Experimental API 1032 */ 1033 TVG_API Tvg_Result tvg_paint_get_type(const Tvg_Paint* paint, Tvg_Type* type); 1034 1035 1036 /** 1037 * \see tvg_paint_get_type() 1038 */ 1039 TVG_DEPRECATED TVG_API Tvg_Result tvg_paint_get_identifier(const Tvg_Paint* paint, Tvg_Identifier* identifier); 1040 1041 1042 /** 1043 * @brief Sets the blending method for the paint object. 1044 * 1045 * The blending feature allows you to combine colors to create visually appealing effects, including transparency, lighting, shading, and color mixing, among others. 1046 * its process involves the combination of colors or images from the source paint object with the destination (the lower layer image) using blending operations. 1047 * The blending operation is determined by the chosen @p BlendMethod, which specifies how the colors or images are combined. 1048 * 1049 * \param[in] paint The Tvg_Paint object of which to set the blend method. 1050 * \param[in] method The blending method to be set. 1051 * 1052 * \return Tvg_Result enumeration. 1053 * \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. 1054 * 1055 * \since 0.15 1056 */ 1057 TVG_API Tvg_Result tvg_paint_set_blend_method(Tvg_Paint* paint, Tvg_Blend_Method method); 1058 1059 1060 /** \} */ // end defgroup ThorVGCapi_Paint 1061 1062 /** 1063 * \defgroup ThorVGCapi_Shape Shape 1064 * 1065 * \brief A module for managing two-dimensional figures and their properties. 1066 * 1067 * A shape has three major properties: shape outline, stroking, filling. The outline in the shape is retained as the path. 1068 * Path can be composed by accumulating primitive commands such as tvg_shape_move_to(), tvg_shape_line_to(), tvg_shape_cubic_to() or complete shape interfaces such as tvg_shape_append_rect(), tvg_shape_append_circle(), etc. 1069 * Path can consists of sub-paths. One sub-path is determined by a close command. 1070 * 1071 * The stroke of a shape is an optional property in case the shape needs to be represented with/without the outline borders. 1072 * It's efficient since the shape path and the stroking path can be shared with each other. It's also convenient when controlling both in one context. 1073 * 1074 * \{ 1075 */ 1076 1077 /************************************************************************/ 1078 /* Shape API */ 1079 /************************************************************************/ 1080 /*! 1081 * \brief Creates a new shape object. 1082 * 1083 * \return A new shape object. 1084 */ 1085 TVG_API Tvg_Paint* tvg_shape_new(void); 1086 1087 1088 /*! 1089 * \brief Resets the shape path properties. 1090 * 1091 * The color, the fill and the stroke properties are retained. 1092 * 1093 * \param[in] paint A Tvg_Paint pointer to the shape object. 1094 * 1095 * \return Tvg_Result enumeration. 1096 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1097 * 1098 * \note The memory, where the path data is stored, is not deallocated at this stage for caching effect. 1099 */ 1100 TVG_API Tvg_Result tvg_shape_reset(Tvg_Paint* paint); 1101 1102 1103 /*! 1104 * \brief Sets the initial point of the sub-path. 1105 * 1106 * The value of the current point is set to the given point. 1107 * 1108 * \param[in] paint A Tvg_Paint pointer to the shape object. 1109 * \param[in] x The horizontal coordinate of the initial point of the sub-path. 1110 * \param[in] y The vertical coordinate of the initial point of the sub-path. 1111 * 1112 * \return Tvg_Result enumeration. 1113 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1114 */ 1115 TVG_API Tvg_Result tvg_shape_move_to(Tvg_Paint* paint, float x, float y); 1116 1117 1118 /*! 1119 * \brief Adds a new point to the sub-path, which results in drawing a line from the current point to the given end-point. 1120 * 1121 * The value of the current point is set to the given end-point. 1122 * 1123 * \param[in] paint A Tvg_Paint pointer to the shape object. 1124 * \param[in] x The horizontal coordinate of the end-point of the line. 1125 * \param[in] y The vertical coordinate of the end-point of the line. 1126 1127 * \return Tvg_Result enumeration. 1128 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1129 * 1130 * \note In case this is the first command in the path, it corresponds to the tvg_shape_move_to() call. 1131 */ 1132 TVG_API Tvg_Result tvg_shape_line_to(Tvg_Paint* paint, float x, float y); 1133 1134 1135 /*! 1136 * \brief Adds new points to the sub-path, which results in drawing a cubic Bezier curve. 1137 * 1138 * The Bezier curve starts at the current point and ends at the given end-point (@p x, @p y). Two control points (@p cx1, @p cy1) and (@p cx2, @p cy2) are used to determine the shape of the curve. 1139 * The value of the current point is set to the given end-point. 1140 * 1141 * \param[in] paint A Tvg_Paint pointer to the shape object. 1142 * \param[in] cx1 The horizontal coordinate of the 1st control point. 1143 * \param[in] cy1 The vertical coordinate of the 1st control point. 1144 * \param[in] cx2 The horizontal coordinate of the 2nd control point. 1145 * \param[in] cy2 The vertical coordinate of the 2nd control point. 1146 * \param[in] x The horizontal coordinate of the endpoint of the curve. 1147 * \param[in] y The vertical coordinate of the endpoint of the curve. 1148 * 1149 * \return Tvg_Result enumeration. 1150 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1151 * 1152 * \note In case this is the first command in the path, no data from the path are rendered. 1153 */ 1154 TVG_API Tvg_Result tvg_shape_cubic_to(Tvg_Paint* paint, float cx1, float cy1, float cx2, float cy2, float x, float y); 1155 1156 1157 /*! 1158 * \brief Closes the current sub-path by drawing a line from the current point to the initial point of the sub-path. 1159 * 1160 * The value of the current point is set to the initial point of the closed sub-path. 1161 * 1162 * \param[in] paint A Tvg_Paint pointer to the shape object. 1163 * 1164 * \return Tvg_Result enumeration. 1165 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1166 * 1167 * \note In case the sub-path does not contain any points, this function has no effect. 1168 */ 1169 TVG_API Tvg_Result tvg_shape_close(Tvg_Paint* paint); 1170 1171 1172 /*! 1173 * \brief Appends a rectangle to the path. 1174 * 1175 * The rectangle with rounded corners can be achieved by setting non-zero values to @p rx and @p ry arguments. 1176 * The @p rx and @p ry values specify the radii of the ellipse defining the rounding of the corners. 1177 * 1178 * The position of the rectangle is specified by the coordinates of its upper-left corner - @p x and @p y arguments. 1179 * 1180 * The rectangle is treated as a new sub-path - it is not connected with the previous sub-path. 1181 * 1182 * The value of the current point is set to (@p x + @p rx, @p y) - in case @p rx is greater 1183 * than @p w/2 the current point is set to (@p x + @p w/2, @p y) 1184 * 1185 * \param[in] paint A Tvg_Paint pointer to the shape object. 1186 * \param[in] x The horizontal coordinate of the upper-left corner of the rectangle. 1187 * \param[in] y The vertical coordinate of the upper-left corner of the rectangle. 1188 * \param[in] w The width of the rectangle. 1189 * \param[in] h The height of the rectangle. 1190 * \param[in] rx The x-axis radius of the ellipse defining the rounded corners of the rectangle. 1191 * \param[in] ry The y-axis radius of the ellipse defining the rounded corners of the rectangle. 1192 * 1193 * \return Tvg_Result enumeration. 1194 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1195 * 1196 & \note For @p rx and @p ry greater than or equal to the half of @p w and the half of @p h, respectively, the shape become an ellipse. 1197 */ 1198 TVG_API Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y, float w, float h, float rx, float ry); 1199 1200 1201 /*! 1202 * \brief Appends an ellipse to the path. 1203 * 1204 * The position of the ellipse is specified by the coordinates of its center - @p cx and @p cy arguments. 1205 * 1206 * The ellipse is treated as a new sub-path - it is not connected with the previous sub-path. 1207 * 1208 * The value of the current point is set to (@p cx, @p cy - @p ry). 1209 * 1210 * \param[in] paint A Tvg_Paint pointer to the shape object. 1211 * \param[in] cx The horizontal coordinate of the center of the ellipse. 1212 * \param[in] cy The vertical coordinate of the center of the ellipse. 1213 * \param[in] rx The x-axis radius of the ellipse. 1214 * \param[in] ry The y-axis radius of the ellipse. 1215 * 1216 * \return Tvg_Result enumeration. 1217 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1218 */ 1219 TVG_API Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry); 1220 1221 1222 /*! 1223 * \brief Appends a circular arc to the path. 1224 * 1225 * The arc is treated as a new sub-path - it is not connected with the previous sub-path. 1226 * The current point value is set to the end-point of the arc in case @p pie is @c false, and to the center of the arc otherwise. 1227 * 1228 * \param[in] paint A Tvg_Paint pointer to the shape object. 1229 * \param[in] cx The horizontal coordinate of the center of the arc. 1230 * \param[in] cy The vertical coordinate of the center of the arc. 1231 * \param[in] radius The radius of the arc. 1232 * \param[in] startAngle The start angle of the arc given in degrees, measured counter-clockwise from the horizontal line. 1233 * \param[in] sweep The central angle of the arc given in degrees, measured counter-clockwise from @p startAngle. 1234 * \param[in] pie Specifies whether to draw radii from the arc's center to both of its end-point - drawn if @c true. 1235 * 1236 * \return Tvg_Result enumeration. 1237 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1238 * 1239 * \note Setting @p sweep value greater than 360 degrees, is equivalent to calling tvg_shape_append_circle(paint, cx, cy, radius, radius). 1240 */ 1241 TVG_API Tvg_Result tvg_shape_append_arc(Tvg_Paint* paint, float cx, float cy, float radius, float startAngle, float sweep, uint8_t pie); 1242 1243 1244 /*! 1245 * \brief Appends a given sub-path to the path. 1246 * 1247 * The current point value is set to the last point from the sub-path. 1248 * For each command from the @p cmds array, an appropriate number of points in @p pts array should be specified. 1249 * If the number of points in the @p pts array is different than the number required by the @p cmds array, the shape with this sub-path will not be displayed on the screen. 1250 * 1251 * \param[in] paint A Tvg_Paint pointer to the shape object. 1252 * \param[in] cmds The array of the commands in the sub-path. 1253 * \param[in] cmdCnt The length of the @p cmds array. 1254 * \param[in] pts The array of the two-dimensional points. 1255 * \param[in] ptsCnt The length of the @p pts array. 1256 * 1257 * \return Tvg_Result enumeration. 1258 * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument or @p cmdCnt or @p ptsCnt equal to zero. 1259 */ 1260 TVG_API Tvg_Result tvg_shape_append_path(Tvg_Paint* paint, const Tvg_Path_Command* cmds, uint32_t cmdCnt, const Tvg_Point* pts, uint32_t ptsCnt); 1261 1262 1263 /*! 1264 * \brief Gets the points values of the path. 1265 * 1266 * The function does not allocate any data, it operates on internal memory. There is no need to free the @p pts array. 1267 * 1268 * \code 1269 * Tvg_Paint *shape = tvg_shape_new(); 1270 * Tvg_Point *coords = NULL; 1271 * uint32_t len = 0; 1272 * 1273 * tvg_shape_append_circle(shape, 10, 10, 50, 50); 1274 * tvg_shape_get_path_coords(shape, (const Tvg_Point**)&coords, &len); 1275 * //TVG approximates a circle by four Bezier curves. In the example above the coords array stores their coordinates. 1276 * \endcode 1277 * 1278 * \param[in] paint A Tvg_Paint pointer to the shape object. 1279 * \param[out] pts The pointer to the array of the two-dimensional points from the path. 1280 * \param[out] cnt The length of the @p pts array. 1281 * 1282 * \return Tvg_Result enumeration. 1283 * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. 1284 */ 1285 TVG_API Tvg_Result tvg_shape_get_path_coords(const Tvg_Paint* paint, const Tvg_Point** pts, uint32_t* cnt); 1286 1287 1288 /*! 1289 * \brief Gets the commands data of the path. 1290 * 1291 * The function does not allocate any data. There is no need to free the @p cmds array. 1292 * 1293 * \code 1294 * Tvg_Paint *shape = tvg_shape_new(); 1295 * Tvg_Path_Command *cmds = NULL; 1296 * uint32_t len = 0; 1297 * 1298 * tvg_shape_append_circle(shape, 10, 10, 50, 50); 1299 * tvg_shape_get_path_commands(shape, (const Tvg_Path_Command**)&cmds, &len); 1300 * //TVG approximates a circle by four Bezier curves. In the example above the cmds array stores the commands of the path data. 1301 * \endcode 1302 * 1303 * \param[in] paint A Tvg_Paint pointer to the shape object. 1304 * \param[out] cmds The pointer to the array of the commands from the path. 1305 * \param[out] cnt The length of the @p cmds array. 1306 * 1307 * \return Tvg_Result enumeration. 1308 * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. 1309 */ 1310 TVG_API Tvg_Result tvg_shape_get_path_commands(const Tvg_Paint* paint, const Tvg_Path_Command** cmds, uint32_t* cnt); 1311 1312 1313 /*! 1314 * \brief Sets the stroke width for all of the figures from the @p paint. 1315 * 1316 * \param[in] paint A Tvg_Paint pointer to the shape object. 1317 * \param[in] width The width of the stroke. The default value is 0. 1318 * 1319 * \return Tvg_Result enumeration. 1320 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1321 */ 1322 TVG_API Tvg_Result tvg_shape_set_stroke_width(Tvg_Paint* paint, float width); 1323 1324 1325 /*! 1326 * \brief Gets the shape's stroke width. 1327 * 1328 * \param[in] paint A Tvg_Paint pointer to the shape object. 1329 * \param[out] width The stroke width. 1330 * 1331 * \return Tvg_Result enumeration. 1332 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. 1333 */ 1334 TVG_API Tvg_Result tvg_shape_get_stroke_width(const Tvg_Paint* paint, float* width); 1335 1336 1337 /*! 1338 * \brief Sets the shape's stroke color. 1339 * 1340 * \param[in] paint A Tvg_Paint pointer to the shape object. 1341 * \param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0. 1342 * \param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0. 1343 * \param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0. 1344 * \param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. 1345 * 1346 * \return Tvg_Result enumeration. 1347 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1348 * 1349 * \note Either a solid color or a gradient fill is applied, depending on what was set as last. 1350 */ 1351 TVG_API Tvg_Result tvg_shape_set_stroke_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a); 1352 1353 1354 /*! 1355 * \brief Gets the shape's stroke color. 1356 * 1357 * \param[in] paint A Tvg_Paint pointer to the shape object. 1358 * \param[out] r The red color channel value in the range [0 ~ 255]. The default value is 0. 1359 * \param[out] g The green color channel value in the range [0 ~ 255]. The default value is 0. 1360 * \param[out] b The blue color channel value in the range [0 ~ 255]. The default value is 0. 1361 * \param[out] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. 1362 * 1363 * \return Tvg_Result enumeration. 1364 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1365 * \retval TVG_RESULT_INSUFFICIENT_CONDITION No stroke was set. 1366 */ 1367 TVG_API Tvg_Result tvg_shape_get_stroke_color(const Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a); 1368 1369 1370 /*! 1371 * \brief Sets the linear gradient fill of the stroke for all of the figures from the path. 1372 * 1373 * \param[in] paint A Tvg_Paint pointer to the shape object. 1374 * \param[in] grad The linear gradient fill. 1375 * 1376 * \return Tvg_Result enumeration. 1377 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1378 * \retval TVG_RESULT_MEMORY_CORRUPTION An invalid Tvg_Gradient pointer or an error with accessing it. 1379 * 1380 * \note Either a solid color or a gradient fill is applied, depending on what was set as last. 1381 */ 1382 TVG_API Tvg_Result tvg_shape_set_stroke_linear_gradient(Tvg_Paint* paint, Tvg_Gradient* grad); 1383 1384 1385 /*! 1386 * \brief Sets the radial gradient fill of the stroke for all of the figures from the path. 1387 * 1388 * \param[in] paint A Tvg_Paint pointer to the shape object. 1389 * \param[in] grad The radial gradient fill. 1390 * 1391 * \return Tvg_Result enumeration. 1392 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1393 * \retval TVG_RESULT_MEMORY_CORRUPTION An invalid Tvg_Gradient pointer or an error with accessing it. 1394 * 1395 * \note Either a solid color or a gradient fill is applied, depending on what was set as last. 1396 */ 1397 TVG_API Tvg_Result tvg_shape_set_stroke_radial_gradient(Tvg_Paint* paint, Tvg_Gradient* grad); 1398 1399 1400 /*! 1401 * \brief Gets the gradient fill of the shape's stroke. 1402 * 1403 * The function does not allocate any memory. 1404 * 1405 * \param[in] paint A Tvg_Paint pointer to the shape object. 1406 * \param[out] grad The gradient fill. 1407 * 1408 * \return Tvg_Result enumeration. 1409 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. 1410 */ 1411 TVG_API Tvg_Result tvg_shape_get_stroke_gradient(const Tvg_Paint* paint, Tvg_Gradient** grad); 1412 1413 1414 /*! 1415 * \brief Sets the shape's stroke dash pattern. 1416 * 1417 * \param[in] paint A Tvg_Paint pointer to the shape object. 1418 * \param[in] dashPattern The array of consecutive pair values of the dash length and the gap length. 1419 * \param[in] cnt The size of the @p dashPattern array. 1420 * 1421 * \return Tvg_Result enumeration. 1422 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument and @p cnt > 0, the given length of the array is less than two or any of the @p dashPattern values is zero or less. 1423 * 1424 * \note To reset the stroke dash pattern, pass @c nullptr to @p dashPattern and zero to @p cnt. 1425 */ 1426 TVG_API Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt); 1427 1428 1429 /*! 1430 * \brief Gets the dash pattern of the stroke. 1431 * 1432 * The function does not allocate any memory. 1433 * 1434 * \param[in] paint A Tvg_Paint pointer to the shape object. 1435 * \param[out] dashPattern The array of consecutive pair values of the dash length and the gap length. 1436 * \param[out] cnt The size of the @p dashPattern array. 1437 * 1438 * \return Tvg_Result enumeration. 1439 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. 1440 */ 1441 TVG_API Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt); 1442 1443 1444 /*! 1445 * \brief Sets the cap style used for stroking the path. 1446 * 1447 * The cap style specifies the shape to be used at the end of the open stroked sub-paths. 1448 * 1449 * \param[in] paint A Tvg_Paint pointer to the shape object. 1450 * \param[in] cap The cap style value. The default value is @c TVG_STROKE_CAP_SQUARE. 1451 * 1452 * \return Tvg_Result enumeration. 1453 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1454 */ 1455 TVG_API Tvg_Result tvg_shape_set_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap cap); 1456 1457 1458 /*! 1459 * \brief Gets the stroke cap style used for stroking the path. 1460 * 1461 * \param[in] paint A Tvg_Paint pointer to the shape object. 1462 * \param[out] cap The cap style value. 1463 * 1464 * \return Tvg_Result enumeration. 1465 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. 1466 */ 1467 TVG_API Tvg_Result tvg_shape_get_stroke_cap(const Tvg_Paint* paint, Tvg_Stroke_Cap* cap); 1468 1469 1470 /*! 1471 * \brief Sets the join style for stroked path segments. 1472 * 1473 * \param[in] paint A Tvg_Paint pointer to the shape object. 1474 * \param[in] join The join style value. The default value is @c TVG_STROKE_JOIN_BEVEL. 1475 * 1476 * \return Tvg_Result enumeration. 1477 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1478 */ 1479 TVG_API Tvg_Result tvg_shape_set_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Join join); 1480 1481 1482 /*! 1483 * \brief The function gets the stroke join method 1484 * 1485 * \param[in] paint A Tvg_Paint pointer to the shape object. 1486 * \param[out] join The join style value. 1487 * 1488 * \return Tvg_Result enumeration. 1489 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. 1490 */ 1491 TVG_API Tvg_Result tvg_shape_get_stroke_join(const Tvg_Paint* paint, Tvg_Stroke_Join* join); 1492 1493 1494 /*! 1495 * \brief Sets the stroke miterlimit. 1496 * 1497 * \param[in] paint A Tvg_Paint pointer to the shape object. 1498 * \param[in] miterlimit The miterlimit imposes a limit on the extent of the stroke join when the @c TVG_STROKE_JOIN_MITER join style is set. The default value is 4. 1499 * 1500 * \return Tvg_Result enumeration. 1501 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer or Unsupported @p miterlimit values (less than zero). 1502 * 1503 * \since 0.11 1504 */ 1505 TVG_API Tvg_Result tvg_shape_set_stroke_miterlimit(Tvg_Paint* paint, float miterlimit); 1506 1507 1508 /*! 1509 * \brief The function gets the stroke miterlimit. 1510 * 1511 * \param[in] paint A Tvg_Paint pointer to the shape object. 1512 * \param[out] miterlimit The stroke miterlimit. 1513 * 1514 * \return Tvg_Result enumeration. 1515 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. 1516 * 1517 * \since 0.11 1518 */ 1519 TVG_API Tvg_Result tvg_shape_get_stroke_miterlimit(const Tvg_Paint* paint, float* miterlimit); 1520 1521 1522 /*! 1523 * \brief Sets the trim of the stroke along the defined path segment, allowing control over which part of the stroke is visible. 1524 * 1525 * If the values of the arguments @p begin and @p end exceed the 0-1 range, they are wrapped around in a manner similar to angle wrapping, effectively treating the range as circular. 1526 * 1527 * \param[in] paint A Tvg_Paint pointer to the shape object. 1528 * \param[in] begin Specifies the start of the segment to display along the path. 1529 * \param[in] end Specifies the end of the segment to display along the path. 1530 * \param[in] simultaneous Determines how to trim multiple paths within a single shape. If set to @c true (default), trimming is applied simultaneously to all paths; 1531 * Otherwise, all paths are treated as a single entity with a combined length equal to the sum of their individual lengths and are trimmed as such. 1532 * 1533 * \return Tvg_Result enumeration. 1534 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1535 * 1536 * \note Experimental API 1537 */ 1538 TVG_API Tvg_Result tvg_shape_set_stroke_trim(Tvg_Paint* paint, float begin, float end, bool simultaneous); 1539 1540 1541 /*! 1542 * \brief Sets the shape's solid color. 1543 * 1544 * The parts of the shape defined as inner are colored. 1545 * 1546 * \param[in] paint A Tvg_Paint pointer to the shape object. 1547 * \param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0. 1548 * \param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0. 1549 * \param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0. 1550 * \param[in] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0. 1551 * 1552 * \return Tvg_Result enumeration. 1553 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1554 * 1555 * \note Either a solid color or a gradient fill is applied, depending on what was set as last. 1556 * \see tvg_shape_set_fill_rule() 1557 */ 1558 TVG_API Tvg_Result tvg_shape_set_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a); 1559 1560 1561 /*! 1562 * \brief Gets the shape's solid color. 1563 * 1564 * \param[in] paint A Tvg_Paint pointer to the shape object. 1565 * \param[out] r The red color channel value in the range [0 ~ 255]. The default value is 0. 1566 * \param[out] g The green color channel value in the range [0 ~ 255]. The default value is 0. 1567 * \param[out] b The blue color channel value in the range [0 ~ 255]. The default value is 0. 1568 * \param[out] a The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0. 1569 * 1570 * \return Tvg_Result enumeration. 1571 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1572 */ 1573 TVG_API Tvg_Result tvg_shape_get_fill_color(const Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a); 1574 1575 1576 /*! 1577 * \brief Sets the shape's fill rule. 1578 * 1579 * \param[in] paint A Tvg_Paint pointer to the shape object. 1580 * \param[in] rule The fill rule value. The default value is @c TVG_FILL_RULE_WINDING. 1581 * 1582 * \return Tvg_Result enumeration. 1583 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1584 */ 1585 TVG_API Tvg_Result tvg_shape_set_fill_rule(Tvg_Paint* paint, Tvg_Fill_Rule rule); 1586 1587 1588 /*! 1589 * \brief Gets the shape's fill rule. 1590 * 1591 * \param[in] paint A Tvg_Paint pointer to the shape object. 1592 * \param[out] rule shape's fill rule 1593 * 1594 * \return Tvg_Result enumeration. 1595 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. 1596 */ 1597 TVG_API Tvg_Result tvg_shape_get_fill_rule(const Tvg_Paint* paint, Tvg_Fill_Rule* rule); 1598 1599 1600 /*! 1601 * \brief Sets the rendering order of the stroke and the fill. 1602 * 1603 * \param[in] paint A Tvg_Paint pointer to the shape object. 1604 * \param[in] strokeFirst If @c true the stroke is rendered before the fill, otherwise the stroke is rendered as the second one (the default option). 1605 * 1606 * \return Tvg_Result enumeration. 1607 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1608 * 1609 * \since 0.10 1610 */ 1611 TVG_API Tvg_Result tvg_shape_set_paint_order(Tvg_Paint* paint, bool strokeFirst); 1612 1613 1614 /*! 1615 * \brief Sets the linear gradient fill for all of the figures from the path. 1616 * 1617 * The parts of the shape defined as inner are filled. 1618 * 1619 * \code 1620 * Tvg_Gradient* grad = tvg_linear_gradient_new(); 1621 * tvg_linear_gradient_set(grad, 700, 700, 800, 800); 1622 * Tvg_Color_Stop color_stops[4] = 1623 * { 1624 * {0.0 , 0, 0, 0, 255}, 1625 * {0.25, 255, 0, 0, 255}, 1626 * {0.5 , 0, 255, 0, 255}, 1627 * {1.0 , 0, 0, 255, 255} 1628 * }; 1629 * tvg_gradient_set_color_stops(grad, color_stops, 4); 1630 * tvg_shape_set_linear_gradient(shape, grad); 1631 * \endcode 1632 * 1633 * \param[in] paint A Tvg_Paint pointer to the shape object. 1634 * \param[in] grad The linear gradient fill. 1635 * 1636 * \return Tvg_Result enumeration. 1637 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1638 * \retval TVG_RESULT_MEMORY_CORRUPTION An invalid Tvg_Gradient pointer. 1639 * 1640 * \note Either a solid color or a gradient fill is applied, depending on what was set as last. 1641 * \see tvg_shape_set_fill_rule() 1642 */ 1643 TVG_API Tvg_Result tvg_shape_set_linear_gradient(Tvg_Paint* paint, Tvg_Gradient* grad); 1644 1645 1646 /*! 1647 * \brief Sets the radial gradient fill for all of the figures from the path. 1648 * 1649 * The parts of the shape defined as inner are filled. 1650 * 1651 * \code 1652 * Tvg_Gradient* grad = tvg_radial_gradient_new(); 1653 * tvg_radial_gradient_set(grad, 550, 550, 50); 1654 * Tvg_Color_Stop color_stops[4] = 1655 * { 1656 * {0.0 , 0, 0, 0, 255}, 1657 * {0.25, 255, 0, 0, 255}, 1658 * {0.5 , 0, 255, 0, 255}, 1659 * {1.0 , 0, 0, 255, 255} 1660 * }; 1661 * tvg_gradient_set_color_stops(grad, color_stops, 4); 1662 * tvg_shape_set_radial_gradient(shape, grad); 1663 * \endcode 1664 * 1665 * \param[in] paint A Tvg_Paint pointer to the shape object. 1666 * \param[in] grad The radial gradient fill. 1667 * 1668 * \return Tvg_Result enumeration. 1669 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 1670 * \retval TVG_RESULT_MEMORY_CORRUPTION An invalid Tvg_Gradient pointer. 1671 * 1672 * \note Either a solid color or a gradient fill is applied, depending on what was set as last. 1673 * \see tvg_shape_set_fill_rule() 1674 */ 1675 TVG_API Tvg_Result tvg_shape_set_radial_gradient(Tvg_Paint* paint, Tvg_Gradient* grad); 1676 1677 1678 /*! 1679 * \brief Gets the gradient fill of the shape. 1680 * 1681 * The function does not allocate any data. 1682 * 1683 * \param[in] paint A Tvg_Paint pointer to the shape object. 1684 * \param[out] grad The gradient fill. 1685 * 1686 * \return Tvg_Result enumeration. 1687 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. 1688 */ 1689 TVG_API Tvg_Result tvg_shape_get_gradient(const Tvg_Paint* paint, Tvg_Gradient** grad); 1690 1691 1692 /** \} */ // end defgroup ThorVGCapi_Shape 1693 1694 1695 /** 1696 * \defgroup ThorVGCapi_Gradient Gradient 1697 * \brief A module managing the gradient fill of objects. 1698 * 1699 * The module enables to set and to get the gradient colors and their arrangement inside the gradient bounds, 1700 * to specify the gradient bounds and the gradient behavior in case the area defined by the gradient bounds 1701 * is smaller than the area to be filled. 1702 * 1703 * \{ 1704 */ 1705 1706 /************************************************************************/ 1707 /* Gradient API */ 1708 /************************************************************************/ 1709 /*! 1710 * \brief Creates a new linear gradient object. 1711 * 1712 * \code 1713 * Tvg_Paint* shape = tvg_shape_new(); 1714 * tvg_shape_append_rect(shape, 700, 700, 100, 100, 20, 20); 1715 * Tvg_Gradient* grad = tvg_linear_gradient_new(); 1716 * tvg_linear_gradient_set(grad, 700, 700, 800, 800); 1717 * Tvg_Color_Stop color_stops[2] = 1718 * { 1719 * {0.0, 0, 0, 0, 255}, 1720 * {1.0, 0, 255, 0, 255}, 1721 * }; 1722 * tvg_gradient_set_color_stops(grad, color_stops, 2); 1723 * tvg_shape_set_linear_gradient(shape, grad); 1724 * \endcode 1725 * 1726 * \return A new linear gradient object. 1727 */ 1728 TVG_API Tvg_Gradient* tvg_linear_gradient_new(void); 1729 1730 1731 /*! 1732 * \brief Creates a new radial gradient object. 1733 * 1734 * \code 1735 * Tvg_Paint* shape = tvg_shape_new(); 1736 * tvg_shape_append_rect(shape, 700, 700, 100, 100, 20, 20); 1737 * Tvg_Gradient* grad = tvg_radial_gradient_new(); 1738 * tvg_radial_gradient_set(grad, 550, 550, 50); 1739 * Tvg_Color_Stop color_stops[2] = 1740 * { 1741 * {0.0, 0, 0, 0, 255}, 1742 * {1.0, 0, 255, 0, 255}, 1743 * }; 1744 * tvg_gradient_set_color_stops(grad, color_stops, 2); 1745 * tvg_shape_set_radial_gradient(shape, grad); 1746 * \endcode 1747 * 1748 * \return A new radial gradient object. 1749 */ 1750 TVG_API Tvg_Gradient* tvg_radial_gradient_new(void); 1751 1752 1753 /*! 1754 * \brief Sets the linear gradient bounds. 1755 * 1756 * The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing 1757 * the given points (@p x1, @p y1) and (@p x2, @p y2), respectively. Both lines are perpendicular to the line linking 1758 * (@p x1, @p y1) and (@p x2, @p y2). 1759 * 1760 * \param[in] grad The Tvg_Gradient object of which bounds are to be set. 1761 * @param[in] x1 The horizontal coordinate of the first point used to determine the gradient bounds. 1762 * @param[in] y1 The vertical coordinate of the first point used to determine the gradient bounds. 1763 * @param[in] x2 The horizontal coordinate of the second point used to determine the gradient bounds. 1764 * @param[in] y2 The vertical coordinate of the second point used to determine the gradient bounds. 1765 * 1766 * \return Tvg_Result enumeration. 1767 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. 1768 * 1769 * \note In case the first and the second points are equal, an object is filled with a single color using the last color specified in the tvg_gradient_set_color_stops(). 1770 * \see tvg_gradient_set_color_stops() 1771 */ 1772 TVG_API Tvg_Result tvg_linear_gradient_set(Tvg_Gradient* grad, float x1, float y1, float x2, float y2); 1773 1774 1775 /*! 1776 * \brief Gets the linear gradient bounds. 1777 * 1778 * The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing 1779 * the given points (@p x1, @p y1) and (@p x2, @p y2), respectively. Both lines are perpendicular to the line linking 1780 * (@p x1, @p y1) and (@p x2, @p y2). 1781 * 1782 * \param[in] grad The Tvg_Gradient object of which to get the bounds. 1783 * \param[out] x1 The horizontal coordinate of the first point used to determine the gradient bounds. 1784 * \param[out] y1 The vertical coordinate of the first point used to determine the gradient bounds. 1785 * \param[out] x2 The horizontal coordinate of the second point used to determine the gradient bounds. 1786 * \param[out] y2 The vertical coordinate of the second point used to determine the gradient bounds. 1787 * 1788 * \return Tvg_Result enumeration. 1789 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. 1790 */ 1791 TVG_API Tvg_Result tvg_linear_gradient_get(Tvg_Gradient* grad, float* x1, float* y1, float* x2, float* y2); 1792 1793 1794 /*! 1795 * \brief Sets the radial gradient bounds. 1796 * 1797 * The radial gradient bounds are defined as a circle centered in a given point (@p cx, @p cy) of a given radius. 1798 * 1799 * \param[in] grad The Tvg_Gradient object of which bounds are to be set. 1800 * \param[in] cx The horizontal coordinate of the center of the bounding circle. 1801 * \param[in] cy The vertical coordinate of the center of the bounding circle. 1802 * \param[in] radius The radius of the bounding circle. 1803 * 1804 * \return Tvg_Result enumeration. 1805 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer or the @p radius value less than zero. 1806 * 1807 * \note In case the @p radius is zero, an object is filled with a single color using the last color specified in the specified in the tvg_gradient_set_color_stops(). 1808 * \see tvg_gradient_set_color_stops() 1809 */ 1810 TVG_API Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, float cy, float radius); 1811 1812 1813 /*! 1814 * \brief The function gets radial gradient center point ant radius 1815 * 1816 * \param[in] grad The Tvg_Gradient object of which bounds are to be set. 1817 * \param[out] cx The horizontal coordinate of the center of the bounding circle. 1818 * \param[out] cy The vertical coordinate of the center of the bounding circle. 1819 * \param[out] radius The radius of the bounding circle. 1820 * 1821 * \return Tvg_Result enumeration. 1822 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. 1823 */ 1824 TVG_API Tvg_Result tvg_radial_gradient_get(Tvg_Gradient* grad, float* cx, float* cy, float* radius); 1825 1826 1827 /*! 1828 * \brief Sets the parameters of the colors of the gradient and their position. 1829 * 1830 * \param[in] grad The Tvg_Gradient object of which the color information is to be set. 1831 * \param[in] color_stop An array of Tvg_Color_Stop data structure. 1832 * \param[in] cnt The size of the @p color_stop array equal to the colors number used in the gradient. 1833 * 1834 * \return Tvg_Result enumeration. 1835 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. 1836 */ 1837 TVG_API Tvg_Result tvg_gradient_set_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt); 1838 1839 1840 /*! 1841 * \brief Gets the parameters of the colors of the gradient, their position and number 1842 * 1843 * The function does not allocate any memory. 1844 * 1845 * \param[in] grad The Tvg_Gradient object of which to get the color information. 1846 * \param[out] color_stop An array of Tvg_Color_Stop data structure. 1847 * \param[out] cnt The size of the @p color_stop array equal to the colors number used in the gradient. 1848 * 1849 * \return Tvg_Result enumeration. 1850 * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. 1851 */ 1852 TVG_API Tvg_Result tvg_gradient_get_color_stops(const Tvg_Gradient* grad, const Tvg_Color_Stop** color_stop, uint32_t* cnt); 1853 1854 1855 /*! 1856 * \brief Sets the Tvg_Stroke_Fill value, which specifies how to fill the area outside the gradient bounds. 1857 * 1858 * \param[in] grad The Tvg_Gradient object. 1859 * \param[in] spread The FillSpread value. 1860 * 1861 * \return Tvg_Result enumeration. 1862 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. 1863 */ 1864 TVG_API Tvg_Result tvg_gradient_set_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill spread); 1865 1866 1867 /*! 1868 * \brief Gets the FillSpread value of the gradient object. 1869 * 1870 * \param[in] grad The Tvg_Gradient object. 1871 * \param[out] spread The FillSpread value. 1872 * 1873 * \return Tvg_Result enumeration. 1874 * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. 1875 */ 1876 TVG_API Tvg_Result tvg_gradient_get_spread(const Tvg_Gradient* grad, Tvg_Stroke_Fill* spread); 1877 1878 1879 /*! 1880 * \brief Sets the matrix of the affine transformation for the gradient object. 1881 * 1882 * The augmented matrix of the transformation is expected to be given. 1883 * 1884 * \param[in] grad The Tvg_Gradient object to be transformed. 1885 * \param[in] m The 3x3 augmented matrix. 1886 * 1887 * \return Tvg_Result enumeration. 1888 * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr is passed as the argument. 1889 */ 1890 TVG_API Tvg_Result tvg_gradient_set_transform(Tvg_Gradient* grad, const Tvg_Matrix* m); 1891 1892 1893 /*! 1894 * \brief Gets the matrix of the affine transformation of the gradient object. 1895 * 1896 * In case no transformation was applied, the identity matrix is set. 1897 * 1898 * \param[in] grad The Tvg_Gradient object of which to get the transformation matrix. 1899 * \param[out] m The 3x3 augmented matrix. 1900 * 1901 * \return Tvg_Result enumeration. 1902 * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr is passed as the argument. 1903 */ 1904 TVG_API Tvg_Result tvg_gradient_get_transform(const Tvg_Gradient* grad, Tvg_Matrix* m); 1905 1906 /** 1907 * \brief Gets the unique value of the gradient instance indicating the instance type. 1908 * 1909 * \param[in] grad The Tvg_Gradient object of which to get the type value. 1910 * \param[out] type The unique type of the gradient instance type. 1911 * 1912 * \return Tvg_Result enumeration. 1913 * \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. 1914 * 1915 * \note Experimental API 1916 */ 1917 TVG_API Tvg_Result tvg_gradient_get_type(const Tvg_Gradient* grad, Tvg_Type* type); 1918 1919 1920 /** 1921 * \see tvg_gradient_get_type() 1922 */ 1923 TVG_DEPRECATED TVG_API Tvg_Result tvg_gradient_get_identifier(const Tvg_Gradient* grad, Tvg_Identifier* identifier); 1924 1925 1926 /*! 1927 * \brief Duplicates the given Tvg_Gradient object. 1928 * 1929 * Creates a new object and sets its all properties as in the original object. 1930 * 1931 * \param[in] grad The Tvg_Gradient object to be copied. 1932 * 1933 * \return A copied Tvg_Gradient object if succeed, @c nullptr otherwise. 1934 */ 1935 TVG_API Tvg_Gradient* tvg_gradient_duplicate(Tvg_Gradient* grad); 1936 1937 1938 /*! 1939 * \brief Deletes the given gradient object. 1940 * 1941 * \param[in] grad The gradient object to be deleted. 1942 * 1943 * \return Tvg_Result enumeration. 1944 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. 1945 */ 1946 TVG_API Tvg_Result tvg_gradient_del(Tvg_Gradient* grad); 1947 1948 1949 /** \} */ // end defgroup ThorVGCapi_Gradient 1950 1951 1952 /** 1953 * \defgroup ThorVGCapi_Picture Picture 1954 * 1955 * \brief A module enabling to create and to load an image in one of the supported formats: svg, png, jpg, lottie and raw. 1956 * 1957 * 1958 * \{ 1959 */ 1960 1961 /************************************************************************/ 1962 /* Picture API */ 1963 /************************************************************************/ 1964 /*! 1965 * \brief Creates a new picture object. 1966 * 1967 * \return A new picture object. 1968 */ 1969 TVG_API Tvg_Paint* tvg_picture_new(void); 1970 1971 1972 /*! 1973 * \brief Loads a picture data directly from a file. 1974 * 1975 * ThorVG efficiently caches the loaded data using the specified @p path as a key. 1976 * This means that loading the same file again will not result in duplicate operations; 1977 * instead, ThorVG will reuse the previously loaded picture data. 1978 * 1979 * \param[in] paint A Tvg_Paint pointer to the picture object. 1980 * \param[in] path The absolute path to the image file. 1981 * 1982 * \return Tvg_Result enumeration. 1983 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer or an empty @p path. 1984 * \retval TVG_RESULT_NOT_SUPPORTED A file with an unknown extension. 1985 */ 1986 TVG_API Tvg_Result tvg_picture_load(Tvg_Paint* paint, const char* path); 1987 1988 1989 /*! 1990 * \brief Loads a picture data from a memory block of a given size. 1991 * 1992 * ThorVG efficiently caches the loaded data using the specified @p data address as a key 1993 * when the @p copy has @c false. This means that loading the same data again will not result in duplicate operations 1994 * for the sharable @p data. Instead, ThorVG will reuse the previously loaded picture data. 1995 * 1996 * \param[in] paint A Tvg_Paint pointer to the picture object. 1997 * \param[in] data A pointer to a memory location where the content of the picture raw data is stored. 1998 * \param[in] w The width of the image @p data in pixels. 1999 * \param[in] h The height of the image @p data in pixels. 2000 * \param[in] premultiplied If @c true, the given image data is alpha-premultiplied. 2001 * \param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not. 2002 * 2003 * \return Tvg_Result enumeration. 2004 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer or no data are provided or the @p width or @p height value is zero or less. 2005 * \retval TVG_RESULT_FAILED_ALLOCATION A problem with memory allocation occurs. 2006 * 2007 * \since 0.9 2008 */ 2009 TVG_API Tvg_Result tvg_picture_load_raw(Tvg_Paint* paint, uint32_t *data, uint32_t w, uint32_t h, bool copy); 2010 2011 2012 /*! 2013 * \brief Loads a picture data from a memory block of a given size. 2014 * 2015 * ThorVG efficiently caches the loaded data using the specified @p data address as a key 2016 * when the @p copy has @c false. This means that loading the same data again will not result in duplicate operations 2017 * for the sharable @p data. Instead, ThorVG will reuse the previously loaded picture data. 2018 * 2019 * \param[in] paint A Tvg_Paint pointer to the picture object. 2020 * \param[in] data A pointer to a memory location where the content of the picture file is stored. A null-terminated string is expected for non-binary data if @p copy is @c false 2021 * \param[in] size The size in bytes of the memory occupied by the @p data. 2022 * \param[in] mimetype Mimetype or extension of data such as "jpg", "jpeg", "svg", "svg+xml", "lottie", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one. 2023 * \param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not. 2024 * 2025 * \return Tvg_Result enumeration. 2026 * \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument or the @p size is zero or less. 2027 * \retval TVG_RESULT_NOT_SUPPORTED A file with an unknown extension. 2028 * 2029 * \warning: It's the user responsibility to release the @p data memory if the @p copy is @c true. 2030 */ 2031 TVG_API Tvg_Result tvg_picture_load_data(Tvg_Paint* paint, const char *data, uint32_t size, const char *mimetype, bool copy); 2032 2033 2034 /*! 2035 * \brief Resizes the picture content to the given width and height. 2036 * 2037 * The picture content is resized while keeping the default size aspect ratio. 2038 * The scaling factor is established for each of dimensions and the smaller value is applied to both of them. 2039 * 2040 * \param[in] paint A Tvg_Paint pointer to the picture object. 2041 * \param[in] w A new width of the image in pixels. 2042 * \param[in] h A new height of the image in pixels. 2043 * 2044 * \return Tvg_Result enumeration. 2045 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 2046 */ 2047 TVG_API Tvg_Result tvg_picture_set_size(Tvg_Paint* paint, float w, float h); 2048 2049 2050 /*! 2051 * \brief Gets the size of the loaded picture. 2052 * 2053 * \param[in] paint A Tvg_Paint pointer to the picture object. 2054 * \param[out] w A width of the image in pixels. 2055 * \param[out] h A height of the image in pixels. 2056 * 2057 * \return Tvg_Result enumeration. 2058 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 2059 */ 2060 TVG_API Tvg_Result tvg_picture_get_size(const Tvg_Paint* paint, float* w, float* h); 2061 2062 2063 /*! 2064 * \brief Retrieve a paint object from the Picture scene by its Unique ID. 2065 * 2066 * This function searches for a paint object within the Picture scene that matches the provided @p id. 2067 * 2068 * \param[in] paint A Tvg_Paint pointer to the picture object. 2069 * \param[in] id The Unique ID of the paint object. 2070 2071 * \return A pointer to the paint object that matches the given identifier, or @c nullptr if no matching paint object is found. 2072 * 2073 * \see tvg_accessor_generate_id() 2074 * \note experimental API 2075 */ 2076 TVG_API const Tvg_Paint* tvg_picture_get_paint(Tvg_Paint* paint, uint32_t id); 2077 2078 2079 /** \} */ // end defgroup ThorVGCapi_Picture 2080 2081 2082 /** 2083 * \defgroup ThorVGCapi_Scene Scene 2084 * \brief A module managing the multiple paints as one group paint. 2085 * 2086 * As a group, scene can be transformed, translucent, composited with other target paints, 2087 * its children will be affected by the scene world. 2088 * 2089 * \{ 2090 */ 2091 2092 /************************************************************************/ 2093 /* Scene API */ 2094 /************************************************************************/ 2095 /*! 2096 * \brief Creates a new scene object. 2097 * 2098 * A scene object is used to group many paints into one object, which can be manipulated using TVG APIs. 2099 * 2100 * \return A new scene object. 2101 */ 2102 TVG_API Tvg_Paint* tvg_scene_new(void); 2103 2104 2105 /*! 2106 * \brief Sets the size of the container, where all the paints pushed into the scene are stored. 2107 * 2108 * If the number of objects pushed into the scene is known in advance, calling the function 2109 * prevents multiple memory reallocation, thus improving the performance. 2110 * 2111 * \param[in] scene A Tvg_Paint pointer to the scene object. 2112 * \param[in] size The number of objects for which the memory is to be reserved. 2113 * 2114 * \return Tvg_Result enumeration. 2115 * \retval TVG_RESULT_FAILED_ALLOCATION An internal error with a memory allocation. 2116 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. 2117 */ 2118 TVG_DEPRECATED TVG_API Tvg_Result tvg_scene_reserve(Tvg_Paint* scene, uint32_t size); 2119 2120 2121 /*! 2122 * \brief Passes drawing elements to the scene using Tvg_Paint objects. 2123 * 2124 * Only the paints pushed into the scene will be the drawn targets. 2125 * The paints are retained by the scene until the tvg_scene_clear() is called. 2126 * If you know the number of pushed objects in advance, please call tvg_scene_reserve(). 2127 * 2128 * \param[in] scene A Tvg_Paint pointer to the scene object. 2129 * \param[in] paint A graphical object to be drawn. 2130 * 2131 * \return Tvg_Result enumeration. 2132 * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. 2133 * 2134 * \note The rendering order of the paints is the same as the order as they were pushed. Consider sorting the paints before pushing them if you intend to use layering. 2135 */ 2136 TVG_API Tvg_Result tvg_scene_push(Tvg_Paint* scene, Tvg_Paint* paint); 2137 2138 2139 /*! 2140 * \brief Clears a scene objects from pushed paints. 2141 * 2142 * Tvg_Paint objects stored in the scene are released if @p free is set to @c true, otherwise the memory is not deallocated and 2143 * all paints should be released manually in order to avoid memory leaks. 2144 * 2145 * \param[in] scene The scene object to be cleared. 2146 * \param[in] free If @c true the memory occupied by paints is deallocated, otherwise it is not. 2147 * 2148 * \return Tvg_Result enumeration. 2149 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. 2150 * 2151 * \warning Please use the @p free argument only when you know how it works, otherwise it's not recommended. 2152 */ 2153 TVG_API Tvg_Result tvg_scene_clear(Tvg_Paint* scene, bool free); 2154 2155 /** \} */ // end defgroup ThorVGCapi_Scene 2156 2157 2158 2159 /** 2160 * \defgroup ThorVGCapi_Text Text 2161 * \brief A class to represent text objects in a graphical context, allowing for rendering and manipulation of unicode text. 2162 * 2163 * \since 0.15 2164 * 2165 * \{ 2166 */ 2167 2168 /************************************************************************/ 2169 /* Text API */ 2170 /************************************************************************/ 2171 /*! 2172 * \brief Creates a new text object. 2173 * 2174 * \return A new text object. 2175 * 2176 * \since 0.15 2177 */ 2178 TVG_API Tvg_Paint* tvg_text_new(void); 2179 2180 2181 /** 2182 * \brief Sets the font properties for the text. 2183 * 2184 * This function allows you to define the font characteristics used for text rendering. 2185 * It sets the font name, size and optionally the style. 2186 * 2187 * \param[in] paint A Tvg_Paint pointer to the text object. 2188 * \param[in] name The name of the font. This should correspond to a font available in the canvas. 2189 * \param[in] size The size of the font in points. 2190 * \param[in] style The style of the font. If empty, the default style is used. Currently only 'italic' style is supported. 2191 * 2192 * \return Tvg_Result enumeration. 2193 * \retval TVG_RESULT_INVALID_ARGUMENT A \c nullptr passed as the \p paint argument. 2194 * \retval TVG_RESULT_INSUFFICIENT_CONDITION The specified \p name cannot be found. 2195 * 2196 * \note Experimental API 2197 */ 2198 TVG_API Tvg_Result tvg_text_set_font(Tvg_Paint* paint, const char* name, float size, const char* style); 2199 2200 2201 /** 2202 * \brief Assigns the given unicode text to be rendered. 2203 * 2204 * This function sets the unicode text that will be displayed by the rendering system. 2205 * The text is set according to the specified UTF encoding method, which defaults to UTF-8. 2206 * 2207 * \param[in] paint A Tvg_Paint pointer to the text object. 2208 * \param[in] text The multi-byte text encoded with utf8 string to be rendered. 2209 * 2210 * \return Tvg_Result enumeration. 2211 * \retval TVG_RESULT_INVALID_ARGUMENT A \c nullptr passed as the \p paint argument. 2212 * 2213 * \note Experimental API 2214 */ 2215 TVG_API Tvg_Result tvg_text_set_text(Tvg_Paint* paint, const char* text); 2216 2217 2218 /** 2219 * \brief Sets the text solid color. 2220 * 2221 * \param[in] paint A Tvg_Paint pointer to the text object. 2222 * \param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0. 2223 * \param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0. 2224 * \param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0. 2225 * 2226 * \return Tvg_Result enumeration. 2227 * \retval TVG_RESULT_INVALID_ARGUMENT A \c nullptr passed as the \p paint argument. 2228 * 2229 * \note Either a solid color or a gradient fill is applied, depending on what was set as last. 2230 * \see tvg_text_set_font() 2231 * 2232 * \since 0.15 2233 */ 2234 TVG_API Tvg_Result tvg_text_set_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b); 2235 2236 2237 /** 2238 * \brief Sets the gradient fill for the text. 2239 * 2240 * \param[in] paint A Tvg_Paint pointer to the text object. 2241 * \param[in] grad The linear or radial gradient fill 2242 * 2243 * \return Tvg_Result enumeration. 2244 * \retval TVG_RESULT_INVALID_ARGUMENT A \c nullptr passed as the \p paint argument. 2245 * \retval TVG_RESULT_MEMORY_CORRUPTION An invalid Tvg_Gradient pointer. 2246 * 2247 * \note Either a solid color or a gradient fill is applied, depending on what was set as last. 2248 * \see tvg_text_set_font() 2249 * 2250 * \since 0.15 2251 */ 2252 TVG_API Tvg_Result tvg_text_set_gradient(Tvg_Paint* paint, Tvg_Gradient* gradient); 2253 2254 /** 2255 * \brief Loads a scalable font data from a file. 2256 * 2257 * ThorVG efficiently caches the loaded data using the specified \p path as a key. 2258 * This means that loading the same file again will not result in duplicate operations; 2259 * instead, ThorVG will reuse the previously loaded font data. 2260 * 2261 * \param[in] path The path to the font file. 2262 * 2263 * \return Tvg_Result enumeration. 2264 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid \p path passed as an argument. 2265 * \retval TVG_RESULT_NOT_SUPPORTED When trying to load a file with an unknown extension. 2266 * 2267 * \see tvg_font_unload() 2268 * 2269 * \since 0.15 2270 */ 2271 TVG_API Tvg_Result tvg_font_load(const char* path); 2272 2273 2274 /** 2275 * \brief Loads a scalable font data from a memory block of a given size. 2276 * 2277 * ThorVG efficiently caches the loaded font data using the specified \p name as a key. 2278 * This means that loading the same fonts again will not result in duplicate operations. 2279 * Instead, ThorVG will reuse the previously loaded font data. 2280 * 2281 * \param[in] name The name under which the font will be stored and accessible (e.x. in a \p tvg_text_set_font API). 2282 * \param[in] data A pointer to a memory location where the content of the font data is stored. 2283 * \param[in] size The size in bytes of the memory occupied by the @p data. 2284 * \param[in] mimetype Mimetype or extension of font data. In case a \c NULL or an empty "" value is provided the loader will be determined automatically. 2285 * \param[in] copy If @c true the data are copied into the engine local buffer, otherwise they are not (default). 2286 * 2287 * \return Tvg_Result enumeration. 2288 * \retval TVG_RESULT_INVALID_ARGUMENT If no name is provided or if \p size is zero while \p data points to a valid memory location. 2289 * \retval TVG_RESULT_NOT_SUPPORTED When trying to load a file with an unknown extension. 2290 * \retval TVG_RESULT_INSUFFICIENT_CONDITION When trying to unload the font data that has not been previously loaded. 2291 * 2292 * \warning: It's the user responsibility to release the \p data memory. 2293 * 2294 * \note To unload the font data loaded using this API, pass the proper \p name and \c nullptr as \p data. 2295 * 2296 * \since 0.15 2297 */ 2298 TVG_API Tvg_Result tvg_font_load_data(const char* name, const char* data, uint32_t size, const char *mimetype, bool copy); 2299 2300 2301 /** 2302 * \brief Unloads the specified scalable font data that was previously loaded. 2303 * 2304 * This function is used to release resources associated with a font file that has been loaded into memory. 2305 * 2306 * \param[in] path The path to the loaded font file. 2307 * 2308 * \return Tvg_Result enumeration. 2309 * \retval TVG_RESULT_INSUFFICIENT_CONDITION The loader is not initialized. 2310 * 2311 * \note If the font data is currently in use, it will not be immediately unloaded. 2312 * \see tvg_font_load() 2313 * 2314 * \since 0.15 2315 */ 2316 TVG_API Tvg_Result tvg_font_unload(const char* path); 2317 2318 2319 /** \} */ // end defgroup ThorVGCapi_Text 2320 2321 2322 /** 2323 * \defgroup ThorVGCapi_Saver Saver 2324 * \brief A module for exporting a paint object into a specified file. 2325 * 2326 * The module enables to save the composed scene and/or image from a paint object. 2327 * Once it's successfully exported to a file, it can be recreated using the Picture module. 2328 * 2329 * \{ 2330 */ 2331 2332 /************************************************************************/ 2333 /* Saver API */ 2334 /************************************************************************/ 2335 /*! 2336 * \brief Creates a new Tvg_Saver object. 2337 * 2338 * \return A new Tvg_Saver object. 2339 */ 2340 TVG_API Tvg_Saver* tvg_saver_new(void); 2341 2342 2343 /*! 2344 * \brief Exports the given @p paint data to the given @p path 2345 * 2346 * If the saver module supports any compression mechanism, it will optimize the data size. 2347 * This might affect the encoding/decoding time in some cases. You can turn off the compression 2348 * if you wish to optimize for speed. 2349 * 2350 * \param[in] saver The Tvg_Saver object connected with the saving task. 2351 * \param[in] paint The paint to be saved with all its associated properties. 2352 * \param[in] path A path to the file, in which the paint data is to be saved. 2353 * \param[in] compress If @c true then compress data if possible. 2354 * 2355 * \return Tvg_Result enumeration. 2356 * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. 2357 * \retval TVG_RESULT_INSUFFICIENT_CONDITION Currently saving other resources. 2358 * \retval TVG_RESULT_NOT_SUPPORTED Trying to save a file with an unknown extension or in an unsupported format. 2359 * \retval TVG_RESULT_UNKNOWN An empty paint is to be saved. 2360 * 2361 * \note Saving can be asynchronous if the assigned thread number is greater than zero. To guarantee the saving is done, call tvg_saver_sync() afterwards. 2362 * \see tvg_saver_sync() 2363 */ 2364 TVG_API Tvg_Result tvg_saver_save(Tvg_Saver* saver, Tvg_Paint* paint, const char* path, bool compress); 2365 2366 2367 /*! 2368 * \brief Guarantees that the saving task is finished. 2369 * 2370 * The behavior of the Saver module works on a sync/async basis, depending on the threading setting of the Initializer. 2371 * Thus, if you wish to have a benefit of it, you must call tvg_saver_sync() after the tvg_saver_save() in the proper delayed time. 2372 * Otherwise, you can call tvg_saver_sync() immediately. 2373 * 2374 * \param[in] saver The Tvg_Saver object connected with the saving task. 2375 * 2376 * \return Tvg_Result enumeration. 2377 * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. 2378 * \retval TVG_RESULT_INSUFFICIENT_CONDITION No saving task is running. 2379 * 2380 * \note The asynchronous tasking is dependent on the Saver module implementation. 2381 * \see tvg_saver_save() 2382 */ 2383 TVG_API Tvg_Result tvg_saver_sync(Tvg_Saver* saver); 2384 2385 2386 /*! 2387 * \brief Deletes the given Tvg_Saver object. 2388 * 2389 * \param[in] saver The Tvg_Saver object to be deleted. 2390 * 2391 * \return Tvg_Result enumeration. 2392 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Saver pointer. 2393 */ 2394 TVG_API Tvg_Result tvg_saver_del(Tvg_Saver* saver); 2395 2396 2397 /** \} */ // end defgroup ThorVGCapi_Saver 2398 2399 2400 /** 2401 * \defgroup ThorVGCapi_Animation Animation 2402 * \brief A module for manipulation of animatable images. 2403 * 2404 * The module supports the display and control of animation frames. 2405 * 2406 * \{ 2407 */ 2408 2409 /************************************************************************/ 2410 /* Animation API */ 2411 /************************************************************************/ 2412 2413 /*! 2414 * \brief Creates a new Animation object. 2415 * 2416 * \return Tvg_Animation A new Tvg_Animation object. 2417 * 2418 * \since 0.13 2419 */ 2420 TVG_API Tvg_Animation* tvg_animation_new(void); 2421 2422 2423 /*! 2424 * \brief Specifies the current frame in the animation. 2425 * 2426 * \param[in] animation A Tvg_Animation pointer to the animation object. 2427 * \param[in] no The index of the animation frame to be displayed. The index should be less than the tvg_animation_get_total_frame(). 2428 * 2429 * \return Tvg_Result enumeration. 2430 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Animation pointer. 2431 * \retval TVG_RESULT_INSUFFICIENT_CONDITION if the given @p no is the same as the current frame value. 2432 * \retval TVG_RESULT_NOT_SUPPORTED The picture data does not support animations. 2433 * 2434 * \note For efficiency, ThorVG ignores updates to the new frame value if the difference from the current frame value 2435 * is less than 0.001. In such cases, it returns @c Result::InsufficientCondition. 2436 * Values less than 0.001 may be disregarded and may not be accurately retained by the Animation. 2437 * \see tvg_animation_get_total_frame() 2438 * 2439 * \since 0.13 2440 */ 2441 TVG_API Tvg_Result tvg_animation_set_frame(Tvg_Animation* animation, float no); 2442 2443 2444 /*! 2445 * \brief Retrieves a picture instance associated with this animation instance. 2446 * 2447 * This function provides access to the picture instance that can be used to load animation formats, such as Lottie(json). 2448 * After setting up the picture, it can be pushed to the designated canvas, enabling control over animation frames 2449 * with this Animation instance. 2450 * 2451 * \param[in] animation A Tvg_Animation pointer to the animation object. 2452 * 2453 * \return A picture instance that is tied to this animation. 2454 * 2455 * \warning The picture instance is owned by Animation. It should not be deleted manually. 2456 * 2457 * \since 0.13 2458 */ 2459 TVG_API Tvg_Paint* tvg_animation_get_picture(Tvg_Animation* animation); 2460 2461 2462 /*! 2463 * \brief Retrieves the current frame number of the animation. 2464 * 2465 * \param[in] animation A Tvg_Animation pointer to the animation object. 2466 * \param[in] no The current frame number of the animation, between 0 and totalFrame() - 1. 2467 * 2468 * \return Tvg_Result enumeration. 2469 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Animation pointer or @p no 2470 * 2471 * \see tvg_animation_get_total_frame() 2472 * \see tvg_animation_set_frame() 2473 * 2474 * \since 0.13 2475 */ 2476 TVG_API Tvg_Result tvg_animation_get_frame(Tvg_Animation* animation, float* no); 2477 2478 2479 /*! 2480 * \brief Retrieves the total number of frames in the animation. 2481 * 2482 * \param[in] animation A Tvg_Animation pointer to the animation object. 2483 * \param[in] cnt The total number of frames in the animation. 2484 * 2485 * \return Tvg_Result enumeration. 2486 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Animation pointer or @p cnt. 2487 * 2488 * \note Frame numbering starts from 0. 2489 * \note If the Picture is not properly configured, this function will return 0. 2490 * 2491 * \since 0.13 2492 */ 2493 TVG_API Tvg_Result tvg_animation_get_total_frame(Tvg_Animation* animation, float* cnt); 2494 2495 2496 /*! 2497 * \brief Retrieves the duration of the animation in seconds. 2498 * 2499 * \param[in] animation A Tvg_Animation pointer to the animation object. 2500 * \param[in] duration The duration of the animation in seconds. 2501 * 2502 * \return Tvg_Result enumeration. 2503 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Animation pointer or @p duration. 2504 * 2505 * \note If the Picture is not properly configured, this function will return 0. 2506 * 2507 * \since 0.13 2508 */ 2509 TVG_API Tvg_Result tvg_animation_get_duration(Tvg_Animation* animation, float* duration); 2510 2511 2512 /*! 2513 * \brief Specifies the playback segment of the animation. 2514 * 2515 * \param[in] animation The Tvg_Animation pointer to the animation object. 2516 * \param[in] begin segment begin. 2517 * \param[in] end segment end. 2518 * 2519 * \return Tvg_Result enumeration. 2520 * \retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded. 2521 * \retval TVG_RESULT_INVALID_ARGUMENT When the given parameters are out of range. 2522 * 2523 * \note Experimental API 2524 */ 2525 TVG_API Tvg_Result tvg_animation_set_segment(Tvg_Animation* animation, float begin, float end); 2526 2527 2528 /*! 2529 * \brief Gets the current segment. 2530 * 2531 * \param[in] animation The Tvg_Animation pointer to the animation object. 2532 * \param[out] begin segment begin. 2533 * \param[out] end segment end. 2534 * 2535 * \return Tvg_Result enumeration. 2536 * \retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded. 2537 * \retval TVG_RESULT_INVALID_ARGUMENT When the given parameters are @c nullptr. 2538 * 2539 * \note Experimental API 2540 */ 2541 TVG_API Tvg_Result tvg_animation_get_segment(Tvg_Animation* animation, float* begin, float* end); 2542 2543 2544 /*! 2545 * \brief Deletes the given Tvg_Animation object. 2546 * 2547 * \param[in] animation The Tvg_Animation object to be deleted. 2548 * 2549 * \return Tvg_Result enumeration. 2550 * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Animation pointer. 2551 * 2552 * \since 0.13 2553 */ 2554 TVG_API Tvg_Result tvg_animation_del(Tvg_Animation* animation); 2555 2556 2557 /** \} */ // end defgroup ThorVGCapi_Animation 2558 2559 2560 /** 2561 * \defgroup ThorVGCapi_Accesssor Accessor 2562 * \brief A module for manipulation of the scene tree 2563 * 2564 * This module helps to control the scene tree. 2565 * \{ 2566 */ 2567 2568 /************************************************************************/ 2569 /* Accessor API */ 2570 /************************************************************************/ 2571 2572 /*! 2573 * \brief Generate a unique ID (hash key) from a given name. 2574 * 2575 * This function computes a unique identifier value based on the provided string. 2576 * You can use this to assign a unique ID to the Paint object. 2577 * 2578 * \param[in] name The input string to generate the unique identifier from. 2579 * 2580 * \return The generated unique identifier value. 2581 * 2582 * \note Experimental API 2583 */ 2584 TVG_API uint32_t tvg_accessor_generate_id(const char* name); 2585 2586 2587 /** \} */ // end defgroup ThorVGCapi_Accessor 2588 2589 2590 /** 2591 * \defgroup ThorVGCapi_LottieAnimation LottieAnimation 2592 * \brief A module for manipulation of lottie extension features. 2593 * 2594 * The module enables control of advanced Lottie features. 2595 * \{ 2596 */ 2597 2598 /************************************************************************/ 2599 /* LottieAnimation Extension API */ 2600 /************************************************************************/ 2601 2602 /*! 2603 * \brief Creates a new LottieAnimation object. 2604 * 2605 * \return Tvg_Animation A new Tvg_LottieAnimation object. 2606 * 2607 * \since 0.15 2608 */ 2609 TVG_API Tvg_Animation* tvg_lottie_animation_new(void); 2610 2611 2612 /*! 2613 * \brief Override the lottie properties through the slot data. 2614 * 2615 * \param[in] animation The Tvg_Animation object to override the property with the slot. 2616 * \param[in] slot The Lottie slot data in json, or @c nullptr to reset. 2617 * 2618 * \return Tvg_Result enumeration. 2619 * \retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded. 2620 * \retval TVG_RESULT_INVALID_ARGUMENT When the given @p slot is invalid 2621 * \retval TVG_RESULT_NOT_SUPPORTED The Lottie Animation is not supported. 2622 * 2623 * \note Experimental API 2624 */ 2625 TVG_API Tvg_Result tvg_lottie_animation_override(Tvg_Animation* animation, const char* slot); 2626 2627 2628 /*! 2629 * \brief Specifies a segment by marker. 2630 * 2631 * \param[in] animation The Tvg_Animation pointer to the Lottie animation object. 2632 * \param[in] marker The name of the segment marker. 2633 * 2634 * \return Tvg_Result enumeration. 2635 * \retval TVG_RESULT_INSUFFICIENT_CONDITION In case the animation is not loaded. 2636 * \retval TVG_RESULT_INVALID_ARGUMENT When the given @p marker is invalid. 2637 * \retval TVG_RESULT_NOT_SUPPORTED The Lottie Animation is not supported. 2638 * 2639 * \note Experimental API 2640 */ 2641 TVG_API Tvg_Result tvg_lottie_animation_set_marker(Tvg_Animation* animation, const char* marker); 2642 2643 2644 /*! 2645 * \brief Gets the marker count of the animation. 2646 * 2647 * \param[in] animation The Tvg_Animation pointer to the Lottie animation object. 2648 * \param[out] cnt The count value of the markers. 2649 * 2650 * \return Tvg_Result enumeration. 2651 * \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. 2652 * 2653 * \note Experimental API 2654 */ 2655 TVG_API Tvg_Result tvg_lottie_animation_get_markers_cnt(Tvg_Animation* animation, uint32_t* cnt); 2656 2657 2658 /*! 2659 * \brief Gets the marker name by a given index. 2660 * 2661 * \param[in] animation The Tvg_Animation pointer to the Lottie animation object. 2662 * \param[in] idx The index of the animation marker, starts from 0. 2663 * \param[out] name The name of marker when succeed. 2664 * 2665 * \return Tvg_Result enumeration. 2666 * \retval TVG_RESULT_INVALID_ARGUMENT In case @c nullptr is passed as the argument or @c idx is out of range. 2667 * 2668 * \note Experimental API 2669 */ 2670 TVG_API Tvg_Result tvg_lottie_animation_get_marker(Tvg_Animation* animation, uint32_t idx, const char** name); 2671 2672 2673 /** \} */ // end addtogroup ThorVGCapi_LottieAnimation 2674 2675 2676 /** \} */ // end defgroup ThorVGCapi 2677 2678 2679 #ifdef __cplusplus 2680 } 2681 #endif 2682 2683 #endif //_THORVG_CAPI_H_ 2684 2685 #endif /* LV_USE_THORVG_INTERNAL */ 2686 2687