Skip to main content

Crate fast_thumbhash

Crate fast_thumbhash 

Source
Expand description

§fast-thumbhash

A fast ThumbHash encoder/decoder — 10x+ faster drop-in replacement for the thumbhash crate.

§Optimizations

Encoder (rgba_to_thumb_hash):

  • Separable 2D DCT splits O(W·H·N) into two 1D passes
  • Chebyshev cosine recurrence: 2 cos() calls per frequency instead of W or H
  • Stack-allocated cos/partial buffers (zero heap allocation in hot path)
  • Integer average computation avoids N × f32 divisions
  • Opaque fast path: RGBA→LPQA with zero per-pixel alpha dependency
  • Single allocation for all 4 LPQA channels
  • Branchless nibble packing
  • unsafe get_unchecked eliminates bounds checks in inner loops

Decoder (thumb_hash_to_rgba):

  • Separable 2D IDCT with SAXPY row accumulation (auto-vectorizes to NEON/SSE)
  • Chebyshev cosine recurrence for cosine tables
  • Stack-allocated cos tables, AC buffers, and scratch rows
  • Direct nibble indexing (no std::io::Read overhead)
  • unsafe get_unchecked in all hot loops

Functions§

base91_decode
Decode a base91 string back to bytes. Returns Err(()) on invalid input.
base91_encode
Encode bytes to a base91 string.
rgba_to_thumb_hash
Encodes an RGBA image to a ThumbHash byte vector.
rgba_to_thumb_hash_b91
Encode an RGBA image directly to a base91-encoded ThumbHash string.
thumb_hash_from_b91
Decode a base91-encoded ThumbHash string to an RGBA image.
thumb_hash_to_approximate_aspect_ratio
Returns the approximate aspect ratio of a ThumbHash image as width / height.
thumb_hash_to_average_rgba
Extracts the average RGBA color from a ThumbHash.
thumb_hash_to_rgba
Decodes a ThumbHash to an RGBA8 image.