ispc_texcomp

ISPCTextureCompressor Python Bindings

A Python interface for the GameTechDev/ISPCTextureCompressor library, providing GPU texture compression functionality.

This module contains compiled extensions with type information provided through stub files (.pyi).

 1"""
 2ISPCTextureCompressor Python Bindings.
 3
 4This module provides Python bindings for the GameTechDev/ISPCTextureCompressor library.
 5"""
 6
 7__version__ = version = "1.0.1"
 8
 9from ._ispc_texcomp import (
10    BC6HEncSettings,
11    BC7EncSettings,
12    ETCEncSettings,
13    ASTCEncSettings,
14    RGBASurface,
15    compress_blocks_bc1,
16    compress_blocks_bc3,
17    compress_blocks_bc4,
18    compress_blocks_bc5,
19    compress_blocks_bc6h,
20    compress_blocks_bc7,
21    compress_blocks_etc1,
22    compress_blocks_astc,
23)
24
25# Add module-level documentation
26__doc__ = """
27ISPCTextureCompressor Python Bindings
28
29A Python interface for the GameTechDev/ISPCTextureCompressor library,
30providing GPU texture compression functionality.
31
32This module contains compiled extensions with type information provided
33through stub files (.pyi).
34"""
35
36# Explicitly list public symbols
37__all__ = [
38    "__version__",
39    "RGBASurface",
40    "BC6HEncSettings",
41    "BC7EncSettings",
42    "ETCEncSettings",
43    "ASTCEncSettings",
44    "compress_blocks_bc1",
45    "compress_blocks_bc3",
46    "compress_blocks_bc4",
47    "compress_blocks_bc5",
48    "compress_blocks_bc6h",
49    "compress_blocks_bc7",
50    "compress_blocks_etc1",
51    "compress_blocks_astc",
52]
__version__ = '1.0.1'
class RGBASurface:

Represents a RGBA image surface for texture compression.

Attributes
  • width (int): The width of the image in pixels (must be > 0)
  • height (int): The height of the image in pixels (must be > 0)
  • stride (int): The number of bytes per row (calculated as width*4 if 0)
Methods

__init__(src, width, height, stride=0) Initialize from raw pixel data data() Get raw bytes of the surface __buffer__() Get memoryview of pixel data

RGBASurface(src: ByteString, width: int, height: int, stride: int = 0)

Initialize an RGBA surface from raw pixel data.

Parameters
  • src (ByteString): Raw RGBA pixel data (length should be heightstride or widthheight*4)
  • width (int): Surface width in pixels (>0)
  • height (int): Surface height in pixels (>0)
  • stride (int, optional): Bytes per row (0 = width*4)
Notes

Data layout is assumed to be 8-bit per channel RGBA (32bpp)

width: int

width

height: int

height

stride: int

stride

data: bytes

bytes: Raw pixel data bytes of the surface.

class BC6HEncSettings:

Configuration settings for BC6H texture compression (HDR format).

Attributes
  • slow_mode (bool): Enable thorough but slow search for best endpoints
  • fast_mode (bool): Enable fast optimizations (mutually exclusive with slow_mode)
  • refine_iterations_1p (int): Refinement iterations for 1-partition modes
  • refine_iterations_2p (int): Refinement iterations for 2-partition modes
  • fast_skip_threshold (int): Threshold for early termination (0-4)
Methods

from_profile(profile) Create settings from predefined profile

BC6HEncSettings( slow_mode: bool = False, fast_mode: bool = False, refine_iterations_1p: int = 0, refine_iterations_2p: int = 0, fast_skip_threshold: int = 0)

Initialize BC6H compression settings.

Parameters
  • slow_mode (bool, optional): Default False. Enables exhaustive search
  • fast_mode (bool, optional): Default False. Enables performance optimizations
  • refine_iterations_1p (int, optional): Default 0. Iterations for 1-partition refinement
  • refine_iterations_2p (int, optional): Default 0. Iterations for 2-partition refinement
  • fast_skip_threshold (int, optional): Default 0. Early exit threshold (0=disabled)
def from_profile( cls, profile: Literal['fast', 'veryfast', 'basic', 'slow', 'veryslow']) -> BC6HEncSettings:

Create BC6H settings from a named profile.

