createContextFromCameraImage method Null safety

Context createContextFromCameraImage(
  1. dynamic image,
  2. int baseAngle
)

Implementation

Context createContextFromCameraImage(CameraImage image, int baseAngle) {
  int width = image.width;
  int height = image.height;
  ContextFormat format;
  Uint8List data = getRawData(image.planes);

  switch (image.format.group) {
    case ImageFormatGroup.unknown:
      throw Exception("Unknown image format");

    case ImageFormatGroup.yuv420:
      format = ContextFormat.FORMAT_YUV420;

      if (width != image.planes.first.bytesPerRow) {
        data = _removePaddingFromYUV420_888(data, width, height, image.planes.first.bytesPerRow);
      }

      break;

    case ImageFormatGroup.bgra8888:
      format = ContextFormat.FORMAT_BGRA8888;

      break;

    case ImageFormatGroup.jpeg:
      throw Exception("Unsupported image format jpeg");

    case ImageFormatGroup.nv21:
      format = ContextFormat.FORMAT_NV21;
      break;
  }

  return createContextFromFrame(data, width, height, format: format, baseAngle: baseAngle);
}