pyktx.ktx_texture2 module

class pyktx.ktx_texture2.KtxTexture2(ptr: c_ulong)[source]

Bases: KtxTexture

Class representing a KTX version 2 format texture.

static create(create_info: KtxTextureCreateInfo, storage_allocation: KtxTextureCreateStorage) KtxTexture2[source]

Create a new empty KtxTexture2.

static create_from_named_file(filename: str, create_flags: int = KtxTextureCreateFlagBits.LOAD_IMAGE_DATA_BIT) KtxTexture2[source]

Create a KtxTexture2 from a named KTX file.

property vk_format: VkFormat

VkFormat for texture.

property supercompression_scheme: KtxSupercmpScheme

The supercompression scheme used to compress the texture data.

property color_model: KhrDfModel

The color model of the images.

property primaries: KhrDfPrimaries

The color primaries of the images.

property transfer_function: KhrDfTransfer

The transfer function of the images.

property premultipled_alpha: bool

Whether the RGB components have been premultiplied by the alpha component.

compress_astc(params: int | KtxAstcParams) None[source]

Encode and compress a ktx texture with uncompressed images to ASTC.

The images are either encoded to ASTC block-compressed format. The encoded images replace the original images and the texture’s fields including the dfd are modified to reflect the new state.

Such textures can be directly uploaded to a GPU via a graphics API.

compress_basis(params: int | KtxBasisParams) None[source]

Supercompress a KTX2 texture with uncompressed images.

The images are either encoded to ETC1S block-compressed format and supercompressed with Basis LZ or they are encoded to UASTC block-compressed format. UASTC format is selected by setting the uastc field of params to true. The encoded images replace the original images and the texture’s fields including the DFD are modified to reflect the new state. Such textures must be transcoded to a desired target block compressed format before they can be uploaded to a GPU via a graphics API.

decode_astc() None[source]

Decode a ktx2 texture object, if it is ASTC encoded.

The decompressed format is calculated from corresponding ASTC format. There are only 3 possible options currently supported. RGBA8, SRGBA8 and RGBA32.

Note that 3d textures are decoded to a multi-slice 3d texture.

deflate_zstd(compression_level: int) None[source]

Deflate the data in a ktxTexture2 object using Zstandard.

The texture’s level_index, data_size, dfd and supercompression_scheme will all be updated after successful deflation to reflect the deflated data.

transcode_basis(output_format: KtxTranscodeFmt, transcode_flags: int = 0) None[source]

Transcode a KTX2 texture with BasisLZ/ETC1S or UASTC images.

If the texture contains BasisLZ supercompressed images, inflates them from back to ETC1S then transcodes them to the specified block-compressed format. If the texture contains UASTC images, inflates them, if they have been supercompressed with zstd, then transcodes then to the specified format, The transcoded images replace the original images and the texture’s fields including the dfd are modified to reflect the new format.

These types of textures must be transcoded to a desired target block-compressed format before they can be uploaded to a GPU via a graphics API.

The following block compressed transcode targets (KtxTranscodeFmt) are available: ETC1_RGB, ETC2_RGBA, BC1_RGB, BC3_RGBA, BC4_R, BC5_RG, BC7_RGBA, PVRTC1_4_RGB, PVRTC1_4_RGBA, PVRTC2_4_RGB, PVRTC2_4_RGBA, ASTC_4x4_RGBA, ETC2_EAC_R11, ETC2_EAC_RG11, ETC and BC1_OR_3.

ETC automatically selects between ETC1_RGB and ETC2_RGBA according to whether an alpha channel is available. BC1_OR_3 does likewise between BC1_RGB and BC3_RGBA. Note that if PVRTC1_4_RGBA or PVRTC2_4_RGBA is specified and there is no alpha channel PVRTC1_4_RGB or PVRTC2_4_RGB respectively will be selected.

Transcoding to ATC & FXT1 formats is not supported by libktx as there are no equivalent Vulkan formats.

The following uncompressed transcode targets are also available: RGBA32, RGB565, BGR565 and RGBA4444.