RustScreenDiffAI is a Rust CLI pixel-diff engine for screenshot regression checks. It compares two images pixel by pixel, calculates the changed-pixel percentage, and returns a clear PASS or FAIL verdict against a configurable threshold.
Visual regressions are easiest to miss when screens look “mostly fine.” RustScreenDiffAI provides a deterministic, script-friendly image comparison step that can be used in QA workflows, CI jobs, screenshot tests, and digital signage review pipelines.
- Compares two PNG or image files using the Rust
imagecrate. - Validates that both screenshots have identical dimensions.
- Counts changed pixels exactly.
- Calculates diff percentage from total pixels.
- Supports configurable pass/fail threshold.
- Emits terminal output for manual review.
- Emits JSON output for automation.
- Handles identical images, partial diffs, full diffs, and dimension mismatch errors.
git clone https://github.com/SUDARSHANCHAUDHARI/RustScreenDiffAI.git
cd RustScreenDiffAI
cargo build --releaseThe binary is created at:
target/release/screendiffOptional local install:
cargo install --path .# Compare two screenshots with the default 1% threshold
screendiff compare before.png after.png
# Allow up to 5% difference
screendiff compare before.png after.png --threshold 0.05
# Emit JSON
screendiff compare before.png after.png --json
# Write a visual diff image with changed pixels highlighted in magenta
screendiff compare before.png after.png --diff-output diff.pngThe repository includes two tiny PPM fixtures:
screendiff compare examples/before.ppm examples/after.ppm --threshold 0.10
screendiff compare examples/before.ppm examples/after.ppm --diff-output diff.pngReal output:
ScreenDiff Report
Before: examples/before.ppm
After: examples/after.ppm
Total Pixels: 16
Diff Pixels: 1
Diff: 6.25%
Threshold: 10.00%
Verdict: PASS
- Load both images.
- Verify dimensions match.
- Compare every pixel pair.
- Count changed pixels.
- Calculate
diff_percent = diff_pixels / total_pixels. - Optionally write a diff image where changed pixels are magenta and unchanged pixels come from the baseline image.
- Return
PASSwhendiff_percent <= threshold; otherwise returnFAIL.
ScreenDiff Report
Before: before.png
After: after.png
Total Pixels: 10000
Diff Pixels: 42
Diff: 0.42%
Threshold: 1.00%
Verdict: PASS
| Threshold | Typical Use |
|---|---|
0.00 |
Exact pixel match required |
0.01 |
Default, allows up to 1% changed pixels |
0.05 |
Looser check for anti-aliasing or dynamic content |
cargo fmt --check
cargo clippy -- -D warnings
cargo test
cargo build --releaseThe integration tests cover zero diff, full diff, one-pixel changes, threshold behavior, dimension mismatch, CLI output, and visual diff image generation.
src/
cli.rs Command-line interface
diff/ Pixel comparison engine
report.rs Verdict and report output
tests/
integration_test.rs
Current production release: v1.1.0
The v1.1.0 release was verified with formatting, clippy, tests, optimized release build, and cargo package.
MIT. See LICENSE.
Built by Sudarshan Chaudhari under SudarshanTechLabs.