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);
29 #define FORMAT_STR_SZ 100
82 if (strcmp(xmapset, mapset) != 0)
93 if (strcmp(mapset,
G_mapset()) == 0) {
113 if (getenv(
"FORCE_GRASS3_COLORS"))
114 forced_write_old_colors(fd, colors);
116 write_old_colors(fd, colors);
118 write_new_colors(fd, colors);
121 static void write_new_colors(FILE *fd,
struct Colors *colors)
123 char str1[100], str2[100];
125 format_min(str1, (
double)colors->
cmin);
126 format_max(str2, (
double)colors->
cmax);
127 fprintf(fd,
"%% %s %s\n", str1, str2);
130 snprintf(str2,
sizeof(str2),
"%.17g", (
double)colors->
shift);
132 fprintf(fd,
"shift:%s\n", str2);
135 fprintf(fd,
"invert\n");
138 fprintf(fd,
"nv:%d", colors->
null_red);
152 fprintf(fd,
"%s\n",
"%%");
154 fprintf(fd,
"%s\n",
"%%");
173 for (; rule; rule = rule->
prev) {
174 if (rule->low.value == dmin)
175 format_min(str, (
double)rule->low.value);
177 snprintf(str,
FORMAT_STR_SZ,
"%.17g", (
double)rule->low.value);
180 fprintf(fd,
"%s:%d", str, (
int)rule->low.red);
181 if (rule->low.red != rule->low.grn || rule->low.red != rule->low.blu)
182 fprintf(fd,
":%d:%d", rule->low.grn, rule->low.blu);
186 format_max(str, (
double)rule->
high.
value);
191 fprintf(fd,
" %s:%d", str, (
int)rule->
high.
red);
200 static void write_old_colors(FILE *fd,
struct Colors *colors)
204 fprintf(fd,
"#%ld first color\n", (
long)colors->
fixed.
min);
210 fprintf(fd,
"255 255 255\n");
214 for (i = 0; i < n; i++) {
224 static void forced_write_old_colors(FILE *fd,
struct Colors *colors)
229 fprintf(fd,
"#%ld first color\n", (
long)colors->
cmin);
232 fprintf(fd,
"%d %d %d\n", red, grn, blu);
234 for (cat = colors->
cmin; cat <= colors->cmax; cat++) {
236 fprintf(fd,
"%d", red);
237 if (red != grn || red != blu)
238 fprintf(fd,
" %d %d", grn, blu);
243 static void format_min(
char *str,
double dval)
250 sscanf(str,
"%lf", &dtmp);
260 static void format_max(
char *str,
double dval)
267 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