[MPlayer-dev-eng] rgb<->yuv convertion question

mayaray mayaray at 263.sina.com
Wed Jan 14 03:23:02 CET 2004


i saw the following matrix in docs/tech/colorspaces.txt:

Y = (0.257 * R) + (0.504 * G) + (0.098 * B) + 16
Cr = V = (0.439 * R) - (0.368 * G) - (0.071 * B) + 128
Cb = U = -(0.148 * R) - (0.291 * G) + (0.439 * B) + 128

B = 1.164(Y - 16) + 2.018(U - 128)
G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128)
R = 1.164(Y - 16) + 1.596(V - 128)

then i used it in my program, but the result of a RGB2YUV followed by a YUV2RGB has some red dots or dashes in places 
where the lumination is high.
the pRGB is a BYTE * and Y, U, V are all BYTE.
does my accuracy not high enough?
-----------------------------------------------------
the code:

void inline RGB2YUV(BYTE *pRGB, YUV *pYUV)
{
pYUV->Y = (BYTE)(0.257f * (float)pRGB[RINDEX] + 0.504f * (float)pRGB[GINDEX] + 0.098f * (float)pRGB[BINDEX] + 16);
pYUV->U = (BYTE)((-0.148f) * (float)pRGB[RINDEX] + (-0.291f) * (float)pRGB[GINDEX] + (0.439f) * (float)pRGB[BINDEX]+128);
pYUV->V = (BYTE)((0.439f) * (float)pRGB[RINDEX] + (-0.368f) * (float)pRGB[GINDEX] + (-0.071f) * (float)pRGB[BINDEX] + 128);
}
void inline YUV2RGB(YUV *pYUV, BYTE *pRGB)
{
pRGB[RINDEX] = (BYTE)(1.164f*((float)pYUV->Y - 16) + 1.596f*((float)pYUV->V - 128));
pRGB[GINDEX] = (BYTE)(1.164f*((float)pYUV->Y - 16) - 0.813f*((float)pYUV->V - 128) - 0.391f*((float)pYUV->U - 128));
pRGB[BINDEX] = (BYTE)(1.164f*((float)pYUV->Y - 16) + 2.018f*((float)pYUV->U - 128));
}

===================================================================




More information about the MPlayer-dev-eng mailing list