[MPlayer-dev-eng] rgb<->yuv convertion question
mayaray
mayaray at 263.sina.com
Thu Jan 15 02:28:04 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?
> >
> > No, but you have to clamp the results so they fit in a byte. Otherwise
> > they'll overflow/wrap.
> >
> > BTW you should probably use fixed point rather than float. Float will
> > be _very_ slow.
> >
> > Rich
> >
>
> so how can i clamp and use fixed point in vc using c++?
> should i write the clamp function?
> i can only find fixed point type in opengl and asm, does it
> exist in c++?
> thanks.
>
> felix
>
i put my Clamp function:
unsigned char Clamp(float i) {
if (i>256.0f)
return 256;
if (i<0.0f)
return 0;
return (unsigned char)i;
}
like : pYUV->Y = Clamp(0.257f * (float)pRGB[RINDEX] + 0.504f * (float)pRGB[GINDEX] + 0.098f * (float)pRGB[BINDEX] + 16.0f);
i put it in every color element calculation, but the red dots
still come out.
why?
===================================================================
More information about the MPlayer-dev-eng
mailing list