The input pointer *data
contains the data that needs to be split into different arrays and put in yuvInput
. Each pixel is 32 bytes 4 * 8. Note the (j*4) to break it up per pixel segment. The 4th byte is the alpha channel which gets skipped (the reason there is no idx+3).
This method needs optimization. If anyone is willing to help, please do.
void SplitYUVPlanes(int width, int height, unsigned char *data, int size, unsigned char *yuvInput[3])
{
// live input *data is YUV444 Packed
// Conversion from 444 Packed -> 444 Planar
int index = 0;
int srcStride = size;
// need to flip image from bottom-up to top-down
int revheight = height - 1;
unsigned char* pLuma = yuvInput[0];
unsigned char* pChromaU = yuvInput[1];
unsigned char* pChromaV = yuvInput[2];
for (int i = 0; i < height; ++i)
{
// read bottom line first
int line = (revheight - i) * srcStride;
for (int j = 0; j < width; ++j)
{
int idx = line + (j * 4);
pLuma[index] = data[idx + 2]; //Y
pChromaV[index] = data[idx + 1]; //V
pChromaU[index] = data[idx + 0]; //U
index++;
}
}
}