wrong colors with Xv extension and image format id: 0x59565955 (UYVY) from an rgb mapping
Corbin Simpson
mostawesomedude at gmail.com
Wed Jan 21 21:33:35 PST 2009
Amos Tibaldi wrote:
> Hello,
> I am trying to use the Xv extension in order to display images on windows.
> I have obtained the image formats with
> xvc.fo = XvListImageFormats( xvc.display, xvc.port, (int *)&formats );
> and I have chosen the format
> id: 0x59565955 (UYVY)
> guid: 55595659-0000-0010-8000-00aa00389b71
> bits per pixel: 16
> number of planes: 1
> type: YUV (packed)
>
> I'd like to convert from RGB to UYVY and I have found that for the struct
>
> typedef struct {
> int id; /* Unique descriptor for the format */
> int type; /* XvRGB, XvYUV */
> int byte_order; /* LSBFirst, MSBFirst */
> char guid[16]; /* Globally Unique IDentifier */
> int bits_per_pixel;
> int format; /* XvPacked, XvPlanar */
> int num_planes;
>
> /* for RGB formats only */
> int depth;
> unsigned int red_mask;
> unsigned int green_mask;
> unsigned int blue_mask;
>
> /* for YUV formats only */
> unsigned int y_sample_bits;
> unsigned int u_sample_bits;
> unsigned int v_sample_bits;
> unsigned int horz_y_period;
> unsigned int horz_u_period;
> unsigned int horz_v_period;
> unsigned int vert_y_period;
> unsigned int vert_u_period;
> unsigned int vert_v_period;
> char component_order[32]; /* eg. UYVY */
> int scanline_order; /* XvTopToBottom, XvBottomToTop */
> } XvImageFormatValues;
>
> 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
>
> So I'm trying to convert the bytes from rgb with:
>
>
> void RGBToUYVY(unsigned short int r,
> unsigned short int g,
> unsigned short int b,
> unsigned short int * u,
> unsigned short int * y,
> unsigned short int * v)
> {
> //cout << "r=" << r << " g=" << g << " b=" << b;
> r &= 0x00FF; g &= 0x00FF; b &= 0x00FF;
> *y = (unsigned short
> int)(0.299f*(float)r+0.587f*(float)g+0.114f*(float)b);
> *u = (unsigned short
> int)(-0.147f*(float)r-0.289f*(float)g+0.436f*(float)b);
> *v = (unsigned short
> int)(0.615f*(float)r-0.515f*(float)g-0.100f*(float)b);
> *y &= 0x00FF;
> *u &= 0x00FF;
> *v &= 0x00FF;
> //cout << " y=" << *y << " u=" << *u << " v=" << *v <<endl;
> }
>
> and to display the image with
> void XVWindow::Redraw()
> {
> unsigned short int u, y, v;
> RGBToUYVY(255,255,0,&u,&y,&v);
> unsigned short int thecolor = u << 12 | y << 8 | v << 4 | y;
>
> for ( int y=0; y<ImageHeight; y++ )
> for ( int x=0; x<ImageWidth; x++ )
> ((unsigned short int *)BGimage->data)[ y * ImageWidth + x ] =
> thecolor;
>
> counter++;
> XvPutImage( xvc.display, xvc.port, window, gc,
> BGimage, 0, 0, ImageWidth, ImageHeight,
> 0, 0, WindowWidth, WindowHeight );
> }
>
> 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.
>
> 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?
Which driver, exactly? Most drivers provide RGB Xv formats, and those
that don't probably could be hacked to add it.
~ C.
More information about the xorg
mailing list