emptyBuffer method Null safety

RawImageF emptyBuffer(
  1. int width,
  2. int height,
  3. {Format format = Format.FORMAT_RGB}
)

Implementation

static RawImageF emptyBuffer(int width, int height, {Format format = Format.FORMAT_RGB}) {
  if (!_formatMap.containsKey(format)) throw Exception("Unsuport image format");

  int size = width * height * (format == Format.FORMAT_GRAY ? 1 : 3);
  Pointer<Uint8> dataPtr = malloc.allocate(size);

  if (dataPtr.address == nullptr.address) throw Exception("RawImageF.emptyBuffer: Failed to allocate a $size bytes");

  return RawImageF(width, height, format, dataPtr.cast());
}