Class Ktx2WriterOptions
Options for writing KTX 2.
public sealed class Ktx2WriterOptions : WriterOptions
- Inheritance
-
Ktx2WriterOptions
- Inherited Members
Examples
// With no options: the nearest uncompressed format (R8G8B8A8_SRGB for 8-bit colour) and the full mip chain.
using (FileStream output = File.Create("duck.ktx2"))
{
image.Save(output, Ktx2Format.Info);
}
// A GPU block format: BC7 for desktop, ASTC or ETC2 for mobile; effort runs 0 (fastest) to 6 (best).
using (FileStream output = File.Create("duck-astc.ktx2"))
{
image.Save(output, Ktx2Format.Info, new Ktx2WriterOptions { Format = KtxTextureFormat.Astc6x6, Effort = 3 });
}
// Basis Universal, which a viewer transcodes to whatever its GPU reads: UASTC with RDO and Zstandard (glTF's usual
// pick), or ETC1S for the smallest files.
using (FileStream output = File.Create("duck-uastc.ktx2"))
{
image.Save(output, Ktx2Format.Info, new Ktx2WriterOptions
{
Format = KtxTextureFormat.Uastc,
UastcRdo = 2,
Supercompression = KtxSupercompression.Zstandard,
});
}
using (FileStream output = File.Create("duck-etc1s.ktx2"))
{
image.Save(output, Ktx2Format.Info, new Ktx2WriterOptions { Format = KtxTextureFormat.Etc1s, BasisQuality = 128 });
}
// Six faces into a cube map; SaveAll without Cube writes a texture array.
using RasterList faces = Raster.LoadAll("sky.ktx2", context);
using (FileStream output = File.Create("sky-bc1.ktx2"))
{
Raster.SaveAll(faces, output, Ktx2Format.Info, new Ktx2WriterOptions { Cube = true, Format = KtxTextureFormat.Bc1 });
}
Remarks
Re-saving a raster loaded from KTX or KTX 2 keeps its format and sRGB flag for every option left at null when the writer writes that format; a raster loaded from DDS keeps its block format the same way.
Properties
BasisQuality
Gets the quality of Etc1s, 1 to 255: it sets the size of the endpoint and selector codebooks, from 16 entries to 16128. Defaults to 128 (about 1000 entries).
public int BasisQuality { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is outside 1 to 255.
CompressionLevel
Gets the Zstandard (1 to 22) or zlib (1 to 9) level, or 0 (the default) for the scheme's default: Zstandard DefaultLevel, zlib 6.
public int CompressionLevel { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is outside 0 to 22.
Cube
Gets whether SaveAll writes its rasters as cube maps, six faces a cube in the order +X, −X, +Y, −Y, +Z, −Z, rather than as a texture array. The rasters must then be square and a multiple of six. Defaults to false.
public bool Cube { get; init; }
Property Value
Default
Gets the default options.
public static Ktx2WriterOptions Default { get; }
Property Value
Effort
Gets how hard the block encoders search, 0 (fastest) to 6 (best), on WebP's scale. Defaults to 4. The output is the same for any number of threads.
public int Effort { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is outside 0 to 6.
Format
Gets the format to write, or null (the default) for a KTX, KTX 2 or DDS source's own format when it is writable, else the uncompressed one nearest the raster's pixel type (Rgba8 for 8-bit colour, R8 for 8-bit gray, RgbaF16 for half floats and so on). A block format is chosen only from a texture source.
public KtxTextureFormat? Format { get; init; }
Property Value
MipLevels
Gets how many mip levels to write: 0 (the default) for the full chain down to 1 × 1, 1 for mip 0 alone, or that many, at most the full chain. Mips average 2 × 2 blocks of premultiplied pixels (MipChain), in linear light for an sRGB format. An integer or depth format writes mip 0 alone unless a count is given, since averaging its values rarely means anything.
public int MipLevels { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is negative.
PremultipliedAlpha
Gets whether to write colour premultiplied by alpha, flagged so in the data format descriptor. Defaults to false.
public bool PremultipliedAlpha { get; init; }
Property Value
Srgb
Gets whether to write the format's _SRGB form, or null (the default) to write it when the source texture was sRGB, or else when the raster is tagged sRGB. The 8-bit colour formats, BC1 to BC3, BC7, ETC1, ETC2, ASTC and the Basis formats have one; for the others the default falls back to UNORM, and true throws.
public bool? Srgb { get; init; }
Property Value
- bool?
Supercompression
Gets the supercompression of each mip level: None (the default), Zstandard or Zlib. Etc1s always takes BasisLZ, which no other format can.
public KtxSupercompression Supercompression { get; init; }
Property Value
UastcRdo
Gets the rate-distortion trade for Uastc: 0 (the default) leaves the blocks alone; higher values let blocks repeat bytes of their neighbours so Zstandard compresses them better, at a loss of quality. About 1 makes files a few per cent smaller, 16 about a third smaller and 3 to 4 dB lower.
public float UastcRdo { get; init; }
Property Value
Exceptions
- ArgumentOutOfRangeException
The value is negative or not a number.