thorvg.h

Defines

TVG_BUILD
TVG_API
TVG_DEPRECATED
_TVG_DECLARE_PRIVATE(A)
_TVG_DISABLE_CTOR(A)
_TVG_DECLARE_ACCESSOR(A)
namespace tvg

Enums

enum class Result

Enumeration specifying the result from the APIs.

All ThorVG APIs could potentially return one of the values in the list. Please note that some APIs may additionally specify the reasons that trigger their return values.

Values:

enumerator Success

The value returned in case of a correct request execution.

enumerator InvalidArguments

The value returned in the event of a problem with the arguments given to the API - e.g. empty paths or null pointers.

enumerator InsufficientCondition

The value returned in case the request cannot be processed - e.g. asking for properties of an object, which does not exist.

enumerator FailedAllocation

The value returned in case of unsuccessful memory allocation.

enumerator MemoryCorruption

The value returned in the event of bad memory handling - e.g. failing in pointer releasing or casting.

enumerator NonSupport

The value returned in case of choosing unsupported engine features(options).

enumerator Unknown

The value returned in all other cases.

enum class PathCommand

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.

Values:

enumerator Close

Ends the current sub-path and connects it with its initial point. This command doesn't expect any points.

enumerator MoveTo

Sets a new initial point of the sub-path and a new current point. This command expects 1 point: the starting position.

enumerator LineTo

Draws a line from the current point to the given point and sets a new value of the current point. This command expects 1 point: the end-position of the line.

enumerator CubicTo

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. This command expects 3 points: the 1st control-point, the 2nd control-point, the end-point of the curve.

enum class StrokeCap

Enumeration determining the ending type of a stroke in the open sub-paths.

Values:

enumerator Square

The stroke is extended in both end-points 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.

enumerator Round

The stroke is extended in both end-points 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.

enumerator Butt

The stroke ends exactly at each of the two end-points of a sub-path. For zero length sub-paths no stroke is rendered.

enum class StrokeJoin

Enumeration determining the style used at the corners of joined stroked path segments.

Values:

enumerator Bevel

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.

enumerator Round

The outer corner of the joined path segments is rounded. The circular region is centered at the join point.

enumerator 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.

enum class FillSpread

Enumeration specifying how to fill the area outside the gradient bounds.

Values:

enumerator Pad

The remaining area is filled with the closest stop color.

enumerator Reflect

The gradient pattern is reflected outside the gradient area until the expected region is filled.

enumerator Repeat

The gradient pattern is repeated continuously beyond the gradient area until the expected region is filled.

enum class FillRule

Enumeration specifying the algorithm used to establish which parts of the shape are treated as the inside of the shape.

Values:

enumerator Winding

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.

enumerator EvenOdd

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.

enum class CompositeMethod

Enumeration indicating the method used in the composition of two objects - the target and the source.

Notation: S(Source), T(Target), SA(Source Alpha), TA(Target Alpha)

Values:

enumerator None

No composition is applied.

enumerator ClipPath

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.

enumerator AlphaMask

Alpha Masking using the compositing target's pixels as an alpha value.

enumerator InvAlphaMask

Alpha Masking using the complement to the compositing target's pixels as an alpha value.

enumerator LumaMask

Alpha Masking using the grayscale (0.2125R + 0.7154G + 0.0721*B) of the compositing target's pixels.

Since

0.9

enumerator InvLumaMask

Alpha Masking using the grayscale (0.2125R + 0.7154G + 0.0721*B) of the complement to the compositing target's pixels.

Since

0.11

enumerator AddMask

Combines the target and source objects pixels using target alpha. (T * TA) + (S * (255 - TA)) (Experimental API)

enumerator SubtractMask

Subtracts the source color from the target color while considering their respective target alpha. (T * TA) - (S * (255 - TA)) (Experimental API)

enumerator IntersectMask

Computes the result by taking the minimum value between the target alpha and the source alpha and multiplies it with the target color. (T * min(TA, SA)) (Experimental API)

enumerator DifferenceMask

Calculates the absolute difference between the target color and the source color multiplied by the complement of the target alpha. abs(T - S * (255 - TA)) (Experimental API)

enumerator LightenMask

Where multiple masks intersect, the highest transparency value is used. (Experimental API)

enumerator DarkenMask

Where multiple masks intersect, the lowest transparency value is used. (Experimental API)

enum class BlendMethod : uint8_t

Enumeration indicates the method used for blending paint. Please refer to the respective formulas for each method.

Notation: S(source paint as the top layer), D(destination as the bottom layer), Sa(source paint alpha), Da(destination alpha)

See also

Paint::blend()

Since

0.15

Values:

enumerator Normal

Perform the alpha blending(default). S if (Sa == 255), otherwise (Sa * S) + (255 - Sa) * D.

enumerator 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)

enumerator Screen

The values of the pixels in the two layers are inverted, multiplied, and then inverted again. (S + D) - (S * D)

enumerator Overlay

Combines Multiply and Screen blend modes. (2 * S * D) if (2 * D < Da), otherwise (Sa * Da) - 2 * (Da - S) * (Sa - D)

enumerator SrcOver

Replace the bottom layer with the top layer.

enumerator Darken

Creates a pixel that retains the smallest components of the top and bottom layer pixels. min(S, D)

enumerator Lighten

Only has the opposite action of Darken Only. max(S, D)

enumerator ColorDodge

Divides the bottom layer by the inverted top layer. D / (255 - S)

enumerator ColorBurn

Divides the inverted bottom layer by the top layer, and then inverts the result. 255 - (255 - D) / S.

enumerator 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)

enumerator 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)

enumerator 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)

enumerator Exclusion

The result is twice the product of the top and bottom layers, subtracted from their sum. s + d - (2 * s * d)

enumerator Hue

Reserved. Not supported.

enumerator Saturation

Reserved. Not supported.

enumerator Color

Reserved. Not supported.

enumerator Luminosity

Reserved. Not supported.

enumerator Add

Simply adds pixel values of one layer with the other. (S + D)

enumerator HardMix

Reserved. Not supported.

enum class SceneEffect : uint8_t

