flipHorizontal function

Image flipHorizontal(
  1. Image src
)

Flip the src image horizontally.

Implementation

Image flipHorizontal(Image src) {
  final w = src.width;
  final h = src.height;
  final w2 = src.width ~/ 2;
  for (var y = 0; y < h; ++y) {
    final y1 = y * w;
    for (var x = 0; x < w2; ++x) {
      final x2 = (w - 1 - x);
      final t = src[y1 + x2];
      src[y1 + x2] = src[y1 + x];
      src[y1 + x] = t;
    }
  }
  return src;
}