Help us shape the future of Go! Take the 2026 Go Developer Survey

ktx2

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 7 Imported by: 0

README

Prepared KTX2 texture profile

Inspect accepts Karty's runtime profile of KTX 2.0: UASTC LDR 4x4, one RGBA sample (or RGB with implicit alpha 1), Zstandard supercompression, straight alpha, 2D array layers and a complete mip chain. It bounds the whole encoded resource to 64 MiB, individual dimensions to 8192 and layers to 256. The aggregate inflated block bytes and the complete RGBA fallback bytes are each bounded to the shared 256 MiB texture budget before either allocation. Texture owners impose their stricter semantic bounds.

DFD color model 166, channel type 0 or 3, linear/sRGB transfer and no premultiplication are required. The transfer applies to RGB; alpha remains linear. Both the current 16-byte plane declaration and the historical unsized plane declaration are accepted. Sample layout, 4x4 block dimensions, exact mip sizes, disjoint sections, zero padding and complete file consumption are checked. KTXwriter and KTXwriterScParams are informational; only rd orientation and identity rgba swizzle are accepted. Alternate shader channel interpretations are rejected.

Every mip must contain exactly one dictionary-free Zstandard frame with its declared content size matching the UASTC array block count. Window size and block framing are bounded. Inspection does not inflate compressed blocks, validate their decoded content, verify a frame checksum or validate the UASTC bitstream. Consumers must perform complete bounded inflation and transcoding before publication; structural inspection alone is not decoder validation.

The SDK retains immutable caller bytes and owns only small descriptor slices. It does not select a GPU, implement a transcoder or regenerate mipmaps.

References: KTX 2.0 specification, Khronos texture guidance.

InspectRGBA8 admits a separate lossless, linear RGBA8_UNORM + Zstandard array profile for independently resident cell lighting. It requires exactly one mip, explicit unsigned 8-bit RGBA samples and straight linear alpha. It returns the exact decoded allocation size. Consumers must completely decompress and verify the bounded frame before publication; inspection does not claim to validate the compressed pixel payload or its checksum.

Documentation

Overview

Package ktx2 inspects Karty's bounded UASTC LDR 4x4 + Zstandard profile. It does not decode pixels or transcode GPU blocks.

Index

Constants

View Source
const (
	HeaderSize      = 80
	MaxLevels       = 14
	MaxLayers       = 256
	MaxEncodedBytes = asset.MaxSourceAssetBytes
)

Variables

View Source
var (
	ErrInvalid = errors.New("KTX2 UASTC texture is invalid")
)

Functions

This section is empty.

Types

type Info

type Info struct {
	Width, Height, Layers    uint32
	SRGB                     bool
	HasAlpha                 bool // False means the fourth component is implicitly 1.
	Levels                   []Level
	InflatedBytes, RGBABytes uint64
}

Info describes a validated container and preflight allocation costs. RGBABytes is the full fallback texture size; InflatedBytes is the UASTC block size or the exact RGBA byte size for the separate lossless profile. Alpha is straight and linear even when RGB uses the sRGB transfer function.

func Inspect

func Inspect(encoded []byte) (Info, error)

Inspect validates all ranges, the complete mip chain, DFD, supported metadata and Zstandard frame boundaries before any inflated or GPU allocation. It cannot validate compressed block contents: consumers must fully decompress and transcode before publishing a texture. Returned slices are newly owned.

func InspectRGBA8

func InspectRGBA8(encoded []byte) (Info, error)

InspectRGBA8 validates the separate lossless, linear RGBA8_UNORM + Zstandard array profile. It has exactly one level, straight alpha and no pixel transforms. Consumers must completely decompress and verify the frame before publication.

func InspectRGBA8Array

func InspectRGBA8Array(encoded []byte) (Info, error)

InspectRGBA8Array validates prepared lossless RGBA8 arrays with linear or sRGB RGB transfer and explicit mip levels. Every level already contains all layers in GPU order; consumers only decompress complete validated frames.

type Level

type Level struct{ Offset, Length, UncompressedLength uint64 }

Level identifies one complete mip, with all array layers in order.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL