24 #include <grass/gis.h>
25 #include <grass/glocale.h>
45 DCELL * val,
int *
r,
int *
g,
int *
b,
46 int *norm,
int *nval,
int *dflt)
48 char value[80], color[80];
52 *norm = *nval = *dflt = 0;
54 if (sscanf(buf,
"%s %[^\n]", value, color) != 2)
59 if (sscanf(color,
"%d:%d:%d", r, g, b) == 3 ||
60 sscanf(color,
"%d %d %d", r, g, b) == 3) {
61 if (*r < 0 || *r > 255 || *g < 0 || *g > 255 || *b < 0 || *b > 255)
70 *r = (int)(fr * 255.99);
71 *g = (int)(fg * 255.99);
72 *b = (int)(fb * 255.99);
87 if (sscanf(value,
"%lf%c", &x, &c) == 2 && c ==
'%') {
91 *val = min + (max -
min) * (x / 100);
96 if (sscanf(value,
"%lf", val) == 1) {
110 return _(
"syntax error");
112 return _(
"R/G/B not in range 0-255");
114 return _(
"invalid color name");
116 return _(
"percentage not in range 0-100");
118 return _(
"invalid value");
120 return _(
"unknown error");
125 DCELL * val,
int *
r,
int *
g,
int *
b,
126 int *norm,
int *nval,
int *dflt)
132 *norm = *nval = *dflt = 0;
135 if (!
G_getl2(buf,
sizeof(buf), fp))
139 G_debug(5,
"color buf = [%s]", buf);
159 read_rule_fn * read_rule,
void *closure)
163 struct rule dflt, null;
164 int set, is_null, is_dflt,
r,
g,
b;
174 dflt.
r = dflt.
g = dflt.
b = dflt.
set = 0;
175 null.
r = null.
g = null.
b = null.
set = 0;
178 (closure, min, max, &val, &r, &g, &b, &
set, &is_null, &is_dflt)) {
183 rule = G_realloc(rule, nrules *
sizeof(
struct rule));
202 const struct rule *p = &rule[0];
207 for (n = 1; n < nrules; n++) {
208 struct rule *lo = &rule[n - 1];
209 struct rule *hi = &rule[n];
212 &hi->
val, hi->
r, hi->
g, hi->
b, colors);
225 static int load_rules_file(
struct Colors *colors,
const char *path, DCELL
min,
231 fp = fopen(path,
"r");
243 int G_load_colors(
struct Colors *colors,
const char *path, CELL min, CELL max)
245 return load_rules_file(colors, path, (DCELL) min, (DCELL) max);
251 return load_rules_file(colors, path, min, max);
254 static int load_rules_name(
struct Colors *colors,
const char *
name, DCELL min,
258 char path[GPATH_MAX];
260 sprintf(path,
"%s/etc/colors/%s",
G_gisbase(), name);
262 ret = load_rules_file(colors, path, min, max);
270 int G_make_colors(
struct Colors *colors,
const char *name, CELL min, CELL max)
272 return load_rules_name(colors, name, (DCELL) min, (DCELL) max);
278 return load_rules_name(colors, name, min, max);