<br><br><div class="gmail_quote">2009/1/22 Simon Farnsworth <span dir="ltr"><<a href="mailto:simon.farnsworth@onelan.co.uk">simon.farnsworth@onelan.co.uk</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">Amos Tibaldi wrote:<br>
> unsigned short int thecolor = u << 12 | y << 8 | v << 4 | y;<br>
><br>
</div>This is completely wrong. In a UYVY image, you have two different 8-bit<br>
Y components, sharing an 8-bit U component, and an 8-bit V component. In<br>
pseudocode, creating a 32-bit UYVY pixel pair from two RGB pixels:<br>
<br>
(y, u, v) RGBtoYUV( r, g, b )<br>
{<br>
y = 0.299 * r +<br>
0.587 * g +<br>
0.114 * b;<br>
<br>
u = -0.147 * r +<br>
-0.289 * g +<br>
0.436 * b;<br>
<br>
v = 0.615 * r +<br>
-0.515 * g +<br>
-0.100 * b;<br>
}<br>
<br>
uyvy RGBtoUYUV( r1, g1, b1, r2, g2, b2 )<br>
{<br>
(y1,u1,v1) = RGBtoYUV( r1, g1, b1 )<br>
(y2,u2,v2) = RGBtoYUV( r2, g2, b2 )<br>
<br>
u = (u1 + u2) / 2; // Or other decimation strategy<br>
v = (v1 + v2) / 2; // Or other decimation strategy<br>
<br>
uyvy = 8bits(u) << 24;<br>
uyvy |= 8bits(y1) << 16;<br>
uyvy |= 8bits(v) << 8;<br>
uyvy |= 8bits(y2);<br>
}<br>
--<br>
<font color="#888888">Simon Farnsworth<br>
<br>
</font></blockquote></div><br>You both are right, but for now I obtain only solid color that doesn't correspond to the desired one; here is the code:<br><br>void RGBToUV(unsigned short int r,<br> unsigned short int g,<br>
unsigned short int b,<br> unsigned short int * u,<br> unsigned short int * v)<br>{<br> *u = -0.147 * r +<br> -0.289 * g +<br>
0.436 * b; // min(abs(r * -1214 + g * -2384 + b * 3598 + 4096 + 1048576) >> 13, 240);<br> //(unsigned short int)(-0.147f*(float)r-0.289f*(float)g+0.436f*(float)b);<br> *v = 0.615 * r +<br> -0.515 * g +<br>
-0.100 * b;<br> //min(abs(r * 3598 + g * -3013 + b * -585 + 4096 + 1048576) >> 13, 240);<br> //(unsigned short int)(0.615f*(float)r-0.515f*(float)g-0.100f*(float)b);<br>}<br>void RGBToY(unsigned short int r,<br>
unsigned short int g,<br> unsigned short int b,<br> unsigned short int * y<br> )<br>{<br> *y = 0.299 * r +<br> 0.587 * g +<br>
0.114 * b; // min(abs(r * 2104 + g * 4130 + b * 802 + 4096 + 131072) >> 13, 235);<br>//(unsigned short int)(0.299f*(float)r+0.587f*(float)g+0.114f*(float)b);<br>}<br><br>void XVWindow::Redraw()<br>{ <br>
unsigned short int u, y1, y2, v;<br> /*RGBToY(255,0,0,&y1);<br> RGBToY(255,0,0,&y2);<br> RGBToUV(255,0,0,&u,&v);*/<br>/* RGBToY(0,255,0,&y1);<br> RGBToY(0,255,0,&y2);<br> RGBToUV(0,255,0,&u,&v); */<br>
RGBToY(0,0,255,&y1);<br> RGBToY(0,0,255,&y2);<br> RGBToUV(0,0,255,&u,&v);<br><br> unsigned char * p = (unsigned char *) BGimage->data; <br> for ( int y=0; y<ImageHeight; y++ , p += BGimage->pitches[0] )<br>
for ( int x=0; x<ImageWidth; x++ )<br> {<br> p [ (x << 1) + 3 ] = y2;<br> p [ (x << 1) + 2 ] = v;<br> p [ (x << 1) + 1 ] = y1;<br> p [ (x << 1) ] = u;<br> }<br> <br>
counter++;<br> XvPutImage( xvc.display, xvc.port, window, gc,<br> BGimage, 0, 0, ImageWidth, ImageHeight, <br> 0, 0, WindowWidth, WindowHeight );<br>}<br><br>I cannot understand but it works only if I use (x<<1). What can I do to associate the colours correctly?<br>
<br><br>Thanks,<br clear="all"><br>-- <br>Amos Tibaldi<br>