ktx_encode(1)
πΈ NAME πΈ
This is ktx_encode(1) β the manual page for ktx encode, and it is literally here to encode a KTX2 file. Bestie, this is your go-to for turning a KTX file into a universal format or one of the ASTC formats, optionally supercompressing it, and saving the result. π
π¦ SYNOPSIS π¦
ktx encode [option...] input-file output-file
π DESCRIPTION π
ktx encode can encode the KTX file specified as the input-file argument to a universal format or one of the ASTC formats, optionally supercompress the result, and save it as the output-file. If the input-file is '-' the file will be read from the stdin. If the output-path is '-' the output file will be written to the stdout. slay β¨
For universal and ASTC LDR formats, the input file must be R8, R8G8, R8G8B8 or R8G8B8A8 (or their sRGB variants). No cap.
If the input file is invalid the first encountered validation error is displayed to the stderr and the command exits with the relevant non-zero status code. vibe check failed, bestie π
β¨ OPTIONS β¨
π General Options π
The following options are available:
--codec basis-lz | uastcβ target codec followed by the codec specific options. With each choice the specific and common encoder options listed below become valid, otherwise they are ignored. Case-insensitive.basis-lz: Supercompress the image data with transcodable ETC1S / BasisLZ. RED images will become RGB with RED in each component (RRR). RG images will have R in the RGB part and G in the alpha part of the compressed texture (RRRG). When set, the basis-lz options become valid.uastc: Create a texture in high-quality transcodable UASTC format. When set the uastc options become valid.
--formatβ KTX format enum that specifies the target ASTC format. Non-ASTC formats are invalid. When specified the ASTC-specific and common encoder options listed below become valid, otherwise they are ignored.--zstd <level>β Supercompress the data with Zstandard. Cannot be used with ETC1S / BasisLZ format. Level range is[1,22]. Lower levels give faster but worse compression. Values above20should be used with caution as they require more memory. highkey watch that memory, bestie π«Ά--zlib <level>β Supercompress the data with ZLIB. Cannot be used with ETC1S / BasisLZ format. Level range is[1,9]. Lower levels give faster but worse compression.-h,--helpβ Print this usage message and exit.-v,--versionβ Print the version number of this program and exit.
π§ Specific and Common Encoding Options π§
The following specific and common encoder options are available. Specific options become valid only if their encoder has been selected. Common encoder options become valid when an encoder they apply to has been selected. Otherwise they are ignored. iykyk π
β ASTC β
--astc-quality <level>β The quality level configures the quality-performance tradeoff for the compressor; more complete searches of the search space improve image quality at the expense of compression time. Default is'medium'. The quality level can be set between fastest (0) and exhaustive (100) via the following fixed quality presets:fastestβ equivalent to quality =0fastβ equivalent to quality =10mediumβ equivalent to quality =60thoroughβ equivalent to quality =98exhaustiveβ equivalent to quality =100
--astc-perceptualβ The codec should optimize for perceptual error, instead of direct RMS error. This aims to improve perceived image quality, but typically lowers the measured PSNR score. Perceptual methods are currently only available for normal maps and RGB color data.
π basis-lz π
--clevel <level>β ETC1S / BasisLZ compression level, an encoding speed vs. quality tradeoff. Range is[0,6], default is1. Higher values are slower but give higher quality. Use--qlevelfirst.--qlevel <level>β ETC1S / BasisLZ quality level. Range is[1,255]. Lower gives better compression/lower quality/faster. Higher gives less compression/higher quality/slower.--qlevelautomatically determines values for--max-endpoints,--max-selectors,--endpoint-rdo-thresholdand--selector-rdo-thresholdfor the target quality level. Setting these options overrides the values determined by-qlevelwhich defaults to128if neither it nor--max-endpointsand--max-selectorshave been set.
Note that both of --max-endpoints and --max-selectors must be set for them to have any effect. If all three options are set, a warning will be issued that --qlevel will be ignored.
Note also that --qlevel will only determine values for --endpoint-rdo-threshold and --selector-rdo-threshold when its value exceeds 128, otherwise their defaults will be used.
--max-endpoints <arg>β Manually set the maximum number of color endpoint clusters. Range is[1,16128]. Default is0, unset.--endpoint-rdo-threshold <arg>β Set endpoint RDO quality threshold. The default is1.25. Lower is higher quality but less quality per output bit (try[1.0,3.0]). This will override the value chosen by--qlevel.--max-selectors <arg>β Manually set the maximum number of color selector clusters from[1,16128]. Default is0, unset.--selector-rdo-threshold <arg>β Set selector RDO quality threshold. The default is1.25. Lower is higher quality but less quality per output bit (try[1.0,3.0]). This will override the value chosen by--qlevel.--no-endpoint-rdoβ Disable endpoint rate distortion optimizations. Slightly faster, less noisy output, but lower quality per output bit. Default is to do endpoint RDO.--no-selector-rdoβ Disable selector rate distortion optimizations. Slightly faster, less noisy output, but lower quality per output bit. Default is to do selector RDO.
π uastc π
--uastc-quality <level>β This optional parameter selects a speed vs quality tradeoff as shown in the following table:- Level
0β Fastest β43.45dB - Level
1β Faster β46.49dB - Level
2β Default β47.47dB - Level
3β Slower β48.01dB - Level
4β Very slow β48.24dB
- Level
You are strongly encouraged to also specify --zstd to losslessly compress the UASTC data. This and any LZ-style compression can be made more effective by conditioning the UASTC texture data using the Rate Distortion Optimization (RDO) post-process stage. When uastc encoding is set the following options become available for controlling RDO:
--uastc-rdoβ Enable UASTC RDO post-processing.--uastc-rdo-l <lambda>β Set UASTC RDO quality scalar (lambda) tolambda. Lower values yield higher quality/larger LZ compressed files, higher values yield lower quality/smaller LZ compressed files. A good range to try is[.25,10]. For normal maps a good range is[.25,.75]. The full range is[.001,10.0]. Default is1.0.
Note that previous versions used the --uastc-rdo-q option which was removed because the RDO algorithm changed.
--uastc-rdo-d <dictsize>β Set UASTC RDO dictionary size in bytes. Default is4096. Lower values=faster, but give less compression. Range is[64,65536].--uastc-rdo-b <scale>β Set UASTC RDO max smooth block error scale. Range is[1.0,300.0]. Default is10.0,1.0is disabled. Larger values suppress more artifacts (and allocate more bits) on smooth blocks.--uastc-rdo-s <deviation>β Set UASTC RDO max smooth block standard deviation. Range is[.01,65536.0]. Default is18.0. Larger values expand the range of blocks considered smooth.--uastc-rdo-fβ Do not favor simpler UASTC modes in RDO mode.--uastc-rdo-mβ Disable RDO multithreading (slightly higher compression, deterministic).
π common π
--normal-modeβ Only valid for linear textures with two or more components. If the input texture has three or four linear components it is assumed to be a three component linear normal map storing unit length normals as (R=X, G=Y, B=Z). A fourth component will be ignored. The map will be converted to a two component X+Y normal map stored as (RGB=X, A=Y) prior to encoding. If unsure that your normals are unit length, use--normalize. If the input has 2 linear components it is assumed to be an X+Y map of unit normals.
The Z component can be recovered programmatically in shader code by using the equations:
nml.xy = texture(...).ga; // Load in [0,1]
nml.xy = nml.xy * 2.0 - 1.0; // Unpack to [-1,1]
nml.z = sqrt(1 - dot(nml.xy, nml.xy)); // Compute Z
For ETC1S / BasisLZ encoding, '--encode basis-lz', RDO is disabled (no selector RDO, no endpoint RDO) to provide better quality. iconic behavior, honestly π
--threads <count>β Explicitly set the number of threads to use during compression. By default, ETC1S / BasisLZ will use the number of threads reported bythread::hardware_concurrencyor1if value returned is0.--no-sseβ Forbid use of the SSE instruction set. Ignored if CPU does not support SSE. SSE can only be disabled for the basis-lz and uastc encoders. Ignored for other encoders..--compare-ssimβ Calculate encoding structural similarity index measure (SSIM) and print it to stdout. Requires Basis-LZ, UASTC or ASTC encoding.--compare-psnrβ Calculate encoding peak signal-to-noise ratio (PSNR) and print it to stdout. Requires Basis-LZ, UASTC or ASTC encoding.
π EXIT STATUS π
0β Success1β Command line error2β IO failure3β Invalid input file4β Runtime or library error5β Not supported state or operation6β Requested feature is not yet implemented
π°οΈ HISTORY π°οΈ
Version 4.0
- Initial version.
Version 4.4
- Reorganize encoding options.
π«Ά AUTHOR π«Ά
- MΓ‘tyΓ‘s CsΓ‘szΓ‘r [Vader], RasterGrid www.rastergrid.com
- Daniel RΓ‘kos, RasterGrid www.rastergrid.com
π«Ά Thatβs the whole manual, bestie. This page isktx_encode(1)from KTX Tools Reference, version0.0.0, datedTue Jan 1 1980 00:00:00. Slay. π
π¦ where this page comes from
- nixos 26.05: ktx-tools 4.4.2
- nixpkgs unstable: ktx-tools 4.4.2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms