I'm trying to import 10/16 bit YUV HDR video files in my video sequencer and I got , with media foundation, a MFVideoFormat_P010, which is, according to the docs, a 4:2:0 10-bit sample. Normally I 'd use the Video Processor MFT to convert to RGB but , as of now, the MFT doesn't convert other than 8 bit samples.

I have two problems.

First, to ensure that my calculation of YUV is correct (no extra stride), "by" is the buffer start:
Code:
BYTE* StartLineUV = by + wi * he * sizeof(short);
for (int x = 0; x < wi; x++)
{
	for (int y = 0; y < he; y++)
	{
		BYTE* StartLine = by + (wi +strideext) * sizeof(short) * y;
		// Calculate YUV shorts for position xy
		BYTE* b1 = StartLine + x * sizeof(short);
		short Y = b1[0];

		// Find the UV line for this xy
		int y2 = y / 2; // subsampling
		BYTE* StartLineUV2 = StartLineUV + (wi + strideext) * sizeof(short) * y2;

		// Find the UV for this row (subsampled)
		int x2 = x / 2;

		// 32 bits per x
		BYTE* pX = StartLineUV2 + x2 * 4;
		short U = pX[0];
		short V = pX[1];
	}
}
Is the above correct?

Second, assuming I got a YUV values [0..1023]. How to convert them to floating point RGB ? The following would not work (which works for 8-bit YUV):
Code:
void RGBfromYUV(double& R, double& G, double& B, double Y, double U, double V)
{
  Y -= 16;
  U -= 128;
  V -= 128;
  R = 1.164 * Y             + 1.596 * V;
  G = 1.164 * Y - 0.392 * U - 0.813 * V;
  B = 1.164 * Y + 2.017 * U;
}

I'm trying to understand this also: https://forum.videohelp.com/threads/379292-Converting-Between-10-bit-RGB-and-YUV-and-Back