getMatrix method

  1. @override
Int8List getMatrix()
override

Fetches luminance data for the underlying bitmap. Values should be fetched using: {int luminance = arrayy * width + x & 0xff}

@return A row-major 2D array of luminance values. Do not use result.length as it may be larger than width * height bytes on some platforms. Do not modify the contents of the result.

Implementation

@override
Int8List getMatrix() {
  var width = this.width;
  var height = this.height;

  // If the caller asks for the entire underlying image, save the copy and give them the
  // original data. The docs specifically warn that result.length must be ignored.
  if (width == _dataWidth && height == _dataHeight) {
    return _luminances;
  }

  var area = width * height;
  var matrix = Int8List(area);
  var inputOffset = _top * _dataWidth + _left;

  // If the width matches the full width of the underlying data, perform a single copy.
  if (width == _dataWidth) {
    system.arraycopy(_luminances, inputOffset, matrix, 0, area);
    return matrix;
  }

  // Otherwise copy one cropped row at a time.
  for (var y = 0; y < height; y++) {
    var outputOffset = y * width;
    system.arraycopy(_luminances, inputOffset, matrix, outputOffset, width);
    inputOffset += _dataWidth;
  }
  return matrix;
}