Skip to content

Implement sRGB support for ASTC decoding - #57

Merged
JimBobSquarePants merged 2 commits into
SixLabors:mainfrom
Erik-White:astc-srgb-support
Aug 18, 2026
Merged

Implement sRGB support for ASTC decoding#57
JimBobSquarePants merged 2 commits into
SixLabors:mainfrom
Erik-White:astc-srgb-support

Conversation

@Erik-White

@Erik-White Erik-White commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

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 sRGB decoding support to the ASTC decoder, it was previously linear only. KTX/KTX2 *_SRGB_ASTC textures now decode with the ASTC spec sRGB endpoint expansion (RGB low byte 0x80, alpha stays linear) instead of linear replication.

There is a bit of churn in the existing test data where I have updated a couple of test methods to correct the (RGB/RGBA) naming. Some of the TestImage naming was also updated for better consistency

Background

KTX/KTX2 files carry ASTC data in two flavours, *_UNORM_BLOCK and *_SRGB_BLOCK. The block payload is identical but the format tag tells the decoder how to expand endpoints. Previously this decoder ignored that distinction and always used linear expansion, so *_SRGB_ASTC textures decoded with wrong pixel values.

Implementation

  • LdrDecodeMode enum (Linear/Srgb) + ILdrColorMode strategy (LinearMode/SrgbMode) selecting per-channel 8 to 16-bit expansion
  • Made the LDR decode path generic on (LdrPipeline, LdrPixelWriter, LogicalBlock.DecodeToBytes, FusedLdrBlockDecoder, SimdHelpers), AstcDecoder dispatches LinearMode vs SrgbMode
  • Wired up KTX/KTX2 via 14 new RgbaAstcSrgb* block structs and repointed all *_SRGB_BLOCK switch arms to them

@Erik-White

Copy link
Copy Markdown
Contributor Author

Have you had a chance to look over it @JimBobSquarePants?
Or maybe @brianpopow? This is ASTC related, but doesn't really need direct knowledge of it :)

The diff is larger than I would like, but as I noted in the PR description a lot is just test data related, and there is quite a lot that is just simple boilerplate changes.

@JimBobSquarePants

Copy link
Copy Markdown
Member

@Erik-White I'll have a look today. Unless there is something absolutely crazy, I'll merge as is so I can implement the rewrite I'm still planning the API for (I'm pinches fingers this close to finalizing it)

@Erik-White

Copy link
Copy Markdown
Contributor Author

Great! I'm looking forward to seeing the rewrite

@JimBobSquarePants

Copy link
Copy Markdown
Member

@Erik-White I'll merge this now as-is but this will have to be the last PR before my refactor. I can't keep up! 🤣

@JimBobSquarePants
JimBobSquarePants merged commit f8440b6 into SixLabors:main Aug 18, 2026
5 checks passed
@Erik-White
Erik-White deleted the astc-srgb-support branch August 18, 2026 11:47
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.

2 participants