libgpac
Documentation of the core library of GPAC
Texture Interface Reference

import"evg.idl";

+ Collaboration diagram for Texture:

Public Member Functions

 Texture (unsigned long width, unsigned long height, DOMString pixfmt, ArrayBuffer data, optional unsigned long stride=0, optional unsigned long stride_uv=0)
 
 Texture (DOMString filename, optional boolean is_rel_script=false)
 
 Texture (ArrayBuffer img_data)
 
 Texture (unsigned long width, unsigned long height, DOMString pixfmt, Function param_fun, optional boolean use_screen_coords=false)
 
 Texture (Canvas canvas)
 
 Texture (FilterPacket packet)
 
 Texture ()
 
void set_alpha (unsigned long alpha)
 
void set_alphaf (double alpha)
 
Texture rgb2hsv ()
 
Texture hsv2rgb ()
 
Texture rgb2yuv (Canvas surf)
 
Texture yuv2rgb (Canvas surf)
 
Texture convolution (ConvolutionKernel k)
 
Texture split (unsigned long idx)
 
void update (FilterPacket packet)
 
 load (DOMString filename, optional boolean is_rel_script=false)
 
 load (ArrayBuffer img_data)
 
 set_named (DOMString name)
 
 set_pad_color (DOMString color)
 
DOMString get_pad_color ()
 
Object get_pixelf (Float s, Float t, optional bool as_array=false)
 
Object get_pixel (unsigned long x, unsigned long y, optional bool as_array=false)
 

Data Fields

writeonly unsigned long filtering
 
writeonly ColorMatrix cmx
 
attribute Matrix2D mx
 
attribute boolean repeat_s
 
attribute boolean repeat_t
 
attribute boolean flip
 
readonly attribute boolean width
 
readonly attribute boolean height
 
readonly attribute DOMString pixfmt
 
readonly attribute unsigned long comp
 
readonly attribute ArrayBuffet data
 

Detailed Description

texture stencil

Constructor & Destructor Documentation

◆ Texture() [1/7]

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

pixel data constructor.

Parameters
widthwidth of the texture
heightheight of the texture
pixfmtpixel format of the texture
datatexture data to use
stridestride of pixel buffer or of first plane for planar formats
stride_uvstride of second plane for planar formats

◆ Texture() [2/7]

Texture::Texture ( DOMString  filename,
optional boolean  is_rel_script = false 
)

image file constructor. Only JPEG and PNG local files are supported. This constructor is used to quickly load an image file without using a filter chain for that

Parameters
filenamefile name on local drive
is_rel_scriptif true, indicates the file path is relative to the script location. Otherwise it is relative to the current directory

◆ Texture() [3/7]

Texture::Texture ( ArrayBuffer  img_data)

ArrayBuffer. Only JPEG and PNG local files are supported. This constructor is used to quickly load an image file without using a filter chain for that

Parameters
img_dataarray buffer containing the compressed image data

◆ Texture() [4/7]

Texture::Texture ( unsigned long  width,
unsigned long  height,
DOMString  pixfmt,
Function  param_fun,
optional boolean  use_screen_coords = false 
)

parametric texture constructor. A parametric texture gets its pixel values from a javascript callback function, the resulting value being blended according to the antialiasing level of the pixel. This allows creating rather complex custom textures, in a fashion similar to fragment shaders.

Warning
Parametric textures in JS cannot use multithreaded canvas, use 2D shaders for that.
Parameters
widthwidth of the texture
heightheight of the texture
pixfmtpixel format of the texture
param_funtexture data to use. This function is called on the texture object with two parameters x and y indicating the desired pixel in the texture, where (0,0) is top-left; the function shall return a Colorf interface
use_screen_coordsif set, the calbback function is passed screen coordinates rather than texture coordinates (and width/height of texture are ignored)

◆ Texture() [5/7]

Texture::Texture ( Canvas  canvas)

canvas constructor.

Note
There is no restriction on the source canvas, you can even use the target drawing canvas as a source to produce nice effects.
Parameters
canvasthe canvas to use as a texture

◆ Texture() [6/7]

Texture::Texture ( FilterPacket  packet)

packet constructor. This is usually needed for planar YUV format where planes are not contiguous in memory (eg output of hardware decoder). The size of the pixel buffer will be derived from the packet's PID properties

Parameters
packetthe source packet to use as a source for the data

◆ Texture() [7/7]

Texture::Texture ( )

Empty texture constructor. This is usually needed async texture load.

Member Function Documentation

◆ set_alpha()

void Texture::set_alpha ( unsigned long  alpha)

sets alpha value for stencil. The alpha is multiplied with the alpha component of the solid brush or gradient color

Parameters
alphathe alpha to set, between 0 and 255

◆ set_alphaf()

void Texture::set_alphaf ( double  alpha)

sets alpha value for stencil. The alpha is multiplied with the alpha component of the solid brush or gradient color

Parameters
alphathe alpha to set, between 0.0 and 1.0

◆ rgb2hsv()

Texture Texture::rgb2hsv ( )

converts texture from RGB/YUV to new HSV texture

