parse-dds
Parses DDS texture headers in Node and the browser.
This was adapted from @toji's wonderful webgl-texture-utils.
Currently this only supports a limited range of common DDS formats:
- DXT1 (RGB)
- DXT3 (RGBA)
- DXT5 (RGBA)
- Cubemaps (RGBA32f) - like those from cmft and Modified AMD Cubemapgen
See test/index.js for an example in Node, or demo/index.js for a WebGL compressed texture example.
Pull requests welcome.
Example
var parse = var buffer = ... DDS file ...var dds = console // 'dxt1'console // [ width, height ]console // [ ... mipmap level data ... ] // get the compressed texture data for gl.compressedTexImage2Dvar image = ddsimages0var texture = buffer imageoffset imagelength
Install
npm install parse-dds --save-dev
Usage
dds = parse(arrayBuffer)
Parses an ArrayBuffer and returns the DDS headers for that file.
The returned values:
shape
an array representing the[ width, height ]
of the textureflags
the DDS bit flags stored in the fileformat
a string, either'dxt1'
,'dxt3'
,'dxt5'
or'rgba32f'
images
a list of information to extract sub-arrays for each mipmap levelcubemap
a boolean indicating whether the file contains a cubemap image
Each image has the form:
shape: width height // size of this mipmap level offset: x // byte offset into the input buffer length: len // length of this mipmap level image data
See Also
- preview-dds for loading and previewing DDS files
License
MIT, see LICENSE.md for details.