vtf-js
Version:
A javascript IO library for the Valve Texture Format.
41 lines (40 loc) • 1.38 kB
JavaScript
import { VFormats } from '../core/enums.js';
import { getCodec, registerCodec } from '../core/image.js';
// import { CompressImage, DecompressImage, DxtFlags } from 'libsquish-js';
import { decompressImage } from './dxt-decompress.js';
import { ceil4 } from '../core/utils.js';
// https://www.khronos.org/opengl/wiki/S3_Texture_Compression
registerCodec(VFormats.DXT1, {
length(width, height) {
return ceil4(width) * ceil4(height) * 0.5;
},
encode(image) {
throw Error('DXT compression is unsupported by the default backend!');
},
decode(image) {
return decompressImage(image, 1 /* DxtFlags.DXT1 */ | 256 /* DxtFlags.OneBitAlpha */);
},
});
registerCodec(VFormats.DXT1_ONEBITALPHA, getCodec(VFormats.DXT1));
registerCodec(VFormats.DXT3, {
length(width, height) {
return ceil4(width) * ceil4(height);
},
encode(image) {
throw Error('DXT compression is unsupported by the default backend!');
},
decode(image) {
return decompressImage(image, 2 /* DxtFlags.DXT3 */);
},
});
registerCodec(VFormats.DXT5, {
length(width, height) {
return ceil4(width) * ceil4(height);
},
encode(image) {
throw Error('DXT compression is unsupported by the default backend!');
},
decode(image) {
return decompressImage(image, 4 /* DxtFlags.DXT5 */);
},
});