<span class="gmail_quote"><br></span>Hello,<br>
I am trying to use the Xv extension in order to display images on windows. I have obtained the image formats with<br>
<a href="http://xvc.fo" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">xvc.fo</a> = XvListImageFormats( xvc.display, xvc.port, (int *)&formats );<br>
and I have chosen the format <br>
id: 0x59565955 (UYVY)<br>
guid: 55595659-0000-0010-8000-00aa00389b71<br>
bits per pixel: 16<br>
number of planes: 1<br>
type: YUV (packed)<br>
<br>
I'd like to convert from RGB to UYVY and I have found that for the struct<br>
<br>
typedef struct {<br>
int
id;
/* Unique descriptor for the format */<br>
int
type;
/* XvRGB, XvYUV */<br>
int byte_order; /* LSBFirst, MSBFirst */<br>
char
guid[16];
/* Globally Unique IDentifier */<br>
int bits_per_pixel;<br>
int
format;
/* XvPacked, XvPlanar */<br>
int num_planes;<br>
<br>
/* for RGB formats only */<br>
int depth;<br>
unsigned int red_mask; <br>
unsigned int green_mask; <br>
unsigned int blue_mask; <br>
<br>
/* for YUV formats only */<br>
unsigned int y_sample_bits;<br>
unsigned int u_sample_bits;<br>
unsigned int v_sample_bits; <br>
unsigned int horz_y_period;<br>
unsigned int horz_u_period;<br>
unsigned int horz_v_period;<br>
unsigned int vert_y_period;<br>
unsigned int vert_u_period;<br>
unsigned int vert_v_period;<br>
char component_order[32]; /* eg. UYVY */<br>
int scanline_order; /* XvTopToBottom, XvBottomToTop */<br>
} XvImageFormatValues; <br>
<br>
that image format has: ysb 8; usb 8; vsb 8; hyp 1; hup 2; hvp 2; vyp 1; vup 1; vvp 1; 'UYVY'slo: 0<br>
<br>
So I'm trying to convert the bytes from rgb with:<br>
<br>
<br>
void RGBToUYVY(unsigned short int r, <br>
unsigned short int g, <br>
unsigned short int b, <br>
unsigned short int * u, <br>
unsigned short int * y, <br>
unsigned short int * v)<br>
{<br>
//cout << "r=" << r << " g=" << g << " b=" << b;<br>
r &= 0x00FF; g &= 0x00FF; b &= 0x00FF;<br>
*y = (unsigned short int)(0.299f*(float)r+0.587f*(float)g+0.114f*(float)b);<br>
*u = (unsigned short int)(-0.147f*(float)r-0.289f*(float)g+0.436f*(float)b);<br>
*v = (unsigned short int)(0.615f*(float)r-0.515f*(float)g-0.100f*(float)b);<br>
*y &= 0x00FF;<br>
*u &= 0x00FF;<br>
*v &= 0x00FF;<br>
//cout << " y=" << *y << " u=" << *u << " v=" << *v <<endl;<br>
}<br>
<br>
and to display the image with<br>
void XVWindow::Redraw()<br>
{<br>
unsigned short int u, y, v;<br>
RGBToUYVY(255,255,0,&u,&y,&v);<br>
unsigned short int thecolor = u << 12 | y << 8 | v << 4 | y;<br>
<br>
for ( int y=0; y<ImageHeight; y++ )<br>
for ( int x=0; x<ImageWidth; x++ )<br>
((unsigned short int *)BGimage->data)[ y * ImageWidth + x ] = thecolor;<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>
but the colors are always different. I have tried to use the blue, the
red and the green to see if I could obtain them separately but the
mapping was always wrong and different colours were showing on the
window with respect to those that I'd like to use in RGB.<br>
<br>
What can I do? Is my RGB to UYVY correct? Why do I obtain on the screen
different colours. There are some kind of manual on how to map colors
with XV images?<br>
<br>
Thanks in advance,<br><span class="sg">
<br>
Amos Tibaldi<br>
<br>
<br clear="all">
</span>