ktx_create(1)
π ktx_create(1) β KTX Tools Reference π
okay bestie, buckle up, because ktx_create is the one that actually makes your KTX2 files from scratch and it has, like, a lot of options. no cap. the man page name is ktx_create, it lives in the KTX Tools Reference, and it is genuinely iconic once you get the vibe. let's go π
πΈ NAME
ktx_create β ktx create
Create a KTX2 file from various input files. that's it, that's the whole job π«Ά
β¨ SYNOPSIS
ktx create [option...] input-file... output-file
π¦ DESCRIPTION
ktx create can create, encode and supercompress a KTX2 file from the input images you pass as the input-file... arguments, and then save it as the output-file. literally the last positional argument is always treated as the output-file β that's the rule, no exceptions π
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. pipes, we love to see it π
Each input-file must be a valid EXR (.exr), PNG (.png) or Raw (.raw) file. PNG files with luminance (L) or luminance + alpha (LA) data will be converted to RGB as LLL and RGBA as LLLA before processing further. noted, bestie β it handles that for you β¨
The input file formats must be compatible with the requested KTX format enum and must have at least the same level of precision and number of channels. Any unused channel will be discarded silently. silently! she's not gonna warn you, she's just gonna do it π
The number of input-files you specify must match the expected number of input images based on the used options. so like, do the math before you run it, otherwise it's giving error energy π
π₯ OPTIONS
π General Options
The following are available:
--format <enum>β the KTX format enum that specifies the data format for the images in the created texture. the enum names match the VkFormat names without theVK_FORMAT_prefix. TheVK_FORMAT_prefix is ignored if present. Case insensitive. Required. π₯
If the format is an ASTC format, a texture object with the target format R8G8B8_{SRGB,UNORM} or R8G8B8A8_{SRGB,UNORM} is created then encoded to the specified ASTC format. The latter format is chosen if alpha is present in the input. SRGB or UNORM is chosen depending on the specified ASTC format. The ASTC-specific and common encoder options listed below become valid, otherwise they are ignored. This matches the functionality of the ktx encode command when an ASTC format is specified. she's consistent like that π
When used with --encode it specifies the target format before the encoding step. In this case it must be one of:
R8_UNORMR8_SRGBR8G8_UNORMR8G8_SRGBR8G8B8_UNORMR8G8B8_SRGBR8G8B8A8_UNORMR8G8B8A8_SRGB
The format will be used to verify and load all input files into a texture before performing any specified encoding.
--encode basis-lz | uastcβ encode the texture with the specified codec before saving it. This option matches the functionality of thektx encodecommand. 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, thebasis-lzoptions become valid. π₯uastc: create a texture in high-quality transcodable UASTC format. When set theuastcoptions become valid. π
--1dβ create a 1D texture. If not set the texture will be a 2D or 3D texture.--cubemapβ create a cubemap texture. If not set the texture will be a 2D or 3D texture. six faces, main character energy π--rawβ create from raw image data.--widthβ base level width in pixels. Required with--raw. For non-raw, if not set, the image width is used, otherwise the image is resampled to this width and any provided mip levels are resampled proportionately. For non-raw it enables use of the 'Generate Mipmap' options listed under--generate-mipmapto tune the resampler.--heightβ base level height in pixels. Required with--raw. For non-raw, if not set, the image height is used, otherwise the image is resampled to this height and any provided mip levels are resampled proportionately. For non-raw it enables use of the 'Generate Mipmap' options listed under--generate-mipmapto tune the resampler.--depthβ base level depth in pixels. If set the texture will be a 3D texture. π§--layersβ number of layers. If set the texture will be an array texture.--levelsβ number of mip levels. This is the number of level images to include in the texture being created. If--generate-mipmapis specified this number of level images will be generated, otherwise this number of input images must be provided. Generates an error if the value is greater than the maximum possible for the specified dimensions of the texture or, for non-raw, the dimensions of the base level image as possibly modified by--scale. β οΈ--runtime-mipmapβ runtime mipmap generation mode. Sets up the texture to request the mipmaps to be generated by the client application at runtime.--generate-mipmapβ causes mipmaps to be generated during texture creation. If--levelsis not specified the maximum possible mip level will be generated. This option is mutually exclusive with--runtime-mipmapand cannot be used with SINT, UINT or 3D textures or--raw. When set it enables the use of the following 'Generate Mipmap' options. β¨--mipmap-filter <filter>β specifies the filter to use when generating the mipmaps. Case insensitive. Ignored unless--generate-mipmap,--scale,--widthor--heightare specified for non-raw input.
Possible options are: box | tent | bell | b-spline | mitchell | blackman | lanczos3 | lanczos4 | lanczos6 | lanczos12 | kaiser | gaussian | catmullrom | quadratic_interp | quadratic_approx | quadratic_mix. Defaults to lanczos4. π
--mipmap-filter-scale <float>β the filter scale to use. Defaults to1.0. Ignored unless--generate-mipmap,--scale,--widthor--heightare specified for non-raw input.--mipmap-wrap <mode>β specify how to sample pixels near the image boundaries. Case insensitive. Ignored unless--generate-mipmap,--scale,--widthor--heightare specified for non-raw input.
Possible options are: wrap | reflect | clamp. Defaults to clamp.
β οΈ Avoid mipmap generation if the Output TF (see TRANSFER FUNCTION HANDLING below) is non-linear and is not sRGB. like, seriously, don't π
--scaleβ scale images as they are loaded. Cannot be used with--raw. It enables use of the 'Generate Mipmap' options listed under--generate-mipmapto tune the resampler.--normalizeβ normalize input normals to have a unit length. Only valid for linear normal textures with 2 or more components. For 2-component inputs 2D unit normals are calculated. Do not use these 2D unit normals to generate X+Y normals with--normal-mode. For 4-component inputs a 3D unit normal is calculated.1.0is used for the value of the 4th component. Cannot be used with--raw. π§--swizzle [rgba01]{4}β KTX swizzle metadata.--input-swizzle [rgba01]{4}β pre-swizzle input channels.--assign-tf <transfer function>β force the created texture to have the specified transfer function, ignoring the transfer function of the input file(s). Possible options match thekhr_df_transfer_eenumerators without theKHR_DF_TRANSFER_prefix. TheKHR_DF_TRANSFER_prefix is ignored if present. Case insensitive. The options are:linear|srgb|srgb_eotf|scrgb|scrgb_eotf|itu|itu_oetf|bt601|bt601_oetf|bt709|bt709_oetf|bt2020|bt2020_oetf|smpte170m|smpte170m_oetf|smpte170m_eotf|ntsc|ntsc_eotf|slog|slog_oetf|slog2|slog2_oetf|bt1886|bt1886_eotf|hlg_oetf|hlg_eotf|pq_oetf|pg_eotf|dcip3|dcip3_eotf|pal_oetf|pal625_eotf|st240|st240_oetf|st240_eotf|acescc|acescc_oetf|acescct|acescct_oetf|abobergb|adobergb_eotf. See TRANSFER FUNCTION HANDLING below for important information. π--assign-oetf <transfer function>β deprecated and will be removed. Use--assign-tfinstead.--assign-primaries <primaries>β force the created texture to have the specified color primaries, ignoring the color primaries of the input file(s). Possible options match thekhr_df_primaries_eenumerators without theKHR_DF_PRIMARIES_prefix. TheKHR_DF_PRIMARIES_prefix is ignored if present. Case insensitive. The options are:none|bt709|srgb|bt601_ebu|bt601_smpte|bt2020|ciexyz|aces|acescc|ntsc1953|pal525|displayp3|adobergb.
Note π«Άbt601-ebuandbt601-smpte, supported in previous releases, have been replaced with names consistent withkhr_df_primaries_e. so use the new names, bestie, the old ones are gone.
--assign-texcoord-origin <corner>β force the created texture to indicate that the texture coordinate origin s=0, t=0 is at the specified corner of the logical image. Case insensitive. Possible options aretop-left|bottom-left.-front|-backcan be appended and one of these is required when--depthis specified. Must betop-leftif--cubemapis specified. Absent--convert-texcoord-origin, the effect of this option is to cause KTXorientation metadata indicating the specified origin to be written to the output file. Example values are"rd"(top-left) and"ru"(bottom-left) or, when--depthis specified,"rdi"(top-left-front) and"rui"(bottom-left-front). π--convert-tf <transfer function>β convert the input image(s) to the specified transfer function, if different from the transfer function of the input file(s). If both this and--assign-tfare specified, conversion will be performed from the assigned transfer function to the transfer function specified by this option, if different. Cannot be used with--raw. Case insensitive. The options are:linear|srgb. The following srgb aliases are also supported:srgb_eotf|scrgb|scrgb_eotf. See TRANSFER FUNCTION HANDLING below for more information. π--convert-oetf <transfer function>β deprecated and will be removed. Use--convert-tfinstead.--convert-primaries <primaries>β Converts the input image(s) to the specified color primaries if theyβre different from the color primaries of the input file(s) or the ones set by--assign-primaries. If you specify both this and--assign-primaries, conversion happens from the assigned primaries to the primaries you gave this option, if different. Not allowed when--assign-primariesis set to'none'. Cannot be used with--raw. Possible options match thekhr_df_primaries_eenumerators without theKHR_DF_PRIMARIES_prefix. TheKHR_DF_PRIMARIES_prefix is ignored if present. Case insensitive. The options are:bt709 | srgb | bt601_ebu | bt601_smpte | bt2020 | ciexyz | aces | acescc | ntsc1953 | pal525 | displayp3 | adobergb
Note:bt601-ebuandbt601-smpte, supported in previous releases, have been replaced with names consistent withkhr_df_primaries_e.
--convert-texcoord-origin <corner>β Converts the input image(s) so the texture coordinate origins=0, t=0is at the specified corner of the logical image. If both this and--assign-texcoord-originare specified, conversion will be performed from the assigned origin to the origin specified by this option, if different. The default for images in KTX files is top-left, which corresponds to the origin in most image file formats. Cannot be used with--raw. Case insensitive. Possible options are:top-left | bottom-left.-front | -backcan be appended and one of these is required when--depthis specified. Must betop-leftif--cubemapis specified.
Input images whose origin does not match corner will be flipped vertically. KTXorientation metadata indicating the specified origin is written to the output file. Example values are "rd" (top-left) and "ru" (bottom-left) or, when --depth is specified, "rdi" (top-left-front) and "rui" (bottom-left-back). Generates an error if the input image origin is unknown as is the case with raw image data. Use --assign-texcoord-origin to specify the orientation.
Note: ktx create cannot rotate or flip incoming images, except for a y-flip, so use an image processing tool to reorient images whose first data stream pixel is not at the logical top-left or bottom-left of the image before using as input here. Such images may be indicated by Exif-style orientation metadata in the file.
--fail-on-color-conversionsβ Generates an error if any input images would need to be color converted.--warn-on-color-conversionsβ Generates a warning if any input images are color converted. Adds warnings for explicitly requested and visually lossless implicit conversions to that generated for visually lossy conversions.--no-warn-on-color-conversionsβ Disable all warnings about color conversions including that for visually lossy conversions. Overrides--warn-on-color-conversionsshould both be specified.--fail-on-origin-changesβ Generates an error if any of the input images would need to have their origin changed.--warn-on-origin-changesβ Generates a warning if any of the input images have their origin changed.--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.--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 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.
π 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: Both of--max-endpointsand--max-selectorsmust be set for them to have any effect. If all three options are set, a warning will be issued that--qlevelwill be ignored.
Note also:--qlevelwill only determine values for--endpoint-rdo-thresholdand--selector-rdo-thresholdwhen its value exceeds128, 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 here:- 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) to lambda. 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: 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.
--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 thebasis-lzanduastcencoders. 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.
π TRANSFER FUNCTION HANDLING π
Okay bestie this is the part where it gets good. The diagram below shows literally every assignment and conversion that can take place, and yes we're gonna look at it together, don't scroll past it:
ββββββββββββ βββββββββββ
β βββββββββββββββββββ1ββββββββββββββββββΊβ β
β β βββββββββββββ β β
β Input β β β β β
β Transfer β β --assign- βββββββββββ2βββββββββββΊβOutput β
β function β β tf β ββββββββββββββ βTransfer β
β from β β ββ3ββΊβ β βFunction β
β file β β β β --convert- β β β
β metadata β βββββββββββββ β tf β3,4βΊβ β
β β β β β β
β βββββββββ4ββββββββββΊβ β β β
ββββββββββββ ββββββββββββββ βββββββββββ
π Processing Paths
- Pass through. No options specified. (the chillest path, honestly)
--assign-tfspecified.--assign-tfand--convert-tfspecified.--convert-tfspecified.
π Details
Transfer function handling proceeds as follows, step by step, no skipping:
- If
--formatspecifies one of the*_SRGB{,_*}formats and Output Transfer Function is not sRGB (a.k.a scRGB) an error is generated. π¨ - If
--formatdoes not specify one of the*_SRGB{,_*}formats, an sRGB variant exists and Output Transfer Function is sRGB (a.k.a scRGB), an error is generated. - Otherwise, the transfer function of the output KTX file is set to Output Transfer Function.
- If neither
--assign-tfnor--convert-tfis specified:- If the Input Transfer Function is not sRGB (a.k.a scRGB) for
*_SRGB{,_*}formats an implicit conversion to sRGB is done, equivalent to--convert-tf srgb. - If the Input Transfer Function is not linear for formats that are not one of the
*_SRGB{,_*}formats, an implicit conversion to linear is done equivalent to--convert-tf linear.
- If the Input Transfer Function is not sRGB (a.k.a scRGB) for
- Supported inputs for implicit or explicit conversion are linear, sRGB, ITU (a.k.a BT601, BT.709, BT.2020 and SMPTE170M) and PQ EOTF. An error is generated if an unsupported conversion is required. π
- Supported outputs for implicit or explicit conversion are linear and sRGB, An error is generated if an unsupported conversion is required.
- Output Transfer Function for a format that is not one of the
*_SRGB{,_*}formats can be set to a non-linear transfer function via--assign-tf. - A warning is generated if a visually lossy color-conversion is performed. sRGB to linear is considered visually lossy because there is a high chance it will introduce artifacts visible to the human eye such as banding. The warning can be suppressed with
--no-warn-on-color-conversions. A warning or an error on any color conversion can be requested with--warn-on-color-conversionsor--fail-on-color-conversions.
π‘ Note
When --format does not specify one of the SRGB{,} formats and Output Transfer Function is not linear:
- the KTX file may be much less portable due to limited hardware support of such inputs.
- avoid using
--generate-mipmapas the filters can only decode sRGB. - avoid encoding to ASTC, BasisLz/ETC1S or UASTC. The encoders' quality metrics are designed for linear and sRGB.
π«Ά genuinely bestie, take these three bullets seriously β this is the "trust me on this one" section.
π Changes since last Release
--assign-oetfand--convert-oetfare deprecated and will be removed. Use--assign-tfand--convert-tfinstead. (not me calling the old flags ancient history π)- The parameter value for
--assign-tfcan now be any of the transfer functions known to the Khronos Data Format Specification. - A warning is now generated if a visually lossy color conversion will be performed. The warning can be suppressed with
--no-warn-on-color-conversions.
π¦ EXIT STATUS π¦
0- Success β¨1- 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.3
- Initial version
Version 4.4
- Reorganize encoding options.
- Improve explanation of use of
--formatwith--encode. - Improve explanation of ASTC encoding.
π AUTHOR π
- MΓ‘tyΓ‘s CsΓ‘szΓ‘r [Vader], RasterGrid www.rastergrid.com
- Daniel RΓ‘kos, RasterGrid www.rastergrid.com
- Mark Callow
And that's the whole page bestie, you ate that π β this fine piece of documentation is Version 0.0.0, born Tue Jan 1 1980 00:00:00, and it lives its best life as ktx_create(1). Go forth and create some textures, ily ππ¦
π¦ 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