请大家分析一下为什么这个YUV420转RGB32的程序效率如此低下
#define RGB4Y 1.164
#define B4U 2.018
#define Y2ADD 16
#define G4U 0.391
#define G4V 0.813
#define U2ADD 128
#define R4V 1.596
#define V2ADD 128
#define SCALEBITS 13
#define FIX(x) ((WORD) ((x) * (1L << SCALEBITS) + 0.5))
int g_RGB4Y_Tab[256];
int g_B4U_Tab[256];
int g_G4U_Tab[256];
int g_G4V_Tab[256];
int g_R4V_Tab[256];
void InitColorSpace()
{
for (UINT i = 0; i < 256; i++)
{
g_RGB4Y_Tab[i] = FIX(RGB4Y) * (i - Y2ADD);
g_B4U_Tab[i] = FIX(B4U ) * (i - U2ADD);
g_G4U_Tab[i] = FIX(G4U ) * (i - U2ADD);
g_G4V_Tab[i] = FIX(G4V ) * (i - V2ADD);
g_R4V_Tab[i] = FIX(R4V ) * (i - V2ADD);
}
}
inline BYTE ClipColorValue(int x)
{
return x < 0 ? 0 : (x > 255 ? 255 : x);
}
inline void YUV420_RGB32_4Pixel(LPBYTE pRGB, LPBYTE pY, LPBYTE pU, LPBYTE pV, UINT Width)
{
int nRGB4Y = 0;
int nB4U = g_B4U_Tab[pU[0]];
int nG4UV = g_G4U_Tab[pU[0]] + g_G4V_Tab[pV[0]];
int nR4V = g_R4V_Tab[pV[0]];
// (0, 0)
nRGB4Y = g_RGB4Y_Tab[pY[0]];
pRGB[0] = ClipColorValue((nRGB4Y + nB4U ) >> SCALEBITS);
pRGB[1] = ClipColorValue((nRGB4Y - nG4UV) >> SCALEBITS);
pRGB[2] = ClipColorValue((nRGB4Y + nR4V ) >> SCALEBITS);
pRGB[3] = 0;
// (0, 1)
nRGB4Y = g_RGB4Y_Tab[pY[1]];
pRGB[4] = ClipColorValue((nRGB4Y + nB4U ) >> SCALEBITS);
pRGB[5] = ClipColorValue((nRGB4Y - nG4UV) >> SCALEBITS);
pRGB[6] = ClipColorValue((nRGB4Y + nR4V ) >> SCALEBITS);
pRGB[7] = 0;
// (1, 0)
nRGB4Y = g_RGB4Y_Tab[pY[Width]];
pRGB[(Width<<2)+0] = ClipColorValue((nRGB4Y + nB4U ) >> SCALEBITS);
pRGB[(Width<<2)+1] = ClipColorValue((nRGB4Y - nG4UV) >> SCALEBITS);
pRGB[(Width<<2)+2] = ClipColorValue((nRGB4Y + nR4V ) >> SCALEBITS);
pRGB[(Width<<2)+3] = 0;
// (1, 1)
nRGB4Y = g_RGB4Y_Tab[pY[Width+1]];
pRGB[(Width<<2)+4] = ClipColorValue((nRGB4Y + nB4U ) >> SCALEBITS);
pRGB[(Width<<2)+5] = ClipColorValue((nRGB4Y - nG4UV) >> SCALEBITS);
pRGB[(Width<<2)+6] = ClipColorValue((nRGB4Y + nR4V ) >> SCALEBITS);
pRGB[(Width<<2)+7] = 0;
}
///////////////////////////////////////////////////////////////////////////////////
//
void YUV420_RGB32(LPBYTE pRGB, LPBYTE pYUV, DWORD Width, DWORD Height)
{
LPBYTE pY = pYUV, pU = pY + Width * Height, pV = pU + Width * Height/4;
UINT x, y;
for (y = 0; y < Height; y += 2)
{
for (x = 0; x < Width; x += 2)
{
YUV420_RGB32_4Pixel(pRGB, pY, pU, pV, Width);
pRGB += 8; pY += 2; pU += 1; pV += 1;
}
pRGB += Width<<2;
pY += Width;
}
}