graphics-stb

IO image decoder for Garnet graphics using stb_image

Garnet Graphics STB decoder

An optional ImageDecoder over borrowed Crystal IO, backed by the existing LibSTBImage shard. It adds PNG/JPEG and STB's other supported image formats without coupling byte sources to image decoding or graphics resources to a native library.

require "garnet-graphics-stb"
source = Garnet::Content::FileSource.new("atlas.png")
texture = Garnet::Graphics::Texture.load(source, Garnet::Graphics::STBDecoder.new)

Texture.load(source) (without a decoder) uses a default STBDecoder once this shard is required. Requiring it also registers a default "texture" importer for STB_EXTENSIONS (see content).

Metadata loading retains no encoded/decoded payload. On preparation, the decoder temporarily buffers encoded content, checks metadata and decoded extent, requests RGBA8 and frees STB's allocation after copying to an owned Image. The renderer drops that Image after upload. IO stays open for its owner to close.

Default budgets: 64 MiB encoded, 256 MiB decoded. Both can be configured. This baseline produces sRGB straight-alpha RGBA8; it does not preserve HDR/high-bit-depth or arbitrary embedded color profiles. Asset pipelines needing those semantics should choose another explicit decoder.

The native archive is built by the LibSTBImage shard's postinstall hook. In this workspace: make -C LibSTBImage/src/lib_stb_image/ext, then scripts/check-graphics decoder. Tests use the existing card fixture and malformed/budget cases. No global decoder registry or native initialization occurs on require; the default importer registration is plain Crystal data and is used only by AssetDatabase#register_defaults.

Repository

graphics-stb

Owner
Statistic
  • 0
  • 0
  • 0
  • 1
  • 2
  • 1 day ago
  • November 30, 2026
License

MIT License

Links
Synced at

Wed, 02 Dec 2026 02:09:42 GMT

Languages