How to get path of rgb.txt? - Xwindows

This is a discussion on How to get path of rgb.txt? - Xwindows ; Hi, All Does exist any function/variable in Xlib that return/containing a full path to rgb.txt file? -Templar-...

+ Reply to Thread
Results 1 to 10 of 10

Thread: How to get path of rgb.txt?

  1. How to get path of rgb.txt?

    Hi, All

    Does exist any function/variable in Xlib that return/containing a full
    path to rgb.txt file?

    -Templar-


  2. Re: How to get path of rgb.txt?

    Templar wrote:
    >Hi, All
    >
    >Does exist any function/variable in Xlib that return/containing a full
    >path to rgb.txt file?
    >
    >-Templar-
    >


    No. The file may not even exist on X terminals, or other (non-xorg)
    server implementations.


  3. Re: How to get path of rgb.txt?

    On Sat Jul 10 20:38:24, Kip Rugger wrote:

    > Templar wrote:
    >> Hi, All
    >>
    >> Does exist any function/variable in Xlib that return/containing a
    >> full path to rgb.txt file?
    >>
    >> -Templar-
    >>

    > No. The file may not even exist on X terminals, or other (non-xorg)
    > server implementations.




    So, if I need color names, does this mean that my app must drag out
    such data like showrgb program does? Is there any portable method at
    all?

    -Templar-


  4. Re: How to get path of rgb.txt?

    "Templar" writes:

    > On Sat Jul 10 20:38:24, Kip Rugger wrote:
    >
    >> Templar wrote:
    >>> Hi, All
    >>>
    >>> Does exist any function/variable in Xlib that return/containing a
    >>> full path to rgb.txt file?
    >>>
    >>> -Templar-
    >>>

    >> No. The file may not even exist on X terminals, or other (non-xorg)
    >> server implementations.

    >
    >
    >
    > So, if I need color names, does this mean that my app must drag out
    > such data like showrgb program does? Is there any portable method at
    > all?


    XParseColor() converts names to pixel values. Is that what you need,
    or do you want a list of all names known to the X server?

    --
    Måns Rullgård
    mru@kth.se

  5. Re: How to get path of rgb.txt?

    On Sat Jul 10 23:24:14, Måns Rullgård wrote:

    > "Templar" writes:
    >> On Sat Jul 10 20:38:24, Kip Rugger wrote:
    >>> Templar wrote:
    >>>> Hi, All
    >>>>
    >>>> Does exist any function/variable in Xlib that return/containing a
    >>>> full path to rgb.txt file?
    >>>>
    >>>> -Templar-
    >>>>
    >>> No. The file may not even exist on X terminals, or other (non-xorg)
    >>> server implementations.

    >>
    >>
    >>
    >> So, if I need color names, does this mean that my app must drag out
    >> such data like showrgb program does? Is there any portable method at
    >> all?

    >
    > XParseColor() converts names to pixel values. Is that what you need,
    > or do you want a list of all names known to the X server?


    I need to convert XColor to its string value. I did it by looking in
    rgb.txt, but, evidently, the result of this isn't portable, as says
    Kip Rugger, "the file may not even exist on X terminals". So, I'd like
    to know about some proper solution.

    -Templar-


  6. Re: How to get path of rgb.txt?

    Templar wrote:
    >I need to convert XColor to its string value. I did it by looking in
    >rgb.txt, but, evidently, the result of this isn't portable, as says
    >Kip Rugger, "the file may not even exist on X terminals". So, I'd like
    >to know about some proper solution.
    >


    Given that a cheap, TrueColor card has a palette of about 16 million
    colors, and that the rgb.txt database lists only a few hundred colors,
    I would ask how you plan to do this inverse mapping.


  7. Re: How to get path of rgb.txt?


    Templar> I need to convert XColor to its string value. I did it by
    Templar> looking in rgb.txt, but, evidently, the result of this isn't
    Templar> portable, as says Kip Rugger, "the file may not even exist on X
    Templar> terminals". So, I'd like to know about some proper solution.

    Kip> Given that a cheap, TrueColor card has a palette of about 16
    Kip> million colors, and that the rgb.txt database lists only a few
    Kip> hundred colors, I would ask how you plan to do this inverse
    Kip> mapping.

    In general this is of course ill-defined. But you can use some kind of
    approximation, such as least square approximation. The xcolorsel
    program has traditionally been used for this. I have recently written a
    gtk 2.x program similar to xcolorsel:

    http://primate.net/~itz/gcolorsel_1.9.1.orig.tar.gz

    It allows you to use any list of colors in the format of rgb.txt, so you
    can write your own if your system doesn't have one.

    It recalculates the Euclidean distance in RGB space (more precisely, its
    square) for every color in the list. If you're only looking for the
    closest match, there are some easy optimizations I can think about.

    --
    "It's not true or not." A reality show producer (real quote)

  8. Re: How to get path of rgb.txt?

    Kip Rugger wrote:
    > Templar wrote:
    >>I need to convert XColor to its string value. I did it by looking in
    >>rgb.txt, but, evidently, the result of this isn't portable, as says
    >>Kip Rugger, "the file may not even exist on X terminals". So, I'd like
    >>to know about some proper solution.

    >
    > Given that a cheap, TrueColor card has a palette of about 16 million
    > colors, and that the rgb.txt database lists only a few hundred colors,
    > I would ask how you plan to do this inverse mapping.


    The usual way is to imagine the RGB colorspace as a physical 3D space,
    and look for the named color which is closest to your RGB color.
    In other words, compute the sum of the squares of the differences
    between the R, G, and B components, and look for the named color with
    the smallest sum.

    Except, of course, that there is no Xlib call for listing the named
    colors. I usually get around that by parsing the output of the "showrgb"
    command, but even that isn't as portable as I'd like since "showrgb"
    might not be installed on the workstation.

    ----------------------------------------------------------------------------

    #include

    /* Return the name of a color, given its RGB components. The input
    * values are assumed to be in the range 0-255 as used by "showrgb",
    * not 0-65535 as used by Xlib. The return value is the name of the
    * nearest color that has a name, or NULL if something goes wrong.
    */
    char *colorname(int r, int g, int b)
    {
    FILE *fp;
    int rr, gg, bb;
    char name[50];
    static char bestname[50];
    long bestdist, dist;

    /* open a pipe from "showrgb" */
    fp = popen("showrgb", "r");
    if (!fp)
    return NULL;

    /* look for the best match */
    bestdist = 195076; /* higher than any possible actual difference */
    *bestname = '\0';
    while (fscanf(fp, "%d %d %d %[^\n]\n", &rr, &gg, &bb, name) == 4)
    {
    dist = (r - rr) * (r - rr)
    + (g - gg) * (g - gg)
    + (b - bb) * (b - bb);
    if (dist < bestdist)
    {
    bestdist = dist;
    strcpy(bestname, name);

    /* if exact match, then stop looking */
    if (dist == 0)
    break;
    }
    }

    /* close the pipe */
    if (pclose(fp) != 0)
    return NULL;

    /* if no name found, return NULL */
    if (!*bestname)
    return NULL;

    /* return the best name */
    return bestname;
    }

  9. Re: How to get path of rgb.txt?

    On Sun Jul 11 18:43:27, Kip Rugger wrote:

    > Templar wrote:
    >> I need to convert XColor to its string value. I did it by looking in
    >> rgb.txt, but, evidently, the result of this isn't portable, as says
    >> Kip Rugger, "the file may not even exist on X terminals". So, I'd
    >> like to know about some proper solution.
    >>

    > Given that a cheap, TrueColor card has a palette of about 16 million
    > colors, and that the rgb.txt database lists only a few hundred colors,
    > I would ask how you plan to do this inverse mapping.


    What I need is to find existing name in rgb database; if search was
    false, then to use #hhhhhh value from XColor - as usual. This is done.
    My issue was about getting path of the color database. For example,
    in showrgb this work does imake before compilation. Is there any other
    way, that is the problem

    -Templar-

    PS
    Sorry for my terrible English


  10. Re: How to get path of rgb.txt?

    Templar wrote:
    >On Sun Jul 11 18:43:27, Kip Rugger wrote:
    >
    >> Templar wrote:
    >>> I need to convert XColor to its string value. I did it by looking in
    >>> rgb.txt, but, evidently, the result of this isn't portable, as says
    >>> Kip Rugger, "the file may not even exist on X terminals". So, I'd
    >>> like to know about some proper solution.
    >>>

    >> Given that a cheap, TrueColor card has a palette of about 16 million
    >> colors, and that the rgb.txt database lists only a few hundred colors,
    >> I would ask how you plan to do this inverse mapping.

    >
    >What I need is to find existing name in rgb database; if search was
    >false, then to use #hhhhhh value from XColor - as usual. This is done.
    >My issue was about getting path of the color database. For example,
    >in showrgb this work does imake before compilation. Is there any other
    >way, that is the problem


    First, you cannot assume access to the rgb.txt file on the server.
    It might be internal to an X terminal or printer, or your app might
    not have NFS (or equivalent) access to the X server files, or you
    might not have read access even if the app is running on the server
    box. The file should be considered an implementation detail of
    certain types of servers; it is not part of X or X protocols.

    The rgb.txt file has certain obvious problems. For the sake of
    backward compatibility, you can only add entries to the file. Also,
    there is an obvious bias towards English which is not so appropriate
    in our now i18n world. Then there also seems to be a problem with
    synonyms:

    0 0 205 MediumBlue
    0 0 205 blue3
    0 0 205 medium blue

    0 104 139 DeepSkyBlue4

    These types of problems mean that the file is not likely to undergo
    any major changes, so using a copy of the file as a fallback is,
    therefore, not such a bad solution. Or, even use a very old copy

    2995 Dec 2 12:36 1986 X.V10R4/rgb/rgb.txt

    as a fallback (the above file has about 50 unique colors).


+ Reply to Thread