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_uncheckedeliminates 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::Readoverhead) unsafe get_uncheckedin 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.