一个比较简单的平面yuv422格式转rgb24格式的代码(速度比较快)
int table_y[240];
int table_ub[256];
int table_ug[256];
int table_vg[256];
int table_vr[256];
void InitialTable()
{
for (int i = 0; i < 240; ++i)
{
table_y[i] = 4767*i;
table_y[i] = table_y[i] >>12;
}
for (int j = 0; j < 256; ++j)
{
table_ub[j] = 8265*(j-128);
table_ub[j] = table_ub[j]>>12;
table_ug[j] = 1556*(j-128);
table_ug[j] = table_ug[j]>>12;
table_vg[j] = 3330 * (j-128);
table_vg[j] = table_vg[j]>>12;
table_vr[j] = 4747*(j-128);
table_vr[j] = table_vr[j] >>12;
}
}
BOOL YUV422TORGB24( BYTE* pDest, int width, int height, int channel, const BYTE* pSrc )
{
int offset1 = width * height;
int offset2 = offset1 + (width >>1)*height;
for (int i = 0; i < height; i++)
{
int widthOffset1 = i*width;
int index1 = widthOffset1 * channel;
for (int j =0; j < width; j+=2)
{
{
int y = pSrc[widthOffset1 + j];
int u = pSrc[offset1 + ((widthOffset1 + j)>>1)];
int v = pSrc[offset2 + ((widthOffset1 + j)>>1)];
int yy = y-16;
int b = table_y[yy] + table_ub[u]; //查表
int g = table_y[yy] - table_ug[u] - table_vg[v];
int r = table_y[yy] + table_vr[v];
if (r > 255) r = 255;
if (r < 0) r = 0;
if (g > 255) g = 255;
if (g < 0) g = 0;
if (b > 255) b = 255;
if (b < 0) b = 0;
int index = index1 + j*channel;
pDest[index] = b;
pDest[index + 1] = g;
pDest[index + 2] = r;
}
{
int y = pSrc[widthOffset1 + (j+1)];
int u = pSrc[offset1 + ((widthOffset1 + (j+1))>>1)];
int v = pSrc[offset2 + ((widthOffset1 + (j+1))>>1)];
int yy = y-16;
int b = table_y[yy] + table_ub[u];
int g = table_y[yy] - table_ug[u] - table_vg[v];
int r = table_y[yy] + table_vr[v];
if (r > 255)r = 255;
if (r < 0) r = 0;
if (g > 255) g = 255;
if (g < 0) g = 0;
if (b > 255) b = 255;
if (b < 0) b = 0;
int index = index1 + (j+1)*channel;
pDest[index] = b;
pDest[index + 1] = g;
pDest[index + 2] = r;
}
}
}
return TRUE;
}