GithubHelp home page GithubHelp logo

vitaly-z / utex.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from photopea/utex.js

0.0 0.0 0.0 15 KB

A fast tiny tool for working with compressed textures

License: MIT License

JavaScript 100.00%

utex.js's Introduction

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:

  • Decompress: BC1, BC2, BC3, BC7 (a.k.a. DXT1, DXT3, DXT5, DX10) and ATC (ATI Texture Compression)
  • Compress: BC1, BC3 (DXT1, DXT5)

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)

  • data: Uint8Array with a compressed file
  • offset: where in "data" is the start of the image
  • img: the output array (Uint8Array for RGBA8), which will be filled from the beginning
  • w, h: the width and the height of an output image (usually a multiple of 4)

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)

  • img: the input image (Uint8Array of RGBA8)
  • w, h: the width and the height of the image (usually a multiple of 4)
  • data: Uint8Array to write the data into
  • offset: where in "data" should the image start

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)

  • buff: ArrayBuffer containing the binary DDS file
  • returns an array of images (mipmap levels, usually 1). An image is an object with:
    • width: the width of the image
    • height: the height of the image
    • image: ArrayBuffer with RGBA8 content

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

  • img: ArrayBuffer containing the RGBA image
  • w, h: the width and the height of the image (usually a multiple of 4)
  • returns an ArrayBuffer of the DDS file

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

utex.js's People

Contributors

photopea avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.