/*! * \file thorvg_capi.h * * \brief The module provides C bindings for the ThorVG library. (BETA version) * Please refer to src/examples/Capi.cpp to find the thorvg_capi usage examples. * * The thorvg_capi module allows to implement the ThorVG client and provides * the following functionalities: * - drawing shapes: line, arc, curve, polygon, circle, user-defined, ... * - filling: solid, linear and radial gradient * - scene graph & affine transformation (translation, rotation, scale, ...) * - stroking: width, join, cap, dash * - composition: blending, masking, path clipping * - pictures: SVG, PNG, bitmap */ #ifndef __THORVG_CAPI_H__ #define __THORVG_CAPI_H__ #include #ifdef TVG_EXPORT #undef TVG_EXPORT #endif #ifdef TVG_BUILD #define TVG_EXPORT __attribute__ ((visibility ("default"))) #else #define TVG_EXPORT #endif #ifdef __cplusplus extern "C" { #endif /** * \defgroup ThorVG_CAPI ThorVG_CAPI (BETA version) * \brief ThorVG C language binding APIs. * * \{ */ /*! * CPU raster engine type. * * \ingroup ThorVGCapi_Initializer */ #define TVG_ENGINE_SW (1 << 1) /*! * OpenGL raster engine type. * * \ingroup ThorVGCapi_Initializer */ #define TVG_ENGINE_GL (1 << 2) /*! * \brief The 8-bit color channels are combined into 32-bit color in the order: alpha, blue, green, red. * * \ingroup ThorVGCapi_Canvas */ #define TVG_COLORSPACE_ABGR8888 0 /*! * \brief The 8-bit color channels are combined into 32-bit color in the order: alpha, red, green, blue. * * \ingroup ThorVGCapi_Canvas */ #define TVG_COLORSPACE_ARGB8888 1 /** * \brief A structure responsible for managing and drawing graphical elements. * * It sets up the target buffer, which can be drawn on the screen. It stores the Tvg_Paint objects (Shape, Scene, Picture). */ typedef struct _Tvg_Canvas Tvg_Canvas; /** * \brief A structure representing a graphical element. * * \warning The TvgPaint objects can not be shared between Canvases. */ typedef struct _Tvg_Paint Tvg_Paint; /** * \brief A structure representing a gradient fill of a Tvg_Paint object. */ typedef struct _Tvg_Gradient Tvg_Gradient; /** * \brief Enumeration specifying the result from the APIs. */ typedef enum { TVG_RESULT_SUCCESS = 0, ///< The value returned in case of a correct request execution. 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. 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. TVG_RESULT_FAILED_ALLOCATION, ///< The value returned in case of unsuccessful memory allocation. TVG_RESULT_MEMORY_CORRUPTION, ///< The value returned in the event of bad memory handling - e.g. failing in pointer releasing or casting TVG_RESULT_NOT_SUPPORTED, ///< The value returned in case of choosing unsupported options. TVG_RESULT_UNKNOWN ///< The value returned in all other cases. } Tvg_Result; /** * \brief Enumeration indicating the method used in the composition of two objects - the target and the source. * * \ingroup ThorVGCapi_Paint */ typedef enum { TVG_COMPOSITE_METHOD_NONE = 0, ///< No composition is applied. 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. 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. 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. } Tvg_Composite_Method; /** * \addtogroup ThorVGCapi_Shape * \{ */ /** * \brief Enumeration specifying the values of the path commands accepted by TVG. * * Not to be confused with the path commands from the svg path element (like M, L, Q, H and many others). * TVG interprets all of them and translates to the ones from the PathCommand values. */ typedef enum { 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. 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. 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. 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. } Tvg_Path_Command; /** * \brief Enumeration determining the ending type of a stroke in the open sub-paths. */ typedef enum { 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. 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. 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. } Tvg_Stroke_Cap; /** * \brief Enumeration specifying how to fill the area outside the gradient bounds. */ typedef enum { 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. TVG_STROKE_JOIN_ROUND, ///< The outer corner of the joined path segments is rounded. The circular region is centered at the join point. 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. } Tvg_Stroke_Join; /** * \brief Enumeration specifying how to fill the area outside the gradient bounds. */ typedef enum { TVG_STROKE_FILL_PAD = 0, ///< The remaining area is filled with the closest stop color. TVG_STROKE_FILL_REFLECT, ///< The gradient pattern is reflected outside the gradient area until the expected region is filled. TVG_STROKE_FILL_REPEAT ///< The gradient pattern is repeated continuously beyond the gradient area until the expected region is filled. } Tvg_Stroke_Fill; /** * \brief Enumeration specifying the algorithm used to establish which parts of the shape are treated as the inside of the shape. */ typedef enum { 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. 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. } Tvg_Fill_Rule; /** \} */ // end addtogroup ThorVGCapi_Shape /*! * \addtogroup ThorVGCapi_Gradient * \{ */ /*! * \brief A data structure storing the information about the color and its relative position inside the gradient bounds. */ typedef struct { float offset; /**< The relative position of the color. */ uint8_t r; /**< The red color channel value in the range [0 ~ 255]. */ uint8_t g; /**< The green color channel value in the range [0 ~ 255]. */ uint8_t b; /**< The blue color channel value in the range [0 ~ 255]. */ uint8_t a; /**< The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. */ } Tvg_Color_Stop; /** \} */ // end addtogroup ThorVGCapi_Gradient /** * \brief A data structure representing a point in two-dimensional space. */ typedef struct { float x, y; } Tvg_Point; /** * \brief A data structure representing a three-dimensional matrix. */ typedef struct { float e11, e12, e13; float e21, e22, e23; float e31, e32, e33; } Tvg_Matrix; /** * \defgroup ThorVGCapi_Initializer Initializer * \brief A module enabling initialization and termination of the TVG engines. * * \{ */ /************************************************************************/ /* Engine API */ /************************************************************************/ /*! * \brief Initializes TVG engines. * * It must be called before any other function, at the beginning of the TVG client. * * \code * tvg_engine_init(TVG_ENGINE_SW, 0); //Initialize software renderer and use the main thread only * \endcode * * \param[in] engine_method The engine types * - TVG_ENGINE_SW: CPU rasterizer * - TVG_ENGINE_GL: OpenGL rasterizer (not supported yet) * \param[in] threads The number of additional threads used to perform rendering. Zero indicates only the main thread is to be used. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INSUFFICIENT_CONDITION An internal error possibly with memory allocation. * \retval TVG_RESULT_INVALID_ARGUMENT Unknown engine type. * \retval TVG_RESULT_NOT_SUPPORTED Unsupported engine type. * \retval TVG_RESULT_UNKNOWN Other error. * * \note For multiple backeneds bitwise operation on the engine types is allowed. * \see tvg_engine_term() * \see TVG_ENGINE_SW, TVG_ENGINE_GL */ TVG_EXPORT Tvg_Result tvg_engine_init(unsigned engine_method, unsigned threads); /*! * \brief Terminates TVG engines. * * 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. * * \code * tvg_engine_init(TVG_ENGINE_SW, 0); * //define canvas and shapes, update shapes, general rendering calls * tvg_engine_term(TVG_ENGINE_SW); * \endcode * * \param engine_method renderer type * - TVG_ENGINE_SW: CPU rasterizer * - TVG_ENGINE_GL: OpenGL rasterizer (not supported yet) * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INSUFFICIENT_CONDITION Multiple function calls. * \retval TVG_RESULT_INVALID_ARGUMENT Unknown engine type. * \retval TVG_RESULT_NOT_SUPPORTED Unsupported engine type. * \retval TVG_RESULT_UNKNOWN An internal error. * * \see tvg_engine_init() * \see TVG_ENGINE_SW, TVG_ENGINE_GL */ TVG_EXPORT Tvg_Result tvg_engine_term(unsigned engine_method); /** \} */ // end defgroup ThorVGCapi_Initializer /** * \defgroup ThorVGCapi_Canvas Canvas * \brief A module for managing and drawing graphical elements. * * \{ */ /** * \defgroup ThorVGCapi_SwCanvas SwCanvas * \ingroup ThorVGCapi_Canvas * * \brief A module for rendering the graphical elements using the software engine. * * \{ */ /************************************************************************/ /* SwCanvas API */ /************************************************************************/ /*! * \brief Creates a Canvas object. * * \code * Tvg_Canvas *canvas = NULL; * * tvg_engine_init(TVG_ENGINE_SW, 4); * canvas = tvg_swcanvas_create(); * * //set up the canvas buffer * uint32_t *buffer = NULL; * buffer = (uint32_t*) malloc(sizeof(uint32_t) * 100 * 100); * if (!buffer) return; * * tvg_swcanvas_set_target(canvas, buffer, 100, 100, 100, TVG_COLORSPACE_ARGB8888); * * //set up paints and add them into the canvas before drawing it * * tvg_canvas_destroy(canvas); * tvg_engine_term(TVG_ENGINE_SW); * \endcode * * \return A new Tvg_Canvas object. */ TVG_EXPORT Tvg_Canvas* tvg_swcanvas_create(); /*! * \brief Sets the buffer used in the rasterization process and defines the used colorspace. * * For optimisation reasons TVG does not allocate memory for the output buffer on its own. * The buffer of a desirable size should be allocated and owned by the caller. * * \param[in] canvas The Tvg_Canvas object managing the @p buffer. * \param[in] buffer A pointer to the allocated memory block of the size @p stride x @p h. * \param[in] stride The stride of the raster image - in most cases same value as @p w. * \param[in] w The width of the raster image. * \param[in] h The height of the raster image. * \param[in] cs The colorspace value defining the way the 32-bits colors should be read/written. * - TVG_COLORSPACE_ABGR8888 * - TVG_COLORSPACE_ARGB8888 * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_MEMORY_CORRUPTION Casting in the internal function implementation failed. * \retval TVG_RESULT_INVALID_ARGUMENTS An invalid buffer pointer passed or one of the @p stride, @p w or @p h being zero. * \retval TVG_RESULT_NOT_SUPPORTED The software engine is not supported. * * \see TVG_COLORSPACE_ARGB8888, TVG_COLORSPACE_ABGR8888 */ TVG_EXPORT Tvg_Result tvg_swcanvas_set_target(Tvg_Canvas* canvas, uint32_t* buffer, uint32_t stride, uint32_t w, uint32_t h, uint32_t cs); /** \} */ // end defgroup ThorVGCapi_SwCanvas /************************************************************************/ /* Common Canvas API */ /************************************************************************/ /*! * \brief Clears the canvas internal data, releases all paints stored by the canvas and destroys the canvas object itself. * * \code * static Tvg_Canvas *canvas = NULL; * static uint32_t *buffer = NULL; * * static void _init() { * canvas = tvg_swcanvas_create(); * buffer = (uint32_t*) malloc(sizeof(uint32_t) * 100 * 100); * tvg_swcanvas_set_target(canvas, buffer, 100, 100, 100, TVG_COLORSPACE_ARGB8888); * } * * //a task called from main function in a loop * static void _job(const int cmd) { * switch (cmd) { * case CMD_EXIT: return 0; * case CMD_ADD_RECT: * //define valid rectangle shape * tvg_canvas_push(canvas, rect); * break; * case CMD_DEL_RECT: * tvg_paint_del(rect); * //now to safely delete Tvg_Canvas, tvg_canvas_clear() API have to be used * break; * default: * break; * } * } * * int main(int argc, char **argv) { * int cmd = 0; * int stop = 1; * * tvg_engine_init(TVG_ENGINE_SW, 4); * * while (stop) { * //wait for a command e.g. from a console * stop = _job(cmd); * } * tvg_canvas_clear(canvas, false); * tvg_canvas_destroy(canvas); * tvg_engine_term(TVG_ENGINE_SW); * return 0; * } * * tvg_canvas_destroy(canvas); * tvg_engine_term() * \endcode * * \param[in] canvas The Tvg_Canvas object to be destroyed. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer to the Tvg_Canvas object is passed. * * \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. * 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. * * \see tvg_paint_del(), tvg_canvas_clear() */ TVG_EXPORT Tvg_Result tvg_canvas_destroy(Tvg_Canvas* canvas); /*! * \brief Inserts a drawing element into the canvas using a Tvg_Paint object. * * \param[in] canvas The Tvg_Canvas object managing the @p paint. * \param[in] paint The Tvg_Paint object to be drawn. * * Only the paints pushed into the canvas will be drawing targets. * They are retained by the canvas until you call tvg_canvas_clear(). * If you know the number of the pushed objects in the advance, please call tvg_canvas_reserve(). * * \return Tvg_Result return values: * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. * \retval TVG_RESULT_INSUFFICIENT_CONDITION An internal error. * * \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. * \see tvg_canvas_reserve(), tvg_canvas_clear() */ TVG_EXPORT Tvg_Result tvg_canvas_push(Tvg_Canvas* canvas, Tvg_Paint* paint); /*! * \brief Reserves a memory block where the objects pushed into a canvas are stored. * * If the number of Tvg_Paints to be stored in a canvas is known in advance, calling this function reduces the multiple * memory allocations thus improves the performance. * * \code * Tvg_Canvas *canvas = NULL; * * tvg_engine_init(TVG_ENGINE_SW, 4); * canvas = tvg_swcanvas_create(); * * uint32_t *buffer = NULL; * buffer = (uint32_t*) malloc(sizeof(uint32_t) * 100 * 100); * if (!buffer) return; * * tvg_swcanvas_set_target(canvas, buffer, 100, 100, 100, TVG_COLORSPACE_ARGB8888); * tvg_canvas_reserve(canvas, 100); //reserve array for 100 paints in canvas. * * tvg_canvas_destroy(canvas); * tvg_engine_term() * \endcode * * \param[in] canvas The Tvg_Canvas object managing the reserved memory. * \param[in] n The number of objects for which the memory is to be reserved. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. */ TVG_EXPORT Tvg_Result tvg_canvas_reserve(Tvg_Canvas* canvas, uint32_t n); /*! * \brief Clears a Tvg_Canvas objects from pushed paints. * * Tvg_Paint objects stored in the canvas are released if @p free is set to @c true, otherwise the memory is not deallocated and * all paints should be released manually in order to avoid memory leaks. * * \param[in] canvas The Tvg_Canvas object to be cleared. * \param[in] free If @c true the memory occupied by paints is deallocated, otherwise it is not. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. * * \warning Please use the @p free argument only when you know how it works, otherwise it's not recommended. * * \see tvg_canvas_destroy() */ TVG_EXPORT Tvg_Result tvg_canvas_clear(Tvg_Canvas* canvas, bool free); /*! * \brief Updates all paints in a canvas. * * Should be called before drawing in order to prepare paints for the rendering. * * \code * //A frame drawing example. Thread safety and events implementation is skipped to show only TVG code. * * static Tvg_Canvas *canvas = NULL; * static Tvg_Paint *rect = NULL; * * int _frame_render(void) { * tvg_canvas_update(canvas); * tvg_canvas_draw(canvas); * tvg_canvas_sync(canvas); * } * * //event handler from your code or third party library * void _event_handler(event *event_data) { * if (!event_data) return NULL; * switch(event_data.type) { * case EVENT_RECT_ADD: * if (!rect) { * tvg_shape_append_rect(rect, 10, 10, 50, 50, 0, 0); * tvg_shape_set_stroke_width(rect, 1.0f); * tvg_shape_set_stroke_color(rect, 255, 0, 0, 255); * tvg_canvas_push(canvas, rect); * } * break; * case EVENT_RECT_MOVE: * if (rect) tvg_paint_translate(rect, 10.0, 10.0); * break; * default: * break; * } * } * * int main(int argc, char **argv) { * //example handler from your code or third party lib * event_handler_add(handler, _event_handler); * * //create frame rendering process which calls _frame_render() function. * app_loop_begin(_frame_render); * app_loop_finish(); * cleanup(); * } * \endcode * * \param[in] canvas The Tvg_Canvas object to be updated. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. * \retval TVG_RESULT_INSUFFICIENT_CONDITION An internal error. */ TVG_EXPORT Tvg_Result tvg_canvas_update(Tvg_Canvas* canvas); /*! * \brief Updates the given Tvg_Paint object from the canvas before the rendering. * * If a client application using the TVG library does not update the entire canvas with tvg_canvas_update() in the frame * rendering process, Tvg_Paint objects previously added to the canvas should be updated manually with this function. * * \param[in] canvas The Tvg_Canvas object to which the @p paint belongs. * \param[in] paint The Tvg_Paint object to be updated. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. */ TVG_EXPORT Tvg_Result tvg_canvas_update_paint(Tvg_Canvas* canvas, Tvg_Paint* paint); /*! * \brief The function start rendering process. * * All paints from the given canvas will be rasterized to the buffer. * * \param[in] canvas The Tvg_Canvas object to be drawn. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. * \retval TVG_RESULT_INSUFFICIENT_CONDITION An internal error. * * \note Drawing can be asynchronous based on the assigned thread number. To guarantee the drawing is done, call tvg_canvas_sync() afterwards. * \see tvg_canvas_sync() */ TVG_EXPORT Tvg_Result tvg_canvas_draw(Tvg_Canvas* canvas); /*! * \brief Guarantees the drawing process is finished. * * It should be called after tvg_canvas_draw(). * * \param[in] canvas The Tvg_Canvas object which was drawn. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Canvas pointer. * * @see tvg_canvas_sync() */ TVG_EXPORT Tvg_Result tvg_canvas_sync(Tvg_Canvas* canvas); /** \} */ // end defgroup ThorVGCapi_Canvas /** * \defgroup ThorVGCapi_Paint Paint * \brief A module for managing graphical elements. It enables duplication, transformation and composition. * * \{ */ /************************************************************************/ /* Paint API */ /************************************************************************/ /*! * \brief Releases the given Tvg_Paint object. * * \code * //example of cleanup function * Tvg_Paint *rect = NULL; //rectangle shape added in other function * * //rectangle delete API * int rectangle_delete(void) { * if (rect) tvg_paint_del(rect); * rect = NULL; * } * * int cleanup(void) { * tvg_canvas_clear(canvas, false); * tvg_canvas_destroy(canvas); * canvas = NULL; * } * \endcode * * \param[in] paint The Tvg_Paint object to be released. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * * \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. * * \see tvg_canvas_clear(), tvg_canvas_destroy() */ TVG_EXPORT Tvg_Result tvg_paint_del(Tvg_Paint* paint); /*! * \brief Scales the given Tvg_Paint object by the given factor. * * \param[in] paint The Tvg_Paint object to be scaled. * \param[in] factor The value of the scaling factor. The default value is 1. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * \retval TVG_RESULT_FAILED_ALLOCATION An internal error with memory allocation. */ TVG_EXPORT Tvg_Result tvg_paint_scale(Tvg_Paint* paint, float factor); /*! * \brief Rotates the given Tvg_Paint by the given angle. * * \param[in] paint The Tvg_Paint object to be rotated. * \param[in] degree The value of the rotation angle in degrees. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * \retval TVG_RESULT_FAILED_ALLOCATION An internal error with memory allocation. */ TVG_EXPORT Tvg_Result tvg_paint_rotate(Tvg_Paint* paint, float degree); /*! * \brief Moves the given Tvg_Paint in a two-dimensional space. * * \param[in] paint The Tvg_Paint object to be shifted. * \param[in] x The value of the horizontal shift. * \param[in] y The value of the vertical shift. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * \retval TVG_RESULT_FAILED_ALLOCATION An internal error with memory allocation. */ TVG_EXPORT Tvg_Result tvg_paint_translate(Tvg_Paint* paint, float x, float y); /*! * \brief Transforms the given Tvg_Paint using the augmented transformation matrix. * * \param[in] paint The Tvg_Paint object to be transformed. * \param[in] m The 3x3 augmented matrix. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * \retval TVG_RESULT_FAILED_ALLOCATION An internal error with memory allocation. */ TVG_EXPORT Tvg_Result tvg_paint_transform(Tvg_Paint* paint, const Tvg_Matrix* m); /*! * \brief Sets the opacity of the given Tvg_Paint. * * \param[in] paint The Tvg_Paint object of which the opacity value is to be set. * \param[in] opacity The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * * \note Setting the opacity with this API may require multiple renderings using a composition. It is recommended to avoid changing the opacity if possible. */ TVG_EXPORT Tvg_Result tvg_paint_set_opacity(Tvg_Paint* paint, uint8_t opacity); /*! * \brief Gets the opacity of the given Tvg_Paint. * * \param[in] paint The Tvg_Paint object of which to get the opacity value. * \param[out] opacity The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT In case a @c nullptr is passed as the argument. */ TVG_EXPORT Tvg_Result tvg_paint_get_opacity(Tvg_Paint* paint, uint8_t* opacity); /*! * \brief Duplicates the given Tvg_Paint object. * * Creates a new object and sets its all properties as in the original object. * * \param[in] paint The Tvg_Paint object to be copied. * * \return A copied Tvg_Paint object if succeed, @c nullptr otherwise. */ TVG_EXPORT Tvg_Paint* tvg_paint_duplicate(Tvg_Paint* paint); /*! * \brief Gets the bounding box of the Tvg_Paint object before any transformation. * * \param[in] paint The Tvg_Paint object of which to get the bounds. * \param[out] x The x coordinate of the upper left corner of the object. * \param[out] y The y coordinate of the upper left corner of the object. * \param[out] w The width of the object. * \param[out] h The height of the object. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * \retval TVG_RESULT_INSUFFICIENT_CONDITION Other errors. */ TVG_EXPORT Tvg_Result tvg_paint_get_bounds(const Tvg_Paint* paint, float* x, float* y, float* w, float* h); /*! * \brief Sets the composition target object and the composition method. * * \param[in] paint The source object of the composition. * \param[in] target The target object of the composition. * \param[in] method The method used to composite the source object with the target. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid @p paint or @p target object or the @p method equal to TVG_COMPOSITE_METHOD_NONE. */ TVG_EXPORT Tvg_Result tvg_paint_set_composite_method(Tvg_Paint* paint, Tvg_Paint* target, Tvg_Composite_Method method); /** \} */ // end defgroup ThorVGCapi_Paint /** * \defgroup ThorVGCapi_Shape Shape * * \brief A module for managing two-dimensional figures and their properties. * * A shape has three major properties: shape outline, stroking, filling. The outline in the shape is retained as the path. * 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. * Path can consists of sub-paths. One sub-path is determined by a close command. * * The stroke of a shape is an optional property in case the shape needs to be represented with/without the outline borders. * 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. * * \{ */ /************************************************************************/ /* Shape API */ /************************************************************************/ /*! * \brief Creates a new shape object. * * \return A new shape object. */ TVG_EXPORT Tvg_Paint* tvg_shape_new(); /*! * \brief Resets the shape path properties. * * The color, the fill and the stroke properties are retained. * * \param[in] paint A Tvg_Paint pointer to the shape object. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * * \note The memory, where the path data is stored, is not deallocated at this stage for caching effect. */ TVG_EXPORT Tvg_Result tvg_shape_reset(Tvg_Paint* paint); /*! * \brief Sets the initial point of the sub-path. * * The value of the current point is set to the given point. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] x The horizontal coordinate of the initial point of the sub-path. * \param[in] y The vertical coordinate of the initial point of the sub-path. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. */ TVG_EXPORT Tvg_Result tvg_shape_move_to(Tvg_Paint* paint, float x, float y); /*! * \brief Adds a new point to the sub-path, which results in drawing a line from the current point to the given end-point. * * The value of the current point is set to the given end-point. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] x The horizontal coordinate of the end-point of the line. * \param[in] y The vertical coordinate of the end-point of the line. * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * * \note In case this is the first command in the path, it corresponds to the tvg_shape_move_to() call. */ TVG_EXPORT Tvg_Result tvg_shape_line_to(Tvg_Paint* paint, float x, float y); /*! * \brief Adds new points to the sub-path, which results in drawing a cubic Bezier curve. * * 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. * The value of the current point is set to the given end-point. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] cx1 The horizontal coordinate of the 1st control point. * \param[in] cy1 The vertical coordinate of the 1st control point. * \param[in] cx2 The horizontal coordinate of the 2nd control point. * \param[in] cy2 The vertical coordinate of the 2nd control point. * \param[in] x The horizontal coordinate of the endpoint of the curve. * \param[in] y The vertical coordinate of the endpoint of the curve. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * * \note In case this is the first command in the path, no data from the path are rendered. */ TVG_EXPORT Tvg_Result tvg_shape_cubic_to(Tvg_Paint* paint, float cx1, float cy1, float cx2, float cy2, float x, float y); /*! * \brief Closes the current sub-path by drawing a line from the current point to the initial point of the sub-path. * * The value of the current point is set to the initial point of the closed sub-path. * * \param[in] paint A Tvg_Paint pointer to the shape object. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * * \note In case the sub-path does not contain any points, this function has no effect. */ TVG_EXPORT Tvg_Result tvg_shape_close(Tvg_Paint* paint); /*! * \brief Appends a rectangle to the path. * * The rectangle with rounded corners can be achieved by setting non-zero values to @p rx and @p ry arguments. * The @p rx and @p ry values specify the radii of the ellipse defining the rounding of the corners. * * The position of the rectangle is specified by the coordinates of its upper left corner - @p x and @p y arguments. * * The rectangle is treated as a new sub-path - it is not connected with the previous sub-path. * * The value of the current point is set to (@p x + @p rx, @p y) - in case @p rx is greater * than @p w/2 the current point is set to (@p x + @p w/2, @p y) * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] x The horizontal coordinate of the upper left corner of the rectangle. * \param[in] y The vertical coordinate of the upper left corner of the rectangle. * \param[in] w The width of the rectangle. * \param[in] h The height of the rectangle. * \param[in] rx The x-axis radius of the ellipse defining the rounded corners of the rectangle. * \param[in] ry The y-axis radius of the ellipse defining the rounded corners of the rectangle. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * & \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. */ TVG_EXPORT Tvg_Result tvg_shape_append_rect(Tvg_Paint* paint, float x, float y, float w, float h, float rx, float ry); /*! * \brief Appends an ellipse to the path. * * The position of the ellipse is specified by the coordinates of its center - @p cx and @p cy arguments. * * The ellipse is treated as a new sub-path - it is not connected with the previous sub-path. * * The value of the current point is set to (@p cx, @p cy - @p ry). * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] cx The horizontal coordinate of the center of the ellipse. * \param[in] cy The vertical coordinate of the center of the ellipse. * \param[in] rx The x-axis radius of the ellipse. * \param[in] ry The y-axis radius of the ellipse. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. */ TVG_EXPORT Tvg_Result tvg_shape_append_circle(Tvg_Paint* paint, float cx, float cy, float rx, float ry); /*! * \brief Appends a circular arc to the path. * * The arc is treated as a new sub-path - it is not connected with the previous sub-path. * 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. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] cx The horizontal coordinate of the center of the arc. * \param[in] cy The vertical coordinate of the center of the arc. * \param[in] radius The radius of the arc. * \param[in] startAngle The start angle of the arc given in degrees, measured counter-clockwise from the horizontal line. * \param[in] sweep The central angle of the arc given in degrees, measured counter-clockwise from @p startAngle. * \param[in] pie Specifies whether to draw radii from the arc's center to both of its end-point - drawn if @c true. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * * \note Setting @p sweep value greater than 360 degrees, is equivalent to calling appendCircle(cx, cy, radius, radius). */ TVG_EXPORT Tvg_Result tvg_shape_append_arc(Tvg_Paint* paint, float cx, float cy, float radius, float startAngle, float sweep, uint8_t pie); /*! * \brief Appends a given sub-path to the path. * * The current point value is set to the last point from the sub-path. * For each command from the @p cmds array, an appropriate number of points in @p pts array should be specified. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] cmds The array of the commands in the sub-path. * \param[in] cmdCnt The length of the @p cmds array. * \param[in] pts The array of the two-dimensional points. * \param[in] ptsCnt The length of the @p pts array. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument or @p cmdCnt or @p ptsCnt equal to zero. */ TVG_EXPORT Tvg_Result tvg_shape_append_path(Tvg_Paint* paint, const Tvg_Path_Command* cmds, uint32_t cmdCnt, const Tvg_Point* pts, uint32_t ptsCnt); /*! * \brief Gets the points values of the path. * * The function does not allocate any data, it operates on internal memory. There is no need to free the @p pts array. * * \code * Tvg_Shape *shape = tvg_shape_new(); * Tvg_Point *coords = NULL; * uint32_t len = 0; * * tvg_shape_append_circle(shape, 10, 10, 50, 50); * tvg_shape_get_path_coords(shape, (const Tvg_Point**)&coords, &len); * //TVG approximates a circle by four Bezier lines. In the example above the cmds array stores their coordinates * \endcode * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[out] pts The pointer to the array of the two-dimensional points from the path. * \param[out] cnt The length of the @p pts array. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. */ TVG_EXPORT Tvg_Result tvg_shape_get_path_coords(const Tvg_Paint* paint, const Tvg_Point** pts, uint32_t* cnt); /*! * \brief Gets the commands data of the path. * * The function does not allocate any data. There is no need to free the @p cmds array. * * \code * Tvg_Shape *shape = tvg_shape_new(); * Tvg_Path_Command *cmds = NULL; * uint32_t len = 0; * * tvg_shape_append_circle(shape, 10, 10, 50, 50); * tvg_shape_get_path_commands(shape, (const Tvg_Path_Command**)&cmds, &len); * //TVG approximates a circle by four Bezier lines. In the example above the cmds array stores their coordinates * \endcode * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[out] cmds The pointer to the array of the commands from the path. * \param[out] cnt The length of the @p cmds array. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. */ TVG_EXPORT Tvg_Result tvg_shape_get_path_commands(const Tvg_Paint* paint, const Tvg_Path_Command** cmds, uint32_t* cnt); /*! * \brief Sets the stroke width for all of the figures from the @p paint. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] width The width of the stroke. The default value is 0. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * \retval TVG_RESULT_FAILED_ALLOCATION An internal error with a memory allocation. */ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_width(Tvg_Paint* paint, float width); /*! * \brief Gets the shape's stroke width. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[out] width The stroke width. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. */ TVG_EXPORT Tvg_Result tvg_shape_get_stroke_width(const Tvg_Paint* paint, float* width); /*! * \brief Sets the shape's stroke color. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0. * \param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0. * \param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0. * \param[in] a opacity value * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * \retval TVG_RESULT_FAILED_ALLOCATION An internal error with a memory allocation. * * \note Either a solid color or a gradient fill is applied, depending on what was set as last. */ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a); /*! * \brief Gets the shape's stroke color. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[out] r The red color channel value in the range [0 ~ 255]. The default value is 0. * \param[out] g The green color channel value in the range [0 ~ 255]. The default value is 0. * \param[out] b The blue color channel value in the range [0 ~ 255]. The default value is 0. * \param[out] a opacity value * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. */ TVG_EXPORT Tvg_Result tvg_shape_get_stroke_color(const Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a); /*! * \brief Sets the linear gradient fill of the stroke for all of the figures from the path. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] grad The linear gradient fill. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * \retval TVG_RESULT_FAILED_ALLOCATION An internal error with a memory allocation. * \retval TVG_RESULT_MEMORY_CORRUPTION An invalid Tvg_Gradient pointer. * * \note Either a solid color or a gradient fill is applied, depending on what was set as last. */ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_linear_gradient(Tvg_Paint* paint, Tvg_Gradient* grad); /*! * \brief Sets the radial gradient fill of the stroke for all of the figures from the path. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] grad The radial gradient fill. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * \retval TVG_RESULT_FAILED_ALLOCATION An internal error with a memory allocation. * \retval TVG_RESULT_MEMORY_CORRUPTION An invalid Tvg_Gradient pointer. * * \note Either a solid color or a gradient fill is applied, depending on what was set as last. */ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_radial_gradient(Tvg_Paint* paint, Tvg_Gradient* grad); /*! * \brief Gets the gradient fill of the shape's stroke. * * The function does not allocate any memory. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[out] grad The gradient fill. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. */ TVG_EXPORT Tvg_Result tvg_shape_get_stroke_gradient(const Tvg_Paint* paint, Tvg_Gradient** grad); /*! * \brief Sets the shape's stroke dash pattern. * * \code * //dash pattern examples * float dashPattern[2] = {20, 10}; // -- - -- - -- - * float dashPattern[2] = {40, 20}; // ---- ---- ---- * float dashPattern[4] = {10, 20, 30, 40} // - --- - --- * \endcode * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] dashPattern The array of consecutive pair values of the dash length and the gap length. * \param[in] cnt The size of the @p dashPattern array. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument, the given length of the array is less than two or any of the @p dashPattern values is zero or less. * \retval TVG_RESULT_FAILED_ALLOCATION An internal error with a memory allocation. */ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_dash(Tvg_Paint* paint, const float* dashPattern, uint32_t cnt); /*! * \brief Gets the dash pattern of the stroke. * * The function does not allocate any memory. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[out] dashPattern The array of consecutive pair values of the dash length and the gap length. * \param[out] cnt The size of the @p dashPattern array. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. */ TVG_EXPORT Tvg_Result tvg_shape_get_stroke_dash(const Tvg_Paint* paint, const float** dashPattern, uint32_t* cnt); /*! * \brief Sets the cap style used for stroking the path. * * The cap style specifies the shape to be used at the end of the open stroked sub-paths. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] cap The cap style value. The default value is @c TVG_STROKE_CAP_SQUARE. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * \retval TVG_RESULT_FAILED_ALLOCATION An internal error with a memory allocation. */ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_cap(Tvg_Paint* paint, Tvg_Stroke_Cap cap); /*! * \brief Gets the stroke cap style used for stroking the path. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[out] cap The cap style value. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. */ TVG_EXPORT Tvg_Result tvg_shape_get_stroke_cap(const Tvg_Paint* paint, Tvg_Stroke_Cap* cap); /*! * \brief Sets the join style for stroked path segments. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] join The join style value. The default value is @c TVG_STROKE_JOIN_BEVEL . * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * \retval TVG_RESULT_FAILED_ALLOCATION An internal error with a memory allocation. */ TVG_EXPORT Tvg_Result tvg_shape_set_stroke_join(Tvg_Paint* paint, Tvg_Stroke_Join join); /*! * \brief The function gets the stroke join method * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[out] join The join style value. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. */ TVG_EXPORT Tvg_Result tvg_shape_get_stroke_join(const Tvg_Paint* paint, Tvg_Stroke_Join* join); /*! * \brief Sets the shape's solid color. * * The parts of the shape defined as inner are colored. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] r The red color channel value in the range [0 ~ 255]. The default value is 0. * \param[in] g The green color channel value in the range [0 ~ 255]. The default value is 0. * \param[in] b The blue color channel value in the range [0 ~ 255]. The default value is 0. * \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. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * * \note Either a solid color or a gradient fill is applied, depending on what was set as last. * \see tvg_shape_set_fill_rule() */ TVG_EXPORT Tvg_Result tvg_shape_set_fill_color(Tvg_Paint* paint, uint8_t r, uint8_t g, uint8_t b, uint8_t a); /*! * \brief Gets the shape's solid color. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[out] r The red color channel value in the range [0 ~ 255]. The default value is 0. * \param[out] g The green color channel value in the range [0 ~ 255]. The default value is 0. * \param[out] b The blue color channel value in the range [0 ~ 255]. The default value is 0. * \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. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. */ TVG_EXPORT Tvg_Result tvg_shape_get_fill_color(const Tvg_Paint* paint, uint8_t* r, uint8_t* g, uint8_t* b, uint8_t* a); /*! * \brief Sets the shape's fill rule. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] rule The fill rule value. The default value is @c TVG_FILL_RULE_WINDING. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. */ TVG_EXPORT Tvg_Result tvg_shape_set_fill_rule(Tvg_Paint* paint, Tvg_Fill_Rule rule); /*! * \brief Gets the shape's fill rule. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[out] rule shape's fill rule * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. */ TVG_EXPORT Tvg_Result tvg_shape_get_fill_rule(const Tvg_Paint* paint, Tvg_Fill_Rule* rule); /*! * \brief Sets the linear gradient fill for all of the figures from the path. * * The parts of the shape defined as inner are filled. * * \code * Tvg_Gradient* grad = tvg_linear_gradient_new(); * tvg_linear_gradient_set(grad, 700, 700, 800, 800); * Tvg_Color_Stop color_stops[4] = * { * {.offset=0.0, .r=0, .g=0, .b=0, .a=255}, * {.offset=0.25, .r=255, .g=0, .b=0, .a=255}, * {.offset=0.5, .r=0, .g=255, .b=0, .a=255}, * {.offset=1.0, .r=0, .g=0, .b=255, .a=255} * }; * tvg_gradient_set_color_stops(grad, color_stops, 4); * tvg_shape_set_linear_gradient(shape, grad); * \endcode * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] grad The linear gradient fill. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * \retval TVG_RESULT_MEMORY_CORRUPTION An invalid Tvg_Gradient pointer. * * \note Either a solid color or a gradient fill is applied, depending on what was set as last. * \see tvg_shape_set_fill_rule() */ TVG_EXPORT Tvg_Result tvg_shape_set_linear_gradient(Tvg_Paint* paint, Tvg_Gradient* grad); /*! * \brief Sets the radial gradient fill for all of the figures from the path. * * The parts of the shape defined as inner are filled. * * \code * Tvg_Gradient* grad = tvg_radial_gradient_new(); * tvg_radial_gradient_set(grad, 550, 550, 50)); * Tvg_Color_Stop color_stops[4] = * { * {.offset=0.0, .r=0, .g=0, .b=0, .a=255}, * {.offset=0.25, .r=255, .g=0, .b=0, .a=255}, * {.offset=0.5, .r=0, .g=255, .b=0, .a=255}, * {.offset=1.0, .r=0, .g=0, .b=255, .a=255} * }; * tvg_gradient_set_color_stops(grad, color_stops, 4); * tvg_shape_set_radial_gradient(shape, grad); * \endcode * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[in] grad The radial gradient fill. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. * \retval TVG_RESULT_MEMORY_CORRUPTION An invalid Tvg_Gradient pointer. * * \note Either a solid color or a gradient fill is applied, depending on what was set as last. * \see tvg_shape_set_fill_rule() */ TVG_EXPORT Tvg_Result tvg_shape_set_radial_gradient(Tvg_Paint* paint, Tvg_Gradient* grad); /*! * \brief Gets the gradient fill of the shape. * * The function does not allocate any data. * * \param[in] paint A Tvg_Paint pointer to the shape object. * \param[out] grad The gradient fill. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer passed as an argument. */ TVG_EXPORT Tvg_Result tvg_shape_get_gradient(const Tvg_Paint* paint, Tvg_Gradient** grad); /** \} */ // end defgroup ThorVGCapi_Shape /** * \defgroup ThorVGCapi_Gradient Gradient * \brief A module managing the gradient fill of objects. * * The module enables to set and to get the gradient colors and their arrangement inside the gradient bounds, * to specify the gradient bounds and the gradient behavior in case the area defined by the gradient bounds * is smaller than the area to be filled. * * \{ */ /************************************************************************/ /* Gradient API */ /************************************************************************/ /*! * \brief Creates a new linear gradient object. * * \code * Tvg_Paint shape = tvg_shape_new(); * tvg_shape_append_rect(shape, 700, 700, 100, 100, 20, 20); * Tvg_Gradient* grad = tvg_linear_gradient_new(); * tvg_linear_gradient_set(grad, 700, 700, 800, 800); * Tvg_Color_Stop color_stops[2] = * { * {.offset=0, .r=0, .g=0, .b=0, .a=255}, * {.offset=1, .r=0, .g=255, .b=0, .a=255}, * }; * tvg_gradient_set_color_stops(grad, color_stops, 2); * tvg_shape_set_linear_gradient(shape, grad); * \endcode * * \return A new linear gradient object. */ TVG_EXPORT Tvg_Gradient* tvg_linear_gradient_new(); /*! * \brief Creates a new radial gradient object. * * \code * Tvg_Paint shape = tvg_shape_new(); * tvg_shape_append_rect(shape, 700, 700, 100, 100, 20, 20); * Tvg_Gradient* grad = tvg_radial_gradient_new(); * tvg_linear_gradient_set(grad, 550, 550, 50); * Tvg_Color_Stop color_stops[2] = * { * {.offset=0, .r=0, .g=0, .b=0, .a=255}, * {.offset=1, .r=0, .g=255, .b=0, .a=255}, * }; * tvg_gradient_set_color_stops(grad, color_stops, 2); * tvg_shape_set_radial_gradient(shape, grad); * \endcode * * \return A new radial gradient object. */ TVG_EXPORT Tvg_Gradient* tvg_radial_gradient_new(); /*! * \brief Sets the linear gradient bounds. * * The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing * the given points (@p x1, @p y1) and (@p x2, @p y2), respectively. Both lines are perpendicular to the line linking * (@p x1, @p y1) and (@p x2, @p y2). * * \param[in] grad The Tvg_Gradient object of which bounds are to be set. * @param[in] x1 The horizontal coordinate of the first point used to determine the gradient bounds. * @param[in] y1 The vertical coordinate of the first point used to determine the gradient bounds. * @param[in] x2 The horizontal coordinate of the second point used to determine the gradient bounds. * @param[in] y2 The vertical coordinate of the second point used to determine the gradient bounds. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer or the first and the second points are equal. */ TVG_EXPORT Tvg_Result tvg_linear_gradient_set(Tvg_Gradient* grad, float x1, float y1, float x2, float y2); /*! * \brief Gets the linear gradient bounds. * * The bounds of the linear gradient are defined as a surface constrained by two parallel lines crossing * the given points (@p x1, @p y1) and (@p x2, @p y2), respectively. Both lines are perpendicular to the line linking * (@p x1, @p y1) and (@p x2, @p y2). * * \param[in] grad The Tvg_Gradient object of which to get the bounds. * \param[out] x1 The horizontal coordinate of the first point used to determine the gradient bounds. * \param[out] y1 The vertical coordinate of the first point used to determine the gradient bounds. * \param[out] x2 The horizontal coordinate of the second point used to determine the gradient bounds. * \param[out] y2 The vertical coordinate of the second point used to determine the gradient bounds. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. */ TVG_EXPORT Tvg_Result tvg_linear_gradient_get(Tvg_Gradient* grad, float* x1, float* y1, float* x2, float* y2); /*! * \brief Sets the radial gradient bounds. * * The radial gradient bounds are defined as a circle centered in a given point (@p cx, @p cy) of a given radius. * * \param[in] grad The Tvg_Gradient object of which bounds are to be set. * \param[in] cx The horizontal coordinate of the center of the bounding circle. * \param[in] cy The vertical coordinate of the center of the bounding circle. * \param[in] radius The radius of the bounding circle. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer or the @p radius value less than zero. */ TVG_EXPORT Tvg_Result tvg_radial_gradient_set(Tvg_Gradient* grad, float cx, float cy, float radius); /*! * \brief The function gets radial gradient center point ant radius * * \param[in] grad The Tvg_Gradient object of which bounds are to be set. * \param[out] cx The horizontal coordinate of the center of the bounding circle. * \param[out] cy The vertical coordinate of the center of the bounding circle. * \param[out] radius The radius of the bounding circle. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. */ TVG_EXPORT Tvg_Result tvg_radial_gradient_get(Tvg_Gradient* grad, float* cx, float* cy, float* radius); /*! * \brief Sets the parameters of the colors of the gradient and their position. * * \param[in] grad The Tvg_Gradient object of which the color information is to be set. * \param[in] color_stop An array of Tvg_Color_Stop data structure. * \param[in] cnt The size of the @p color_stop array equal to the colors number used in the gradient. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. */ TVG_EXPORT Tvg_Result tvg_gradient_set_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop* color_stop, uint32_t cnt); /*! * \brief Gets the parameters of the colors of the gradient, their position and number * * The function does not allocate any memory. * * \param[in] grad The Tvg_Gradient object of which to get the color information. * \param[out] color_stop An array of Tvg_Color_Stop data structure. * \param[out] cnt The size of the @p color_stop array equal to the colors number used in the gradient. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. */ TVG_EXPORT Tvg_Result tvg_gradient_get_color_stops(Tvg_Gradient* grad, const Tvg_Color_Stop** color_stop, uint32_t* cnt); /*! * \brief Sets the Tvg_Stroke_Fill value, which specifies how to fill the area outside the gradient bounds. * * \param[in] grad The Tvg_Gradient object. * \param[in] spread The FillSpread value. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. */ TVG_EXPORT Tvg_Result tvg_gradient_set_spread(Tvg_Gradient* grad, const Tvg_Stroke_Fill spread); /*! * \brief Gets the FillSpread value of the gradient object. * * \param[in] grad The Tvg_Gradient object. * \param[out] spread The FillSpread value. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT A @c nullptr passed as the argument. */ TVG_EXPORT Tvg_Result tvg_gradient_get_spread(Tvg_Gradient* grad, Tvg_Stroke_Fill* spread); /*! * \brief Deletes the given gradient object. * * \param[in] grad The gradient object to be deleted. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Gradient pointer. */ TVG_EXPORT Tvg_Result tvg_gradient_del(Tvg_Gradient* grad); /** \} */ // end defgroup ThorVGCapi_Gradient /** * \defgroup ThorVGCapi_Picture Picture * * \brief A module enabling to create and to load an image in one of the supported formats: svg, png and raw. * * * \{ */ /************************************************************************/ /* Picture API */ /************************************************************************/ /*! * \brief Creates a new picture object. * * \return A new picture object. */ TVG_EXPORT Tvg_Paint* tvg_picture_new(); /*! * \brief Loads a picture data directly from a file. * * \param[in] paint A Tvg_Paint pointer to the picture object. * \param[in] path The absolute path to the image file. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer or an empty @p path. * \retval TVG_RESULT_NOT_SUPPORTED A file with an unknown extension. * \retval TVG_RESULT_UNKNOWN An error at a later stage. */ TVG_EXPORT Tvg_Result tvg_picture_load(Tvg_Paint* paint, const char* path); /*! * \brief Loads a picture data from a memory block of a given size. (BETA version) * * \warning Please do not use it, this API is not official one. It can be modified in the next version. */ TVG_EXPORT Tvg_Result tvg_picture_load_raw(Tvg_Paint* paint, uint32_t *data, uint32_t w, uint32_t h, bool copy); /*! * \brief Gets the position and the size of the loaded picture. (BETA version) * * \warning Please do not use it, this API is not official one. It can be modified in the next version. */ TVG_EXPORT Tvg_Result tvg_picture_get_viewbox(const Tvg_Paint* paint, float* x, float* y, float* w, float* h); /** \} */ // end defgroup ThorVGCapi_Picture /** * \defgroup ThorVGCapi_Scene Scene * \brief A module managing the multiple paints as one group paint. * * As a group, scene can be transformed, translucent, composited with other target paints, * its children will be affected by the scene world. * * \{ */ /************************************************************************/ /* Scene API */ /************************************************************************/ /*! * \brief Creates a new scene object. * * A scene object is used to group many paints into one object, which can be manipulated using TVG APIs. * * \return A new scene object. */ TVG_EXPORT Tvg_Paint* tvg_scene_new(); /*! * \brief Sets the size of the container, where all the paints pushed into the scene are stored. * * If the number of objects pushed into the scene is known in advance, calling the function * prevents multiple memory reallocation, thus improving the performance. * * \param[in] scene A Tvg_Paint pointer to the scene object. * \param[in] size The number of objects for which the memory is to be reserved. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid Tvg_Paint pointer. */ TVG_EXPORT Tvg_Result tvg_scene_reserve(Tvg_Paint* scene, uint32_t size); /*! * \brief Passes drawing elements to the scene using Tvg_Paint objects. * * Only the paints pushed into the scene will be drawing targets. * If you know the number of pushed objects in the advance, please call tvg_scene_reserve(). * * \param[in] scene A Tvg_Paint pointer to the scene object. * \param[in] paint A graphical object to be drawn. * * \return Tvg_Result enumeration. * \retval TVG_RESULT_SUCCESS Succeed. * \retval TVG_RESULT_INVALID_ARGUMENT An invalid pointer to the @p scene. * \retval TVG_RESULT_MEMORY_CORRUPTION An invalid pointer to the @p paint. * \retval TVG_RESULT_INSUFFICIENT_CONDITION An internal error. * * \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. * \see tvg_scene_reserve() */ TVG_EXPORT Tvg_Result tvg_scene_push(Tvg_Paint* scene, Tvg_Paint* paint); /*! * \brief Sets the total number of the paints pushed into the scene to be zero. (BETA version) * * \warning Please do not use it, this API is not official one. It could be modified in the next version. */ TVG_EXPORT Tvg_Result tvg_scene_clear(Tvg_Paint* scene); /** \} */ // end defgroup ThorVGCapi_Scene /** \} */ // end defgroup ThorVG_CAPI #ifdef __cplusplus } #endif #endif //_THORVG_CAPI_H_