25 #include <grass/gis.h>
26 #include <grass/glocale.h>
29 static int read_colors(
const char *,
const char *,
const char *,
31 static int read_new_colors(FILE *,
struct Colors *);
32 static int read_old_colors(FILE *,
struct Colors *);
67 char xname[GNAME_MAX];
69 struct FPRange drange;
84 sprintf(buf,
"colr2/%s", mapset);
85 if (read_colors(buf, name,
G_mapset(), colors) >= 0)
89 switch (read_colors(
"colr", name, mapset, colors)) {
116 G_warning(_(
"color support for [%s] in mapset [%s] %s"), name, mapset,
121 static int read_colors(
const char *element,
const char *
name,
122 const char *mapset,
struct Colors *colors)
135 if (fgets(buf,
sizeof buf, fd) ==
NULL) {
143 stat = read_new_colors(fd, colors);
147 stat = read_old_colors(fd, colors);
148 colors->version = -1;
168 static int read_new_colors(FILE * fd,
struct Colors *colors)
175 char word1[256], word2[256];
181 if (fgets(buf,
sizeof buf, fd) ==
NULL)
185 if (sscanf(buf + 1,
"%lf %lf", &val1, &val2) == 2)
189 while (fgets(buf,
sizeof buf, fd)) {
190 null = undef = fp_rule = 0;
192 n = sscanf(buf,
"%s %s", word1, word2);
196 if (sscanf(word1,
"shift:%lf", &shift) == 1
197 || (strcmp(word1,
"shift:") == 0 &&
198 sscanf(word2,
"%lf", &shift) == 1)) {
202 if (strcmp(word1,
"invert") == 0) {
206 if (strcmp(word1,
"%%") == 0) {
211 switch (sscanf(word1,
"nv:%d:%d:%d", &r1, &g1, &b1)) {
221 switch (sscanf(word1,
"*:%d:%d:%d", &r1, &g1, &b1)) {
231 switch (sscanf(word1,
"%ld:%d:%d:%d", &cat1, &r1, &g1, &b1)) {
238 if (sscanf(word1,
"%lf:%d:%d:%d", &val1, &r1, &g1, &b1) == 4)
240 else if (sscanf(word1,
"%lf:%d", &val1, &r1) == 2) {
248 switch (sscanf(word2,
"%ld:%d:%d:%d", &cat2, &r2, &g2, &b2)) {
259 if (sscanf(word2,
"%lf:%d:%d:%d", &val2, &r2, &g2, &b2) == 4) {
264 else if (sscanf(word2,
"%lf:%d", &val2, &r2) == 2) {
291 b1, (DCELL *) & val2, r2,
295 (CELL) cat2, r2, g2, b2, colors);
300 (DCELL *) & val2, r2, g2, b2,
304 (CELL) cat2, r2, g2, b2, colors);
313 static int read_old_colors(FILE * fd,
struct Colors *colors)
318 float red_f, grn_f, blu_f;
328 if (fgets(buf,
sizeof buf, fd) ==
NULL)
334 if (sscanf(buf + 1,
"%ld", &min) != 1)
346 while (fgets(buf,
sizeof buf, fd)) {
348 if (sscanf(buf,
"%f %f %f", &red_f, &grn_f, &blu_f) != 3)
356 switch (sscanf(buf,
"%d %d %d", &red, &grn, &blu)) {
378 colors->cmax = n - 1;
398 colors->is_float = 1;
char * G_mapset(void)
current mapset name
int G_is_c_null_value(const CELL *cellVal)
Returns 1 if cell is NULL, 0 otherwise. This will test if the value cell is the largest int...
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_read_colors(const char *name, const char *mapset, struct Colors *colors)
read map layer color table
int G_read_range(const char *name, const char *mapset, struct Range *range)
read raster range
int G_raster_map_is_fp(const char *name, const char *mapset)
Check if raster map is floating-point.
int G_invert_colors(struct Colors *colors)
int G_get_range_min_max(const struct Range *range, CELL *min, CELL *max)
get range min and max
int G_make_rainbow_colors(struct Colors *colors, CELL min, CELL max)
make rainbow colors
G_mark_colors_as_fp(colors)
char * G_find_cell(char *name, const char *mapset)
find a raster map
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 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)
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
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_read_fp_range(const char *name, const char *mapset, struct FPRange *drange)
Read the floating point range file f_range. This file is written in binary using XDR format...
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)