of static method

PixelDiff of({
  1. required Uint8List base,
  2. required int baseWidth,
  3. required int baseHeight,
  4. required Uint8List head,
  5. required int headWidth,
  6. required int headHeight,
  7. bool wantMask = false,
})

Compares two rgba8888 buffers.

Frames of different sizes are compared over their common region and sizeChanged is set; the caller decides what to say about the rest, and there is nothing sensible to say about pixels one side does not have.

Implementation

static PixelDiff of({
  required Uint8List base,
  required int baseWidth,
  required int baseHeight,
  required Uint8List head,
  required int headWidth,
  required int headHeight,
  bool wantMask = false,
}) {
  var width = math.min(baseWidth, headWidth);
  var height = math.min(baseHeight, headHeight);
  var mask = Uint8List(width * height);
  var changed = 0;

  for (var y = 0; y < height; y++) {
    var baseRow = y * baseWidth * 4;
    var headRow = y * headWidth * 4;
    var maskRow = y * width;
    for (var x = 0; x < width; x++) {
      var b = baseRow + x * 4;
      var h = headRow + x * 4;
      if (_differs(base, b, head, h)) {
        mask[maskRow + x] = 1;
        changed++;
      }
    }
  }

  return PixelDiff(
    width: width,
    height: height,
    changedPixels: changed,
    comparedPixels: width * height,
    clusters: _clusters(mask, width, height),
    sizeChanged: baseWidth != headWidth || baseHeight != headHeight,
    mask: wantMask ? mask : null,
  );
}