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)
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);
227 static int load_rules_file(
struct Colors *colors,
const char *path, DCELL
min,
233 fp = fopen(path,
"r");
245 int G_load_colors(
struct Colors *colors,
const char *path, CELL min, CELL max)
247 return load_rules_file(colors, path, (DCELL) min, (DCELL) max);
253 return load_rules_file(colors, path, min, max);
256 static int load_rules_name(
struct Colors *colors,
const char *
name, DCELL min,
260 char path[GPATH_MAX];
264 ret = load_rules_file(colors, path, min, max);
272 int G_make_colors(
struct Colors *colors,
const char *name, CELL min, CELL max)
274 return load_rules_name(colors, name, (DCELL) min, (DCELL) max);
280 return load_rules_name(colors, name, min, max);
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
int G_set_default_color(int red, int grn, int blu, struct Colors *colors)
Sets the default color (in colors) to r,g,b. This is the color for values which do not have an explic...
int G_set_null_value_color(int red, int grn, int blu, struct Colors *colors)
Sets the color (in colors) for the NULL-value to r,g,b.
int G_add_d_raster_color_rule(const DCELL *val1, int r1, int g1, int b1, const DCELL *val2, int r2, int g2, int b2, struct Colors *colors)
Adds the floating-point rule (DCELL version)
int G_read_color_rules(struct Colors *colors, DCELL min, DCELL max, read_rule_fn *read_rule, void *closure)
int G_load_fp_colors(struct Colors *colors, const char *path, DCELL min, DCELL max)
char * G_chop(char *line)
Chop leading and trailing white spaces:
int G_getl2(char *buf, int n, FILE *fd)
gets a line of text from a file of any pedigree
int G_color_values(const char *name, float *r, float *g, float *b)
int G_set_d_color(DCELL val, int r, int g, int b, struct Colors *colors)
int G_strip(char *buf)
Removes all leading and trailing white space from string.
int G_load_colors(struct Colors *colors, const char *path, CELL min, CELL max)
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
int G_make_colors(struct Colors *colors, const char *name, CELL min, CELL max)
int G_debug(int level, const char *msg,...)
Print debugging message.
char * G_gisbase(void)
top level module directory
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
const char * G_parse_color_rule_error(int code)
int G_read_color_rule(void *closure, DCELL min, DCELL max, DCELL *val, int *r, int *g, int *b, int *norm, int *nval, int *dflt)
int G_parse_color_rule(DCELL min, DCELL max, const char *buf, DCELL *val, int *r, int *g, int *b, int *norm, int *nval, int *dflt)
int G_make_fp_colors(struct Colors *colors, const char *name, DCELL min, DCELL max)