yuv420sp2rgb method
Convert YUV420SP to RGB
yuv420sp
is Image data in YUV420SP(NV12) format. width
and height
specify the width and height of the Image.
Returns RGB bytes.
Implementation
Uint8List yuv420sp2rgb({
required Uint8List yuv420sp,
required int width,
required int height,
}) {
assert(width > 0, 'width is too small');
assert(height > 0, 'height is too small');
assert(yuv420sp.isNotEmpty, 'yuv420sp is empty');
if (width <= 0 || height <= 0 || yuv420sp.isEmpty) {
return Uint8List(0);
}
final pixels = calloc.allocate<Uint8>(yuv420sp.length);
for (var i = 0; i < yuv420sp.length; i++) {
pixels[i] = yuv420sp[i];
}
final rgb = calloc.allocate<Uint8>(width * height * 3);
_yuv420sp2rgbFunction(
pixels,
width,
height,
rgb,
);
final results = _copyUint8PointerToUint8List(rgb, width * height * 3);
calloc
..free(pixels)
..free(rgb);
return results;
}