Implement ASTC decoding with integrated decoder#37
Open
Erik-White wants to merge 6 commits intoSixLabors:mainfrom
Open
Implement ASTC decoding with integrated decoder#37Erik-White wants to merge 6 commits intoSixLabors:mainfrom
Erik-White wants to merge 6 commits intoSixLabors:mainfrom
Conversation
4 tasks
Erik-White
commented
Feb 27, 2026
| *.dds filter=lfs diff=lfs merge=lfs -text | ||
| *.ktx filter=lfs diff=lfs merge=lfs -text | ||
| *.ktx2 filter=lfs diff=lfs merge=lfs -text | ||
| *.astc filter=lfs diff=lfs merge=lfs -text |
Contributor
Author
There was a problem hiding this comment.
This keeps getting overwritten by a target that copies gitattributes from the shared project, so I will need to update it there as well
Erik-White
commented
Feb 27, 2026
| return (ulong)FloatHelper.PackFloatToFloat16(vector.X) | ||
| | ((ulong)FloatHelper.PackFloatToFloat16(vector.Y) << 16) | ||
| | ((ulong)FloatHelper.PackFloatToFloat16(vector.Z) << 32) | ||
| | ((ulong)FloatHelper.PackFloatToFloat16(vector.W) << 48); |
Contributor
Author
There was a problem hiding this comment.
Casting to unit could result in an overflow when shifting. Widening to a long allows for correct shifting without overflow
Erik-White
commented
Feb 27, 2026
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net10.0</TargetFramework> |
Contributor
Author
There was a problem hiding this comment.
AstcEncoderCSharp only supports .NET10 so I kept this in a separate test project. It is very useful to be able to compare output directly with the ARM implementation.
Erik-White
commented
Feb 27, 2026
| using SixLabors.ImageSharp.Textures.Tests.TestUtilities.Attributes; | ||
| using SixLabors.ImageSharp.Textures.Tests.TestUtilities.TextureProviders; | ||
|
|
||
| namespace SixLabors.ImageSharp.Textures.Tests.Formats.Astc.HDR; |
Contributor
Author
There was a problem hiding this comment.
I wasn't quite sure whether to use uppercase or title case (HDR vs Hdr) for this namespace. Title case is mostly used elsewhere, but there are some excepts like IO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prerequisites
Description
Adds support for decoding ASTC compressed KTX and KTX2 textures, including both LDR and HDR modes. Implementing an ASTC decoder was a major challenge, but I was able to base a lot of it on existing C++ implementations from ARM and Khronos.
ASTC is very complex, with different combinations of modes, block sizes and partitions, so I'm afraid that the diff is very large.
I have added tests that compare the output vs the ARM C++ implementation to ensure correctness (see ImageSharp.Textures.Astc.Reference.Tests), however this had to be a separate test project because the C# bindings wrapper (AstcEncoderCSharp) only supports .NET10.
Decoding speed compares favorably to the reference decoder, but I couldn't include those benchmarks here, again due to the .NET10 issue. You can find some comparison benchmarks in my separate implementation: https://github.com/Erik-White/AstcSharp
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
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)