processCameraImageToRGB method
Image?
processCameraImageToRGB({
- int? width,
- int? height,
- Uint8List? plane0,
- Uint8List? plane1,
- Uint8List? plane2,
- double? rotationAngle,
- int? bytesPerRowPlane0,
- int? bytesPerRowPlane1,
- int? bytesPerPixelPlan1,
- int backGroundColor = 0xFFFFFFFF,
- bool isFlipHoriozntal = false,
- bool isFlipVectical = false,
override
ProcessCameraImageToRGB.
Implementation
@override
imglib.Image? processCameraImageToRGB({
int? width,
int? height,
Uint8List? plane0,
Uint8List? plane1,
Uint8List? plane2,
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 ||
plane2 == null ||
plane0.isEmpty ||
plane1.isEmpty ||
plane2.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);
Pointer<Uint8> p2 = ffi.malloc.allocate(plane2.length);
Uint8List pointerList = p.asTypedList(plane0.length);
Uint8List pointerList1 = p1.asTypedList(plane1.length);
Uint8List pointerList2 = p2.asTypedList(plane2.length);
pointerList.setRange(0, plane0.length, plane0);
pointerList1.setRange(0, plane1.length, plane1);
pointerList2.setRange(0, plane2.length, plane2);
Pointer<Uint32> imgP = _convertImageYuv420pToRGB(
p,
p1,
p2,
bytesPerRowPlane1,
bytesPerPixelPlan1,
bytesPerRowPlane0,
height,
rotationAngle,
backGroundColor,
isFlipVectical,
isFlipHoriozntal,
);
List<int> imgData = imgP.asTypedList(((newImgWidth) * (newImgHeight)));
imglib.Image img = imglib.Image.fromBytes(
bytes: Uint32List.fromList(imgData).buffer,
width: newImgWidth,
height: newImgHeight,
order: imglib.ChannelOrder.rgba);
ffi.malloc.free(p);
ffi.malloc.free(p1);
ffi.malloc.free(p2);
ffi.malloc.free(imgP);
return img;
}