libgpac
Documentation of the core library of GPAC
Canvas Interface Reference

import"evg.idl";

+ Collaboration diagram for Canvas:

Public Member Functions

 Canvas (unsigned long width, unsigned long height, DOMString pixfmt)
 
 Canvas (unsigned long width, unsigned long height, DOMString pixfmt, ArrayBuffer data, optional unsigned long stride=0, optional unsigned long stride_uv=0)
 
void clear (IRect rc, unsigned long r, unsigned long g, unsigned long b, unsigned long a)
 
void clear (IRect rc, DOMString color)
 
void clear (IRect rc, DOMString color)
 
void clearf (IRect rc, double r, double g, double b, double a)
 
void clearf (IRect rc, DOMString color)
 
void fill (Stencil stencil)
 
void fill (Texture texture)
 
void fill (GF_EVGMultiTextureMode operand, optional float param=0, Texture texture1, optional Texture texture2=null, optional Texture texture3=null)
 
void reassign (ArrayBuffer data)
 
void blit (Texture texture, optional IRect dst_wnd=null, optional IRect src_wnd=null, optional BlitParameters params=null)
 
void enable_threading (optional int nb_threads=-1)
 
void enable_3d ()
 
Object toRGB (optional bool as_array=false, Float y, Float u, Float v, optional Float a=1.0)
 
Object toRGB (optional bool as_array=false, Vec4f color)
 
Object toYUV (optional bool as_array=false, Float r, Float g, Float b, optional Float a=1.0)
 
Object toYUV (optional bool as_array=false, Vec4f color)
 
void projection (Float32Buffer projection_matrix)
 
void modelview (Float32Buffer modelview_matrix)
 
void draw_array (Int32Buffer indices, Float32Buffer vertices, optional GF_EVGPrimitiveType primitive_type=GF_EVG_TRIANGLES, optional long nb_components=3)
 
void draw_path (Path path, optional float z=0)
 
void draw_path (Text text, optional float z=0)
 
void clear_depth (float depth)
 
void viewport (long x, long y, long width, long height)
 
void viewport ()
 
Shader new_shader (ShaderType shader_type)
 

Data Fields

attribute boolean centered
 
writeonly Path path
 
writeonly Matrix2D matrix
 
writeonly IRect clipper
 
readonly boolean has_clipper
 
attribute unsigned long compositeOperation
 
attribute unsigned long level
 
attribute AlphaCallback on_alpha
 
readonly attribute boolean is_yuv
 
readonly attribute unsigned long depth
 
Shader fragment
 
Shader vertex
 
writeonly boolean ccw
 
writeonly boolean backcull
 
writeonly boolean antialias
 
writeonly float min_depth
 
writeonly float max_depth
 
writeonly float point_size
 
writeonly boolean point_smooth
 
writeonly float line_size
 
writeonly boolean clip_zero
 
writeonly GF_EVGDepthTest depth_test
 
writeonly boolean write_depth
 
Float32Buffer depth_buffer
 

Detailed Description

The Canvas object is used to draw vectorial 2D path

Constructor & Destructor Documentation

◆ Canvas() [1/2]

Canvas::Canvas ( unsigned long  width,
unsigned long  height,
DOMString  pixfmt 
)

Canvas constructor. The canvas memory is owned by the canvas object

Parameters
widththe width in pixels of the canvas
heightthe height in pixels of the canvas
pixfmtthe pixel fomat of the canvas

◆ Canvas() [2/2]

Canvas::Canvas ( unsigned long  width,
unsigned long  height,
DOMString  pixfmt,
ArrayBuffer  data,
optional unsigned long  stride = 0,
optional unsigned long  stride_uv = 0 
)

Canvas constructor

Parameters
widththe width in pixels of the canvas
heightthe height in pixels of the canvas
pixfmtthe pixel fomat of the canvas
datathe data buffer on which to write. The size shall be greater than the size required for the given size and pixel format.
stridehorizontal stride in pixel of the data
stride_uvhorizontal stride in pixel of the data for the U and V planes

