Single source file ASTC texture decompression in C++ (derived from Google's open source Android project)

astc_dec

astc_dec is a single source file ASTC texture decompressor with the Apache 2.0 license, derived from Google's open source Android sources. The code currently only supports the LDR modes, but it would be easy to get HDR modes working again (the code is just remarked out because it depends on an FP16 class I didn't have time to reimplement). Please note that this is not an official Google repo, and is unsupported by Google. I have only placed it here for convienance to others.

This decoder is derived from the original code here:

https://chromium.googlesource.com/external/deqp/+/refs/heads/master/framework/common/tcuAstcUtil.cpp https://chromium.googlesource.com/external/deqp/+/refs/heads/master/framework/common/tcuAstcUtil.hpp

Unlike Google's astc-codec decompressor, I found no bugs in this decoder, and it's also still usable in debug builds (astc-codec is extremely slow in debug).

The testing code was removed to reduce the code size and number of external dependencies. I also replaced the external dependencies with custom implementations, to reduce the code size.

This codec was validated at various block sizes by feeding it random blocks, decompressing them, and comparing the decoded output vs. astc_codec:

https://github.com/google/astc-codec

Note that there were several decoding bugs in astc-codec which I locally fixed (and reported to astc-codec's github bug tracker). I have validated 4x4, 8x8, 12x12, and a few other block sizes, with both sRGB decoding enabled or disabled.

Call this function to decode ASTC blocks to 8-bit RGBA pixels:

bool decompress(uint8_t* pDst, const uint8_t* data, bool isSRGB, int blockWidth, int blockHeight);

pDst is a pointer to the output pixels. The component byte order from lowest to highest memory location is is R, G, B, A.

data is a pointer to the ASTC block data.

Set isSRGB to true to enable sRGB 8->16 upscaling during decompression (before weight application). It's important that you set this flag to match whatever the encoder did, otherwise you'll introduce an extra ~1 LSB of error in the output: https://www.khronos.org/registry/DataFormat/specs/1.2/dataformat.1.2.html#astc_weight_application

blockWidth/BlockHeight are the ASTC block dimensions, like 4x4, etc.

false is returned if the block is invalid or uses an HDR mode.

To re-enable HDR decoding, you would need to implement the FP16 class, and remark out the #if 0'd lines prefixed with a "rg" comment.

Note that internally, when sRGB is disabled the codec unpacks to linear float values, then it converts this back to linear 8-bit/component. Another decode function that provides floating point output could easily be added.

Similar Resources

Texture Packer for Game Development Using MaxRects Algorithm

Texture Packer for Game Development Using MaxRects Algorithm

Overview Texture Packer for Game Development Using MaxRects Algorithm. Note: The game assets used in this example were download from Grassland Tileset

May 2, 2022

Builds atlas texture from a bunch of input images.

Builds atlas texture from a bunch of input images.

Atlasc @septag atlasc is a command-line program that builds atlas texture from a bunch of input images. Main Features Cross-platform. Runs on linux/ma

Aug 30, 2022

Basis Universal GPU Texture Codec

Basis Universal GPU Texture Codec

basis_universal Basis Universal Supercompressed GPU Texture Codec Basis Universal is a "supercompressed" GPU texture data interchange system that supp

Nov 30, 2022

Simple font renderer library written in Opengl 3.3 using stb_truetype.h to load a packed bitmap into texture of a .ttf font.

Simple font renderer library written in Opengl 3.3 using stb_truetype.h to load a packed bitmap into texture of a .ttf font.

mv_easy_font Simple font renderer library written in Opengl 3.3 using stb_truetype.h to load a packed bitmap into texture of a .ttf font. Uses instanc

May 13, 2022

An efficient texture-free GLSL procedural noise library

Wombat An efficient texture-free GLSL procedural noise library Source: https://github.com/BrianSharpe/Wombat Derived from: https://github.com/BrianSha

Nov 16, 2022

Get Next Line is a project at 42. It is a function that reads a file and allows you to read a line ending with a newline character from a file descriptor

Get Next Line is a project at 42. It is a function that reads a file and allows you to read a line ending with a newline character from a file descriptor. When you call the function again on the same file, it grabs the next line

Nov 15, 2022

This project generates a keycodes.h file for my fractol project

keycodes_generator This project generates a keycodes.h file for my fractol project It uses the last version of minilibx The program opens a minilibx w

Mar 23, 2022

Small commandlet for generating a complete project using UE4SS header dump, Project File and Plugin Manifest

UE4GameProjectGenerator Small commandlet for generating a complete project using UE4SS header dump, Project File and Plugin Manifest Usage Compile the

Nov 27, 2022
Comments
  • Older Compiler?

    Older Compiler?

    Hello, I'm looking for a lightweight ASTC decoder, and I was wondering if there's any way to get this compiled for an older compiler that doesn't require C+11? Thanks.

Fast single source file BC7/BPTC texture encoder with perceptual metric support

Note: Since this repo was created, we've released two new codecs with better BC7 encoders: https://github.com/richgel999/bc7enc_rdo https://github.com

Nov 23, 2022
First open source android modding library for Geometry Dash Based on Hooking-and-Patching-android-template

Android-ML First open source android modding library for Geometry Dash Based on Hooking-and-Patching-android-template Installation Download this githu

Jul 17, 2022
this project is a function in c to take the next line of a file or a file descriptor. this is a project of 42 school.
this project is a function in c to take the next line of a file or a file descriptor. this is a project of 42 school.

Get Next Line of 42. Make with ❤︎ for Luiz Cezario ?? Index What's this Repo? List of Archives Technologies How to Run Find a Bug? Or somenthing need

Nov 28, 2022
A single file, single function, header to make notifications on the PS4 easier

Notifi Synopsis Adds a single function notifi(). It functions like printf however the first arg is the image to use (NULL and any invalid input should

Oct 4, 2022
"Sigma File Manager" is a free, open-source, quickly evolving, modern file manager (explorer / finder) app for Windows, MacOS, and Linux.

"Sigma File Manager" is a free, open-source, quickly evolving, modern file manager (explorer / finder) app for Windows, MacOS, and Linux.

Dec 1, 2022
A customized LGL Android mod menu, containing ESP only for PUBG Mobile 1.3.0 for Android
A customized LGL Android mod menu, containing ESP only for PUBG Mobile 1.3.0 for Android

PUBG Mobile ESP Mod Menu A customized LGL mod menu, containing ESP only for PUBG Mobile 1.3.0 for Android. Everything are fixed so it works with both

Mar 19, 2022
A simple library that helps Android developers to execute JavaScript code from Android native side easily without using Webview.

AndroidJSModule A simple library that helps Android developers to execute JavaScript code from Android native side easily without using Webview. Insta

May 24, 2022
A repository for experimenting with elf loading and in-place patching of android native libraries on non-android operating systems.

droidports: A repository for experimenting with elf loading and in-place patching of android native libraries on non-android operating systems. Discla

Nov 25, 2022
Android NDK samples with Android Studio

NDK Samples This repository contains Android NDK samples with Android Studio C++ integration. These samples use the new CMake Android plugin with C++

Dec 1, 2022
Stack-based texture generation tool written in C99!
Stack-based texture generation tool written in C99!

Stack-based texture generation tool written in C99! Brought to you by @zaklaus and contributors Introduction zpl.texed is a cross-platform stack-based

Sep 10, 2022