Enumeration that defines methods used for Scene Effects.

This enum provides options to apply various post-processing effects to a scene. Scene effects are typically applied to modify the final appearance of a rendered scene, such as blurring.

Note

Experimental API

Values:

enumerator ClearAll

Reset all previously applied scene effects, restoring the scene to its original state.

enumerator GaussianBlur

Apply a blur effect with a Gaussian filter. Param(3) = {sigma(float)[> 0], direction(int)[both: 0 / horizontal: 1 / vertical: 2], border(int)[duplicate: 0 / wrap: 1], quality(int)[0 - 100]}.

enum class CanvasEngine

Enumeration specifying the engine type used for the graphics backend. For multiple backends bitwise operation is allowed.

Values:

enumerator Sw

CPU rasterizer.

enumerator Gl

OpenGL rasterizer.

enumerator Wg

WebGPU rasterizer.

Since

0.15

enum class Type : uint8_t

Enumeration specifying the ThorVG class type value.

ThorVG's drawing objects can return class type values, allowing you to identify the specific class of each object.

See also

Paint::type()

See also

Fill::type()

Note

Experimental API

Values:

enumerator Undefined

Unkown class.

enumerator Shape

Shape class.

enumerator Scene

Scene class.

enumerator Picture

Picture class.

enumerator Text

Text class.

enumerator LinearGradient

LinearGradient class.

enumerator RadialGradient

RadialGradient class.

Functions

template<typename T = tvg::Paint>
std::unique_ptr<T> cast(Paint *paint)

The cast() function is a utility function used to cast a 'Paint' to type 'T'.

Since

0.11

template<typename T = tvg::Fill>
std::unique_ptr<T> cast(Fill *fill)

The cast() function is a utility function used to cast a 'Fill' to type 'T'.

Since

0.11

struct Point
#include <thorvg.h>

A data structure representing a point in two-dimensional space.

Public Members

float x
float y
struct Matrix
#include <thorvg.h>

A data structure representing a three-dimensional matrix.

The elements e11, e12, e21 and e22 represent the rotation matrix, including the scaling factor. The elements e13 and e23 determine the translation of the object along the x and y-axis, respectively. The elements e31 and e32 are set to 0, e33 is set to 1.

Public Members

float e11
float e12
float e13
float e21
float e22
float e23
float e31
float e32
float e33
class Paint
#include <thorvg.h>

An abstract class for managing graphical elements.

A graphical element in TVG is any object composed into a Canvas. Paint represents such a graphical object and its behaviors such as duplication, transformation and composition. TVG recommends the user to regard a paint as a set of volatile commands. They can prepare a Paint and then request a Canvas to run them.

Subclassed by tvg::Picture, tvg::Scene, tvg::Shape, tvg::Text

Public Functions

virtual ~Paint()
Result rotate(float degree) noexcept

Sets the angle by which the object is rotated.

The angle in measured clockwise from the horizontal axis. The rotational axis passes through the point on the object with zero coordinates.

Parameters:

degree[in] The value of the angle in degrees.

Return values:

Result::InsufficientCondition – in case a custom transform is applied.

Result scale(float factor) noexcept

Sets the scale value of the object.

Parameters:

factor[in] The value of the scaling factor. The default value is 1.

Return values:

Result::InsufficientCondition – in case a custom transform is applied.

Result translate(float x, float y) noexcept

Sets the values by which the object is moved in a two-dimensional space.

The origin of the coordinate system is in the upper-left corner of the canvas. The horizontal and vertical axes point to the right and down, respectively.

Parameters:
  • x[in] The value of the horizontal shift.

  • y[in] The value of the vertical shift.

Return values:

Result::InsufficientCondition – in case a custom transform is applied.

Result transform(const Matrix &m) noexcept

Sets the matrix of the affine transformation for the object.

The augmented matrix of the transformation is expected to be given.

Parameters:

m[in] The 3x3 augmented matrix.

Matrix transform() noexcept

Gets the matrix of the affine transformation of the object.

The values of the matrix can be set by the transform() API, as well by the translate(), scale() and rotate(). In case no transformation was applied, the identity matrix is returned.

Since

0.4

Returns:

The augmented transformation matrix.

Result opacity(uint8_t o) noexcept

Sets the opacity of the object.

Note

Setting the opacity with this API may require multiple render pass for composition. It is recommended to avoid changing the opacity if possible.

Parameters:

o[in] The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.

Result composite(std::unique_ptr<Paint> target, CompositeMethod method) noexcept

Sets the composition target object and the composition method.

Parameters:
  • target[in] The paint of the target object.

  • method[in] The method used to composite the source object with the target.

Result clip(std::unique_ptr<Paint> clipper) noexcept

Clip the drawing region of the paint object.

This function restricts the drawing area of the paint object to the specified shape's paths.

Note

clipper only supports the Shape type.

Note

Experimental API

Parameters:

clipper[in] The shape object as the clipper.

Return values:

Result::NonSupport – If the clipper type is not Shape.

Result blend(BlendMethod method) noexcept

Sets the blending method for the paint object.

The blending feature allows you to combine colors to create visually appealing effects, including transparency, lighting, shading, and color mixing, among others. its process involves the combination of colors or images from the source paint object with the destination (the lower layer image) using blending operations. The blending operation is determined by the chosen BlendMethod, which specifies how the colors or images are combined.

Note

Experimental API

Parameters:

method[in] The blending method to be set.

Result bounds(float *x, float *y, float *w, float *h) const noexcept

Deprecated:

Use bounds(float* x, float* y, float* w, float* h, bool transformed) instead

Result bounds(float *x, float *y, float *w, float *h, bool transformed) const noexcept

Gets the axis-aligned bounding box of the paint object.

See also

Canvas::update()

Note

This is useful when you need to figure out the bounding box of the paint in the canvas space.

Note

The bounding box doesn't indicate the actual drawing region. It's the smallest rectangle that encloses the object.

Note

If transformed is true, the paint needs to be pushed into a canvas and updated before this api is called.