Warning
the texture format will still be RGB (or RGBA if the source has alpha), in packed format
experimental, slow
Returns
new texture

◆ hsv2rgb()

Texture Texture::hsv2rgb ( )

converts texture from HSV to new RGB texture

Warning
experimental, slow
Returns
new texture

◆ rgb2yuv()

Texture Texture::rgb2yuv ( Canvas  surf)

converts texture from RGB to new YUV texture

Warning
experimental, slow This function can be used to convert an RGB texture to a YUV one, typically for rasterizing an RGB static texture over a YUV video (avoids performing the RGB to YUV conversion at each frame)
Parameters
surfthe target Canvas
Returns
new texture

◆ yuv2rgb()

Texture Texture::yuv2rgb ( Canvas  surf)

converts texture from YUV to new RGB texture

Warning
experimental, slow This function can be used to convert a YUV texture to an RGB one, typically for rasterizing a YUV static texture over an RGB video (avoids performing the TYV to RGB conversion at each frame)
Parameters
surfthe target Canvas
Returns
new texture

◆ convolution()

Texture Texture::convolution ( ConvolutionKernel  k)

performs a convolution on the texture

Warning
experimental, slow
Parameters
kthe convolution kernel to use
Returns
new texture

◆ split()

Texture Texture::split ( unsigned long  idx)

splits the given component into a new texture

Warning
experimental, slow (uses pixel by pixel access)
Parameters
idxthe component index. 0 is red or greyscale, 1 is alpha (alhpagrey formats) or green, 2 is green and 4 is alpha
Returns
new texture

◆ update()

void Texture::update ( FilterPacket  packet)

updates pixel data of texture using source packet

Parameters
packetthe new packet to use for the texture

◆ load() [1/2]

Texture::load ( DOMString  filename,
optional boolean  is_rel_script = false 
)

load local file into texture. Only JPEG and PNG local files are supported.

Parameters
filenamefile name on local drive
is_rel_scriptif true, indicates the file path is relative to the script location. Otherwise it is relative to the current directory

◆ load() [2/2]

Texture::load ( ArrayBuffer  img_data)

load file data into texture. Only JPEG and PNG data are supported.

Parameters
img_dataimage file data

◆ set_named()

Texture::set_named ( DOMString  name)

Makes the texture a named texture for WebGL.

If a texImage2D is done with a named EVG texture:

  • the associated WebGL texture becomes a named texture
  • any update() on the EVG texture will update the WebGL texture.
Warning
The shaders must be (re)compiled after the first update() on the texture.
Parameters
namethe named texture to use.

◆ set_pad_color()

Texture::set_pad_color ( DOMString  color)

Sets padding color for texture - see gf_evg_stencil_set_pad_color

The parameters can also be 4 doubles, an array of 4 doubles or an object with 'r', 'g', 'b', 'a' properties. In these cases, the component values must be between 0 and 1

Parameters
colorthe color to use.

◆ get_pad_color()

DOMString Texture::get_pad_color ( )

gets padding color associated for texture

Returns
the color used to pad or null if none.

◆ get_pixelf()

Object Texture::get_pixelf ( Float  s,
Float  t,
optional bool  as_array = false 
)

gets RGB pixel value in a texture

Parameters
shorizontal normalized texture coordinate of pixel, between 0 (left) and 1.0 (right)
tvertical normalized texture coordinate of pixel, between 0 (top) and 1.0 (bottom)
as_arrayif true, the return object is an array of 4 components, otherwise it is a Color object
Returns
the converted value

◆ get_pixel()

Object Texture::get_pixel ( unsigned long  x,
unsigned long  y,
optional bool  as_array = false 
)

gets RGB pixel value in a texture

Parameters
xhorizontal coordinate of pixel, between 0 (left) and width (right)
yvertical coordinate of pixel, between 0 (top) and height (bottom)
as_arrayif true, the return object is an array of 4 components, otherwise it is a Color object
Returns
the converted value

Field Documentation

◆ filtering

writeonly unsigned long Texture::filtering

filtering mode - see gf_evg_stencil_set_filter

◆ cmx

writeonly ColorMatrix Texture::cmx

color matrix - see gf_evg_stencil_set_color_matrix. Setting to null resets the color matrix

◆ mx

attribute Matrix2D Texture::mx

matrix - see gf_evg_stencil_set_matrix. Setting to null resets the matrix

Warning
: this is a copy of the associated matrix, not a live object

◆ repeat_s

attribute boolean Texture::repeat_s

horizontal repeat flag

◆ repeat_t

attribute boolean Texture::repeat_t

vertical repeat flag

◆ flip

attribute boolean Texture::flip

vertical flip flag

◆ width

readonly attribute boolean Texture::width

width in pixels of image (RGB width or luma plane width)

◆ height

readonly attribute boolean Texture::height

height in pixels of image (RGB height or luma plane height)

◆ pixfmt

readonly attribute DOMString Texture::pixfmt

pixel format

◆ comp

readonly attribute unsigned long Texture::comp

number of components

◆ data

readonly attribute ArrayBuffet Texture::data

texture data