Colormap Issue in Linux - Motif

This is a discussion on Colormap Issue in Linux - Motif ; I have a colormap question dealing with a project that must be supported on Sun workstations (Solaris 8 - Motif 1.2) as well as Dell Linux machines (Redhat 9 w/ OpenMotif 2.2). I am currently using XAllocColorCells on the default ...

+ Reply to Thread
Results 1 to 11 of 11

Thread: Colormap Issue in Linux

  1. Colormap Issue in Linux

    I have a colormap question dealing with a project that must be supported
    on Sun workstations (Solaris 8 - Motif 1.2) as well as Dell Linux
    machines (Redhat 9 w/ OpenMotif 2.2).

    I am currently using XAllocColorCells on the default colormap of the
    screen to allocate 24 colors. This works fine on the Sun workstations,
    however, it fails on the Linux machines. I have a feeling that this is
    an issued with Psuedocolor being set on the Suns and Truecolor (being a
    read only colormap) being set on the Linux machines.

    My first question is: how do I set X on the Linux machines to be in
    DirectColor?

    And... if this causes a problem with other applications, I'll probably
    need to come up with another solution (i.e. - make a private colormap).

    And so, my second question is if anyone has any code examples of a
    private colormap being allocated and then used for XAllocColorCells. I
    haven't been quite able to get this working yet, so I'm looking for some
    code examples.

    Any help would be apprecaited. Thanks.


  2. Re: Colormap Issue in Linux

    coaxl wrote:
    > I have a colormap question dealing with a project that must be supported
    > on Sun workstations (Solaris 8 - Motif 1.2) as well as Dell Linux
    > machines (Redhat 9 w/ OpenMotif 2.2).
    >
    > I am currently using XAllocColorCells on the default colormap of the
    > screen to allocate 24 colors. This works fine on the Sun workstations,
    > however, it fails on the Linux machines. I have a feeling that this is
    > an issued with Psuedocolor being set on the Suns and Truecolor (being a
    > read only colormap) being set on the Linux machines.
    >
    > My first question is: how do I set X on the Linux machines to be in
    > DirectColor?
    >
    > And... if this causes a problem with other applications, I'll probably
    > need to come up with another solution (i.e. - make a private colormap).
    >
    > And so, my second question is if anyone has any code examples of a
    > private colormap being allocated and then used for XAllocColorCells. I
    > haven't been quite able to get this working yet, so I'm looking for some
    > code examples.
    >
    > Any help would be apprecaited. Thanks.
    >



    Eric Foster-Johnson wrote an article for Unix Review in November 1999
    named "High-Definition X Color". That would be a good starting point.

    Unfortunately the archive of that article seems to have disappeared
    from unixreview.com.

    However I'm sure if you contact Eric he'd be happy to provide you with
    a copy. His website has his email address:

    http://www.pconline.com/~erc/


  3. Re: Colormap Issue in Linux

    Chris Sorenson wrote:
    > coaxl wrote:
    >
    >> I have a colormap question dealing with a project that must be
    >> supported on Sun workstations (Solaris 8 - Motif 1.2) as well as Dell
    >> Linux machines (Redhat 9 w/ OpenMotif 2.2).
    >>
    >> I am currently using XAllocColorCells on the default colormap of the
    >> screen to allocate 24 colors. This works fine on the Sun workstations,
    >> however, it fails on the Linux machines. I have a feeling that this is
    >> an issued with Psuedocolor being set on the Suns and Truecolor (being
    >> a read only colormap) being set on the Linux machines.
    >>
    >> My first question is: how do I set X on the Linux machines to be in
    >> DirectColor?
    >>
    >> And... if this causes a problem with other applications, I'll probably
    >> need to come up with another solution (i.e. - make a private colormap).
    >>
    >> And so, my second question is if anyone has any code examples of a
    >> private colormap being allocated and then used for XAllocColorCells. I
    >> haven't been quite able to get this working yet, so I'm looking for
    >> some code examples.
    >>
    >> Any help would be apprecaited. Thanks.
    >>

    >
    >
    > Eric Foster-Johnson wrote an article for Unix Review in November 1999
    > named "High-Definition X Color". That would be a good starting point.
    >
    > Unfortunately the archive of that article seems to have disappeared
    > from unixreview.com.
    >
    > However I'm sure if you contact Eric he'd be happy to provide you with
    > a copy. His website has his email address:
    >
    > http://www.pconline.com/~erc/
    >


    Thanks Chris,

    I was actually able to get to the article. Here's the link in case you
    are interested:

    http://web.archive.org/web/200105090.../9911ct/ct.htm

    I tried a couple of suggested methods in the article without success.

    Namely, I tried to use XMatchVisualInfo() to return a visual w/
    DirectColor. The status returned is consistently zero.

    I guess my next step is to try to force X to start in DirectColor mode
    rather than Truecolor. Any ideas on how to do this on the Linux
    machines? I thought it might be in the XF86defaults file but couldn't
    find where that would be.

    Any more thoughts?


  4. Re: Colormap Issue in Linux

    Nick Vitalbo wrote:

    >
    > Thanks Chris,
    >
    > I was actually able to get to the article. Here's the link in case you
    > are interested:
    >
    > http://web.archive.org/web/200105090.../9911ct/ct.htm
    >


    Huh! Who knew? That's rather amazing...

    >
    > I tried a couple of suggested methods in the article without success.
    >
    > Namely, I tried to use XMatchVisualInfo() to return a visual w/
    > DirectColor. The status returned is consistently zero.
    >
    > I guess my next step is to try to force X to start in DirectColor mode
    > rather than Truecolor. Any ideas on how to do this on the Linux
    > machines? I thought it might be in the XF86defaults file but couldn't
    > find where that would be.
    >
    > Any more thoughts?
    >


    I think you can get directcolor by forcing X to start with 24 bits per
    pixel. So, in XF86Config, in the "Screen" section, you want to comment
    out any 8 bit or 16 bit or 32 bit options, and just leave the 24 bit
    option. I'm no expert but I think that ought to do it.

    And remember: X Windows is to graphics hacking as roman numerals are to
    the square root of pi...


  5. Re: Colormap Issue in Linux

    Nick Vitalbo wrote:

    >>> I am currently using XAllocColorCells on the default colormap of the
    >>> screen to allocate 24 colors. This works fine on the Sun
    >>> workstations, however, it fails on the Linux machines. I have a
    >>> feeling that this is an issued with Psuedocolor being set on the Suns
    >>> and Truecolor (being a read only colormap) being set on the Linux
    >>> machines.

    [...]
    >
    > http://web.archive.org/web/200105090.../9911ct/ct.htm
    >
    > I tried a couple of suggested methods in the article without success.


    I suggest you use XAllocColor instead of XAllocColorCells. It's much simpler
    and works with any colormap/depth. Here's a code snippet that returns color
    pixel provided you know the color RGB components (which should be 16-bits long):

    long x11_allocate_color(const RGB *rgb)
    {
    XColor xc;

    xc.pixel = 0;
    xc.flags = DoRed | DoGreen | DoBlue;

    xc.red = rgb->red;
    xc.green = rgb->green;
    xc.blue = rgb->blue;

    if (XAllocColor(disp, cmap, &xc)) {
    return xc.pixel;
    } else {
    return -1;
    }
    }

    Regards,

    Evgeny


  6. Re: Colormap Issue in Linux

    Evgeny Stambulchik wrote:

    > long x11_allocate_color(const RGB *rgb)
    > {
    > XColor xc;
    >
    > xc.pixel = 0;
    > xc.flags = DoRed | DoGreen | DoBlue;
    >
    > xc.red = rgb->red;
    > xc.green = rgb->green;
    > xc.blue = rgb->blue;
    >
    > if (XAllocColor(disp, cmap, &xc)) {
    > return xc.pixel;
    > } else {
    > return -1;
    > }
    > }


    This works well for allocating the colors actually. Now, I am trying to
    use an overlay plane. For instance, I'm using this overlay plane for
    drag and drop features within my application. Let's say that once you
    click on some item, the outline is drawn in red (the overlay color).
    Here's a snipet of what I have.

    This occurs if XAllocColorCells doesn't fail (returns non something
    nonzero)

    for(n = 0;n < NUM_COLORS;n++)
    {
    if(!XParseColor( mapDisplay,def_cmap,
    color_names[n],&exact_defs[n]))
    {
    fprintf(stderr, "FATAL: color not in database %s\n", color_names[n]);
    exit(0);
    }
    exact_defs[n].flags = DoRed | DoGreen | DoBlue;
    }
    for(n = 0;n < NUM_COLORS;n++)
    {
    exact_defs[n].pixel = color_list[n];
    }
    for(n = 0;n < NUM_COLORS;n++)
    {
    exact_defs[NUM_COLORS+n].pixel = color_list[n] | overlay_plane;
    exact_defs[NUM_COLORS+n].red = exact_defs[RED].red;
    exact_defs[NUM_COLORS+n].green = exact_defs[RED].green;
    exact_defs[NUM_COLORS+n].blue = exact_defs[RED].blue;
    exact_defs[NUM_COLORS+n].flags = DoRed | DoGreen | DoBlue;
    }

    XStoreColors( mapDisplay,def_cmap,exact_defs,2*NUM_COLORS);



    If XAllocColorCells does fail (returns zero), here's what I do:

    for(n = 0;n < NUM_COLORS;n++)
    {
    if( !XParseColor( mapDisplay,def_cmap, color_names[n],&exact_defs[n]))
    {
    fprintf(stderr, "FATAL: color not in database %s\n", color_names[n]);
    exit(0);
    }
    if(!XAllocColor( mapDisplay,def_cmap,&exact_defs[n]))
    {
    fprintf(stderr,"FATAL: Can't allocate %s\n", color_names[n]);
    exit(0);
    }

    /* set the pixel value */
    color_list[n] = (int)exact_defs[n].pixel;
    }

    Any thoughts on how to get the overlay plane to work w/ XAllocColor? I
    tried doing something like you had suggested (using my variable names)
    and then calling XAllocColor but that pesky overlay still won't work.


  7. Re: Colormap Issue in Linux

    Chris Sorenson wrote:
    > I think you can get directcolor by forcing X to start with 24 bits per
    > pixel. So, in XF86Config, in the "Screen" section, you want to comment
    > out any 8 bit or 16 bit or 32 bit options, and just leave the 24 bit
    > option. I'm no expert but I think that ought to do it.
    >
    > And remember: X Windows is to graphics hacking as roman numerals are to
    > the square root of pi...
    >


    Chris... thanks for the tip. I tried it but with no luck unfortunately.
    I'll try on some of the other machines to see if I get better results.


  8. Re: Colormap Issue in Linux

    Nick Vitalbo wrote:

    > This works well for allocating the colors actually. Now, I am trying to
    > use an overlay plane. For instance, I'm using this overlay plane for
    > drag and drop features within my application. Let's say that once you
    > click on some item, the outline is drawn in red (the overlay color).


    IMHO, a use of overlay isn't justified here. Also, you run into problems when
    the outline happens to be drawn over a region with the same color - then it
    becomes invisible. I'd use an alternative graphics context intead:

    GC gc_alt;
    XGCValues gc_val;

    /* set alternative GC; you can (optionally) use GXxor function instead */
    gc_val.function = GXinvert;
    gc_alt = XCreateGC(disp, root, GCFunction, &gc_val);

    ...
    XDrawRectangle(disp, pixmap, gc_alt, x1, y1, x2, y2);


    This garantees the outline is drawn with maximum contrast. To clear the
    selection, you simply draw the rectangle again.

    Regards,

    Evgeny


  9. Re: Colormap Issue in Linux

    Nick Vitalbo wrote:

    > I guess my next step is to try to force X to start in DirectColor mode
    > rather than Truecolor. Any ideas on how to do this on the Linux
    > machines? I thought it might be in the XF86defaults file but couldn't
    > find where that would be.
    >
    > Any more thoughts?
    >


    First check if your driver supports DirectColor (it should be listed as a supported visual by xdpyinfo). If it does, it's usually irrelevant whether the bit depth is 16, 24 or 32 bpp.

    If so, you can create your window(s) using that visual, even if the default visual is TrueColor.

    If you explicitly need the root window to be in DirectColor, you can force it by inserting 'Visual: DirectColor' in the Screen section in your XF86Config file (assuming you're using XFree; that will be different for other X servers).

    GNOME is known to display the wrong colours in some platforms when using DirectColor as the default visual, though.


    --
    To reach me by email: transform my account name like IBM -> HAL.


  10. Re: Colormap Issue in Linux

    neoholistic wrote:
    > Nick Vitalbo wrote:
    >
    >> I guess my next step is to try to force X to start in DirectColor mode
    >> rather than Truecolor. Any ideas on how to do this on the Linux
    >> machines? I thought it might be in the XF86defaults file but couldn't
    >> find where that would be.
    >>
    >> Any more thoughts?
    >>

    >
    > First check if your driver supports DirectColor (it should be listed as
    > a supported visual by xdpyinfo). If it does, it's usually irrelevant
    > whether the bit depth is 16, 24 or 32 bpp.
    >
    > If so, you can create your window(s) using that visual, even if the
    > default visual is TrueColor.
    >
    > If you explicitly need the root window to be in DirectColor, you can
    > force it by inserting 'Visual: DirectColor' in the Screen section in
    > your XF86Config file (assuming you're using XFree; that will be
    > different for other X servers).
    >
    > GNOME is known to display the wrong colours in some platforms when using
    > DirectColor as the default visual, though.
    >
    >


    Oops! Sorry! It should be:

    Visual "DirectColor"

    NOT

    Visual: DirectColor

    My fault!

    --
    To reach me by email: transform my account name like IBM -> HAL.


  11. Re: Colormap Issue in Linux

    Did you solve this problem? I have encounted exactly same issues as you and thanks to google to find out your post. If you know how to resolve it, could you please send me an email sr_liu@yahoo.com. I will appreciate it very much.


    ------------
    Quote Originally Posted by unix View Post
    I have a colormap question dealing with a project that must be supported
    on Sun workstations (Solaris 8 - Motif 1.2) as well as Dell Linux
    machines (Redhat 9 w/ OpenMotif 2.2).

    I am currently using XAllocColorCells on the default colormap of the
    screen to allocate 24 colors. This works fine on the Sun workstations,
    however, it fails on the Linux machines. I have a feeling that this is
    an issued with Psuedocolor being set on the Suns and Truecolor (being a
    read only colormap) being set on the Linux machines.

    My first question is: how do I set X on the Linux machines to be in
    DirectColor?

    And... if this causes a problem with other applications, I'll probably
    need to come up with another solution (i.e. - make a private colormap).

    And so, my second question is if anyone has any code examples of a
    private colormap being allocated and then used for XAllocColorCells. I
    haven't been quite able to get this working yet, so I'm looking for some
    code examples.

    Any help would be apprecaited. Thanks.

+ Reply to Thread