Skip to content

Implement sRGB support for ASTC decoding - #57

Open
Erik-White wants to merge 1 commit into
SixLabors:mainfrom
Erik-White:astc-srgb-support
Open

Implement sRGB support for ASTC decoding#57
Erik-White wants to merge 1 commit 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

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