Member Function Documentation

◆ clear() [1/3]

void Canvas::clear ( IRect  rc,
unsigned long  r,
unsigned long  g,
unsigned long  b,
unsigned long  a 
)

clears the canvas with the given color - see gf_evg_surface_clear

Note
Omitting the last values will assume 0xFF for alpha, and 0 for other values.
Parameters
rcthe rectangle to clear, in pixel coordinates
rred value, between 0 and 255
ggreen value, between 0 and 255
bblue value, between 0 and 255
aalpha value, between 0 and 255

◆ clear() [2/3]

void Canvas::clear ( IRect  rc,
DOMString  color 
)

clears the canvas with the given color. See gf_evg_surface_clear

Parameters
rcthe rectangle to clear, in pixel coordinates
coloran HTML/SVG color name or an HTML color value formatted as $RRGGBB, #RRGGBB or 0xRRGGBB

◆ clear() [3/3]

void Canvas::clear ( IRect  rc,
DOMString  color 
)

clears the canvas with the given color. See gf_evg_surface_clear

Parameters
rcthe rectangle to clear, in pixel coordinates
coloran HTML/SVG color name or an HTML color value formatted as $RRGGBB, #RRGGBB or 0xRRGGBB

◆ clearf() [1/2]

void Canvas::clearf ( IRect  rc,
double  r,
double  g,
double  b,
double  a 
)

clears the canvas with the given color

Note
Omitting the last values will assume 1.0 for alpha, and 0.0 for other values. See gf_evg_surface_clear
Parameters
rcthe rectangle to clear, in pixel coordinates
rred value, between 0.0 and 1.0
ggreen value, between 0.0 and 1.0
bblue value, between 0.0 and 1.0
aalpha value, between 0.0 and 1.0

◆ clearf() [2/2]

void Canvas::clearf ( IRect  rc,
DOMString  color 
)

clears the canvas with the given color. See gf_evg_surface_clear

Parameters
rcthe rectangle to clear, in pixel coordinates
coloran HTML/SVG color name or an HTML color value formatted as $RRGGBB, #RRGGBB or 0xRRGGBB

◆ fill() [1/3]

void Canvas::fill ( Stencil  stencil)

fills the path with the given solid brush or gradient stencil - see gf_evg_surface_fill

Parameters
stencilthe stencil to use

◆ fill() [2/3]

void Canvas::fill ( Texture  texture)

fills the path with the given texture - see gf_evg_surface_fill

Parameters
texturethe texture to use

◆ fill() [3/3]

void Canvas::fill ( GF_EVGMultiTextureMode  operand,
optional float  param = 0,
Texture  texture1,
optional Texture  texture2 = null,
optional Texture  texture3 = null 
)

fills the path with the given texture(s) - see gf_evg_surface_multi_fill

Parameters
operandmultitexture operand to use
paramfloat or float array used to control multitexture effect
texture1the texture or stencil to use as main texture
texture2the texture or stencil to use as secondary texture
texture3the texture or stencil to use as third texture

◆ reassign()

void Canvas::reassign ( ArrayBuffer  data)

reassign internal data (typically at each new packet)

Warning
This assumes the data layout has not changed (width, height, pixel format, strides). If these are modified, create a new canvas.
Parameters
datathe buffer to use

◆ blit()

void Canvas::blit ( Texture  texture,
optional IRect  dst_wnd = null,
optional IRect  src_wnd = null,
optional BlitParameters  params = null 
)

blits a texture pixel data onto the surface

Warning
All texture properties (matrix, color matrix, ...) and canvas properties (path, matrix...) are ignored.
This does not perform alpha blending.

The blit operations are usually faster than path fill operations, but only operate on axis-aligned rectangles.

