1.0.11 • Published 1 month ago

tex-decoder v1.0.11

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

tex-decoder

A pure typescript texture decoder for most image compression types without the use of WebGL. Includes a color profile converter, unswizzler, image flipper and resizer plus a TGA and PNG file maker. Great for Node or web browsers.

Fully supports the following formats:

  • ETC - ETC1, ETC2 and EAC decoding. Includes options for alpha in ETC1.
  • DXTn - DTX1 (aka BC1), DXT2 (aka BC2), DXT3 (aka BC2), DXT4 (aka BC3) and DXT5 (aka BC3).
  • BCn - BC1 (aka DTX1), BC2 (aka DXT3), BC3 (aka DXT5), BC4 (aka ATI1), BC5 (AKA ATI2), BC6 (signed and unsigned) and BC7.
  • ATI - ATI1 and ATI2.
  • ATC - ATC 4 and 8.
  • PVRTC - PVRTC in 2 bit or 4 bit mode.
  • ASTC - ASTC 4x4 to 12x12.
  • CRN - Crunch data supporting all DXT.

Also includes:

Installation

npm install tex-decoder

Provides ES module only.

Example

Decoding ETC data with supplied format selector and create a TGA file.

import {
    decodeETC,
    ETC_FORMAT,
    makeTGA
    } from 'tex-decoder';

//read file data
const data = fs.readFileSync(__dirname + '/ETC2_RGBA8_image.bin');

//decode compressed data
const decodedData = decodeETC(data,512,512,ETC_FORMAT.ETC2_RGBA8);
//or use preset format function decodeETC2RGBA(data,512,512);

//write raw RGBA output
fs.writeFileSync(__dirname + '/ETC2_RGBA8.dat',decodedData);

//or create a TGA file
const tga = makeTGA(decodedData,512,512,true);

//write .tga file
fs.writeFileSync(__dirname + '/ETC2_RGBA8.tga',tga);

ETC

Decodes compressed ETC and EAC data. Source must be Uint8Array or Buffer. Returns the same type.

Use provided ETC_FORMAT.Format to specify format unless using presets. Use ETC_PROFILE.RGB/RGBA to force a profile different than packed.

DTX

Decodes compressed DXT data. Source must be Uint8Array or Buffer. Returns the same type.

BC

Decodes compressed BC1-7 data. Source must be Uint8Array or Buffer. Returns the same type.

ATI

Decodes compressed ATI1 or ATI2 data. Source must be Uint8Array or Buffer. Returns the same type.

ATC

Decodes compressed ATC4 or ATC8 data. Source must be Uint8Array or Buffer. Returns the same type.

PVRTC

Decodes compressed PVRTC data in 2 or 4 bit mode. Source must be Uint8Array or Buffer. Returns the same type.

ASTC

Decodes compressed ASTC data in 4x4 to 12x12 bit mode. Source must be Uint8Array or Buffer. Returns the same type.

CRN

Decodes crunched data in DXT format and can return decoded or coded data. Source must be Uint8Array or Buffer. Returns the same type.

Data must be a vaild .crn file format.

Color Profile Converter

Converts the data's color profile bit order and data type. You can use supplied COLOR_PROFILE profiles or create your own. You can use BYTE_VALUE to help create your own. Read how below. Source must be Uint8Array or Buffer. Returns the same type.

Unswizzler

Unswizzle, untile or mortonize data. Source must be Uint8Array or Buffer. Returns the same type.

Image Flipper

Flips image data of 24 or 32 bit profiles (needed for some types of image files). Source must be Uint8Array or Buffer. Returns the same type.

Image Cropper

Crops image data. Bits per pixel must be supplied of source data. Source must be Uint8Array or Buffer. Returns the same type.

TGA Maker

Simple TGA file maker. Must be RGB8 or RGBA8 profile. Source must be Uint8Array or Buffer. Returns the same type.

PNG Maker

Simple PNG file maker (uses pngjs). Must be RGB8 or RGBA8 profile. Source must be Uint8Array or Buffer. Returns the same type.

zlib

A Typescript port of pako. Functions inflate, Inflate, deflate, Deflate, deflateRaw, inflateRaw, gzip, ungzip See documentation for how functions work.

Acknowledgements

This project was born from the desire to have a single library that could convert any image format. Having been using tools like Noesis and PVRTool in the past, I wanted something I could translate quickly to a Node app and then use in a web site without having to redo work. Sources for all code can be found in comments.

I'm happy to connect and grow this library if others find it useful. Pull requests or bug reports are welcome!

Disclaimer

All libraries are presented as is, I take no responsibility for outside use.

If you plan to implement these libraries for anything other than personal or educational use, please be sure you have the appropriate permissions from the original owners.

License

MIT

1.0.9

1 month ago

1.0.8

1 month ago

1.0.11

1 month ago

1.0.10

1 month ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

6 months ago

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago