toGray method
Wraps the luminance data as a grayscale image without copying when the frame already carries a Y plane.
Implementation
UGrayImage toGray() {
switch (format) {
case UFrameFormat.nv21:
case UFrameFormat.yuv420:
case UFrameFormat.gray8:
final int stride = rowStrides.isNotEmpty ? rowStrides.first : width;
return UGrayImage(bytes, width, height, rowStride: stride);
case UFrameFormat.bgra8888:
return UGrayImage.fromPacked(bytes, width, height, rowStride: rowStrides.isNotEmpty ? rowStrides.first : 0);
case UFrameFormat.rgba8888:
return UGrayImage.fromPacked(bytes, width, height, bgra: false, rowStride: rowStrides.isNotEmpty ? rowStrides.first : 0);
case UFrameFormat.jpeg:
return UGrayImage(Uint8List(0), 0, 0);
}
}