downscale method

UGrayImage downscale(
  1. int factor
)

Nearest-neighbour downscale by an integer factor; 1 returns this.

Implementation

UGrayImage downscale(int factor) {
  if (factor <= 1) return this;
  final int w = width ~/ factor;
  final int h = height ~/ factor;
  if (w <= 0 || h <= 0) return this;
  final Uint8List out = Uint8List(w * h);
  for (int y = 0; y < h; y++) {
    final int src = y * factor * stride;
    final int dst = y * w;
    for (int x = 0; x < w; x++) {
      out[dst + x] = data[src + x * factor];
    }
  }
  return UGrayImage(out, w, h, left: left, top: top, sourceWidth: sourceWidth == 0 ? width : sourceWidth, sourceHeight: sourceHeight == 0 ? height : sourceHeight);
}