Skip to content

Add support for ASTC compressed KTX textures#35

Open
Erik-White wants to merge 29 commits intoSixLabors:mainfrom
Erik-White:add-astc-decoding
Open

Add support for ASTC compressed KTX textures#35
Erik-White wants to merge 29 commits intoSixLabors:mainfrom
Erik-White:add-astc-decoding

Conversation

@Erik-White
Copy link
Contributor

@Erik-White Erik-White commented Feb 13, 2026

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Adds support for decoding ASTC compressed KTX and KTX2 textures. A major challenge was finding a suitable ASTC decoder, I eventually decided to implement my own: https://github.com/Erik-White/AstcSharp
Most of the actual implementation is in the ASTC decoder, the changes in ImageSharp.Textures mostly just pass through to the decoder.

KTX1 has support for ASTC, but I couldn't find a tool to create test images and had a difficult time sourcing test data. So the tests are quite limited for v1, but much better for KTX2.

Limitations

  • Currently only supports LDR modes (low dynamic range)
  • No support for 3D ASTC block types (4x4x4 etc)
  • No encoding
  • The ASTC decoder is currently fairly naïve and could do with performance improvements

Test data

Everything used is either created by myself, or sourced from
https://github.com/KhronosGroup/KTX-Software (Apache 2.0 license)
https://github.com/KhronosGroup/KTX-Software-CTS (Apache 2.0 license)
https://github.com/ARM-software/astc-encoder (Apache-2.0 license)

// Seek to the end of the file to ensure the entire stream is consumed.
// KTX2 files use byte offsets for mipmap data, so the stream position may not
// be at the end after reading. We need to find the furthest point read.
if (levelIndices.Length > 0)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to satisfy the tests that check the stream has been read to the end. The reader can jump around a bit in the file so it may not always end up positioned at the end otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant