getWhiteBalance method Null safety

int getWhiteBalance()

Return the average gray value of the image.

Implementation

int getWhiteBalance() {
  final len = data.length;
  var r = 0;
  var g = 0;
  var b = 0;
  for (var i = 0; i < len; ++i) {
    r += getRed(data[i]);
    g += getGreen(data[i]);
    b += getBlue(data[i]);
  }

  r ~/= len;
  g ~/= len;
  b ~/= len;

  return (r + g + b) ~/ 3;
}