yuv420ThreePlanesToNV21

open fun yuv420ThreePlanesToNV21(yuv420888planes: Array<Image.Plane>, width: Int, height: Int): Array<Byte>

Converts YUV_420_888 to NV21 bytes.

The NV21 format consists of a single byte array containing the Y, U and V values. For an image of size S, the first S positions of the array contain all the Y values. The remaining positions contain interleaved V and U values. U and V are subsampled by a factor of 2 in both dimensions, so there are S/4 U values and S/4 V values. In summary, the NV21 array will contain S Y values followed by S/4 VU values: YYYYYYYYYYYYYY(...)YVUVUVUVU(...)VU

YUV_420_888 is a generic format that can describe any YUV image where U and V are subsampled by a factor of 2 in both dimensions. getPlanes returns an array with the Y, U and V planes. The Y plane is guaranteed not to be interleaved, so we can just copy its values into the first part of the NV21 array. The U and V planes may already have the representation in the NV21 format. This happens if the planes share the same buffer, the V buffer is one position before the U buffer and the planes have a pixelStride of 2. If this is case, we can just copy them to the NV21 array.