Available on crate feature
snapshot only.Expand description
Perceptual snapshot assertions.
A snapshot is named, and where its bytes come from depends on where the
test runs. Natively they are read from the asset submodule beside the test
file, so a mismatch can be re-stored in place with SNAPSHOT_UPDATE=1. In a
browser there is no filesystem to read or write, so
snapshot! embeds the baseline into the wasm binary at
the call site instead β and the comparison itself, a real SSIMULACRA2 score,
runs there unchanged.
Both paths decode the same WebP and score it the same way; only the origin of the bytes differs.
Re-exportsΒ§
use image::ImageEncoder;πuse ssimulacra2::ColorPrimaries;πuse ssimulacra2::Rgb;πuse ssimulacra2::TransferCharacteristic;πuse ssimulacra2::compute_frame_ssimulacra2;π
StructsΒ§
- Comparison π
- What comparing a frame against its baseline found.
- Snapshot
- A snapshot baseline, and where its bytes come from.
- Tolerance
- How closely a frame must match its snapshot.
EnumsΒ§
- Snapshot
Error - What went wrong storing or comparing a snapshot.
ConstantsΒ§
- DEFAULT_
MIN_ SCORE - The perceptual score a frame must reach to match its snapshot.
- DEFAULT_
MISMATCH_ DIR Non-WebAssembly - Where mismatched frames are written when
MISMATCH_DIR_ENVis unset. - DEFAULT_
TOLERANCE - The tolerance a snapshot gets when it names none: the perceptual floor
DEFAULT_MIN_SCORE, with no bound on how many pixels may stand out. - MISMATCH_
DIR_ ENV Non-WebAssembly - The environment variable that collects mismatched frames on the host.
- SNAPSHOT_
DIR πNon-WebAssembly - Where
Snapshot::on_disklooks a snapshot up by name, relative to the processβs working directory β which for a test is its package root.
FunctionsΒ§
- assert_
image_ snapshot - Assert that
rgbamatchessnapshotwithinDEFAULT_TOLERANCE. - assert_
image_ snapshot_ with_ tolerance - Assert that
rgbamatchessnapshotwithintolerance. - check_
frame_ πsize - Reject a frame whose bytes do not describe
widthxheightRGBA pixels. - compare π
Non-WebAssembly - Measure a frame against its baseline, storing one where none exists yet.
- compare_
frame_ πbytes - Measure
rgbaagainst a WebP baseline held in memory. - compare_
frame_ πwebp Non-WebAssembly - Measure the frame
rgbaagainst the snapshot atpath. - encode_
frame_ webp - Encode
rgbaas a lossless WebP. - outlier_
fraction π - The fraction of pixels whose largest per-channel difference from the
baseline exceeds
channel_delta. - rgb_
frame π - Turn an RGBA8 frame into the RGB the metric reads.
- score_
frame_ webp Non-WebAssembly - Score the frame
rgbaagainst the snapshot atpath, on SSIMULACRA2βs 0β100 scale where higher is closer. - snapshot_
path Non-WebAssembly - Where a snapshot named
namelives, under the snapshots directory. - store_
frame_ webp Non-WebAssembly - Write
rgbatopathas a lossless WebP, creating its directory. - store_
mismatch πNon-WebAssembly - Keep a frame that did not match, so a failing run leaves it behind.