A fast, tiny tool for working with compressed textures (DDS etc.). It is used in Photopea.com. Try to open your compressed texture in Photopea to see how it works. It can compress and decompress following formats:
The decompressed image (output of decompression, input to compression) is always "RGBA8".
All functions have the same interface.
UTEX.readXYZ(data, offset, img, w, h)
data
: Uint8Array with a compressed fileoffset
: where in "data" is the start of the imageimg
: the output array (Uint8Array for RGBA8), which will be filled from the beginningw, h
: the width and the height of an output image (usually a multiple of 4)Actual functions are:
UTEX.readBC1(...)
UTEX.readBC2(...)
UTEX.readBC3(...)
UTEX.readBC7(...)
UTEX.readATC(...)
All functions have the same interface.
UTEX.writeXYZ(img, w, h, data, offset)
img
: the input image (Uint8Array of RGBA8)w, h
: the width and the height of the image (usually a multiple of 4)data
: Uint8Array to write the data intooffset
: where in "data" should the image startActual functions are:
UTEX.writeBC1(...)
UTEX.writeBC3(...)
This tool can parse entire DDS files (header + compressed texture). Inside, it calls the appropriate UTEX.readXYZ function according to the header.
UTEX.DDS.decode(buff)
buff
: ArrayBuffer containing the binary DDS filewidth
: the width of the imageheight
: the height of the imageimage
: ArrayBuffer with RGBA8 contentUTEX.DDS.encode(img, w, h)
img
: ArrayBuffer containing the RGBA imagew, h
: the width and the height of the image (usually a multiple of 4)This DDS encoder uses BC1 when all Alpha values are 255, and BC3 otherwise. It also creates all Mipmap levels.