python_vali.Surface

class python_vali.Surface

Image stored in vRAM. Consists of 1+ SurfacePlane(s).

__init__(*args, **kwargs)

Methods

Clone(self)

Create a deep copy of the surface.

Make(*args, **kwargs)

Overloaded function.

__init__(*args, **kwargs)

from_cai(dict, format)

DLPack: Make Surface from CAI, don not own memory.

from_dlpack(capsule, format)

DLPack: Make Surface from dlpack, don not own memory.

Attributes

Format

Get the pixel format of the surface.

Height

Get the height of the first plane in pixels.

HostSize

Get the total amount of host memory needed for device-to-host copy.

IsEmpty

Check if the surface has allocated memory.

IsOwnMemory

Check if the surface owns its memory.

NumPlanes

Get the number of planes in the surface.

Pitch

Get the pitch (stride) of the first plane in bytes.

Planes

Get SurfacePlane reference

Shape

Get the numpy-like shape of the surface.

Width

Get the width of the first plane in pixels.

Clone(self: python_vali._python_vali.Surface) python_vali._python_vali.Surface

Create a deep copy of the surface.

Allocates new CUDA memory and copies all surface data. The returned object is managed by the Python interpreter.

Returns:

A new surface containing a copy of the data

Return type:

Surface

property Format

Get the pixel format of the surface.

Returns:

Pixel format of the surface

Return type:

Pixel_Format

property Height

Get the height of the first plane in pixels.

Returns:

Height of the first plane in pixels

Return type:

int

property HostSize

Get the total amount of host memory needed for device-to-host copy.

This is the total size in bytes required to store all planes of the surface in host memory, taking into account the pitch and height of each plane.

Returns:

Required host memory size in bytes

Return type:

int

property IsEmpty

Check if the surface has allocated memory.

Returns:

True if the surface has no allocated memory, False otherwise

Return type:

bool

property IsOwnMemory

Check if the surface owns its memory.

Returns:

True if the surface owns its memory, False if it only references memory owned by another object

Return type:

bool

static Make(*args, **kwargs)

Overloaded function.

  1. Make(format: python_vali._python_vali.PixelFormat, width: int, height: int, gpu_id: int) -> python_vali._python_vali.Surface

    Create a new surface with the specified parameters.

    Allocates a new surface with the given pixel format and dimensions on the specified GPU. The surface will be managed by the Python interpreter.

    param format:

    Pixel format for the new surface

    type format:

    Pixel_Format

    param width:

    Width of the surface in pixels

    type width:

    int

    param height:

    Height of the surface in pixels

    type height:

    int

    param gpu_id:

    ID of the GPU to allocate memory on

    type gpu_id:

    int

    return:

    New surface with allocated memory

    rtype:

    Surface

    raises RuntimeError:

    If memory allocation fails

  2. Make(format: python_vali._python_vali.PixelFormat, width: int, height: int, context: int) -> python_vali._python_vali.Surface

    Constructor method.

    param format:

    target pixel format

    param width:

    width in pixels

    param height:

    height in pixels

    param context:

    CUDA contet to use

property NumPlanes

Get the number of planes in the surface.

Different pixel formats may have different numbers of planes. For example, RGB has 1 plane while YUV420 has 3 planes.

Returns:

Number of planes in the surface

Return type:

int

property Pitch

Get the pitch (stride) of the first plane in bytes.

The pitch represents the number of bytes between the start of consecutive rows in the first plane. This may be larger than the width * element size due to memory alignment requirements.

Returns:

Pitch of the first plane in bytes

Return type:

int

property Planes

Get SurfacePlane reference

Parameters:

plane – SurfacePlane index

property Shape

Get the numpy-like shape of the surface.

For multi-plane formats (like YUV420), returns the total memory size. The shape represents the dimensions of the surface data.

Returns:

Tuple containing the dimensions of the surface

Return type:

tuple

property Width

Get the width of the first plane in pixels.

Returns:

Width of the first plane in pixels

Return type:

int

static from_cai(dict: object, format: python_vali._python_vali.PixelFormat = <PixelFormat.RGB: 2>) python_vali._python_vali.Surface

DLPack: Make Surface from CAI, don not own memory.

Parameters:
  • dict – dictionary which corresponds to CUDA Array Interface specs.

  • fmt – pixel format, by default python_vali.PixelFormat.RGB

Returns:

Surface

Return type:

python_vali.Surface

static from_dlpack(capsule: capsule, format: python_vali._python_vali.PixelFormat = <PixelFormat.RGB: 2>) python_vali._python_vali.Surface

DLPack: Make Surface from dlpack, don not own memory.

Parameters:
  • capsule – capsule object with manager dltensor inside

  • fmt – pixel format, by default python_vali.PixelFormat.RGB

Returns:

Surface

Return type:

python_vali.Surface