Find the answer to your Linux question:
Results 1 to 3 of 3
Hi, I have decoder code which uses X11 window to show the decoded video output. But the problem is firstly X11 window was unable to show the images. Then after ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2006
    Posts
    4

    Question X11 display related Problem!!!!!!


    Hi,
    I have decoder code which uses X11 window to show the decoded video output.
    But the problem is firstly X11 window was unable to show the images.
    Then after changing some parameter of some X11 function it is showing video in X11 window. But the video is not clear and it is showing multiple(4)images of the same video. Please guide me to solve the problem?

    The Display code is like:---

    void dec_InitializeDisplayProcess(char *pp_Name)
    {
    int crv, cbu, cgu, cgv;
    int Y, Cb, Cr, R, G, B;
    int i;
    char dummy;
    int screen;
    Colormap cmap;
    int private;
    XColor xcolor;
    unsigned int fg, bg;
    char *hello = "MPEG-2 Display";
    XSizeHints hint;
    XVisualInfo vinfo;
    XEvent xev;
    unsigned long tmp_pixel;
    XWindowAttributes xwa;

    p_dec_DisplayPtr = XOpenDisplay(pp_Name);

    if (p_dec_DisplayPtr == NULL)
    dec_Error("Can not open display\n");

    screen = DefaultScreen(p_dec_DisplayPtr);

    hint.x = 200;
    hint.y = 200;
    hint.width = v_dec_HorizontalSize;
    hint.height = v_dec_VerticalSize;
    hint.flags = PPosition | PSize;

    /* Get some colors */

    bg = WhitePixel (p_dec_DisplayPtr, screen);
    fg = BlackPixel (p_dec_DisplayPtr, screen);

    /* Make the window */

    if (!XMatchVisualInfo(p_dec_DisplayPtr, screen, 8, PseudoColor, &vinfo))
    {
    if (!XMatchVisualInfo(p_dec_DisplayPtr, screen, 8, GrayScale, &vinfo))
    dec_Error("requires 8 bit display\n");
    }

    v_dec_WindowInstance = XCreateSimpleWindow (p_dec_DisplayPtr, DefaultRootWindow (p_dec_DisplayPtr),
    hint.x, hint.y, hint.width, hint.height, 4, fg, bg);

    XSelectInput(p_dec_DisplayPtr, v_dec_WindowInstance, StructureNotifyMask);

    /* Tell other applications about this window */

    XSetStandardProperties (p_dec_DisplayPtr, v_dec_WindowInstance, hello, hello, None, NULL, 0, &hint);

    /* Map window. */

    XMapWindow(p_dec_DisplayPtr, v_dec_WindowInstance);

    /* Wait for map. */
    do
    {
    XNextEvent(p_dec_DisplayPtr, &xev);
    }
    while (xev.type != MapNotify || xev.xmap.event != v_dec_WindowInstance);

    XSelectInput(p_dec_DisplayPtr, v_dec_WindowInstance, NoEventMask);

    /* matrix coefficients */
    crv = a_dec_Inverse_Table_6_9[v_dec_MatrixCoefficients][0];
    cbu = a_dec_Inverse_Table_6_9[v_dec_MatrixCoefficients][1];
    cgu = a_dec_Inverse_Table_6_9[v_dec_MatrixCoefficients][2];
    cgv = a_dec_Inverse_Table_6_9[v_dec_MatrixCoefficients][3];

    /* allocate colors */

    v_dec_GCInstance = DefaultGC(p_dec_DisplayPtr, screen);
    cmap = DefaultColormap(p_dec_DisplayPtr, screen);
    private = 0;

    /* color allocation:
    * i is the (internal) 8 bit color number, it consists of separate
    * bit fields for Y, U and V: i = (yyyyuuvv), we don't use yyyy=0000
    * and yyyy=1111, this leaves 32 colors for other applications
    *
    * the allocated colors correspond to the following Y, U and V values:
    * Y: 24, 40, 56, 72, 88, 104, 120, 136, 152, 168, 184, 200, 216, 232
    * U,V: -48, -16, 16, 48
    *
    * U and V values span only about half the color space; this gives
    * usually much better quality, although highly saturated colors can
    * not be displayed properly
    *
    * translation to R,G,B is implicitly done by the color look-up table
    */
    for (i=16; i<240; i++)
    {
    /* color space conversion */
    Y = 16*((i>>4)&15) + 8;
    Cb = 32*((i>>2)&3) - 48;
    Cr = 32*(i&3) - 48;

    Y = 76309 * (Y - 16); /* (255/219)*65536 */

    R = p_dec_Clip[(Y + crv*Cr + 3276>>16];
    G = p_dec_Clip[(Y - cgu*Cb - cgv*Cr + 3276>>16];
    B = p_dec_Clip[(Y + cbu*Cb + 32786)>>16];

    /* X11 colors are 16 bit */
    xcolor.red = R << 8;
    xcolor.green = G << 8;
    xcolor.blue = B << 8;

    if (XAllocColor(p_dec_DisplayPtr, cmap, &xcolor) != 0)
    a_dec_Pixel[i] = xcolor.pixel;
    else
    {
    /* allocation failed, have to use a private colormap */

    if (private)
    dec_Error("Couldn't allocate private colormap");

    private = 1;

    if (!v_dec_QuietFlag)
    fprintf(stderr, "Using private colormap (%d colors were available).\n",
    i-16);

    /* Free colors. */
    while (--i >= 16)
    {
    tmp_pixel = a_dec_Pixel[i]; /* because XFreeColors expects unsigned long */
    XFreeColors(p_dec_DisplayPtr, cmap, &tmp_pixel, 1, 0);
    }

    /* i is now 15, this restarts the outer loop */

    /* create private colormap */

    XGetWindowAttributes(p_dec_DisplayPtr, v_dec_WindowInstance, &xwa);
    cmap = XCreateColormap(p_dec_DisplayPtr, v_dec_WindowInstance, xwa.visual, AllocNone);
    XSetWindowColormap(p_dec_DisplayPtr, v_dec_WindowInstance, cmap);
    }
    }

    p_dec_XimagePtr = XCreateImage(p_dec_DisplayPtr,None,8,ZPixmap,0,&du mmy,
    v_dec_CodedPictureWidth,v_dec_CodedPictureHeight,8 ,0);

    if (!(p_dec_DitheredImage = (unsigned char *)malloc(v_dec_CodedPictureWidth*
    v_dec_CodedPictureHeight)))
    dec_Error("malloc failed");

    if (!v_dec_ProgressiveSequence)
    {
    p_dec_XimagePtr2 = XCreateImage(p_dec_DisplayPtr,None,8,ZPixmap,0,&du mmy,
    v_dec_CodedPictureWidth,v_dec_CodedPictureHeight,8 ,0);

    if (!(p_dec_DitheredImage2 = (unsigned char *)malloc(v_dec_CodedPictureWidth*
    v_dec_CodedPictureHeight)))
    dec_Error("malloc failed");
    }
    Thank You.
    Dinesh

  2. #2
    Linux Engineer Javasnob's Avatar
    Join Date
    Jul 2005
    Location
    Wisconsin
    Posts
    942
    Please don't double post, and please put your code in code braces next time so it's easier for us to help you out.
    Flies of a particular kind, i.e. time-flies, are fond of an arrow.

    Registered Linux User #408794

  3. #3
    Just Joined!
    Join Date
    Jun 2006
    Posts
    4

    Question

    Sorry for doing this.
    And thanks for reply.
    I have overcome the problem but not fully. Every thig is fine. Video speed, resolution,size,time everything. But the only problem is it is showing 4 images. Can u plz tell me whether there is any thing called image scaling. Because I think Image scaling is the solution of this problem. But I m not getting anything like this. Plz help me.
    Thanks
    Dinesh

  4. $spacer_open
    $spacer_close

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •