Skip to content

Gdk.TextureDownloader

record (struct)

Used to download the contents of a Texture.

It is intended to be created as a short-term object for a single download, but can be used for multiple downloads of different textures or with different settings.

GdkTextureDownloader can be used to convert data between different formats. Create a GdkTexture for the existing format and then download it in a different format.

Constructors

new

@classmethod
def new(cls, texture: Texture) -> TextureDownloader

Creates a new texture downloader for texture.

By default, the downloader will convert the data to the default memory format, and to the sRGB color state.

Parameters:

  • texture — texture to download

Methods

copy

def copy(self) -> TextureDownloader

Creates a copy of the downloader.

This function is meant for language bindings.

download_bytes

def download_bytes(self) -> tuple[bytes, int]

Downloads the given texture pixels into a GBytes. The rowstride will be stored in the stride value.

This function will abort if it tries to download a large texture and fails to allocate memory. If you think that may happen, you should handle memory allocation yourself and use TextureDownloader.download_into once allocation succeeded.

This function cannot be used with a multiplanar format. Use TextureDownloader.download_bytes_with_planes for that purpose.

download_bytes_with_planes

def download_bytes_with_planes(self) -> tuple[bytes, list[int], list[int]]

Downloads the given texture pixels into a GBytes. The offsets and strides of the resulting buffer will be stored in the respective values.

If the format does have less than 4 planes, the remaining offsets and strides will be set to 0.

download_into

def download_into(self, data: list[int], stride: int) -> None

Downloads the texture into local memory.

This function cannot be used with a multiplanar format.

Parameters:

  • data — pointer to enough memory to be filled with the downloaded data of the texture
  • stride — rowstride in bytes

free

def free(self) -> None

Frees the given downloader and all its associated resources.

get_color_state

def get_color_state(self) -> ColorState

Gets the color state that the data will be downloaded in.

get_format

def get_format(self) -> MemoryFormat

Gets the format that the data will be downloaded in.

get_texture

def get_texture(self) -> Texture

Gets the texture that the downloader will download.

set_color_state

def set_color_state(self, color_state: ColorState) -> None

Sets the color state the downloader will convert the data to.

By default, the sRGB colorstate returned by ColorState.get_srgb is used.

Parameters:

  • color_state — the color state to use

set_format

def set_format(self, format: MemoryFormat | int) -> None

Sets the format the downloader will download.

By default, GDK_MEMORY_DEFAULT is set.

Parameters:

  • format — the format to use

set_texture

def set_texture(self, texture: Texture) -> None

Changes the texture the downloader will download.

Parameters:

  • texture — the new texture to download