Parameters
  • profile (BC6HEncProfile): Compression profile. Valid options:
    • 'veryfast': Fastest compression
    • 'fast': Balanced speed/quality
    • 'basic': Standard quality
    • 'slow': High quality
    • 'veryslow': Best quality
Returns
  • BC6HEncSettings: Preconfigured settings instance
slow_mode: bool

slow_mode

fast_mode: bool

fast_mode

refine_iterations_1p: int

refineIterations_1p

refine_iterations_2p: int

refineIterations_2p

fast_skip_treshold

fastSkipTreshold

class BC7EncSettings:

Configuration settings for BC7 texture compression.

Attributes
  • skip_mode2 (bool): Skip BC7 mode 2 during compression
  • fast_skip_threshold_mode1 (int): Early exit threshold for mode 1 (0-4)
  • fast_skip_threshold_mode2 (int): Early exit threshold for mode 2 (0-4)
  • fast_skip_threshold_mode7 (int): Early exit threshold for mode 7 (0-4)
  • mode45_channel0 (bool): Use modes 4/5 for channel 0 (RGB)
  • refine_iterations_channel (int): Number of refinement iterations per channel
  • channels (int): Number of channels (3=RGB, 4=RGBA)
Methods

from_profile(profile) Create settings from predefined profile

BC7EncSettings( mode_selection: list[bool], refine_iterations: list[int], skip_mode2: bool, fast_skip_threshold_mode1: int, fast_skip_threshold_mode2: int, fast_skip_threshold_mode7: int, mode45_channel0: int, refine_iterations_channel: int, channels: int)

Create custom BC7 compression settings.

Parameters
  • mode_selection (list[bool]): 4-element list enabling compression modes
  • refine_iterations (list[int]): 8-element list of refinement iterations per mode
  • skip_mode2 (bool): Skip mode 2 during compression
  • fast_skip_threshold_mode1 (int): Mode 1 early exit threshold (0-4)
  • fast_skip_threshold_mode2 (int): Mode 2 early exit threshold (0-4)
  • fast_skip_threshold_mode7 (int): Mode 7 early exit threshold (0-4)
  • mode45_channel0 (int): Use modes 4/5 for RGB channel
  • refine_iterations_channel (int): Refinement iterations per channel
  • channels (int): Number of color channels (3 or 4)
def from_profile( cls, profile: Literal['ultrafast', 'veryfast', 'fast', 'basic', 'slow', 'alpha_ultrafast', 'alpha_veryfast', 'alpha_fast', 'alpha_basic', 'alpha_slow']) -> BC7EncSettings:

Create settings from a predefined BC7 compression profile.

Parameters
  • profile (BC7EncProfile): Compression profile name. Valid options:
    • ultrafast/veryfast/fast/basic/slow: For opaque textures
    • alpha_* variants: For textures with alpha channel
Returns
  • BC7EncSettings: Preconfigured settings instance
skip_mode2: bool

skip_mode2

fast_skip_threshold_mode1: int

fastSkipTreshold_mode1

fast_skip_threshold_mode3

fastSkipTreshold_mode3

fast_skip_threshold_mode7: int

fastSkipTreshold_mode7

mode45_channel0: bool

mode45_channel0

refine_iterations_channel: int

refineIterations_channel

channels: int

channels

class ETCEncSettings:

Configuration settings for ETC1 texture compression.

Attributes
  • fast_skip_threshold (int): Threshold for early termination (0-4)
Methods

from_profile(profile) Create settings from predefined profile

ETCEncSettings(fast_skip_threshold: int = 0)

Initialize ETC1 compression settings.

Parameters
  • fast_skip_threshold (int, optional): Default 0. Early exit threshold (0=disabled)
def from_profile(cls, profile: Literal['slow']) -> ETCEncSettings:

Create ETC1 settings from a named profile.

Parameters
  • profile (ETCEncProfile): 'slow' is the only preset profile
Returns
  • ETCEncSettings: Preconfigured settings instance
fast_skip_treshold

fastSkipTreshold

class ASTCEncSettings:

Configuration settings for ASTC texture compression.

Attributes
  • block_width (int): ASTC block width (4-12)
  • block_height (int): ASTC block height (4-12)
  • channels (int): Color channels (3=RGB, 4=RGBA)
  • fast_skip_threshold (int): Early termination threshold (0-4)
  • refine_iterations (int): Number of endpoint refinement iterations
