<br><br><div class="gmail_quote"><br><div class="gmail_quote"><div class="Ih2E3d">2009/1/22 Tomas Carnecky <span dir="ltr"><<a href="mailto:tom@dbservice.com" target="_blank">tom@dbservice.com</a>></span><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><div></div><div>On 01/22/2009 07:35 PM, Amos Tibaldi wrote:<div><div></div><div class="Wj3C7c"><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
You both are right, but for now I obtain only solid color that doesn't<br>
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)<br>
 >> 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) >><br>
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<br>
associate the colours correctly?<br>
</blockquote>
<br></div></div></div></div><div><div></div><div class="Wj3C7c">
ImageWidth is the width in pixels, but in each iteration you fill in two pixels. So you either need 'x<ImageWidth/2' in the for() loop or use 'x/2' which is what you did.<br>
<br>
Also, keep in mind that you are filling only the first line of the whole image. The rest of the image probably has undefined/random colors. That you are seeing wrong colors could have several causes. Your formulas could be wrong (take a look at ffmpeg, xvid or any other projects that have rgb-to-yuv functions and borrow their code), endian issues (try YUYV or VYVU) or others.<br>


<br>
If in doubt, paste the minimal possible sample of your code that compiles and runs so we can test it.<br>
<br>
tom<br>
<br>
</div></div></blockquote></div>I have tried t look at ffmpeg and xvid but there is no code for YUV 8b each. Only for YUV444. Here is the compilable code, if you can help, the program shows a violet window, while it should not.<br>
<br>
tibaldi@core2duoE:~/XVideoTest$ cat Makefile <br>all: testxv2<br><br>INCLUDES = -I ./ -I /usr/include/X11/<br>LINKLIBS = -lpthread -lX11 -lXext -lXv<br>SOURCES := $(wildcard *.cc)<br>OBJECTS :=  $(SOURCES:.cc=.o)<br><br>
XVWindow.o: XVWindow.cc $(wildcard *.h)<br>
    g++ -c $< -o $@ $(INCLUDES)<br><br>testxv2.o: testxv2.cc $(wildcard *.h)<br>    g++ -c $< -o $@ $(INCLUDES)<br><br>testxv2: Makefile $(OBJECTS) $(wildcard *.h)<br>     g++ -o testxv2  $(OBJECTS) -L/usr/X11R6/lib $(LINKLIBS)<br>

<br>clean:<br>    rm -f *.o testxv2<br><br>tibaldi@core2duoE:~/XVideoTest$ cat testxv2.cc<br>// XVideo test program by Jan Wedekind (jan at <a href="http://wedesoft.de" target="_blank">wedesoft.de</a>).<br>//<br>// Based on<br>
// * <a href="http://bellet.info/XVideo/testxv.c" target="_blank">http://bellet.info/XVideo/testxv.c</a><br>
// * <a href="http://svn.mplayerhq.hu/mplayer/trunk/libvo/vo_xv.c?view=markup" target="_blank">http://svn.mplayerhq.hu/mplayer/trunk/libvo/vo_xv.c?view=markup</a><br>// * <a href="http://svn.mplayerhq.hu/mplayer/trunk/libvo/x11_common.c?view=markup" target="_blank">http://svn.mplayerhq.hu/mplayer/trunk/libvo/x11_common.c?view=markup</a><br>

//<br>// Compile using<br>// g++ -o testxv2 testxv2.cc -L/usr/X11R6/lib -lX11 -lXext -lXv<br><br>#include <iostream><br>#include <iomanip><br>#include <X11/Xlib.h><br>#include <X11/Xutil.h><br>#include <X11/extensions/Xv.h><br>

#include <X11/extensions/Xvlib.h><br>#include <unistd.h><br>#include <stdint.h><br>#include <XVWindow.h><br><br>extern XVWindowsContext xvc;<br><br><br>using namespace std;<br><br><br><br>int main( int argc, char *argv[] )<br>

{<br>  int<br>    width = 320,<br>    height = 240;<br><br>LaunchXVWindowThread();<br>    <br>    while(!xvc.can_start);<br>    <br><br>    XVWindow * window = new XVWindow(width, height, (char*)"pippo");<br>    XVWindow * window2 = new XVWindow(width, height, (char*)"pluto");<br>

<br><br><br>while(!xvc.can_exit);<br><br><br>    delete window;<br>    delete window2;<br><br>    XVWindowsContextUnInitialize();<br>}<br><br>tibaldi@core2duoE:~/XVideoTest$ cat XVWindow.h <br>#ifndef XVWINDOW_H<br>#define XVWINDOW_H<br>

<br>#include <X11/Xlib.h><br>#include <X11/extensions/Xv.h><br>#include <X11/extensions/Xvlib.h><br>#include <X11/Xutil.h><br>#include <pthread.h><br><br>#define GUID_YUV12_PLANAR 0x32315659<br>

#define GUID_UYVY_PLANAR 0x59565955<br>   <br>class XVWindow<br>{    <br>private:<br>char name[256];<br> XGCValues xgcv; <br>GC gc;<br>XvImage * BGimage;<br>unsigned int WindowWidth, WindowHeight, OldWindowWidth, OldWindowHeight; <br>

int ImageWidth, ImageHeight; <br>float WindowAspectRatio;<br>bool fullscreen;<br>public:<br>Window window;<br>XVWindow * pme;<br>XVWindow(int w, int h, char * name);<br>~XVWindow();<br>void CreateBGImage(int w, int h);<br>

void SetWindowDimension(int w, int h);<br>void Redraw();<br>void ToggleFullScreen();<br>void FixAspectRatioOfWindow();<br>};<br><br>typedef struct {<br>    Display * display;<br>    XvAdaptorInfo * ai;<br>    XVisualInfo visualInfo;<br>

    unsigned long mask;<br>    XSetWindowAttributes xswa;<br>    int NumberOfWindows;<br>    XVWindow * WindowsArray[256];<br>    Colormap colourMap;<br>      XvPortID port;<br>        unsigned int format;<br>          XvImageFormatValues *fo;<br>

          unsigned int DisplayWidth, DisplayHeight;<br>    pthread_t xvwindowThread;<br>    pthread_mutex_t ctxMutex;<br>    pthread_cond_t ctxCond;<br>    bool can_start, can_exit;<br>} XVWindowsContext;<br><br><br>#ifdef __cplusplus<br>

extern"C"{<br>#endif<br>void XVWindowsContextInitialize();<br>void XVWindowsContextUnInitialize();<br>XVWindow * GetWindowPointer(Window w);<br>void RedrawAllWindows();<br>void LaunchXVWindowThread();<br>#ifdef __cplusplus<br>

}<br>#endif<br><br><br>#endif<br>tibaldi@core2duoE:~/XVideoTest$ cat XVWindow.cc <br>#include <iostream><br>#include <iomanip><br>#include <unistd.h><br>#include <stdint.h><br>#include <Xatom.h><br>

#include <XVWindow.h><br><br>using namespace std;<br>XVWindowsContext xvc;<br>void RedrawAllWindows()<br>{<br>                int i;<br>        for(i=0; i<xvc.NumberOfWindows; i++)<br>                xvc.WindowsArray[i]->pme->Redraw();<br>

}<br>Bool waitForNotify( Display *, XEvent *e, char *arg )<br>{<br>  return ( e->type == MapNotify ) && ( e->xmap.window == (Window)arg );<br>}<br>XVWindow::XVWindow(int w, int h, char * thename)<br>{<br>        pthread_mutex_lock(&xvc.ctxMutex);<br>

        //pthread_cond_wait(&xvc.ctxCond, &xvc.ctxMutex);<br>          XEvent event;<br>        ImageWidth = WindowWidth = OldWindowWidth = w;<br>        ImageHeight = WindowHeight = OldWindowHeight = h;<br>          window = XCreateWindow( xvc.display,<br>

                                 RootWindow( xvc.display, xvc.visualInfo.screen ),<br>                                 0, 0, w, h, 0,<br>                                 xvc.visualInfo.depth, InputOutput,<br>                                 xvc.visualInfo.visual,<br>

                                 xvc.mask,<br>                                 &(xvc.xswa) );<br>        strcpy(name, thename);<br>        char * aname = (char*) malloc(256);<br>        strcpy(aname, thename);<br>        XTextProperty titleprop;<br>

        XStringListToTextProperty(&aname, 1, &titleprop);<br>        XSetTextProperty(xvc.display, window, &titleprop, XA_WM_NAME);<br>        XFree(titleprop.value);<br>        free(aname);<br><br>          XMapWindow( xvc.display, window );<br>

        XIfEvent( xvc.display, &event, waitForNotify, (char *)window );<br>  gc = XCreateGC( xvc.display, window, 0L, &xgcv );<br>        pme = this;<br>        xvc.WindowsArray[xvc.NumberOfWindows] = this;<br>        xvc.NumberOfWindows++;<br>

        fullscreen = false;<br>        CreateBGImage(ImageWidth, ImageHeight);<br>        WindowAspectRatio = (float) ((float)ImageWidth)/((float)ImageHeight);<br>        cout << name << " ha aspect ratio " << WindowAspectRatio << endl;<br>

<br>        //pthread_cond_signal(&xvc.ctxCond);<br>    pthread_mutex_unlock(&xvc.ctxMutex);<br><br>}<br><br>void XVWindow::ToggleFullScreen()<br>{<br>    if(!fullscreen)<br>    {<br> XMoveResizeWindow(xvc.display, window, 0, 0, xvc.DisplayWidth, xvc.DisplayHeight);<br>

    XRaiseWindow(xvc.display, window);<br>    XFlush(xvc.display);<br>    WindowWidth = xvc.DisplayWidth; WindowHeight = xvc.DisplayHeight;<br>    fullscreen = true;<br>    return;<br>    }<br>    else<br>    {<br>        XMoveResizeWindow(xvc.display, window, 50, 50, ImageWidth, ImageHeight);<br>

    XRaiseWindow(xvc.display, window);<br>    XFlush(xvc.display);<br>    WindowWidth = ImageWidth; WindowHeight = ImageHeight;<br>    fullscreen = false;    <br>    }<br>}<br><br>XVWindow::~XVWindow()<br>{<br>        free( BGimage->data );<br>

<br>  XFree( BGimage );<br>          XFreeGC( xvc.display, gc );<br>      XDestroyWindow( xvc.display, window );<br>}<br><br>void XVWindow::SetWindowDimension(int w, int h)<br><br>{  <br>    OldWindowWidth = WindowWidth;<br>

    OldWindowHeight = WindowHeight;<br>    WindowWidth = w;<br>    WindowHeight = h;<br>}<br><br>void XVWindow::FixAspectRatioOfWindow()<br>{<br>    //cout << "swd w=" << w<<" h="<<h<<endl;<br>

    int deltax = 0, deltay = 0;<br>    deltax = WindowWidth-OldWindowWidth; deltay = WindowHeight-OldWindowHeight;<br>    deltax = abs(deltax); deltay = abs(deltay);<br>    cout << "dx=" <<deltax << "dy=" <<deltay<<endl;<br>

    if((deltax==0)&&(deltay==0)) return;<br>    if(deltax>deltay)<br>    {<br>            WindowHeight = (unsigned int) (((float)WindowWidth)/WindowAspectRatio);<br>    }<br>    else<br>    {<br>            WindowWidth = (unsigned int) (WindowAspectRatio*((float)WindowHeight));    <br>

    }<br>    <br>    cout << "new w dim " << WindowWidth<<"x"<<WindowHeight<<endl;<br>    XWindowChanges xwc; xwc.width = WindowWidth; xwc.height = WindowHeight;<br>    XConfigureWindow(xvc.display, window, CWWidth|CWHeight, &xwc);<div>
<div></div><div class="Wj3C7c"><br>
    <br>}<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>
