10 #include <grass/gis.h>
13 static int read_colors(
const char *,
const char *,
const char *,
15 static int read_new_colors(FILE *,
struct Colors *);
16 static int read_old_colors(FILE *,
struct Colors *);
26 sprintf(buf,
"%s/%s", G3D_DIRECTORY, xname);
27 sprintf(buf2,
"%s@%s", G3D_COLOR_ELEMENT, xmapset);
30 sprintf(buf,
"%s/%s", G3D_DIRECTORY, name);
31 sprintf(buf2,
"%s", G3D_COLOR_ELEMENT);
37 G3D_DIRECTORY, G3D_COLOR2_DIRECTORY,
G_mapset());
46 G3d_readColors(
const char *
name,
const char *mapset,
struct Colors *colors)
58 if (strcmp(xmapset, mapset) != 0)
63 sprintf(buf,
"%s/%s/%s", G3D_DIRECTORY, G3D_COLOR2_DIRECTORY, mapset);
64 if (read_colors(buf, name,
G_mapset(), colors) >= 0)
74 sprintf(buf,
"%s/%s", G3D_DIRECTORY, name);
75 sprintf(buf2,
"%s", G3D_COLOR_ELEMENT);
79 switch (read_colors(buf, buf2, mapset, colors)) {
81 if (G3d_readRange(name, mapset, &
drange) >= 0) {
96 G_warning(
"color support for [%s] in mapset [%s] %s", name, mapset, err);
100 static int read_colors(
const char *element,
const char *name,
101 const char *mapset,
struct Colors *colors)
114 if (fgets(buf,
sizeof buf, fd) ==
NULL) {
122 stat = read_new_colors(fd, colors);
126 stat = read_old_colors(fd, colors);
127 colors->version = -1;
145 static int read_new_colors(FILE * fd,
struct Colors *colors)
152 char word1[256], word2[256];
158 if (fgets(buf,
sizeof buf, fd) ==
NULL)
162 if (sscanf(buf + 1,
"%lf %lf", &val1, &val2) == 2)
166 while (fgets(buf,
sizeof buf, fd)) {
167 null = undef = fp_rule = 0;
169 n = sscanf(buf,
"%s %s", word1, word2);
173 if (sscanf(word1,
"shift:%lf", &shift) == 1
174 || (strcmp(word1,
"shift:") == 0 &&
175 sscanf(word2,
"%lf", &shift) == 1)) {
179 if (strcmp(word1,
"invert") == 0) {
183 if (strcmp(word1,
"%%") == 0) {
188 switch (sscanf(word1,
"nv:%d:%d:%d", &r1, &g1, &b1)) {
198 switch (sscanf(word1,
"*:%d:%d:%d", &r1, &g1, &b1)) {
208 switch (sscanf(word1,
"%ld:%d:%d:%d", &cat1, &r1, &g1, &b1)) {
215 if (sscanf(word1,
"%lf:%d:%d:%d", &val1, &r1, &g1, &b1) == 4)
217 else if (sscanf(word1,
"%lf:%d", &val1, &r1) == 2) {
225 switch (sscanf(word2,
"%ld:%d:%d:%d", &cat2, &r2, &g2, &b2)) {
236 if (sscanf(word2,
"%lf:%d:%d:%d", &val2, &r2, &g2, &b2) == 4) {
241 else if (sscanf(word2,
"%lf:%d", &val2, &r2) == 2) {
268 b1, (DCELL *) & val2, r2,
272 (CELL) cat2, r2, g2, b2, colors);
277 (DCELL *) & val2, r2, g2, b2,
281 (CELL) cat2, r2, g2, b2, colors);
290 static int read_old_colors(FILE * fd,
struct Colors *colors)
295 float red_f, grn_f, blu_f;
305 if (fgets(buf,
sizeof buf, fd) ==
NULL)
311 if (sscanf(buf + 1,
"%ld", &min) != 1)
323 while (fgets(buf,
sizeof buf, fd)) {
325 if (sscanf(buf,
"%f %f %f", &red_f, &grn_f, &blu_f) != 3)
333 switch (sscanf(buf,
"%d %d %d", &red, &grn, &blu)) {
355 colors->cmax = n - 1;
363 G3d_writeColors(
const char *name,
const char *mapset,
struct Colors *colors)
366 char element[512], buf[512], buf2[200];
367 char xname[512], xmapset[512];
372 if (strcmp(xmapset, mapset) != 0)
383 sprintf(element,
"%s/%s/%s", G3D_DIRECTORY, G3D_COLOR2_DIRECTORY, mapset);
388 sprintf(buf,
"%s/%s", G3D_DIRECTORY, xname);
389 sprintf(buf2,
"%s@%s", G3D_COLOR_ELEMENT, xmapset);
392 sprintf(buf,
"%s/%s", G3D_DIRECTORY, name);
393 sprintf(buf2,
"%s", G3D_COLOR_ELEMENT);
char * G_mapset(void)
current mapset name
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
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_modular_color_rule(CELL cat1, int r1, int g1, int b1, CELL cat2, int r2, int g2, int b2, struct Colors *colors)
Add modular color rule.
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_invert_colors(struct Colors *colors)
G_mark_colors_as_fp(colors)
int G_is_d_null_value(const DCELL *dcellVal)
Returns 1 if dcell is NULL, 0 otherwise. This will test if the value dcell is a NaN. Same test as in G_is_f_null_value().
int G3d_removeColor(const char *name)
int G_strip(char *buf)
Removes all leading and trailing white space from string.
int G_set_d_color_range(DCELL min, DCELL max, struct Colors *colors)
int G_make_rainbow_fp_colors(struct Colors *colors, DCELL min, DCELL max)
int G__insert_color_into_lookup(CELL cat, int red, int grn, int blu, struct _Color_Info_ *cp)
int G_remove(const char *element, const char *name)
Remove a database file.
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
FILE * G_fopen_new(const char *element, const char *name)
Open a new database file.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_get_fp_range_min_max(const struct FPRange *range, DCELL *min, DCELL *max)
Extract the min/max from the range structure r. If the range structure has no defined min/max (first!...
int G_add_color_rule(CELL cat1, int r1, int g1, int b1, CELL cat2, int r2, int g2, int b2, struct Colors *colors)
Set colors rules.
int G_shift_d_colors(DCELL shift, struct Colors *colors)
FILE * G_fopen_old(const char *element, const char *name, const char *mapset)
Open a database file for reading.
int G_add_modular_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)
Add modular color rule (DCELL version)
int G__write_colors(FILE *fd, struct Colors *colors)
int G__name_is_fully_qualified(const char *fullname, char *name, char *mapset)
Check if map name is fully qualified (map @ mapset)