Parameters:
  • x[out] The x-coordinate of the upper-left corner of the object.

  • y[out] The y-coordinate of the upper-left corner of the object.

  • w[out] The width of the object.

  • h[out] The height of the object.

  • transformed[in] If true, the paint's transformations are taken into account in the scene it belongs to. Otherwise they aren't.

Paint *duplicate() const noexcept

Duplicates the object.

Creates a new object and sets its all properties as in the original object.

Returns:

The created object when succeed, nullptr otherwise.

uint8_t opacity() const noexcept

Gets the opacity value of the object.

Returns:

The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.

CompositeMethod composite(const Paint **target) const noexcept

Gets the composition target object and the composition method.

Since

0.5

Parameters:

target[out] The paint of the target object.

Returns:

The method used to composite the source object with the target.

virtual Type type() const noexcept = 0

Returns the ID value of this class.

This method can be used to check the current concrete instance type.

Since

Experimental API

Returns:

The class type ID of the Paint instance.

uint32_t identifier() const noexcept

See also

Paint::type()

Public Members

uint32_t id = 0

Unique ID of this instance.

This is reserved to specify an paint instance in a scene.

Since

Experimental API

Impl *pImpl

Protected Functions

Paint(const Paint&) = delete
const Paint &operator=(const Paint&) = delete
Paint()
class Fill
#include <thorvg.h>

An abstract class representing the gradient fill of the Shape object.

It contains the information about the gradient colors and their arrangement inside the gradient bounds. The gradients bounds are defined in the LinearGradient or RadialGradient class, depending on the type of the gradient to be used. It specifies the gradient behavior in case the area defined by the gradient bounds is smaller than the area to be filled.

Subclassed by tvg::LinearGradient, tvg::RadialGradient

Public Functions

virtual ~Fill()
Result colorStops(const ColorStop *colorStops, uint32_t cnt) noexcept

Sets the parameters of the colors of the gradient and their position.

Parameters:
  • colorStops[in] An array of ColorStop data structure.

  • cnt[in] The count of the colorStops array equal to the colors number used in the gradient.

Result spread(FillSpread s) noexcept

Sets the FillSpread value, which specifies how to fill the area outside the gradient bounds.

Parameters:

s[in] The FillSpread value.

Result transform(const Matrix &m) noexcept

Sets the matrix of the affine transformation for the gradient fill.

The augmented matrix of the transformation is expected to be given.

Parameters:

m[in] The 3x3 augmented matrix.

uint32_t colorStops(const ColorStop **colorStops) const noexcept

Gets the parameters of the colors of the gradient, their position and number.

Parameters:

colorStops[out] A pointer to the memory location, where the array of the gradient's ColorStop is stored.

Returns:

The number of colors used in the gradient. This value corresponds to the length of the colorStops array.

FillSpread spread() const noexcept

Gets the FillSpread value of the fill.

Returns:

The FillSpread value of this Fill.

Matrix transform() const noexcept

Gets the matrix of the affine transformation of the gradient fill.

In case no transformation was applied, the identity matrix is returned.

Returns:

The augmented transformation matrix.

Fill *duplicate() const noexcept

Creates a copy of the Fill object.

Return a newly created Fill object with the properties copied from the original.

Returns:

A copied Fill object when succeed, nullptr otherwise.

virtual Type type() const noexcept = 0

Returns the ID value of this class.

This method can be used to check the current concrete instance type.

Since

Experimental API

Returns:

The class type ID of the Fill instance.

uint32_t identifier() const noexcept

See also

Fill::type()

Public Members

Impl *pImpl

Protected Functions

Fill(const Fill&) = delete
const Fill &operator=(const Fill&) = delete
Fill()
struct ColorStop
#include <thorvg.h>

A data structure storing the information about the color and its relative position inside the gradient bounds.

Public Members

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.

class Canvas
#include <thorvg.h>

An abstract class for drawing graphical elements.

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.

Note

A Canvas behavior depends on the raster engine though the final content of the buffer is expected to be identical.

Warning

The Paint objects belonging to one Canvas can't be shared among multiple Canvases.

Subclassed by tvg::GlCanvas, tvg::SwCanvas, tvg::WgCanvas

Public Functions

Canvas(RenderMethod*)
virtual ~Canvas()
Result reserve(uint32_t n) noexcept
std::list<Paint*> &paints() noexcept

Returns the list of the paints that currently held by the Canvas.

This function provides the list of paint nodes, allowing users a direct opportunity to modify the scene tree.

See also

Canvas::sync()

Note

Experimental API

Warning

Please avoid accessing the paints during Canvas update/draw. You can access them after calling sync().

virtual Result push(std::unique_ptr<Paint> paint) noexcept

Passes drawing elements to the Canvas using Paint objects.

Only pushed paints in the canvas will be drawing targets. They are retained by the canvas until you call Canvas::clear().

See also

Canvas::paints()

See also

Canvas::clear()

Note

The rendering order of the paints is the same as the order as they were pushed into the canvas. Consider sorting the paints before pushing them if you intend to use layering.

Parameters:

paint[in] A Paint object to be drawn.

Return values:

Result::MemoryCorruption – In case a nullptr is passed as the argument.

virtual Result clear(bool free = true) noexcept

Clear the internal canvas resources that used for the drawing.

This API sets the total number of paints pushed into the canvas to zero. Depending on the value of the free argument, the paints are either freed or retained. So if you need to update paint properties while maintaining the existing scene structure, you can set free = false.

See also

Canvas::push()

See also

Canvas::paints()

Parameters:

free[in] If true, the memory occupied by paints is deallocated, otherwise it is not.

virtual Result update(Paint *paint = nullptr) noexcept

Request the canvas to update the paint objects.

If a nullptr is passed all paint objects retained by the Canvas are updated, otherwise only the paint to which the given paint points.

Note

The Update behavior can be asynchronous if the assigned thread number is greater than zero.

Parameters:

paint[in] A pointer to the Paint object or nullptr.

virtual Result draw() noexcept

Requests the canvas to draw the Paint objects.

See also

Canvas::sync()

Note

Drawing can be asynchronous if the assigned thread number is greater than zero. To guarantee the drawing is done, call sync() afterwards.