</div></div>
   for ( int x=0; x<ImageWidth; x+=2 )<div class="Ih2E3d"><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></div><div class="Ih2E3d">            XvPutImage( xvc.display, xvc.port, window, gc,<br>                    BGimage, 0, 0, ImageWidth, ImageHeight, <br>                       0, 0, WindowWidth, WindowHeight );<br>
}<br><br><br></div>void XVWindow::CreateBGImage(int w, int h)<br>
{<br>  BGimage = (XvImage *)XvCreateImage( xvc.display, xvc.port, xvc.format, NULL,<br>                                             w, h );<br>  BGimage->data = (char *)malloc( BGimage->data_size );<br>    ImageWidth = w;<br>

    ImageHeight = h;<br> <br>}<br><br><br>static Atom xv_intern_atom_if_exists( Display *display, XvPortID port,<br>                                      char const *atom_name )<br>{<br>  XvAttribute * attributes;<br>  int attrib_count,i;<br>

  Atom xv_atom = None;<br><br>  attributes = XvQueryPortAttributes( display, port, &attrib_count );<br>  if( attributes!=NULL )<br>  {<br>    for ( i = 0; i < attrib_count; ++i )<br>    {<br>      if ( strcmp(attributes[i].name, atom_name ) == 0 )<br>

      {<br>        xv_atom = XInternAtom( display, atom_name, False );<br>        break; // found what we want, break out<br>      }<br>    }<br>    XFree( attributes );<br>  }<br><br>  return xv_atom;<br>}<br><br>XVWindow * GetWindowPointer(Window w)<br>

{<br>    int i;<br>    <br>        for(i=0; i<xvc.NumberOfWindows; i++)<br>    {<br>        if(xvc.WindowsArray[i]->window == w) return xvc.WindowsArray[i]->pme;<br>    }<br>        return 0;<br>}<br><br><br><br>

void PrintImageFormatCharacteristics(XvImageFormatValues * ifvp)<br>{<br>      cout << "ysb " << ifvp->y_sample_bits << "; ";<br>  cout << "usb " << ifvp->u_sample_bits << "; ";<br>

  cout << "vsb " << ifvp->v_sample_bits << "; ";   <br>  cout << "hyp " << ifvp->horz_y_period << "; ";<br>  cout << "hup " << ifvp->horz_u_period << "; ";<br>

  cout << "hvp " << ifvp->horz_v_period << "; ";<br>  cout << "vyp " << ifvp->vert_y_period << "; ";<br>  cout << "vup " << ifvp->vert_u_period << "; ";<br>

  cout << "vvp " << ifvp->vert_v_period << "; ";<br>    cout << "\'";<br>    for(int i=0; i<32; i++)<br>     cout<< ifvp->component_order[i] ;<br>    cout << "\'" ; <br>

    cout << "slo: " << ifvp->scanline_order;          /* XvTopToBottom, XvBottomToTop */<br>    <br>    <br>    cout << endl;<br>}<br><br>void XVWindowsContextInitialize()<br>{<br>    xvc.display = XOpenDisplay( NULL );<br>

    unsigned int ver, rel, req, ev, err;<br>    bool retVal =<br>      ( XvQueryExtension( xvc.display, &ver, &rel, &req, &ev, &err ) == Success );<br>    if ( !retVal )<br>      exit(-1);<br>  unsigned int adaptors;<br>

  <a href="http://xvc.ai" target="_blank">xvc.ai</a> = NULL;<br>  {<br>    bool retVal =<br>      ( XvQueryAdaptors( xvc.display, DefaultRootWindow( xvc.display ), &adaptors,<br>                         &(<a href="http://xvc.ai" target="_blank">xvc.ai</a>) ) == Success );<br>

    if ( !retVal )<br>      exit(-1);<br>  };<br>  xvc.port = 0;<br>  for ( int i=0; i<adaptors; i++ ) {<br>    if ( ( <a href="http://xvc.ai" target="_blank">xvc.ai</a>[i].type & ( XvInputMask | XvImageMask ) ) ==<br>
         ( XvInputMask | XvImageMask ) ) {<br>
      for ( int p=<a href="http://xvc.ai" target="_blank">xvc.ai</a>[i].base_id; p<<a href="http://xvc.ai" target="_blank">xvc.ai</a>[i].base_id+<a href="http://xvc.ai" target="_blank">xvc.ai</a>[i].num_ports; p++ )<br>
        if ( !XvGrabPort( xvc.display, p, CurrentTime ) ) {<br>
          xvc.port = p;<br>          break;<br>        };<br>      if ( xvc.port != 0 )<br>        break;<br>    };<br>  };<br>  if ( !xvc.port )<br>    exit(-1);<br>  int colourkey = 0;<br>  Atom xvColorKey = xv_intern_atom_if_exists( xvc.display, xvc.port, "XV_COLORKEY" );<br>

  if ( xvColorKey != None ) {<br>    if ( XvGetPortAttribute( xvc.display, xvc.port, xvColorKey, &colourkey ) !=<br>         Success )<br>      exit(-1);<br>    Atom xvAutoPaint = xv_intern_atom_if_exists( xvc.display, xvc.port,<br>

                                                 "XV_AUTOPAINT_COLORKEY" );<br>    if ( xvAutoPaint != None ) {<br>      XvSetPortAttribute( xvc.display, xvc.port, xvAutoPaint, 1 );<br>      xvColorKey = None;<br>

    };<br>  } else {<br>  }<br>  unsigned int formats;<br>  <a href="http://xvc.fo" target="_blank">xvc.fo</a> = 0;<div class="Ih2E3d"><br>  <a href="http://xvc.fo" target="_blank">xvc.fo</a> = XvListImageFormats( xvc.display, xvc.port, (int *)&formats );<br>
</div>  if ( !(<a href="http://xvc.fo" target="_blank">xvc.fo</a>) )<br>
    exit(-1);<br>  xvc.format = 0;<br>  for ( int i=0; i<formats; i++ ) {<br>      cout << "Format " <<i<< "is of type " << (int)(<a href="http://xvc.fo" target="_blank">xvc.fo</a>[i].type==XvYUV) <<endl;<br>

    if ( <a href="http://xvc.fo" target="_blank">xvc.fo</a>[i].id == GUID_UYVY_PLANAR ) {<br>      xvc.format = <a href="http://xvc.fo" target="_blank">xvc.fo</a>[i].id;<br>        PrintImageFormatCharacteristics(&<a href="http://xvc.fo" target="_blank">xvc.fo</a>[i]);<br>

    };<br>  };<br>  if ( !xvc.format )<br>    exit(-1);<br>  <br>  int depth;<br>  <br>    XWindowAttributes attribs;<br>    XGetWindowAttributes( xvc.display, DefaultRootWindow( xvc.display ), &attribs );<br>    depth = attribs.depth;<br>

    if (depth != 15 && depth != 16 && depth != 24 && depth != 32) depth = 24;<br>  <br>  <br>  XMatchVisualInfo( xvc.display, DefaultScreen( xvc.display ), depth, TrueColor,<br>                    &(xvc.visualInfo ));<br>

  <br>  xvc.colourMap =<br>    XCreateColormap( xvc.display, DefaultRootWindow( xvc.display ), xvc.visualInfo.visual,<br>                     AllocNone );<br>  xvc.xswa.colormap = xvc.colourMap;<br>  xvc.xswa.border_pixel = 0;<br>

  xvc.xswa.background_pixel = colourkey;<br>  xvc.xswa.event_mask = ExposureMask | StructureNotifyMask | KeyPressMask | ButtonReleaseMask;<br>  xvc.mask = CWBorderPixel | CWColormap | CWEventMask;<br>  if ( xvColorKey != None ) xvc.mask |= CWBackPixel;<br>

  xvc.DisplayWidth = XDisplayWidth(xvc.display, DefaultScreen(xvc.display));<br>  xvc.DisplayHeight = XDisplayHeight(xvc.display, DefaultScreen(xvc.display));<br>    cout << "SCREEN " << xvc.DisplayWidth << "x" << xvc.DisplayHeight << endl;<br>

}<br><br><br><br>void * XVWindowThreadProcedure(void*data)<br>{<br>    cout <<"A"<<endl;<br>        XVWindowsContextInitialize();<br>    xvc.can_start = true;<br>    cout <<"b"<<endl;<br>

        bool quit = false;<br>  int c=0;<br>  do {<br>      pthread_mutex_lock(&xvc.ctxMutex);<br>      //pthread_cond_wait(&xvc.ctxCond, &xvc.ctxMutex);<br>    XEvent event;<br>      XVWindow * pw;<br>    if ( XCheckMaskEvent( xvc.display,<br>

                          KeyPressMask | ExposureMask | StructureNotifyMask | ButtonReleaseMask,<br>                          &event ) ) {<br>      switch ( event.type ) {<br>      case ConfigureNotify:<br>          pw = GetWindowPointer(event.xconfigure.window);<br>

            pw->SetWindowDimension(event.xconfigure.width, event.xconfigure.height);<br>              pw->Redraw();<br>              break;<br>          case ButtonRelease:<br><br>          pw = GetWindowPointer(event.xbutton.window);<br>

            pw->FixAspectRatioOfWindow();<br>          <br>            break;  <br>          case Expose:<br>        //  cout<<"Expose"<<endl;<br>          pw = GetWindowPointer(event.xexpose.window);<br>

            pw->Redraw();<br>        //  cout<<"Expose end"<<endl;<br>              break;<br>      case KeyPress:<br>         // cout << "press " << event.xkey.keycode << endl;<br>

        if ( event.xkey.keycode == 0x09 )<br>          quit = true;<br>        if ( event.xkey.keycode == 0x29 )<br>          {<br>            //  cout << "GoFullScreen" << endl;<br>              pw = GetWindowPointer(event.xkey.window);<br>

              pw->ToggleFullScreen();<br>          }<br>              if( event.xkey.keycode == 0x26 )<br>          {<br>            pw = GetWindowPointer(event.xkey.window);<br>              pw->FixAspectRatioOfWindow();<br>

          }<br>        break;<br>      default:<br>        break;<br>      };<br>    } else {<br>      RedrawAllWindows();  <br>    };<br>     // cout <<"fine"<<endl;<br>    c++;<br>      //pthread_cond_signal(&xvc.ctxCond);<br>

      pthread_mutex_unlock(&xvc.ctxMutex);<br><br>  } while ( !quit );<br>  cerr << "# frames = " << c << endl;<br>    xvc.can_exit = true;<br>    <br>    <br>}<br><br>void LaunchXVWindowThread()<br>

{<br>    pthread_mutex_init(&xvc.ctxMutex, 0);<br>    pthread_cond_init(&xvc.ctxCond, 0);<br>    xvc.can_start = xvc.can_exit = false;<br>    pthread_create(&xvc.xvwindowThread, 0, XVWindowThreadProcedure, &xvc);<br>

}<br><br>void XVWindowsContextUnInitialize()<br>{<br>    pthread_join(xvc.xvwindowThread, 0);<br><br>  XvUngrabPort( xvc.display, xvc.port, CurrentTime );<br>      XFreeColormap( xvc.display, xvc.colourMap );<br>  XvFreeAdaptorInfo(<a href="http://xvc.ai" target="_blank">xvc.ai</a>);<br>

  XFree(<a href="http://xvc.fo" target="_blank">xvc.fo</a>);<br>  XCloseDisplay( xvc.display );<br>    <br>}<br><br>Can you help me, please? Thanks in advance<br><br>-- <br><font color="#888888">Amos Tibaldi<br>
</font></div><br><br clear="all"><br>