Query for best color matches
int PgColorMatch(int n, PgColor_t const *in, PgColor_t *out);
This function queries the graphics driver for the best color matches for a number of color values. This is particularly useful with a palette-based graphics driver.
An array of n colors from the in array is passed to the driver, which selects the closest match for each color and returns these in the out array.
With a true or direct-color driver, the color is returned unchanged. With a palette-based driver, the closest color is found by computing within a RGB color cube the Cartesian distance between the color and each palette entry, and selecting the closest entry of a similar intensity.
“Color” in the Raw Drawing and Animation chapter of the Photon Programmer's Guide