Parameters
texturethe texture to use for pixel source
dst_wndthe destination rectangle in canvas, must be completely included in canvas. Point{0,0} is top-left and {width,height} is bottom right
src_wndthe source rectangle from the texture, must be completely included in texture. Point{0,0} is top-left and {width,height} is bottom right
paramsthe blit operation parameters. If null, let FFMPEG decide

◆ enable_threading()

void Canvas::enable_threading ( optional int  nb_threads = -1)

enables threading in rasterizer - see gf_evg_enable_threading

Parameters
nb_threadsthe number of extra threads to use, negative values means all cores

◆ enable_3d()

void Canvas::enable_3d ( )

enables 3D extensions in rasterizer - see gf_evg_surface_enable_3d

◆ toRGB() [1/2]

Object Canvas::toRGB ( optional bool  as_array = false,
Float  y,
Float  u,
Float  v,
optional Float  a = 1.0 
)

converts YUV color to RGB

Parameters
as_arrayif true, the return object is an array of 4 components, otherwise it is a Vec4f object
yY component value
uCb/U component value
vCr/V component value
aalpha value, not modified
Returns
the converted value

◆ toRGB() [2/2]

Object Canvas::toRGB ( optional bool  as_array = false,
Vec4f  color 
)

converts YUV color to RGB

Parameters
as_arrayif true, the return object is an array of 4 components, otherwise it is a Vec4f object
colorthe YUV value to convert
Returns
the converted value

◆ toYUV() [1/2]

Object Canvas::toYUV ( optional bool  as_array = false,
Float  r,
Float  g,
Float  b,
optional Float  a = 1.0 
)

converts RGB color to YUV

Parameters
as_arrayif true, the return object is an array of 4 components, otherwise it is Vec4f object
rred component value
ggreen component value
bblue component value
aalpha value, not modified
Returns
the converted value

◆ toYUV() [2/2]

Object Canvas::toYUV ( optional bool  as_array = false,
Vec4f  color 
)

converts RGB color to YUV

Parameters
as_arrayif true, the return object is an array of 4 components, otherwise it is a Vec4f object
colorthe RGB value to convert
Returns
the converted value

◆ projection()

void Canvas::projection ( Float32Buffer  projection_matrix)

sets current projection matrix to use

Parameters
projection_matrixthe 16 float coeficients of the matrix, column-first. When using Matrix object, you can pass Matrix.m

◆ modelview()

void Canvas::modelview ( Float32Buffer  modelview_matrix)

sets current modelview matrix to use

Parameters
modelview_matrixthe 16 float coeficients of the matrix, column-first. When using Matrix object, you can pass Matrix.m

◆ draw_array()

void Canvas::draw_array ( Int32Buffer  indices,
Float32Buffer  vertices,
optional GF_EVGPrimitiveType  primitive_type = GF_EVG_TRIANGLES,
optional long  nb_components = 3 
)

draws a set of primitives (see gf_evg_surface_draw_array)

Parameters
indicesarray of indices in the vertex buffer for the primitives to draw
verticesthe vertices to use
primitive_typethe type of primitive to draw
nb_componentsthe number of components per vertex (eg, 2, 3)

◆ draw_path() [1/2]

void Canvas::draw_path ( Path  path,
optional float  z = 0 
)

draws a path (see gf_evg_surface_draw_path)

Parameters
paththe path to draw
zthe z value to assign to points in the path

◆ draw_path() [2/2]

void Canvas::draw_path ( Text  text,
optional float  z = 0 
)

draws a text (see gf_evg_surface_draw_path)

Parameters
textthe text to draw
zthe z value to assign to points in the text's path

◆ clear_depth()

void Canvas::clear_depth ( float  depth)

clears the depth buffer (see gf_evg_surface_clear_depth)

Parameters
depththe depth value to set

◆ viewport() [1/2]

void Canvas::viewport ( long  x,
long  y,
long  width,
long  height 
)

sets the viewport (see gf_evg_surface_viewport)

Parameters
xthe horizontal coordinate of the top-left corner of the viewport
ythe vertical coordinate of the top-left corner of the viewport
widththe width of the viewport
heightthe height of the viewport

