npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tex-decoder

v1.0.11

Published

Javascript texture data decoders with the need for WebGL

Downloads

237

Readme

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