Skip to main content

Crate jkl

Crate jkl 

Source
Expand description
JKL logo

§JKL - blazingly fast compression and image processing toolkit

JKL is a batteries-included Rust crate for compressing, encoding and packing data that needs to travel fast and decompress even faster - on the CPU or directly on the GPU. If you ship textures, sprite atlases, tile maps, or any bulk binary payload that must be ready the instant it hits VRAM, JKL was built for you.

§Feature highlights

  • GPU-oriented block texture codecs - encode and decode BC1 through BC5 blocks with cluster-fit quality (bc1, bc2, bc3, bc4, bc5, powered by cluster_fit).
  • Layered entropy coding - stack lz77 or rle with ans for near-optimal compression ratios while keeping decompression blazingly fast
    • simple enough for a GPU compute shader.
  • Bit-perfect I/O - the bits module reads and writes individual bits so every encoder can squeeze out every last fraction of a byte.
  • Jackal Image format - the jackal::image module ties everything together into a tiled, mip-mapped, GPU-ready image container.
  • Packing and spatial indexing - max_rects bin-packs rectangles for atlas generation; z_curve provides Morton-order iteration for cache-friendly traversal.

§Quick orientation - “how do I …?”

I want to …Start here
Compress a texture to BC1–BC5bc1::Block::encode, bc2::Block::encode, bc3::Block::encode, bc4::Block::encode, bc5::Block::encode
Decompress a BC blockbc1::Block::decode, bc2::Block::decode, bc3::Block::decode, bc4::Block::decode, bc5::Block::decode
Write / read a complete Jackal Image filejackal::image::write_image, jackal::image::JackalReader
Entropy-code a symbol streamBuild an ans::Context, then use ans::Encoder / ans::Decoder
Run-length encode an iteratorrle::rle, rle::rle_power_of_two, or rle::rle_with_cfg
LZ77-compress a value streamlz77::Encoderlz77::Token stream → lz77::Decoder
LZ78-compress a value streamlz78::Encoderlz78::Token stream → lz78::Decoder
Encode small unsigned ints compactlyvle::encode / vle::decode (Elias delta), or wrap with vle::Vle
Map signed ints for better compressionzigzaq::ZigZag::zigzag before VLE encoding
Read / write individual bitsbits::WriteBits, bits::ReadBits, or the bits::write_bits_scope helper
Bin-pack rectangles into an atlasmax_rects::MaximalRectangles::new then insert in a loop
Work with 2D pixel buffersimage::Image2DRef / image::Image2DMut
Use vector math or pixel typesmath::Vec3, math::Rgb565, math::Rgba32F, etc.

§Module overview

§Compression

ModulePurpose
ansAsymmetric Numeral Systems (ANS) entropy coder
rleRun-length encoding with configurable max length and power-of-two mode
vleVariable-length Elias delta coding for unsigned integers
lz77LZ77 sliding-window compressor / decompressor
lz78LZ78 dictionary compressor (GPU-friendly variant)
zigzaqZigzag signed ↔ unsigned mapping for better VLE compression

§Block-texture codecs

ModuleFormatBlock sizeChannels
[bc1]BC1 / DXT18 bytesRGB + 1-bit A
[bc2]BC2 / DXT316 bytesRGBA (4-bit A)
[bc3]BC3 / DXT516 bytesRGBA (interp A)
[bc4]BC4 / RGTC18 bytesR
[bc5]BC5 / RGTC216 bytesRG
cluster_fitShared quantizer for above--

§Image and math

ModulePurpose
imageNon-owning 2D / 3D image views (Image2DRef, Image2DMut, …)
mathVectors (Vec2Vec4), pixel types, Rect, PCA, bit-interleaving

§I/O and serialization

ModulePurpose
bitsBit-level buffered reader / writer over byte streams
encodeFixedCode and VarCode serialization traits

§Packing and spatial

ModulePurpose
max_rects2D bin packing (maximal-rectangles algorithm) for atlas generation
z_curveZ-order / Morton curve coordinate iteration

§File formats

ModulePurpose
jackal::imageTiled, GPU-decompressible image container format

Modules§

ans
Asymmetric Numeral Systems (ANS) entropy coder.
bits
Types and functions to work with individual bits.
cluster_fit
Least-squares cluster-fit quantization.
encode
Traits for fixed-size and variable-length binary serialization.
image
jackal
Jackal file format.
lz77
LZ77 sliding-window compression.
lz78
LZ78 dictionary compression.
math
Linear algebra primitives, color types, and bit-manipulation utilities.
max_rects
2D rectangle bin packing via the maximal-rectangles algorithm.
palette
rle
Run-length encoding (RLE) compression.
vle
Variable-length Elias delta encoding for unsigned integers.
z_curve
Z-order (Morton) curve utilities for 2D coordinate interleaving.
zigzaq
Zigzag encoding that maps signed integers to unsigned integers.