23 static void write_new_colors(FILE *,
struct Colors *);
24 static void write_old_colors(FILE *,
struct Colors *);
25 static void forced_write_old_colors(FILE *,
struct Colors *);
26 static void format_min(
char *,
double);
27 static void format_max(
char *,
double);
80 if (strcmp(xmapset, mapset) != 0)
90 sprintf(
element,
"colr2/%s", mapset);
91 if (strcmp(mapset,
G_mapset()) == 0) {
111 if (getenv(
"FORCE_GRASS3_COLORS"))
112 forced_write_old_colors(fd, colors);
114 write_old_colors(fd, colors);
116 write_new_colors(fd, colors);
119 static void write_new_colors(FILE *fd,
struct Colors *colors)
121 char str1[100], str2[100];
123 format_min(str1, (
double)colors->
cmin);
124 format_max(str2, (
double)colors->
cmax);
125 fprintf(fd,
"%% %s %s\n", str1, str2);
128 sprintf(str2,
"%.17g", (
double)colors->
shift);
130 fprintf(fd,
"shift:%s\n", str2);
133 fprintf(fd,
"invert\n");
136 fprintf(fd,
"nv:%d", colors->
null_red);
150 fprintf(fd,
"%s\n",
"%%");
152 fprintf(fd,
"%s\n",
"%%");
171 for (; rule; rule = rule->
prev) {
172 if (rule->low.value == dmin)
173 format_min(str, (
double)rule->low.value);
175 sprintf(str,
"%.17g", (
double)rule->low.value);
178 fprintf(fd,
"%s:%d", str, (
int)rule->low.red);
179 if (rule->low.red != rule->low.grn || rule->low.red != rule->low.blu)
180 fprintf(fd,
":%d:%d", rule->low.grn, rule->low.blu);
184 format_max(str, (
double)rule->
high.
value);
186 sprintf(str,
"%.17g", (
double)rule->
high.
value);
189 fprintf(fd,
" %s:%d", str, (
int)rule->
high.
red);
198 static void write_old_colors(FILE *fd,
struct Colors *colors)
202 fprintf(fd,
"#%ld first color\n", (
long)colors->
fixed.
min);
208 fprintf(fd,
"255 255 255\n");
212 for (i = 0; i < n; i++) {
222 static void forced_write_old_colors(FILE *fd,
struct Colors *colors)
227 fprintf(fd,
"#%ld first color\n", (
long)colors->
cmin);
230 fprintf(fd,
"%d %d %d\n", red, grn, blu);
232 for (cat = colors->
cmin; cat <= colors->cmax; cat++) {
234 fprintf(fd,
"%d", red);
235 if (red != grn || red != blu)
236 fprintf(fd,
" %d %d", grn, blu);
241 static void format_min(
char *str,
double dval)
245 sprintf(str,
"%.17g", dval);
248 sscanf(str,
"%lf", &dtmp);
258 static void format_max(
char *str,
double dval)
262 sprintf(str,
"%.17g", dval);
265 sscanf(str,
"%lf", &dtmp);
int G_name_is_fully_qualified(const char *, char *, char *)
Check if map name is fully qualified (map @ mapset)
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
const char * G_mapset(void)
Get current mapset name.
void G_trim_decimal(char *)
Removes trailing zeros from decimal number.
int G_remove(const char *, const char *)
Remove a database file.
FILE * G_fopen_new(const char *, const char *)
Open a new database file.
int Rast_get_c_color(const CELL *, int *, int *, int *, struct Colors *)
Gets color from raster map (CELL)
void Rast__write_colors(FILE *fd, struct Colors *colors)
Write map layer color table.
void Rast_write_colors(const char *name, const char *mapset, struct Colors *colors)
Write map layer color table.
struct _Color_Info_ fixed
struct _Color_Info_ modular
struct _Color_Info_::@3 lookup
struct _Color_Rule_ * rules
struct _Color_Rule_ * prev
struct _Color_Rule_ * next
struct _Color_Value_ low high