matrix property

  1. @override
Uint8List matrix
override

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

@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
Uint8List get matrix {
  // 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;
  }

  final area = width * height;
  final matrix = Uint8List(area);
  int inputOffset = _top * _dataWidth + _left;

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

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