Methods

from_profile(profile, block_width, block_height) Create settings from predefined profile

ASTCEncSettings( block_width: int, block_height: int, channels: int, fast_skip_threshold: int, refine_iterations: int)

Initialize ASTC compression settings.

Parameters
  • block_width (int): ASTC block width (4-12)
  • block_height (int): ASTC block height (4-12)
  • channels (int): Color channels (3 or 4)
  • fast_skip_threshold (int): Early exit threshold (0=disabled)
  • refine_iterations (int): Endpoint refinement iterations
def from_profile( cls, profile: Literal['fast', 'alpha_fast', 'alpha_slow'], block_width: int, block_height: int) -> ASTCEncSettings:

Create ASTC settings from a named profile.

Parameters
  • profile (ASTCEncProfile): Compression profile. Valid options:
    • 'fast': Opaque textures
    • 'alpha_fast': Textures with Alpha channel (fast)
    • 'alpha_slow': Textures with Alpha channel (high quality)
  • block_width (int): ASTC block width (4-8)
  • block_height (int): ASTC block height (4-8)
Returns
  • ASTCEncSettings: Preconfigured settings instance
block_width: int

block_width

block_height: int

block_height

channels: int

channels

fast_skip_treshold

fastSkipTreshold

refine_iterations: int

refineIterations

def compress_blocks_bc1(rgba: RGBASurface) -> bytes:

Compress to BC1 format (DXT1 equivalent).

Parameters
  • rgba (RGBASurface): Input RGBA surface (alpha channel ignored)
Returns
  • bytes: Compressed BC1 texture data
Notes
  • 4x4 blocks, 4bpp
  • Supports RGB with 1-bit alpha
def compress_blocks_bc3(rgba: RGBASurface) -> bytes:

Compress to BC3 format (DXT5 equivalent).

Parameters
  • rgba (RGBASurface): Input RGBA surface
Returns
  • bytes: Compressed BC3 texture data
Notes
  • 4x4 blocks, 8bpp
  • RGBA format with explicit alpha
def compress_blocks_bc4(rgba: RGBASurface) -> bytes:

Compress to BC4 format (single-channel).

Parameters
  • rgba (RGBASurface): Input surface (uses red channel)
Returns
  • bytes: Compressed BC4 texture data
Notes
  • 4x4 blocks, 4bpp
  • Stores single channel (typically red)
def compress_blocks_bc5(rgba: RGBASurface) -> bytes:

Compress to BC5 format (dual-channel).

Parameters
  • rgba (RGBASurface): Input surface (uses red/green channels)
Returns
  • bytes: Compressed BC5 texture data
Notes
  • 4x4 blocks, 8bpp
  • Stores two channels (typically red/green)
def compress_blocks_bc6h( rgba: RGBASurface, settings: BC6HEncSettings) -> bytes:

Compress an RGBA surface to BC6 texture blocks.

The data of RGBA surface has to be FP16 instead of RGBA U8!

Parameters
  • rgba (RGBASurface): Input RGBA surface to compress
  • settings (BC6HEncSettings): Compression configuration settings
Returns
  • bytes: Compressed texture data in BC6 format
def compress_blocks_bc7( rgba: RGBASurface, settings: BC7EncSettings) -> bytes:

Compress an RGBA surface to BC7 texture blocks.

Parameters
  • rgba (RGBASurface): Input RGBA surface to compress
  • settings (BC7EncSettings): Compression configuration settings
Returns
  • bytes: Compressed texture data in BC7 format
def compress_blocks_etc1( rgba: RGBASurface, settings: ETCEncSettings) -> bytes:

Compress to ETC1 format.

Parameters
  • rgba (RGBASurface): Input RGBA surface (alpha channel ignored)
  • settings (ETCEncSettings): Compression settings
Returns
  • bytes: Compressed ETC1 texture data
Notes
  • 4x4 blocks, 4bpp
  • RGB format only
def compress_blocks_astc( rgba: RGBASurface, settings: ASTCEncSettings) -> bytes:

Compress to ASTC format.

Parameters
  • rgba (RGBASurface): Input RGBA surface
  • settings (ASTCEncSettings): Compression settings with block configuration
Returns
  • bytes: Compressed ASTC texture data
Notes
  • 4x4 to 8x8 block sizes