virtual Result viewport(int32_t x, int32_t y, int32_t w, int32_t h) noexcept

Sets the drawing region in the canvas.

This function defines the rectangular area of the canvas that will be used for drawing operations. The specified viewport is used to clip the rendering output to the boundaries of the rectangle.

Since

0.15

Note

When resetting the target, the viewport will also be reset to the target size.

Warning

It's not allowed to change the viewport during Canvas::push() - Canvas::sync() or Canvas::update() - Canvas::sync().

Parameters:
  • x[in] The x-coordinate of the upper-left corner of the rectangle.

  • y[in] The y-coordinate of the upper-left corner of the rectangle.

  • w[in] The width of the rectangle.

  • h[in] The height of the rectangle.

virtual Result sync() noexcept

Guarantees that drawing task is finished.

The Canvas rendering can be performed asynchronously. To make sure that rendering is finished, the sync() must be called after the draw() regardless of threading.

See also

Canvas::draw()

Return values:

Result::InsufficientCondition – The canvas is either already in sync condition or in a damaged condition (a draw is required before syncing).

Public Members

Impl *pImpl

Protected Functions

Canvas(const Canvas&) = delete
const Canvas &operator=(const Canvas&) = delete
Canvas()
class LinearGradient : public tvg::Fill
#include <thorvg.h>

A class representing the linear gradient fill of the Shape object.

Besides the APIs inherited from the Fill class, it enables setting and getting the linear gradient bounds. The behavior outside the gradient bounds depends on the value specified in the spread API.

Public Functions

~LinearGradient()
Result linear(float x1, float y1, float x2, float y2) noexcept

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 (x1, y1) and (x2, y2), respectively. Both lines are perpendicular to the line linking (x1, y1) and (x2, y2).

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 colorStops().

Parameters:
  • x1[in] The horizontal coordinate of the first point used to determine the gradient bounds.

  • y1[in] The vertical coordinate of the first point used to determine the gradient bounds.

  • x2[in] The horizontal coordinate of the second point used to determine the gradient bounds.

  • y2[in] The vertical coordinate of the second point used to determine the gradient bounds.

Result linear(float *x1, float *y1, float *x2, float *y2) const noexcept

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 (x1, y1) and (x2, y2), respectively. Both lines are perpendicular to the line linking (x1, y1) and (x2, y2).

Parameters:
  • x1[out] The horizontal coordinate of the first point used to determine the gradient bounds.

  • y1[out] The vertical coordinate of the first point used to determine the gradient bounds.

  • x2[out] The horizontal coordinate of the second point used to determine the gradient bounds.

  • y2[out] The vertical coordinate of the second point used to determine the gradient bounds.

virtual Type type() const noexcept override

Returns the ID value of this class.

This method can be used to check the current concrete instance type.

Since

Experimental API

Returns:

The class type ID of the LinearGradient instance.

Public Members

Impl *pImpl

Public Static Functions

static std::unique_ptr<LinearGradient> gen() noexcept

Creates a new LinearGradient object.

Returns:

A new LinearGradient object.

static uint32_t identifier() noexcept

Protected Functions

LinearGradient(const LinearGradient&) = delete
const LinearGradient &operator=(const LinearGradient&) = delete
LinearGradient()
class RadialGradient : public tvg::Fill
#include <thorvg.h>

A class representing the radial gradient fill of the Shape object.

Public Functions

~RadialGradient()
Result radial(float cx, float cy, float radius) noexcept

Sets the radial gradient bounds.

The radial gradient bounds are defined as a circle centered in a given point (cx, cy) of a given radius.

Note

In case the radius is zero, an object is filled with a single color using the last color specified in the colorStops().

Parameters:
  • cx[in] The horizontal coordinate of the center of the bounding circle.

  • cy[in] The vertical coordinate of the center of the bounding circle.

  • radius[in] The radius of the bounding circle.

Return values:

Result::InvalidArguments – in case the radius value is zero or less.

Result radial(float *cx, float *cy, float *radius) const noexcept

Gets the radial gradient bounds.

The radial gradient bounds are defined as a circle centered in a given point (cx, cy) of a given radius.

Parameters:
  • cx[out] The horizontal coordinate of the center of the bounding circle.

  • cy[out] The vertical coordinate of the center of the bounding circle.

  • radius[out] The radius of the bounding circle.

virtual Type type() const noexcept override

Returns the ID value of this class.

This method can be used to check the current concrete instance type.

Since

Experimental API

Returns:

The class type ID of the LinearGradient instance.

Public Members

Impl *pImpl

Public Static Functions

static std::unique_ptr<RadialGradient> gen() noexcept

Creates a new RadialGradient object.

Returns:

A new RadialGradient object.

static uint32_t identifier() noexcept

Protected Functions

RadialGradient(const RadialGradient&) = delete
const RadialGradient &operator=(const RadialGradient&) = delete
RadialGradient()
class Shape : public tvg::Paint
#include <thorvg.h>

A class representing 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 moveTo(), lineTo(), cubicTo(), or complete shape interfaces such as appendRect(), appendCircle(), etc. Path can consists of sub-paths. One sub-path is determined by a close command.

The stroke of 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.

Public Functions

~Shape()
Result reset() noexcept

Resets the shape path.

The transformation matrix, color, fill, and stroke properties are retained.

Note

The memory where the path data is stored is not deallocated at this stage to allow for caching.

Result moveTo(float x, float y) noexcept

Sets the initial point of the sub-path.

The value of the current point is set to the given point.

Parameters:
  • x[in] The horizontal coordinate of the initial point of the sub-path.

  • y[in] The vertical coordinate of the initial point of the sub-path.

Result lineTo(float x, float y) noexcept

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.

Note

In case this is the first command in the path, it corresponds to the moveTo() call.

Parameters:
  • x[in] The horizontal coordinate of the end-point of the line.

  • y[in] The vertical coordinate of the end-point of the line.

Result cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) noexcept

Adds new points to the sub-path, which results in drawing a cubic Bezier curve starting at the current point and ending at the given end-point (x, y) using the control points (cx1, cy1) and (cx2, cy2).

