[GRASS-dev] problem with r.colors on Mac

Glynn Clements glynn at gclements.plus.com
Thu Apr 12 17:53:20 EDT 2007

Glynn Clements wrote:

> Beyond that, I'd like to propose eliminating most of the individual
> G_make_*_colors() functions in favour of a general purpose function
> which takes the name of a rules file as an argument.

I've done this, and would appreciate it if the changes could receive
some testing.

The core of r.colors' color=rules and rules= options is now in
lib/gis/color_rules.c. Apart from the lower-level functions used by
r.colors, this provides two new functions:

int G_make_colors(struct Colors *colors, const char *name, CELL min, CELL max);
int G_make_fp_colors(struct Colors *colors, const char *name, DCELL min, DCELL max);

These effectively supersede most of the G_make_*_[fp_]colors()
functions, i.e.:


plus the _fp_ versions.

A call such as:

	G_make_rainbow_colors(&colors, min, max);

can be replaced with:

	G_make_colors(&colors, "rainbow", min, max);

The following functions don't have direct equivalents:


The first two can be replaced with a combination of
G_make_colors(&colors, "grey", ...) and either G_histogram_eq_colors()
or G_log_colors(), e.g.:

	G_make_colors(&colors, "grey", min, max);
	G_histogram_eq_colors(&colors_tmp, &colors, &statf);
	colors = colors_tmp;
	G_make_colors(&colors, "grey", min, max);
	G_log_colors(&colors_tmp, &colors, 100);
	colors = colors_tmp;

[I will modify G_{histogram_eq,log}_colors to allow the colour table
to be updated in-place, to avoid the need for a temporary variable.]

G_make_random_colors() cannot be implemented by means of colour rules,
and so will remain.

The corresponding changes to r.colors are:

1. "r.colors color=rules" is implemented using the lower level functions
G_read_color_rules(), G_parse_color_rule() etc, with r.colors itself
handling terminal interaction.

2. "r.colors rules=" just calls G_make_fp_colors() with the specified
rule name.

Also, the rules files have been moved to the lib/gis/color directory.

The next step is to replace the various G_make_*_[fp_]colors()
functions with wrappers around G_make_[fp_]colors(). Unless that shows
up any problems, I'll replace the use of G_make_*_[fp_]colors() with
direct calls to G_make_[fp_]colors(), and merge the rules= and color=
options in r.colors.

Glynn Clements <glynn at gclements.plus.com>

More information about the grass-dev mailing list