addressing the repeated need to mark a region that should be tolerated based on a diff
snippet:
// Create a tolerance mask by expanding the diff regions. Diff pixels that are non-black will be grown by padding
// into broader white areas to tolerate local differences (e.g., filenames, timestamps).
private static SKBitmap CreateToleranceMaskFromDiff(SKBitmap diffMask, int padding = 3)
{
var w = diffMask.Width;
var h = diffMask.Height;
var mask = new SKBitmap(w, h, SKColorType.Rgba8888, SKAlphaType.Unpremul);
using var canvas = new SKCanvas(mask);
canvas.Clear(SKColors.Black);
using var paint = new SKPaint { Color = SKColors.White, IsAntialias = false };
// For each non-black pixel in diff, draw a filled rectangle expanded by padding.
for (int y = 0; y < h; y++)
{
for (int x = 0; x < w; x++)
{
var col = diffMask.GetPixel(x, y);
// consider any non-transparent / non-black pixel as part of diff
if (col.Alpha > 16 && (col.Red > 16 || col.Green > 16 || col.Blue > 16))
{
var left = Math.Max(0, x - padding);
var top = Math.Max(0, y - padding);
var right = Math.Min(w, x + padding + 1);
var bottom = Math.Min(h, y + padding + 1);
var rect = new SKRectI(left, top, right, bottom);
canvas.DrawRect(rect, paint);
}
}
}
canvas.Flush();
return mask;
}
addressing the repeated need to mark a region that should be tolerated based on a diff
snippet: