fast-ssim2

Fast SIMD-accelerated Rust implementation of SSIMULACRA2, a perceptual image quality metric.
Quick Start
[]
= { = "0.8", = ["imgref"] }
use compute_ssimulacra2;
use ImgVec;
let source: = /* your source image */;
let distorted: = /* compressed/modified version */;
let score = compute_ssimulacra2?;
// 100 = identical, 90+ = imperceptible, <50 = significant degradation
Score Interpretation
| Score | Quality |
|---|---|
| 100 | Identical |
| 90+ | Imperceptible difference |
| 70-90 | Minor, subtle difference |
| 50-70 | Noticeable difference |
| <50 | Significant degradation |
API Overview
Primary Functions
| Function | Use Case |
|---|---|
compute_ssimulacra2 |
Compare two images (recommended) |
Ssimulacra2Reference::new |
Precompute for batch comparisons (~2x faster) |
Input Types
With the imgref feature:
| Type | Color Space |
|---|---|
ImgRef<[u8; 3]> |
sRGB (8-bit) |
ImgRef<[u16; 3]> |
sRGB (16-bit) |
ImgRef<[f32; 3]> |
Linear RGB |
ImgRef<u8>, ImgRef<f32> |
Grayscale |
Convention: Integer types = sRGB gamma. Float types = linear RGB.
Without imgref, use yuvxyb::Rgb or yuvxyb::LinearRgb (add yuvxyb to your own dependencies), or implement ToLinearRgb for custom types.
Batch Comparisons
When comparing multiple images against the same reference (e.g., testing compression levels), precompute the reference:
use Ssimulacra2Reference;
let reference = new?;
for distorted in compressed_variants
Features
| Feature | Default | Description |
|---|---|---|
imgref |
No | Support for imgref image types |
rayon |
No | Parallel computation |
SIMD is always available — runtime CPU detection via archmage selects the best backend automatically (AVX2+FMA on x86_64, NEON on aarch64, SIMD128 on wasm32, scalar fallback elsewhere).
Performance
Benchmarked on AMD Ryzen 9 7950X (x86_64, AVX2+FMA), full SSIMULACRA2 computation vs upstream ssimulacra2 crate:
| Resolution | ssimulacra2 (scalar) | fast-ssim2 (SIMD) | Speedup |
|---|---|---|---|
| 320x240 | 139ms | 8.7ms | 16x |
| 1920x1080 | 1,006ms | 316ms | 3.2x |
| 3840x2160 | 3,615ms | 1,317ms | 2.7x |
Run your own benchmarks:
Advanced Usage
Custom Input Types
use ;
Explicit SIMD Backend
use ;
// Force scalar (for comparison/debugging)
let score = compute_ssimulacra2_with_config?;
// Use SIMD (default — auto-detects AVX2/NEON/WASM128)
let score = compute_ssimulacra2_with_config?;
Using yuvxyb Types Directly
use compute_ssimulacra2;
use ;
let source = new?;
let score = compute_ssimulacra2?;
Requirements
- Minimum image size: 8x8 pixels
- MSRV: 1.89.0
Attribution
Fork of rust-av/ssimulacra2. Thank you to the rust-av team for the original implementation.
What's different: Cross-platform SIMD acceleration (x86_64/aarch64/wasm32 via archmage), precomputed reference API, imgref support, #![forbid(unsafe_code)].
Image tech I maintain
| State of the art codecs* | zenjpeg · zenpng · zenwebp · zengif · zenavif (rav1d-safe · zenrav1e · zenavif-parse · zenavif-serialize) · zenjxl (jxl-encoder · zenjxl-decoder) · zentiff · zenbitmaps · heic · zenraw · zenpdf · ultrahdr · mozjpeg-rs · webpx |
| Compression | zenflate · zenzop |
| Processing | zenresize · zenfilters · zenquant · zenblend |
| Metrics | zensim · fast-ssim2 · butteraugli · resamplescope-rs · codec-eval · codec-corpus |
| Pixel types & color | zenpixels · zenpixels-convert · linear-srgb · garb |
| Pipeline | zenpipe · zencodec · zencodecs · zenlayout · zennode |
| ImageResizer | ImageResizer (C#) — 24M+ NuGet downloads across all packages |
| Imageflow | Image optimization engine (Rust) — .NET · node · go — 9M+ NuGet downloads across all packages |
| Imageflow Server | The fast, safe image server (Rust+C#) — 552K+ NuGet downloads, deployed by Fortune 500s and major brands |
* as of 2026
General Rust awesomeness
archmage · magetypes · enough · whereat · zenbench · cargo-copter
And other projects · GitHub @imazen · GitHub @lilith · lib.rs/~lilith · NuGet (over 30 million downloads / 87 packages)
License
BSD-2-Clause (same as upstream)
Upstream Contribution
This is a fork of rust-av/ssimulacra2 (BSD-2-Clause). We are willing to release our improvements under the original BSD-2-Clause license if upstream takes over maintenance of those improvements. We'd rather contribute back than maintain a parallel codebase. Open an issue or reach out.