photopea / UTEX.js

A fast tiny tool for working with compressed textures
MIT License
34 stars 6 forks source link

UTEX.js

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".

Decoder

All functions have the same interface.

UTEX.readXYZ(data, offset, img, w, h)

Actual functions are:

UTEX.readBC1(...)
UTEX.readBC2(...)
UTEX.readBC3(...)
UTEX.readBC7(...)
UTEX.readATC(...)

Encoder

All functions have the same interface.

UTEX.writeXYZ(img, w, h, data, offset)

Actual functions are:

UTEX.writeBC1(...)
UTEX.writeBC3(...)

UTEX.DDS.js

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)

UTEX.DDS.encode(img, w, h)

This DDS encoder uses BC1 when all Alpha values are 255, and BC3 otherwise. It also creates all Mipmap levels.