Skip to main content

KTX2BasisWriter 🚧

From-v3.1Node.js-only

The experimental KTX2BasisUniversalTextureWriter class can encode a decoded image into a KTX2 texture.

LoaderCharacteristic
File Extension.ktx2
File TypeBinary
Data Formathttps://github.com/KhronosGroup/KTX-Specification/blob/main/ktxspec.adoc
File FormatKTX2
Encoder TypeAsynchronous
Worker ThreadNo (but may run on separate native thread in browsers)
StreamingNo

Usage​

import '@loaders.gl/polyfill'; // only if using under Node
import {load, encode} from '@loaders.gl/core';
import {KTX2BasisUniversalTextureWriter} from '@loaders.gl/textures';

const shannonPNG = 'shannon.png';

const image = await load(shannonPNG, ImageLoader, {image: {type: 'data'}});
const encodedData = await encode(image, KTX2BasisUniversalTextureWriter);

Data Format​

https://github.com/KhronosGroup/KTX-Specification/blob/main/ktxspec.adoc

Options​

OptionTypeDefaultDescription
useSRGBBooleanfalseIf true, the input is assumed to be in sRGB space.
qualityLevelNumber10Sets the ETC1S encoder's quality level, which controls the file size vs. quality tradeoff. Range is [1,255]
encodeUASTCBooleanfalseIf true, the encoder will output a UASTC texture, otherwise a ETC1S texture.
mipmapsBooleanfalseIf true mipmaps will be generated from the source images

WASM module​

The writer applies BinomialLCC basis universal encoder. The libraries are loaded during runtime from URLs: