Skip to main content

Crate ctt

Crate ctt 

Source
Expand description

ctt — a texture compression and conversion library.

§Quick start

use ctt::{convert, ConvertSettings, Container, TargetFormat, Format, Image, Surface, ColorSpace, AlphaMode, TextureKind};
use ctt::encoders::Encoder;

let pixel_bytes = vec![0u8; 512 * 512 * 4];
let surface = Surface {
    data: pixel_bytes,
    width: 512,
    height: 512,
    depth: 1,
    stride: 512 * 4,
    slice_stride: 0,
    format: Format::R8G8B8A8_UNORM,
    color_space: ColorSpace::Srgb,
    alpha: AlphaMode::Straight,
};
let image = Image {
    surfaces: vec![vec![surface]],
    kind: TextureKind::Texture2D,
};

let _ktx2_bytes = convert(image, ConvertSettings {
    format: Some(TargetFormat::Compressed {
        format: Format::BC7_UNORM_BLOCK,
        encoder: Encoder::Auto,
    }),
    container: Container::ktx2(),
    ..Default::default()
})?;

Use parse_format to build a TargetFormat from a string like "bc7", "intel_bc7", or "rgba8unorm".

§Feature flags

Each encoder backend is an independent feature, all enabled by default: encoder-bc7enc, encoder-intel, encoder-etcpak, encoder-amd, and encoder-astcenc. ispc-prebuilt (default) links prebuilt ISPC kernels; ispc-build-from-source compiles them instead and requires ispc on PATH — enable exactly one of the two. The default-off rayon feature parallelizes compression within each image on the active Rayon pool.

Modules§

encoders
input

Structs§

ConvertSettings
Settings for the high-level convert function.
Format
Vulkan VkFormat values for the texture’s texel format.
Image
Multi-layer, multi-mip image.
Surface
A single image surface — either raw pixels or compressed blocks.
Swizzle
A 4-component swizzle pattern.

Enums§

AlphaMode
How a surface’s alpha channel relates to its color channels.
ChannelKind
Channel data type for uncompressed formats.
ColorSpace
Color space metadata for a surface.
Container
Output container format.
CubemapInput
Input for cubemap face extraction.
Error
Errors produced anywhere in the ctt pipeline.
Ktx2Supercompression
Supercompression to apply when writing KTX2 files.
MipmapFilter
Filter types for mipmap downsampling.
PipelineOutput
Output of crate::convert::convert.
Quality
Universal quality preset all encoders understand.
SwizzleChannel
A single channel source for swizzling.
TargetFormat
The target format for a conversion operation.
TextureKind
Texture topology — distinguishes 2D, cubemap, and 3D textures.

Traits§

FormatExt
Extension trait providing introspection and utility methods on Format.

Functions§

convert
Convert an image.
format_short_name
Short display name for a compressed format (used in encoder listings).
parse_format
Parse a format string that may be compressed or uncompressed.
split_cubemap
Split a cubemap input into its 6 individual faces.

Type Aliases§

Result