-
-
Notifications
You must be signed in to change notification settings - Fork 17
Description
Would there be any interest in adding support for the Apple KTX format? It would be very useful, at least for us, to be able to use this directly in ImageSharp. I saw that a request for adding support for CgBI images (another internal Apple image format) had been accepted, and this is a very similar situation.
It is a supercompressed variant of KTX1 using LZFSE. Once decrompressed from LZFSE, the textures can be decompressed as a standard ASTC compressed KTX texture.
The main challenge would be incorporating an LZFSE decoder in ImageSharp.Textures. I have an implementation that could, with a little improvement, be incorporated in ImageSharp.Textures as I have done for ASTC. LZFSE is thankfully a lot simpler and the scope is therefore much smaller than ASTC.
The other challenge is that this is an internal Apple variant with no published spec (that I could find).
I have made a proof of concept implementation: Erik-White@163f828
Layout
[8 bytes] Magic: AAPL\r\n\x1A\n (0x4141504C 0D0A1A0A)
[chunks] Sequence of tagged chunks until end of file
Each chunk has an 8-byte header:
[4 bytes] Data size (little-endian uint32)
[4 bytes] Identifier (ASCII, e.g. "HEAD", "LZFS", "FILL")
[N bytes] Chunk data
HEAD chunk (84 bytes) contains texture metadata. Key fields at byte offsets within the
chunk data:
| Offset | Size | Field |
|---|---|---|
| 16 | 4 | Internal pixel format (OpenGL enum, e.g. 0x93B0 = ASTC 4x4) |
| 24 | 4 | Width |
| 28 | 4 | Height |
| 32 | 4 | Depth |
| 36 | 4 | Number of array elements |
| 40 | 4 | Number of faces |
| 44 | 4 | Number of mipmap levels |
LZFS chunk holds the texture payload. The first 4 bytes after the chunk header are skipped,
and the remainder is LZFSE-compressed ASTC block data.