23 static const struct color_rgb standard_colors_rgb[] = {
42 static const struct color_name standard_color_names[] = {
57 return sizeof(standard_colors_rgb) /
sizeof(standard_colors_rgb[0]);
67 return standard_colors_rgb[n];
77 return sizeof(standard_color_names) /
sizeof(standard_color_names[0]);
87 return &standard_color_names[n];
111 G_debug(3,
"G_str_to_color(): str = '%s'", buf);
116 if (sscanf(buf,
"%d%*[,:; ]%d%*[,:; ]%d", red, grn, blu) == 3) {
117 if (*red < 0 || *red > 255 || *grn < 0 || *grn > 255 || *blu < 0 ||
126 if (sscanf(buf,
"#%x", &hex) == 1) {
127 *red = (hex >> 16) & 0xFF;
128 *grn = (hex >> 8) & 0xFF;
130 if (*red < 0 || *red > 255 || *grn < 0 || *grn > 255 || *blu < 0 ||
138 for (i = 0; i < num_names; i++) {
169 float r_norm = (float)
r / 255.0f;
170 float g_norm = (float)
g / 255.0f;
171 float b_norm = (float)
b / 255.0f;
173 float cmax =
MAX(r_norm,
MAX(g_norm, b_norm));
174 float cmin =
MIN(r_norm,
MIN(g_norm, b_norm));
175 float diff = cmax - cmin;
180 else if (cmax == r_norm) {
181 *h = fmodf((60.0f * ((g_norm - b_norm) / diff) + 360.0f), 360.0f);
183 else if (cmax == g_norm) {
184 *h = fmodf((60.0f * ((b_norm - r_norm) / diff) + 120.0f), 360.0f);
187 *h = fmodf((60.0f * ((r_norm - g_norm) / diff) + 240.0f), 360.0f);
194 *s = (diff / cmax) * 100.0f;
void G_rgb_to_hsv(int r, int g, int b, float *h, float *s, float *v)
Converts RGB color values to HSV format.
int G_num_standard_colors(void)
Get number of named colors (RGB triplets)
int G_str_to_color(const char *str, int *red, int *grn, int *blu)
Parse color string and set red,green,blue.
int G_num_standard_color_names(void)
Get number of named colors (color names)
struct color_rgb G_standard_color_rgb(int n)
Get RGB triplet of given color.
const struct color_name * G_standard_color_name(int n)
Get color name.
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
char * G_chop(char *)
Chop leading and trailing white spaces.
int G_debug(int, const char *,...) __attribute__((format(printf