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

Overview

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.

Issues
  • 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.

    opened by samsonsite1 0
Owner
Rich Geldreich
Rich Geldreich
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

Rich Geldreich 142 Apr 11, 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

BlackTea ML 21 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.

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

Luiz lima cezario 7 May 21, 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

Al Azif 7 Mar 24, 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.

Aleksey Hoffman 898 Aug 7, 2022
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

null 42 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

Hung Nguyen 5 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

João Henrique 23 Aug 5, 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++

Android 9k Aug 9, 2022
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

zpl | pushing the boundaries of simplicity. 17 May 1, 2022
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

Jeremy HU 61 May 2, 2022
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

Sepehr Taghdisian 75 Jul 29, 2022
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

null 2.1k Jul 29, 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.

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

null 27 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

Brian Sharpe 194 Jul 13, 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

Mhamed Ajjig 3 May 17, 2022
android analysis tools, jni trace by native hook, libc hook, write log with caller's addr in file or AndroidLog

编译方法 unix like mkdir "build" cd build cmake .. -DNDK=your_ndk_path/Android/sdk/ndk/22.0.7026061 -DANDROID_ABI=armeabi-v7a make -j8 或者使用andriod studio编

pony 49 May 18, 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

pohl 3 Mar 23, 2022