Files
Powei Feng 541a4feae1 imgdiff: add positional and frequency robustness parameters (#9822)
- Introduce `shiftRadius` to allow positional tolerances by searching
  a local neighborhood, absorbing sub-pixel shifts and MSAA quirks.
- Introduce `blurRadius` to apply local area averaging, ignoring
  high-frequency noise like hardware dithering.
- Enhance `ImageDiffResult` to include an `averageError` array and
  a 10-bin `errorHistogram` for actionable failure debugging.
- Update Android JNI bindings (`ImageDiff.java` and `ImageDiff.cpp`)
  to propagate the new error distribution statistics to Java callers.
- Update C++ unit tests to cover the new heuristic options.
- Document the new parameters and JSON result format in README.md.
- Add synthetic image generation tests in `tools/diffimg/tests/` to
  validate the CLI tool's handling of spatial shifts and dithering.
2026-03-25 00:31:18 +00:00
..

diffimg

diffimg is a command-line tool for comparing two images using the imagediff library's tolerance logic. It supports various image formats and allows for fine-grained control over comparison thresholds via JSON configuration and optional masking.

Usage

diffimg [options] <reference> <candidate>

Arguments

  • <reference>: Path to the golden/expected image.
  • <candidate>: Path to the test/actual image.

Options

  • --config <path>: Path to a JSON configuration file defining comparison thresholds.
  • --mask <path>: Path to a grayscale mask image (0 = ignore, >0 = compare).
  • --diff <path>: Path to output a visual difference image (unmasked absolute difference).
  • --help, -h: Print help message.

Output

The tool outputs a JSON object to stdout containing the comparison results:

{
  "status": 0,
  "passed": true,
  "failingPixelCount": 0,
  "maxDiffFound": [0.0, 0.0, 0.0, 0.0]
}

Status Codes

  • 0: PASSED (Images are considered the same within tolerance)
  • 1: SIZE_MISMATCH (Images have different dimensions)
  • 2: PIXEL_DIFFERENCE (Images differ beyond the allowed tolerance)

Configuration Format

The optional JSON configuration follows the imagediff schema:

{
    "mode": "LEAF",
    "maxAbsDiff": 0.01,
    "maxFailingPixelsFraction": 0.05
}

Dependencies

  • libs/imagediff: Comparison logic.
  • libs/imageio: Primary image decoding (PNG, HDR, EXR).
  • libs/imageio-lite: Fallback decoding (TIFF).