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) {
93 strcpy(element,
"colr");
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);
204 fprintf(fd,
"%d %d %d\n",
209 fprintf(fd,
"255 255 255\n");
213 for (i = 0; i < n; i++) {
217 fprintf(fd,
" %d %d",
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);
244 static void format_min(
char *str,
double dval)
248 sprintf(str,
"%.17g", dval);
251 sscanf(str,
"%lf", &dtmp);
262 static void format_max(
char *str,
double dval)
266 sprintf(str,
"%.17g", dval);
269 sscanf(str,
"%lf", &dtmp);
struct _Color_Info_ fixed
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int G_remove(const char *, const char *)
Remove a database file.
struct _Color_Value_ low high
struct _Color_Rule_ * next
void Rast_write_colors(const char *name, const char *mapset, struct Colors *colors)
Write map layer color table.
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)
const char * G_mapset(void)
Get current mapset name.
void Rast__write_colors(FILE *fd, struct Colors *colors)
Write map layer color table.
struct _Color_Info_::@3 lookup
struct _Color_Info_ modular
int G_name_is_fully_qualified(const char *, char *, char *)
Check if map name is fully qualified (map @ mapset)
struct _Color_Rule_ * prev
struct _Color_Rule_ * rules
void G_trim_decimal(char *)
Removes trailing zeros from decimal number.