#include #include "constant.h" /**** x include files ****/ #include #include #include #include #include #include "extern.h" /****************************************************************************** int match_color (red, green, blue) Given the RGB components (, , ) search through the custom colors for the color which most closely matches. Return the inverse index. This routine used for finding out what inverse should be used for X colors. ******************************************************************************/ int match_color (red, green, blue) int red, green, blue; { int hue, dist, minimum, min_index; minimum = 1000000; red = red>>8; green = green>>8; blue = blue>>8; for (hue=1; huehue_count; hue++) { dist = (Config->palette[hue][0] - red)*(Config->palette[hue][0] - red) + (Config->palette[hue][1] - green)*(Config->palette[hue][1] - green) + (Config->palette[hue][2] - blue)*(Config->palette[hue][2] - blue); if (dist < minimum) { min_index = hue; minimum = dist; } } return (Config->hue_to_inverse[min_index]); } /****************************************************************************** int match_color_name (color_name, default_hue) Match with a palette entry and return the index, or just return . ******************************************************************************/ match_color_name (color_name, default_hue) char *color_name; { int hue; for (hue=0; huehue_count; hue++) if (!strcmp (color_name, Config->hue_name[hue])) return (hue); return (default_hue); } /****************************************************************************** matchstr (line, word) Given a baseline string , return TRUE if is a subset of it. Used solely to match colors like "red_blue" to custom colors like "red" without getting confused by the "_blue" part. Probably should just use strncmp (line, word, strlen(word)). ******************************************************************************/ matchstr (line, word) char line[], word[]; { int i; for (i=0; i-1. ******************************************************************************/ int get_random (base) int base; { return (rand() % base); }