convertYUV420 function
Image
convertYUV420(
- CameraImage image
Implementation
imglib.Image convertYUV420(CameraImage image) {
final imglib.Image img =
imglib.Image(image.width, image.height); // Create Image buffer
final Plane plane = image.planes[0];
const int shift = 0xFF << 24;
// Fill image buffer with plane[0] from YUV420_888
for (int x = 0; x < image.width; x++) {
for (int planeOffset = 0;
planeOffset < image.height * image.width;
planeOffset += image.width) {
final int pixelColor = plane.bytes[planeOffset + x];
// color: 0x FF FF FF FF
// A B G R
// Calculate pixel color
final int newVal =
shift | (pixelColor << 16) | (pixelColor << 8) | pixelColor;
img.data[planeOffset + x] = newVal;
}
}
return img;
}