convertBGRA88882RGB method Null safety

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

Implementation

RawImageF convertBGRA88882RGB(RawImageF image, {required int baseAngle, NativeDataStruct? reusableData}) {
  final exception = _getException();
  final convertBGRA88882RGBConstructor =
      _dll_handle.lookupFunction<_RawImage_convertBGRA88882RGB_c, _RawImage_convertBGRA88882RGB_dart>(
          _c_namespace + 'RawImage_convertBGRA88882RGB');
  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());

  convertBGRA88882RGBConstructor(
      image.data.cast(), image.width, image.height, baseAngle, result.data.cast(), exception);

  checkException(exception, _dll_handle);

  return result;
}