◆ viewport() [2/2]

void Canvas::viewport ( )

sets the viewport to full canvas {0,0,width,height} (see gf_evg_surface_viewport)

◆ new_shader()

Shader Canvas::new_shader ( ShaderType  shader_type)

creats a new shader

Returns
the new shader
Parameters
shader_typethe desired shader type

Field Documentation

◆ centered

attribute boolean Canvas::centered

indicates if surface coordinates are centered or not - see gf_evg_surface_set_center_coords

◆ path

writeonly Path Canvas::path

path to draw - see gf_evg_surface_set_path. The path object is either a Path or a Text

◆ matrix

writeonly Matrix2D Canvas::matrix

matrix to apply to path - see gf_evg_surface_set_matrix.

Note
A same path can be drawn several times with different matrices, null means no matrix.

◆ clipper

writeonly IRect Canvas::clipper

clipper in pixel coordinates - see gf_evg_surface_set_clipper

Note
A same path can be drawn several times with different clipper, null means no clipper. Clipper applies to both fill and clear functions

◆ has_clipper

readonly boolean Canvas::has_clipper

true if cliper is active on canvas

◆ compositeOperation

attribute unsigned long Canvas::compositeOperation

composite operation for alpha surfaces - see gf_evg_surface_set_composite_mode

◆ level

attribute unsigned long Canvas::level

AA level of canvas - see gf_evg_surface_get_raster_level and gf_evg_surface_set_raster_level

Note
This is always equal to GF_RASTER_HIGH_QUALITY when the path drawn is a text object

◆ on_alpha

attribute AlphaCallback Canvas::on_alpha

alpha custom callback composite operation for alpha surfaces - see gf_evg_surface_set_alpha_callback Default is undefined at creation time

◆ is_yuv

readonly attribute boolean Canvas::is_yuv

set to true of canvas is a YUV-based format, false if RGB-based format

◆ depth

readonly attribute unsigned long Canvas::depth

number of bits per component (8, 10, etc)

◆ fragment

Shader Canvas::fragment

fragment shader to use, set to NULL to disable pixel writing.

◆ vertex

Shader Canvas::vertex

vertex shader to use, set to NULL to disable vertex shading, in which case the currently defined projection and modelview matrices will be used

◆ ccw

writeonly boolean Canvas::ccw

set face orientation to counter-clockwise or clockwise (see gf_evg_surface_set_ccw)

◆ backcull

writeonly boolean Canvas::backcull

backface culling enabled (see gf_evg_surface_set_backcull), default is true

◆ antialias

writeonly boolean Canvas::antialias

antialiased enabled (see gf_evg_surface_set_antialias), default is true

◆ min_depth

writeonly float Canvas::min_depth

min depth (see gf_evg_surface_set_min_depth), default is 0

◆ max_depth

writeonly float Canvas::max_depth

max depth (see gf_evg_surface_set_max_depth), default is 1.0

◆ point_size

writeonly float Canvas::point_size

point size (see gf_evg_surface_set_point_size), default is 1.0

◆ point_smooth

writeonly boolean Canvas::point_smooth

point smoothing enabled (see gf_evg_surface_set_point_smooth), default is false

◆ line_size

writeonly float Canvas::line_size

line size (see gf_evg_surface_set_line_size), default is 1.0

◆ clip_zero

writeonly boolean Canvas::clip_zero

clip zero enabled (see gf_evg_surface_set_clip_zero), default is false

◆ depth_test

writeonly GF_EVGDepthTest Canvas::depth_test

depth test mode (see gf_evg_set_depth_test), default is GF_EVGDEPTH_LESS

◆ write_depth

writeonly boolean Canvas::write_depth

write depth buffer enabled (see gf_evg_surface_write_depth), default is true

◆ depth_buffer

Float32Buffer Canvas::depth_buffer

depth buffer (see gf_evg_surface_set_depth_buffer).

Warning
Default is null