GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
named_colr.c
Go to the documentation of this file.
1 #include <grass/gis.h>
2 #include <string.h>
3 #include <stdio.h>
4 
5 static struct
6 {
7  const char *name;
8  float r, g, b;
9 } colors[] = {
10  {"white", 1.00, 1.00, 1.00},
11  {"black", 0.00, 0.00, 0.00},
12  {"red", 1.00, 0.00, 0.00},
13  {"green", 0.00, 1.00, 0.00},
14  {"blue", 0.00, 0.00, 1.00},
15  {"yellow", 1.00, 1.00, 0.00},
16  {"magenta",1.00, 0.00, 1.00},
17  {"cyan", 0.00, 1.00, 1.00},
18  {"aqua", 0.00, 0.75, 0.75},
19  {"grey", 0.75, 0.75, 0.75},
20  {"gray", 0.75, 0.75, 0.75},
21  {"orange", 1.00, 0.50, 0.00},
22  {"brown", 0.75, 0.50, 0.25},
23  {"purple", 0.50, 0.00, 1.00},
24  {"violet", 0.50, 0.00, 1.00},
25  {"indigo", 0.00, 0.50, 1.00},
26  {"", 0.00, 0.00, 0.00} /* do not modify this line */
27 };
28 
29 int G_color_values(const char *name, float *r, float *g, float *b)
30 {
31  int i;
32 
33  *r = *g = *b = 0.0;
34  for (i = 0; colors[i].name[0]; i++)
35  if (strcmp(name, colors[i].name) == 0) {
36  *r = colors[i].r;
37  *g = colors[i].g;
38  *b = colors[i].b;
39  return 1;
40  }
41  return -1;
42 }
43 
44 const char *G_color_name(int n)
45 {
46  int i;
47 
48  if (n >= 0)
49  for (i = 0; colors[i].name[0]; i++)
50  if (i == n)
51  return colors[i].name;
52  return NULL;
53 }
const char * G_color_name(int n)
Definition: named_colr.c:44
float b
Definition: named_colr.c:8
float r
Definition: named_colr.c:8
#define NULL
Definition: ccmath.h:32
int G_color_values(const char *name, float *r, float *g, float *b)
Definition: named_colr.c:29
float g
Definition: named_colr.c:8
const char * name
Definition: named_colr.c:7