s3tc module

The s3tc module provides encoders and decoders for the common S3 Texture Compression formats. BC1-5 encoding is done internally using a modified version of rgbcx.h.

bc1 module

Classes for encoding/decoding BC1 textures

class BC1Encoder

Encodes RGB textures to BC1.

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: _quicktex._s3tc._bc1.BC1Encoder, level: int = 5, color_mode: _quicktex._s3tc._bc1.BC1Encoder.ColorMode = <ColorMode.FourColor: 4>) -> None

  2. __init__(self: _quicktex._s3tc._bc1.BC1Encoder, level: int, color_mode: _quicktex._s3tc._bc1.BC1Encoder.ColorMode, interpolator: _quicktex._s3tc._interpolator.Interpolator) -> None

    Create a new BC1 encoder with the specified preset level, color mode, and interpolator.

    param int level:

    The preset level of the resulting encoder, between 0 and 18 inclusive. See set_level() for more information. Default: 5.

    param ColorMode color_mode:

    The color mode of the resulting BC1Encoder. Default: FourColor.

    param Interpolator interpolator:

    The interpolation mode to use for encoding. Default: Interpolator.

set_level(self: _quicktex._s3tc._bc1.BC1Encoder, level: int) None

Select a preset quality level, between 0 and 18 inclusive. Higher quality levels are slower, but produce blocks that are a closer match to input. This has no effect on the size of the resulting texture, since BC1 is a fixed-ratio compression method. For better control, see the advanced API below

Parameters:

level (int) – The preset level of the resulting encoder, between 0 and 18 inclusive. Default: 5.

property color_mode(self) ColorMode

The ColorMode used by this encoder. This is a readonly property.

property interpolator(self) quicktex.s3tc.interpolator.Interpolator

The Interpolator used by this encoder. This is a readonly property.

class ColorMode

Enum representing various methods of writing BC1 blocks.

Members:

FourColor : Default color mode. Only 4-color blocks will be output, where color0 > color1

ThreeColor : Additionally use 3-color blocks when they have a lower error, where color0 <= color1

ThreeColorBlack : Additionally use 3-color blocks with black pixels (selector 3). Note that this requires your shader/engine to not sample the alpha channel when using a BC1 texture.

Advanced API

Additional properties are provided for finer-grained control over quality and performance

property error_mode(self) ErrorMode

The error mode used by this encoder for finding selectors.

property endpoint_mode(self) EndpointMode

The endpoint mode used by this encoder.

property two_ls_passes(self) bool

Use 2 least squares pass, instead of one (same as stb_dxt’s HIGHQUAL option). Recommended if you’re setting the orderings settings greater than 0.

property two_ep_passes(self) bool

Try 2 different ways of choosing the initial endpoints.

property two_cf_passes(self) bool

Greatly increase encode time, with very slightly higher quality. Same as squish’s iterative cluster fit option. Not really worth the tiny boost in quality, unless you just don’t care about performance at all.

property exhaustive(self) bool

Check all total orderings - very slow. The encoder is not designed to be used in this way

property search_rounds(self) int

Setting search rounds > 0 enables refining the final endpoints by examining nearby colors. A higher value has a higher quality at the expense of performance.

property orderings(self) tuple[int, int]

setting the orderings > 0 enables ordered cluster fit using a lookup table of similar blocks. Value is a tuple of (4 color orders, 3 color orders), where higher values have a higher quality at the expense of performance.

property power_iterations(self) int

Number of power iterations used with the PCA endpoint mode. Value should be around 4 to 6. Automatically clamped to between BC1Encoder.min_power_iterations and BC1Encoder.max_power_iterations

max_power_iterations = 10
min_power_iterations = 4
class EndpointMode

Enum representing various methods of finding endpoints in a block.

Members:

LeastSquares : Find endpoints using a 2D least squares approach.

BoundingBox : Find endpoints using a simple bounding box. Fast but inaccurate.

BoundingBoxInt : Same as BoundingBox but using integers, slightly faster.

PCA : Find endpoints using Principle Component Analysis. Slowest but highest quality method.

class ErrorMode

Enum representing various methods of finding selectors in a block.

Members:

None : The same as Faster but error is not calculated. This disables any cluster-fit options

Faster : Use a slightly lower quality, but ~30% faster MSE evaluation function for 4-color blocks.

Check2 : Default error-checking method.

Full : Examine all colors to compute selectors/MSE. Slower but slightly higher quality.

class BC1Decoder

Decodes BC1 textures to RGB

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: _quicktex._s3tc._bc1.BC1Decoder, write_alpha: bool = False) -> None

  2. __init__(self: _quicktex._s3tc._bc1.BC1Decoder, write_alpha: bool, interpolator: _quicktex._s3tc._interpolator.Interpolator) -> None

    Create a new BC1 decoder with the specificied interpolator.

    param bool write_alpha:

    Determines if the alpha channel of the output is written to. Default: False;

    param Interpolator interpolator:

    The interpolation mode to use for decoding. Default: Interpolator.

