How could I distinguish between NV21 and YV12 codification in imageReader camera API 2?
YUV_420_888 is a wrapper that can host (among others) both NV21 and YV12 images. If must use the planes and strides to access individual colors:
ByteBuffer Y = image.getPlanes()[0];
ByteBuffer U = image.getPlanes()[1];
ByteBuffer V = image.getPlanes()[2];
If the underlying pixels are in NV21 format (as on Nexus 4), the pixelStride will be 2, and
int getU(image, col, row) {
return getPixel(image.getPlanes()[1], col/2, row/2);
}
int getPixel(plane, col, row) {
return plane.getBuffer().get(col*plane.getPixelStride() + row*plane.getRowStride());
}
We take half column and half row because this is how U and V (chroma) planes are stored in 420 image.
This code is for illustration, it is very inefficient, you probably want to access pixels at bulk, using get(byte[], int, int)
, or via a fragment shader, or via JNI function GetDirectBufferAddress in native code. What you cannot use, is method , because the planes are guaranteed to be direct byte buffers.plane.array()