IntPixels constructor

IntPixels(
  1. int width,
  2. int height, {
  3. PixelFormat<int, void> format = abgr8888,
  4. TypedDataList<int>? data,
})

Creates a new buffer of integer-based pixel data.

Both width and height must be greater than zero.

The format defaults to abgr8888, and if data is provided it's contents must are assumed to be in the same format, and data.length must be equal to width * height.

Implementation

factory IntPixels(
  int width,
  int height, {
  PixelFormat<int, void> format = abgr8888,
  TypedDataList<int>? data,
}) {
  if (width < 1) {
    throw ArgumentError.value(width, 'width', 'Must be greater than zero.');
  }
  if (height < 1) {
    throw ArgumentError.value(height, 'height', 'Must be greater than zero.');
  }
  if (data == null) {
    data = newIntBuffer(bytes: format.bytesPerPixel, length: width * height);
    if (format.zero != 0) {
      data.fillRange(0, data.length, format.zero);
    }
  } else if (data.length != width * height) {
    throw RangeError.value(
      data.length,
      'data.length',
      'Must be equal to width * height.',
    );
  }
  return IntPixels._(
    data,
    width: width,
    height: height,
    format: format,
  );
}