Fwd: wrong colors with Xv extension and image format id: 0x59565955 (UYVY) from an rgb mapping
Tomas Carnecky
tom at dbservice.com
Fri Jan 23 00:45:16 PST 2009
On 01/23/2009 02:59 AM, Amos Tibaldi wrote:
> #define GUID_UYVY_PLANAR 0x59565955
Just a sidenote: This is misleading, that format is packed and not planar.
> void RGBToUV(unsigned short int r,
> unsigned short int g,
> unsigned short int b,
> unsigned short int * u,
> unsigned short int * v)
> {
> *u = -0.147 * r +
> -0.289 * g +
> 0.436 * b; // min(abs(r * -1214 + g * -2384 + b * 3598 + 4096 + 1048576)
> >> 13, 240);
> //(unsigned short int)(-0.147f*(float)r-0.289f*(float)g+0.436f*(float)b);
> *v = 0.615 * r +
> -0.515 * g +
> -0.100 * b;
> //min(abs(r * 3598 + g * -3013 + b * -585 + 4096 + 1048576) >> 13, 240);
> //(unsigned short int)(0.615f*(float)r-0.515f*(float)g-0.100f*(float)b);
> }
> void RGBToY(unsigned short int r,
> unsigned short int g,
> unsigned short int b,
> unsigned short int * y
> )
> {
> *y = 0.299 * r +
> 0.587 * g +
> 0.114 * b; // min(abs(r * 2104 + g * 4130 + b * 802 + 4096 + 131072) >>
> 13, 235);
> //(unsigned short int)(0.299f*(float)r+0.587f*(float)g+0.114f*(float)b);
> }
The formulas that are in use are wrong. You need to scale and shift the
YUV values. The formulas that you commented out are correct and yield
the correct colors here (min(abs(...) >> 13, 235)). These formulas also
worked in my test:
*y = ( ( 66 * r + 129 * g + 25 * b + 128) >> 8) + 16;
*u = ( ( -38 * r - 74 * g + 112 * b + 128) >> 8) + 128;
*v = ( ( 112 * r - 94 * g - 18 * b + 128) >> 8) + 128;
See wikipedia or msdn:
http://msdn.microsoft.com/en-us/library/ms893078.aspx
http://en.wikipedia.org/wiki/YUV#Numerical_approximations
tom
More information about the xorg
mailing list