On IRC someone suggested using rgb.txt in the reverse direction: when you have a color and want to know what it is called. The short C program below illustrates the idea.

As some experimentation will show, it does not work too well. I suspect this is due to two factors: that rgb.txt isn't the most suitable sample of names, and that the program measures distances in RGB-space. (the better alternative would be to convert to L*u*v*-space, using the xlib color management functions, and compare distances there). It did find the name turquoise, though, which was the original question. :)

 

/* colorname.c - find the closest color in rgb.txt, in the sense of
                 smallest sum of squares of differences of components.
                 (that is, shortest distance in the RGB cube). */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define RGBFILE "/usr/X11R6/lib/X11/rgb.txt"

int main (int argc, char *argv[]) {
        int R, G, B, r, g, b;
        FILE *f;
        unsigned dist, bestdist = -1;
        char name[42], bestname[42] = "none";
        char buf[100];

        if (argc!=4) {
                fprintf(stderr, "Usage: %s <R> <G> <B>\n", argv[0]);
                exit(1);
        }

        R = atoi(argv[1]); G = atoi(argv[2]); B = atoi(argv[3]);

        if (!(f = fopen(RGBFILE, "r"))) {
                perror(RGBFILE);
                exit(1);
        }

        while (fgets(buf, sizeof(buf), f)) {
                if (sscanf(buf, "%d %d %d %42[^\n]\n", &r, &g, &b, name) != 4)
                        continue;

                dist = (R-r)*(R-r) + (G-g)*(G-g) + (B-b)*(B-b);
                if (dist < bestdist) {
                        bestdist = dist;
                        strcpy(bestname, name);
                }
        }

        printf("Best match: %s (distance %.1f)\n", bestname, sqrt(bestdist));
        return 0;
}