BarrierLab

pixel-diff

Perceptual RGBA image diffing: YIQ pixelmatch, anti-aliasing, SSIM, ignore masks and change clusters.

A standalone, dependency-free engine for deterministic comparison of two RGBA8 screenshots. It sits in layer L0: no a11y-* dependency, no browser, no file system.

Status

New, not yet released. Consumers are the visual-evidence and visual-audit packages and the auditors built on them.

What the package does

  • Pixel metric: YIQ colour delta against 35215 * threshold^2, alpha blended against white, so fully transparent pixels with different RGB do not differ. Anti-aliased edge pixels (3x3 neighbourhood, has_many_siblings) are counted separately in aa_pixels unless include_aa is set. Independent implementation of the pixelmatch algorithm.
  • SSIM: mean over 8x8 luminance windows at stride 4, constants C1 = 6.5025, C2 = 58.5225; identical images give exactly 1.0.
  • Ignore masks: ignore_regions are excluded and reported as ignored_pixels; diff_ratio relates to the remaining pixels.
  • Clusters: cluster_distance merges changed pixels via a grid (cell size max(d, 1), touching cells merge) and union-find, iterative and sorted by y, then x. Bounds are exact pixel bounds.
  • Diff image: optional, with configurable colours for differences, anti-aliasing and masked pixels over a dimmed original.

Features

  • png: png_codec with decode_png, decode_png_with_limit (default 64 MiB) and encode_png; all colour types are converted to RGBA8.
  • serde: derives for PixelRect, DiffOptions, DiffResult, RgbaImage.

What the package does not do

No file or network I/O, no CLI, no accessibility vocabulary, no a11y-report findings, no own PNG/DEFLATE implementation. Images of different size are an error, not resized.

Edit this page on GitHub