convertYUV2RGB method Null safety

RawImageF convertYUV2RGB(
  1. RawImageF image,
  2. {required int baseAngle,
  3. NativeDataStruct? reusableData}
)

Implementation

RawImageF convertYUV2RGB(RawImageF image, {required int baseAngle, NativeDataStruct? reusableData}) {
  final exception = _getException();
  final convertYUV2RGBConstructor = _dll_handle.lookupFunction<_RawImage_convertYUV2RGB_c, _RawImage_convertYUV2RGB_dart>(_c_namespace + 'RawImage_convertYUV2RGB');
  int width;
  int height;

  switch (baseAngle) {
    case 1:
    case 2:
      width = image.height;
      height = image.width;

      break;

    default:
      width = image.width;
      height = image.height;

      break;
  }

  NativeDataStruct data = NativeDataStruct();
  final int totalBytes = width * height * 3;

  if (reusableData != null) {
    if (reusableData.size != totalBytes) {
      reusableData.resize(totalBytes);
    }
  } else {
    data.resize(totalBytes);
  }

  RawImageF result = RawImageF(width, height, Format.FORMAT_RGB, (reusableData == null ? data : reusableData).pointer!.cast());

  convertYUV2RGBConstructor(image.data.cast(), image.width, image.height, image.format.index, image.with_crop, image.crop_info_offset_x, image.crop_info_offset_y,
      image.crop_info_data_image_width, image.crop_info_data_image_height, 0, baseAngle, result.data.cast(), exception);

  checkException(exception, _dll_handle);

  return result;
}