thorvg_python.canvas.sw

Classes

SwCanvas

SwCanvas API

Module Contents

class thorvg_python.canvas.sw.SwCanvas(engine: thorvg_python.engine.Engine, op: thorvg_python.base.EngineOption = EngineOption.DEFAULT, canvas: thorvg_python.base.CanvasPointer | None = None)

Bases: thorvg_python.canvas.Canvas

SwCanvas API

A module for rendering the graphical elements using the software engine.

engine
thorvg_lib
buffer_arr : ctypes.Array[ctypes.c_uint32] | None = None
w : int | None = None
h : int | None = None
stride : int | None = None
cs : thorvg_python.base.Colorspace | None = None
_create(op: thorvg_python.base.EngineOption = EngineOption.DEFAULT) thorvg_python.base.CanvasPointer

Creates a new Software Canvas object with optional rendering engine settings.

This method generates a software canvas instance that can be used for drawing vector graphics. It accepts an optional parameter op to choose between different rendering engine behaviors.

Parameters:
op : thorvg_python.engine.EngineOption

The rendering engine option.

Returns:

A new CanvasPointer object.

Return type:

thorvg_python.base.CanvasPointer

Note

You need not call this method as it is auto called when initializing SwCanvas().

See also

EngineOption

set_target(w: int, h: int, stride: int | None = None, cs: thorvg_python.base.Colorspace = Colorspace.ABGR8888) tuple[thorvg_python.base.Result, ctypes.Array[ctypes.c_uint32]]

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.

w, h, stride, cs and buffer_arr will be stored in instance when calling this method.

Parameters:
w : int

The width of the raster image.

h : int

The height of the raster image.

stride : Optional[int]

The stride of the raster image - default is same value as w.

cs : thorvg.base.Colorspace

The colorspace value defining the way the 32-bits colors should be read/written.

Returns:

  • Result.INVALID_ARGUMENTS An invalid canvas or buffer pointer passed or one of the stride, w or h being zero.

  • Result.INSUFFICIENT_CONDITION if the canvas is performing rendering. Please ensure the canvas is synced.

  • Result.NOT_SUPPORTED The software engine is not supported.

Return type:

thorvg_python.base.Result

Returns:

A pointer to the allocated memory block of the size stride x h.

Return type:

ctypes.Array[ctypes.c_uint32]

Warning

Do not access buffer during Canvas_draw() - Canvas_sync(). It should not be accessed while the engine is writing on it.

See also

Colorspace

get_pillow(pil_mode: str = 'RGBA') PIL.Image.Image

Gets Pillow Image from buffer of canvas

Parameters:
pil_mode : str

Color mode of Pillow Image. Defaults to RGBA

Returns:

Pillow image

Return type:

PIL.Image.Image