The value of the current point is set to the given end-point.

Note

In case this is the first command in the path, no data from the path are rendered.

Parameters:
  • cx1[in] The horizontal coordinate of the 1st control point.

  • cy1[in] The vertical coordinate of the 1st control point.

  • cx2[in] The horizontal coordinate of the 2nd control point.

  • cy2[in] The vertical coordinate of the 2nd control point.

  • x[in] The horizontal coordinate of the end-point of the curve.

  • y[in] The vertical coordinate of the end-point of the curve.

Result close() noexcept

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.

Note

In case the sub-path does not contain any points, this function has no effect.

Result appendRect(float x, float y, float w, float h, float rx = 0, float ry = 0) noexcept

Appends a rectangle to the path.

The rectangle with rounded corners can be achieved by setting non-zero values to rx and ry arguments. The rx and 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 - x and 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 (x + rx, y) - in case rx is greater than w/2 the current point is set to (x + w/2, y)

Note

For rx and ry greater than or equal to the half of w and the half of h, respectively, the shape become an ellipse.

Parameters:
  • x[in] The horizontal coordinate of the upper-left corner of the rectangle.

  • y[in] The vertical coordinate of the upper-left corner of the rectangle.

  • w[in] The width of the rectangle.

  • h[in] The height of the rectangle.

  • rx[in] The x-axis radius of the ellipse defining the rounded corners of the rectangle.

  • ry[in] The y-axis radius of the ellipse defining the rounded corners of the rectangle.

Result appendCircle(float cx, float cy, float rx, float ry) noexcept

Appends an ellipse to the path.

The position of the ellipse is specified by the coordinates of its center - cx and 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 (cx, cy - ry).

Parameters:
  • cx[in] The horizontal coordinate of the center of the ellipse.

  • cy[in] The vertical coordinate of the center of the ellipse.

  • rx[in] The x-axis radius of the ellipse.

  • ry[in] The y-axis radius of the ellipse.

Result appendArc(float cx, float cy, float radius, float startAngle, float sweep, bool pie) noexcept

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 pie is false, and to the center of the arc otherwise.

Note

Setting sweep value greater than 360 degrees, is equivalent to calling appendCircle(cx, cy, radius, radius).

Parameters:
  • cx[in] The horizontal coordinate of the center of the arc.

  • cy[in] The vertical coordinate of the center of the arc.

  • radius[in] The radius of the arc.

  • startAngle[in] The start angle of the arc given in degrees, measured counter-clockwise from the horizontal line.

  • sweep[in] The central angle of the arc given in degrees, measured counter-clockwise from startAngle.

  • pie[in] Specifies whether to draw radii from the arc's center to both of its end-point - drawn if true.

Result appendPath(const PathCommand *cmds, uint32_t cmdCnt, const Point *pts, uint32_t ptsCnt) noexcept

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 cmds array, an appropriate number of points in pts array should be specified. If the number of points in the pts array is different than the number required by the cmds array, the shape with this sub-path will not be displayed on the screen.

Note

The interface is designed for optimal path setting if the caller has a completed path commands already.

Parameters:
  • cmds[in] The array of the commands in the sub-path.

  • cmdCnt[in] The number of the sub-path's commands.

  • pts[in] The array of the two-dimensional points.

  • ptsCnt[in] The number of the points in the pts array.

Result stroke(float width) noexcept

Sets the stroke width for all of the figures from the path.

Parameters:

width[in] The width of the stroke. The default value is 0.

