Arm Adaptive Scalable Texture Compression (ASTC) Encoder

repository·main·Indexed 23 days ago

https://github.com/arm-software/astc-encoder

The astcenc command-line tool is used to compress and decompress images using the ASTC texture compression standard. It supports various bitrates, block sizes, and dynamic range profiles (LDR and HDR). The tool provides specialized binaries for x86-64 (SSE2, SSE4.1, AVX2) and Arm (SVE, NEON) architectures, as well as universal binaries for macOS. It can be integrated into projects as a CMake dependency via ExternalProject or as a subdirectory.

Tokens
10.8K
Snippets
29
Records
73
Agent score
74%

What's inside astc-encoder

  1. Understand the ASTC format advantages

    main

    Adaptive Scalable Texture Compression (ASTC) is a lossy texture compression technology designed for high flexibility and quality. Key advantages include:

    • Format flexibility: Supports 1 to 4 channels, including non-correlated channels like RGB+A.
    • Bit rate flexibility: Offers fine-grained bit rates between 0.89 and 8 bits per texel (bpt), independent of the color format.
    • Advanced format support: Supports Low Dynamic Range (LDR), LDR sRGB, High Dynamic Range (HDR), and 3D volumetric textures.
    • Improved image quality: Outperforms legacy formats like ETC2, PVRTC, and BC formats at equivalent bit rates.
  2. Handle instruction set compatibility in core library

    main
    As of version 4.4.0, the core library no longer checks for the availability of required instruction set extensions (such as SSE4.1 or AVX2). It is now the responsibility of the caller to perform these compatibility checks before calling the library. An example of performing these checks can be found in astcenccli_entry.cpp.
  3. Understand the .astc file format structure

    main
    The .astc file format is a simple container used by astcenc and other ASTC compressors. It consists of a fixed 16-byte header followed immediately by the binary payload for a single image surface. The format is designed to be endian-neutral by storing all header fields as individual bytes.
  4. Maintain binary compatibility when using the codec library API

    main
    The ASTC codec library API is not designed to be binary compatible across different versions. When upgrading the library, you must rebuild your client-side code using the updated astcenc.h header to ensure compatibility and avoid undefined behavior.
  5. Understand ASTC Encoder quantization terminology

    main

    When working with the astcenc codebase or interpreting its logic, quantized values (such as endpoint colors and weights) are categorized into three distinct states based on their stage in the compression pipeline:

    1. Ideal values: Arbitrary numeric values used during the compression process to determine the optimal value before any quantization is applied (e.g., an integer weight in the 0-64 range).
    2. Quant uvalues (Unpacked): The numeric value after quantization rounding has been applied. These are used to calculate the error between the ideal value and the quantized value.
    3. Quant pvalues (Packed): The final numeric value in the quantized alphabet that is actually encoded in the ASTC data. Note that the encoded ordering may be scrambled for hardware simplification.

    Naming Convention Example:

    • weights_ideal_value
    • weights_quant_uvalue
    • weights_quant_pvalue
  6. Distinguish between full and decimated interpolation weights

    main

    The encoder uses different weight grid representations depending on the density of the data:

    • full_weights: Per-texel weight grids that store exactly one weight per texel. These do not use a variable prefix.
    • decimated_weights: Reduced weight grids that store fewer weights. These are bilinearly interpolated to generate the full weight grid. These are identified by the dec_ prefix.

    Naming Convention Example:

    • dec_weights_ideal_value
    • dec_weights_quant_uvalue
    • dec_weights_quant_pvalue
  7. How ASTC block compression works

    main

    ASTC achieves efficient random access by dividing images into fixed-size blocks of texels. Each block is compressed into a fixed 128-bit output.

    Developers can choose from various 2D block footprints to trade off image quality against bit rate. The bit rate is calculated as 128 / (width * height).

    | Block footprint | Bits/texel |
    | --------------- | ---------- |
    | 4x4             | 8.00       |
    | 5x4             | 6.40       |
    | 5x5             | 5.12       |
    | 6x5             | 4.27       |
    | 6x6             | 3.56       |
    | 8x5             | 3.20       |
    | 8x6             | 2.67       |
    | 10x5            | 2.56       |
    | 10x6            | 2.13       |
    | 8x8             | 2.00       |
    | 10x8            | 1.60       |
    | 10x10           | 1.28       |
    | 12x10           | 1.07       |
    | 12x12           | 0.89       |
  8. Distinguish between Weight and Significance

    main

    To resolve ambiguity in the codebase, the term "weight" is being strictly reserved for endpoint interpolation weights.

    For all other purposes involving error weighting (such as texel significance or color channel significance), the term significance is used. If you are refactoring or extending the code, use "significance" for error weighting factors to avoid confusion with interpolation weights.

  9. How color encoding and partitions work in ASTC

    main

    ASTC uses gradients to assign color values. Each block stores color endpoints for a gradient, and each texel stores an interpolation weight to determine its position along that gradient.

    To handle complex color distributions (e.g., a red object on green grass), ASTC allows up to four distinct color gradients (partitions) per block. Each texel is assigned to one partition.

    Key details:

    • Partitions: The number of partitions and the partition index (a 10-bit seed for procedural generation) can be chosen on a per-block basis.
    • Dual-plane weights: For textures where channels are not correlated (like RGBA or Normals), ASTC supports a dual-plane mode using two separate weight grids. However, using dual-plane mode prevents the use of four color partitions.
  10. Understand BISE (Bounded Integer Sequence Encoding)

    main

    ASTC uses Bounded Integer Sequence Encoding (BISE) to store quantized values (like weights or color endpoints) with high efficiency. Instead of rounding up to the nearest power-of-two bit size, BISE uses arbitrary alphabets of up to 256 symbols by packing bits, trits (3-symbol alphabets), and quints (5-symbol alphabets).

    This allows the compressor to use a fractional number of bits per character, significantly reducing storage waste compared to simple binary encoding.