property interpolator(self) quicktex.s3tc.interpolator.Interpolator

The interpolator used by this decoder. This is a readonly property.

property write_alpha(self) bool

Determines if the alpha channel of the output is written to.

bc3 module

class BC3Encoder

Encodes RGBA textures to BC3

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: _quicktex._s3tc._bc3.BC3Encoder, level: int = 5) -> None

  2. __init__(self: _quicktex._s3tc._bc3.BC3Encoder, level: int, interpolator: _quicktex._s3tc._interpolator.Interpolator) -> None

    Create a new BC3 encoder with the specified preset level and interpolator.

    param int level:

    The preset level of the resulting encoder, between 0 and 18 inclusive. See set_level() for more information. Default: 5.

    param Interpolator interpolator:

    The interpolation mode to use for encoding. Default: Interpolator.

property bc1_encoder(self) quicktex.s3tc.bc1.BC1Encoder

Internal BC1Encoder used for RGB data. Readonly.

property bc4_encoder(self) quicktex.s3tc.bc4.BC4Encoder

Internal BC4Encoder used for alpha data. Readonly.

class BC3Decoder

Decodes BC3 textures to RGBA

__init__(*args, **kwargs)

Overloaded function.

  1. __init__(self: _quicktex._s3tc._bc3.BC3Decoder) -> None

  2. __init__(self: _quicktex._s3tc._bc3.BC3Decoder, interpolator: _quicktex._s3tc._interpolator.Interpolator) -> None

    Create a new BC3 decoder with the specified interpolator.

    param Interpolator interpolator:

    The interpolation mode to use for decoding. Default: Interpolator.

property bc1_decoder(self) quicktex.s3tc.bc1.BC1Decoder

Internal BC1Decoder used for RGB data. Readonly.

property bc4_decoder(self) quicktex.s3tc.bc4.BC4Decoder

Internal BC4Decoder used for alpha data. Readonly.

bc4 module

class BC4Encoder

Encodes single-channel textures to BC4.

__init__(self: _quicktex._s3tc._bc4.BC4Encoder, channel: int = 3) None

Create a new BC4 encoder with the specified channel

Parameters:

channel (int) – the channel that will be read from. 0 to 3 inclusive. Default: 3 (alpha).

property channel(self) int

The channel that will be read from. 0 to 3 inclusive. Readonly.

class BC4Decoder

Decodes BC4 textures to a single-channel.

__init__(self: _quicktex._s3tc._bc4.BC4Decoder, channel: int = 3) None

Create a new BC4 decoder with the specified channel

Parameters:

channel (int) – The channel that will be written to. 0 to 3 inclusive. Default: 3 (alpha).

property channel(self) int

The channel that will be written to. 0 to 3 inclusive. Readonly.

bc5 module

class BC5Encoder

Encodes dual-channel textures to BC5.

__init__(self: _quicktex._s3tc._bc5.BC5Encoder, chan0: int = 0, chan1: int = 1) None

Create a new BC5 encoder with the specified channels

Parameters:
  • chan0 (int) – the first channel that will be read from. 0 to 3 inclusive. Default: 0 (red).

  • chan1 (int) – the second channel that will be read from. 0 to 3 inclusive. Default: 1 (green).

property bc4_encoders(self) tuple[quicktex.s3tc.bc4.BC4Encoder]

2-tuple of internal BC4Encoder s used for each channel. Readonly.

property channels(self) tuple[int, int]

A 2-tuple of channels that will be read from. 0 to 3 inclusive. Readonly.

class BC5Decoder

Decodes BC4 textures to two channels.

__init__(self: _quicktex._s3tc._bc5.BC5Decoder, chan0: int = 0, chan1: int = 1) None

Create a new BC5 decoder with the specified channels

Parameters:
  • chan0 (int) – the first channel that will be written to. 0 to 3 inclusive. Default: 0 (red).

  • chan1 (int) – the second channel that will be written to. 0 to 3 inclusive. Default: 1 (green).

property bc4_decoders(self) tuple[quicktex.s3tc.bc4.BC4Decoder]

2-tuple of internal BC4Decoder s used for each channel. Readonly.

property channels(self) tuple[int, int]

A 2-tuple of channels that will be written to. 0 to 3 inclusive. Readonly.

interpolator module

Classes representing various methods of interpolating BC1-3 blocks

class Interpolator

Interpolator base class representing the ideal interpolation mode, with no rounding for colors 2 and 3. This matches the D3D10 docs on BC1.

class InterpolatorAMD

Base: Interpolator

Interpolator class representing the AMD GPU interpolation mode.

class InterpolatorNvidia

Base: Interpolator

Interpolator class representing the Nvidia GPU interpolation mode.

class InterpolatorRound

Base: Interpolator

Interpolator class representing the ideal rounding interpolation mode. Round colors 2 and 3. Matches the AMD Compressonator tool and the D3D9 docs on DXT1.