1 #include <string.h>
2
3 #include <grass/gis.h>
4 #include <grass/raster.h>
5 #include <grass/dbmi.h>
6 #include <grass/glocale.h>
7
make_colors(struct Colors * colors,const char * style,DCELL min,DCELL max,int is_fp)8 void make_colors(struct Colors *colors, const char *style, DCELL min, DCELL max,
9 int is_fp)
10 {
11
12 G_debug(3, "make_colors(): range=%f,%f is_fp=%d", min, max, is_fp);
13
14 if (strcmp(style, "random") == 0) {
15 if (is_fp)
16 G_fatal_error(_("Color table '%s' is not supported for "
17 "floating point attributes"), style);
18 Rast_make_random_colors(colors, (CELL) min, (CELL) max);
19 } else if (strcmp(style, "grey.eq") == 0) {
20 G_fatal_error(_("Color table <%s> not supported"), "grey.eq");
21 /*
22 if (!have_stats)
23 have_stats = get_stats(name, mapset, &statf);
24 Rast_make_histogram_eq_colors(&colors, &statf);
25 */
26 } else if (strcmp(style, "grey.log") == 0) {
27 G_fatal_error(_("Color table <%s> not supported"), "grey.log");
28 /*
29 if (!have_stats)
30 have_stats = get_stats(name, mapset, &statf);
31 Rast_make_histogram_log_colors(&colors, &statf, (CELL) min,
32 (CELL) max);
33 */
34 }
35 else {
36 if (is_fp)
37 Rast_make_fp_colors(colors, style, min, max);
38 else
39 Rast_make_colors(colors, style, (CELL) min, (CELL) max);
40 }
41 }
42
load_colors(struct Colors * colors,const char * rules,DCELL min,DCELL max,int is_fp)43 void load_colors(struct Colors *colors, const char *rules, DCELL min, DCELL max,
44 int is_fp)
45 {
46 int ret;
47
48 if (rules[0] == '-' && rules[1] == 0)
49 ret = Rast_read_color_rules(colors, min, max, Rast_read_color_rule,
50 stdin);
51 else if (is_fp)
52 ret = Rast_load_fp_colors(colors, rules, (DCELL) min, (DCELL) max);
53 else
54 ret = Rast_load_colors(colors, rules, (CELL) min, (CELL) max);
55
56 if (ret == 0)
57 G_fatal_error(_("Unable to load rules file <%s>"), rules);
58 }
59
color_rules_to_cats(dbCatValArray * cvarr,int is_fp,struct Colors * vcolors,struct Colors * colors,int invert,DCELL min,DCELL max)60 void color_rules_to_cats(dbCatValArray *cvarr, int is_fp,
61 struct Colors *vcolors, struct Colors *colors,
62 int invert, DCELL min, DCELL max)
63 {
64 int i, cat;
65 dbCatVal *cv;
66 int red, grn, blu;
67
68 /* color table for categories */
69 G_message(_("Converting color rules into categories..."));
70 for (i = 0; i < cvarr->n_values; i++) {
71 G_percent(i, cvarr->n_values, 2);
72 cv = &(cvarr->value[i]);
73 cat = cv->cat;
74 if (is_fp) {
75 DCELL v = invert ? min + max - cv->val.d : cv->val.d;
76 if (Rast_get_d_color((const DCELL *) &v, &red, &grn, &blu,
77 vcolors) == 0) {
78 /* G_warning(_("No color rule defined for value %f"), v); */
79 G_debug(3, "scan_attr(): cat=%d, val=%f -> no color rule",
80 cat, v);
81 continue;
82 }
83 }
84 else {
85 CELL v = invert ? (CELL) min + (CELL) max - cv->val.i : cv->val.i;
86 if (Rast_get_c_color((const CELL *) &v, &red, &grn, &blu,
87 vcolors) == 0) {
88 /* G_warning(_("No color rule defined for value %d"), v); */
89 G_debug(3, "scan_attr(): cat=%d, val=%d -> no color rule",
90 cat, v);
91 continue;
92 }
93 }
94 G_debug(3, "scan_attr(): cat=%d, val=%f, r=%d, g=%d, b=%d",
95 cat, is_fp ? cv->val.d : cv->val.i, red, grn, blu);
96 Rast_add_c_color_rule((const CELL*) &cat, red, grn, blu,
97 (const CELL*) &cat, red, grn, blu, colors);
98 }
99 G_percent(2, 2, 2);
100 }
101