crop method

UGrayImage crop(
  1. int x,
  2. int y,
  3. int w,
  4. int h,
)

Implementation

UGrayImage crop(int x, int y, int w, int h) {
  final int cx = x.clamp(0, width);
  final int cy = y.clamp(0, height);
  final int cw = w.clamp(0, width - cx);
  final int ch = h.clamp(0, height - cy);
  final Uint8List out = Uint8List(cw * ch);
  for (int row = 0; row < ch; row++) {
    final int src = (cy + row) * stride + cx;
    out.setRange(row * cw, row * cw + cw, data, src);
  }
  return UGrayImage(out, cw, ch, left: left + cx, top: top + cy, sourceWidth: sourceWidth == 0 ? width : sourceWidth, sourceHeight: sourceHeight == 0 ? height : sourceHeight);
}