processCameraImageToRGBIOS method

  1. @override
Image? processCameraImageToRGBIOS({
  1. int? width,
  2. int? height,
  3. Uint8List? plane0,
  4. Uint8List? plane1,
  5. double? rotationAngle,
  6. int? bytesPerRowPlane0,
  7. int? bytesPerRowPlane1,
  8. int? bytesPerPixelPlan1,
  9. int backGroundColor = 0xFFFFFFFF,
  10. bool isFlipHoriozntal = false,
  11. bool isFlipVectical = false,
})
override

processCameraImageToRGBIOS. for IOS with YUV420.

Implementation

@override
imglib.Image? processCameraImageToRGBIOS({
  int? width,
  int? height,
  Uint8List? plane0,
  Uint8List? plane1,
  double? rotationAngle,
  int? bytesPerRowPlane0,
  int? bytesPerRowPlane1,
  int? bytesPerPixelPlan1,
  int backGroundColor = 0xFFFFFFFF,
  bool isFlipHoriozntal = false,
  bool isFlipVectical = false,
}) {
  if (width == null ||
      height == null ||
      plane0 == null ||
      plane1 == null ||
      plane0.isEmpty ||
      plane1.isEmpty ||
      bytesPerRowPlane0 == null ||
      bytesPerRowPlane1 == null ||
      bytesPerPixelPlan1 == null) {
    return null;
  }
  rotationAngle ??= 0;
  double rad =
      (rotationAngle * 3.14159265358979323846264338327950288 / 180.0);
  double sinVal = sin(rad).abs();
  double cosVal = cos(rad).abs();
  int newImgWidth = (sinVal * height + cosVal * bytesPerRowPlane0).toInt();
  int newImgHeight = (sinVal * bytesPerRowPlane0 + cosVal * height).toInt();

  Pointer<Uint8> p = ffi.malloc.allocate(plane0.length);
  Pointer<Uint8> p1 = ffi.malloc.allocate(plane1.length);

  Uint8List pointerList = p.asTypedList(plane0.length);
  Uint8List pointerList1 = p1.asTypedList(plane1.length);
  pointerList.setRange(0, plane0.length, plane0);
  pointerList1.setRange(0, plane1.length, plane1);

  Pointer<Uint32> imgP = _convertImageNV12ToRGB(
    p,
    p1,
    bytesPerRowPlane1,
    bytesPerPixelPlan1,
    bytesPerRowPlane0,
    height,
    rotationAngle,
    backGroundColor,
    isFlipVectical,
    isFlipHoriozntal,
  );

  final imgData = imgP.asTypedList(((newImgWidth) * (newImgHeight)));
  imglib.Image img = imglib.Image.fromBytes(
      bytes: imgData.buffer,
      width: newImgWidth,
      height: newImgHeight,
      order: imglib.ChannelOrder.rgba);

  ffi.malloc.free(p);
  ffi.malloc.free(p1);
  ffi.malloc.free(imgP);

  return img;
}