Result stroke(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept

Sets the color of the stroke for all of the figures from the path.

Parameters:
  • r[in] The red color channel value in the range [0 ~ 255]. The default value is 0.

  • g[in] The green color channel value in the range [0 ~ 255]. The default value is 0.

  • b[in] The blue color channel value in the range [0 ~ 255]. The default value is 0.

  • a[in] The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0.

Result stroke(std::unique_ptr<Fill> f) noexcept

Sets the gradient fill of the stroke for all of the figures from the path.

Parameters:

f[in] The gradient fill.

Return values:

Result::MemoryCorruption – In case a nullptr is passed as the argument.

Result stroke(const float *dashPattern, uint32_t cnt) noexcept

Sets the dash pattern of the stroke.

Note

To reset the stroke dash pattern, pass nullptr to dashPattern and zero to cnt.

Warning

cnt must be greater than 1 if the dash pattern is valid.

Parameters:
  • dashPattern[in] The array of consecutive pair values of the dash length and the gap length.

  • cnt[in] The length of the dashPattern array.

Return values:

Result::InvalidArguments – In case dashPattern is nullptr and cnt > 0, cnt is zero, any of the dash pattern values is zero or less.

Result stroke(StrokeCap cap) noexcept

Sets the cap style of the stroke in the open sub-paths.

Parameters:

cap[in] The cap style value. The default value is StrokeCap::Square.

Result stroke(StrokeJoin join) noexcept

Sets the join style for stroked path segments.

The join style is used for joining the two line segment while stroking the path.

Parameters:

join[in] The join style value. The default value is StrokeJoin::Bevel.

Result strokeMiterlimit(float miterlimit) noexcept

Sets the stroke miterlimit.

Since

0.11

Parameters:

miterlimit[in] The miterlimit imposes a limit on the extent of the stroke join, when the StrokeJoin::Miter join style is set. The default value is 4.

Return values:

Result::InvalidArgument – for miterlimit values less than zero.

Result strokeTrim(float begin, float end, bool simultaneous = true) noexcept

Sets the trim of the stroke along the defined path segment, allowing control over which part of the stroke is visible.

If the values of the arguments begin and end exceed the 0-1 range, they are wrapped around in a manner similar to angle wrapping, effectively treating the range as circular.

Note

Experimental API

Parameters:
  • begin[in] Specifies the start of the segment to display along the path.

  • end[in] Specifies the end of the segment to display along the path.

  • simultaneous[in] Determines how to trim multiple paths within a single shape. If set to true (default), trimming is applied simultaneously to all paths; 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.

Result fill(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255) noexcept

Sets the solid color for all of the figures from the path.

The parts of the shape defined as inner are colored.

Note

Either a solid color or a gradient fill is applied, depending on what was set as last.

Parameters:
  • r[in] The red color channel value in the range [0 ~ 255]. The default value is 0.

  • g[in] The green color channel value in the range [0 ~ 255]. The default value is 0.

  • b[in] The blue color channel value in the range [0 ~ 255]. The default value is 0.

  • a[in] The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque. The default value is 0.

Result fill(std::unique_ptr<Fill> f) noexcept

Sets the gradient fill for all of the figures from the path.

The parts of the shape defined as inner are filled.

Note

Either a solid color or a gradient fill is applied, depending on what was set as last.

Parameters:

f[in] The unique pointer to the gradient fill.

Result fill(FillRule r) noexcept

Sets the fill rule for the Shape object.

Parameters:

r[in] The fill rule value. The default value is FillRule::Winding.

Result order(bool strokeFirst) noexcept

Sets the rendering order of the stroke and the fill.

Since

0.10

Parameters:

strokeFirst[in] If true the stroke is rendered before the fill, otherwise the stroke is rendered as the second one (the default option).

uint32_t pathCommands(const PathCommand **cmds) const noexcept

Gets the commands data of the path.

Parameters:

cmds[out] The pointer to the array of the commands from the path.

Returns:

The length of the cmds array when succeed, zero otherwise.

uint32_t pathCoords(const Point **pts) const noexcept

Gets the points values of the path.

Parameters:

pts[out] The pointer to the array of the two-dimensional points from the path.

Returns:

The length of the pts array when succeed, zero otherwise.

const Fill *fill() const noexcept

Gets the pointer to the gradient fill of the shape.

Returns:

The pointer to the gradient fill of the stroke when succeed, nullptr in case no fill was set.

Result fillColor(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a = nullptr) const noexcept

Gets the solid color of the shape.

Parameters:
  • r[out] The red color channel value in the range [0 ~ 255].

  • g[out] The green color channel value in the range [0 ~ 255].

  • b[out] The blue color channel value in the range [0 ~ 255].

  • a[out] The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.

FillRule fillRule() const noexcept

Gets the fill rule value.

Returns:

The fill rule value of the shape.

float strokeWidth() const noexcept

Gets the stroke width.

Returns:

The stroke width value when succeed, zero if no stroke was set.

Result strokeColor(uint8_t *r, uint8_t *g, uint8_t *b, uint8_t *a = nullptr) const noexcept

Gets the color of the shape's stroke.

Parameters:
  • r[out] The red color channel value in the range [0 ~ 255].

  • g[out] The green color channel value in the range [0 ~ 255].

  • b[out] The blue color channel value in the range [0 ~ 255].

  • a[out] The alpha channel value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.

const Fill *strokeFill() const noexcept

Gets the pointer to the gradient fill of the stroke.

Returns:

The pointer to the gradient fill of the stroke when succeed, nullptr otherwise.

uint32_t strokeDash(const float **dashPattern) const noexcept

Gets the dash pattern of the stroke.

Parameters:

dashPattern[out] The pointer to the memory, where the dash pattern array is stored.

Returns:

The length of the dashPattern array.

StrokeCap strokeCap() const noexcept

Gets the cap style used for stroking the path.

Returns:

The cap style value of the stroke.

StrokeJoin strokeJoin() const noexcept

Gets the join style value used for stroking the path.

Returns:

The join style value of the stroke.

float strokeMiterlimit() const noexcept

Gets the stroke miterlimit.

Since

0.11

Returns:

The stroke miterlimit value when succeed, 4 if no stroke was set.

virtual Type type() const noexcept override

Returns the ID value of this class.

This method can be used to check the current concrete instance type.

Since

Experimental API

Returns:

The class type ID of the Shape instance.

Public Members

Impl *pImpl

Public Static Functions

static std::unique_ptr<Shape> gen() noexcept

Creates a new Shape object.

Returns:

A new Shape object.

static uint32_t identifier() noexcept

See also

Shape::type()

Protected Functions

Shape(const Shape&) = delete
const Shape &operator=(const Shape&) = delete
Shape()
class Picture : public tvg::Paint
#include <thorvg.h>

A class representing an image read in one of the supported formats: raw, svg, png, jpg, lottie(json) and etc. Besides the methods inherited from the Paint, it provides methods to load & draw images on the canvas.

Note

Supported formats are depended on the available TVG loaders.

Note

See Animation class if the picture data is animatable.

Public Functions

~Picture()
Result load(const std::string &path) noexcept

Loads a picture data directly from a file.

ThorVG efficiently caches the loaded data using the specified path as a key. This means that loading the same file again will not result in duplicate operations; instead, ThorVG will reuse the previously loaded picture data.

Note

The Load behavior can be asynchronous if the assigned thread number is greater than zero.

Parameters:

path[in] A path to the picture file.

Return values:
  • Result::InvalidArguments – In case the path is invalid.

  • Result::NonSupport – When trying to load a file with an unknown extension.

Result load(const char *data, uint32_t size, bool copy = false) noexcept

Deprecated:

Use load(const char* data, uint32_t size, const std::string& mimeType, bool copy) instead.

Result load(const char *data, uint32_t size, const std::string &mimeType, bool copy = false) noexcept

Loads a picture data from a memory block of a given size.

ThorVG efficiently caches the loaded data using the specified data address as a key when the copy has false. This means that loading the same data again will not result in duplicate operations for the sharable data. Instead, ThorVG will reuse the previously loaded picture data.

Since

0.5

Note

If you are unsure about the MIME type, you can provide an empty value like "", and thorvg will attempt to figure it out.

Warning

It's the user responsibility to release the data memory.

Parameters:
  • data[in] 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 copy is false.

  • size[in] The size in bytes of the memory occupied by the data.

  • mimeType[in] Mimetype or extension of data such as "jpg", "jpeg", "lottie", "svg", "svg+xml", "png", etc. In case an empty string or an unknown type is provided, the loaders will be tried one by one.

  • copy[in] If true the data are copied into the engine local buffer, otherwise they are not.

Return values:
  • Result::InvalidArguments – In case no data are provided or the size is zero or less.

  • Result::NonSupport – When trying to load a file with an unknown extension.

Result size(float w, float h) noexcept

Resizes the picture content to the given width and height.

The picture content is resized while keeping the default size aspect ratio. The scaling factor is established for each of dimensions and the smaller value is applied to both of them.

Parameters:
  • w[in] A new width of the image in pixels.

  • h[in] A new height of the image in pixels.

Result size(float *w, float *h) const noexcept

Gets the size of the image.

Parameters:
  • w[out] The width of the image in pixels.

  • h[out] The height of the image in pixels.

Result load(uint32_t *data, uint32_t w, uint32_t h, bool copy) noexcept

Loads raw data in ARGB8888 format from a memory block of the given size.

ThorVG efficiently caches the loaded data using the specified data address as a key when the copy has false. This means that loading the same data again will not result in duplicate operations for the sharable data. Instead, ThorVG will reuse the previously loaded picture data.

Since

0.9

Parameters:
  • data[in] A pointer to a memory location where the content of the picture raw data is stored.

  • w[in] The width of the image data in pixels.

  • h[in] The height of the image data in pixels.

  • premultiplied[in] If true, the given image data is alpha-premultiplied.

  • copy[in] If true the data are copied into the engine local buffer, otherwise they are not.

const Paint *paint(uint32_t id) noexcept

Retrieve a paint object from the Picture scene by its Unique ID.

This function searches for a paint object within the Picture scene that matches the provided id.

See also

Accessor::id()

Note

Experimental API

Parameters:

id[in] The Unique ID of the paint object.

Returns:

A pointer to the paint object that matches the given identifier, or nullptr if no matching paint object is found.

virtual Type type() const noexcept override

Returns the ID value of this class.

This method can be used to check the current concrete instance type.

Since

Experimental API

Returns:

The class type ID of the Picture instance.

Public Members

friend Animation
Impl *pImpl

Public Static Functions

static std::unique_ptr<Picture> gen() noexcept

Creates a new Picture object.

Returns:

A new Picture object.

static uint32_t identifier() noexcept

See also

Picture::type()

Protected Functions

Picture(const Picture&) = delete
const Picture &operator=(const Picture&) = delete
Picture()
class Scene : public tvg::Paint
#include <thorvg.h>

A class to composite children paints.

As the traditional graphics rendering method, TVG also enables scene-graph mechanism. This feature supports an array function for managing the multiple paints as one group paint.

As a group, the scene can be transformed, made translucent and composited with other target paints, its children will be affected by the scene world.

Public Functions

~Scene()
Result push(std::unique_ptr<Paint> paint) noexcept

Passes drawing elements to the Scene using Paint objects.

Only the paints pushed into the scene will be the drawn targets. The paints are retained by the scene until Scene::clear() is called.

See also

Scene::paints()

See also

Scene::clear()

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.

Parameters:

paint[in] A Paint object to be drawn.

Result reserve(uint32_t size) noexcept
std::list<Paint*> &paints() noexcept

Returns the list of the paints that currently held by the Scene.

This function provides the list of paint nodes, allowing users a direct opportunity to modify the scene tree.

See also

Canvas::sync()

See also

Scene::clear()

Note

Experimental API

Warning

Please avoid accessing the paints during Scene update/draw. You can access them after calling Canvas::sync().

Result clear(bool free = true) noexcept

Sets the total number of the paints pushed into the scene to be zero. Depending on the value of the free argument, the paints are freed or not.

Since

0.2

Warning

If you don't free the paints they become dangled. They are supposed to be reused, otherwise you are responsible for their lives. Thus please use the free argument only when you know how it works, otherwise it's not recommended.

Parameters:

free[in] If true, the memory occupied by paints is deallocated, otherwise it is not.

Result push(SceneEffect effect, ...) noexcept

Apply a post-processing effect to the scene.

This function adds a specified scene effect, such as clearing all effects or applying a Gaussian blur, to the scene after it has been rendered. Multiple effects can be applied in sequence.

Note

Experimental API

Parameters:
  • effect[in] The scene effect to apply. Options are defined in the SceneEffect enum. For example, use SceneEffect::GaussianBlur to apply a blur with specific parameters.

  • ...[in] Additional variadic parameters required for certain effects (e.g., sigma and direction for GaussianBlur).

virtual Type type() const noexcept override

Returns the ID value of this class.

This method can be used to check the current concrete instance type.

Since

Experimental API

Returns:

The class type ID of the Scene instance.

Public Members

Impl *pImpl

Public Static Functions

static std::unique_ptr<Scene> gen() noexcept

Creates a new Scene object.

Returns:

A new Scene object.

static uint32_t identifier() noexcept

See also

Scene::type()

Protected Functions

Scene(const Scene&) = delete
const Scene &operator=(const Scene&) = delete
Scene()
class Text : public tvg::Paint
#include <thorvg.h>

A class to represent text objects in a graphical context, allowing for rendering and manipulation of unicode text.

Since

0.15

Public Functions

~Text()
Result font(const char *name, float size, const char *style = nullptr) noexcept

Sets the font properties for the text.

This function allows you to define the font characteristics used for text rendering. It sets the font name, size and optionally the style.

Note

Experimental API

Parameters:
  • name[in] The name of the font. This should correspond to a font available in the canvas.

  • size[in] The size of the font in points. This determines how large the text will appear.

  • style[in] The style of the font. It can be used to set the font to 'italic'. If not specified, the default style is used. Only 'italic' style is supported currently.

Return values:

Result::InsufficientCondition – when the specified name cannot be found.

Result text(const char *text) noexcept

Assigns the given unicode text to be rendered.

This function sets the unicode string that will be displayed by the rendering system. The text is set according to the specified UTF encoding method, which defaults to UTF-8.

Note

Experimental API

Parameters:

text[in] The multi-byte text encoded with utf8 string to be rendered.

Result fill(uint8_t r, uint8_t g, uint8_t b) noexcept

Sets the text color.

See also

Text::font()

Since

0.15

Parameters:
  • r[in] The red color channel value in the range [0 ~ 255]. The default value is 0.

  • g[in] The green color channel value in the range [0 ~ 255]. The default value is 0.

  • b[in] The blue color channel value in the range [0 ~ 255]. The default value is 0.

Result fill(std::unique_ptr<Fill> f) noexcept

Sets the gradient fill for all of the figures from the text.

The parts of the text defined as inner are filled.

See also

Text::font()

Since

0.15

Note

Either a solid color or a gradient fill is applied, depending on what was set as last.

Parameters:

f[in] The unique pointer to the gradient fill.

virtual Type type() const noexcept override

Returns the ID value of this class.

This method can be used to check the current concrete instance type.

Since

Experimental API

Returns:

The class type ID of the Text instance.

Public Members

Impl *pImpl

Public Static Functions

static Result load(const std::string &path) noexcept

Loads a scalable font data (ttf) from a file.

ThorVG efficiently caches the loaded data using the specified path as a key. This means that loading the same file again will not result in duplicate operations; instead, ThorVG will reuse the previously loaded font data.

Since

0.15

Parameters:

path[in] The path to the font file.

Return values:
  • Result::InvalidArguments – In case the path is invalid.

  • Result::NonSupport – When trying to load a file with an unknown extension.

static Result load(const char *name, const char *data, uint32_t size, const std::string &mimeType = "ttf", bool copy = false) noexcept

Loads a scalable font data (ttf) from a memory block of a given size.

ThorVG efficiently caches the loaded font data using the specified name as a key. This means that loading the same fonts again will not result in duplicate operations. Instead, ThorVG will reuse the previously loaded font data.

Note

To unload the font data loaded using this API, pass the proper name and nullptr as data.

Note

If you are unsure about the MIME type, you can provide an empty value like "", and thorvg will attempt to figure it out.

Note

0.15

Warning

It's the user responsibility to release the data memory.

Parameters:
  • name[in] The name under which the font will be stored and accessible (e.x. in a font() API).

  • data[in] A pointer to a memory location where the content of the font data is stored.

  • size[in] The size in bytes of the memory occupied by the data.

  • mimeType[in] Mimetype or extension of font data. In case an empty string is provided the loader will be determined automatically.

  • copy[in] If true the data are copied into the engine local buffer, otherwise they are not (default).

Return values:
  • Result::InvalidArguments – If no name is provided or if size is zero while data points to a valid memory location.

  • Result::NonSupport – When trying to load a file with an unsupported extension.

  • Result::InsufficientCondition – If attempting to unload the font data that has not been previously loaded.

static Result unload(const std::string &path) noexcept

Unloads the specified scalable font data (TTF) that was previously loaded.

This function is used to release resources associated with a font file that has been loaded into memory.

Since

0.15

Note

If the font data is currently in use, it will not be immediately unloaded.

Parameters:

path[in] The file path of the loaded font.

Return values:

Result::InsufficientCondition – Fails if the loader is not initialized.

static std::unique_ptr<Text> gen() noexcept

Creates a new Text object.

Since

0.15

Returns:

A new Text object.

Protected Functions

Text(const Text&) = delete
const Text &operator=(const Text&) = delete
Text()
class SwCanvas : public tvg::Canvas
#include <thorvg.h>

A class for the rendering graphical elements with a software raster engine.

Public Types

enum Colorspace

Enumeration specifying the methods of combining the 8-bit color channels into 32-bit color.

Values:

enumerator ABGR8888

The channels are joined in the order: alpha, blue, green, red. Colors are alpha-premultiplied. (a << 24 | b << 16 | g << 8 | r)

enumerator ARGB8888

The channels are joined in the order: alpha, red, green, blue. Colors are alpha-premultiplied. (a << 24 | r << 16 | g << 8 | b)

enumerator ABGR8888S

The channels are joined in the order: alpha, blue, green, red. Colors are un-alpha-premultiplied.

Since

0.12

enumerator ARGB8888S

The channels are joined in the order: alpha, red, green, blue. Colors are un-alpha-premultiplied.

Since

0.12

enum MempoolPolicy

Enumeration specifying the methods of Memory Pool behavior policy.

Since

0.4

Values:

enumerator Default

Default behavior that ThorVG is designed to.

enumerator Shareable

Memory Pool is shared among the SwCanvases.

enumerator Individual

Allocate designated memory pool that is only used by current instance.

Public Functions

~SwCanvas()
Result target(uint32_t *buffer, uint32_t stride, uint32_t w, uint32_t h, Colorspace cs) noexcept

Sets the drawing target for the rasterization.

The buffer of a desirable size should be allocated and owned by the caller.

See also

Canvas::sync()

Warning

Do not access buffer during Canvas::push() - Canvas::sync(). It should not be accessed while the engine is writing on it.

Parameters:
  • buffer[in] A pointer to a memory block of the size stride x h, where the raster data are stored.

  • stride[in] The stride of the raster image - greater than or equal to w.

  • w[in] The width of the raster image.

  • h[in] The height of the raster image.

  • cs[in] The value specifying the way the 32-bits colors should be read/written.

Return values:
  • Result::InvalidArguments – In case no valid pointer is provided or the width, or the height or the stride is zero.

  • Result::InsufficientCondition – if the canvas is performing rendering. Please ensure the canvas is synced.

  • Result::NonSupport – In case the software engine is not supported.

Result mempool(MempoolPolicy policy) noexcept

Set sw engine memory pool behavior policy.

Basically ThorVG draws a lot of shapes, it allocates/deallocates a few chunk of memory while processing rendering. It internally uses one shared memory pool which can be reused among the canvases in order to avoid memory overhead.

Thus ThorVG suggests using a memory pool policy to satisfy user demands, if it needs to guarantee the thread-safety of the internal data access.

Since

0.4

Note

When policy is set as MempoolPolicy::Individual, the current instance of canvas uses its own individual memory data, which is not shared with others. This is necessary when the canvas is accessed on a worker-thread.

Warning

It's not allowed after pushing any paints.

Parameters:

policy[in] The method specifying the Memory Pool behavior. The default value is MempoolPolicy::Default.

Return values: