[GRASS-dev] problem with Rast_get_c_color()

Glynn Clements glynn at gclements.plus.com
Tue Aug 16 04:31:57 EDT 2011


Martin Landa wrote:

> when I define
> 
> Rast_make_colors(colors, "ryg", (CELL) 1, (CELL) 2);
> val = 3;
> 
> fn
> 
> Rast_get_c_color((const CELL *) &val, &red, &grn, &blu, colors)
> 
> returns 1 (color rule defined). I would expect no color rules defined
> (return code 0) or am I wrong?

It's a bug in Rast__lookup_colors(), a combination of:

	226    max = (CELL) dmax + 1;
and:
	313	    if (cat >= min && cat <= max) {

Either the +1 should be present, or the comparison should use <=, but
not both.

Either change line 226 should to:

    max = (CELL) dmax;

or change line 313 to:

	    if (cat >= min && cat < max) {

I suspect that it hasn't been noticed before because the colour table
for a map usually[1] covers the range of the map's data, so
out-of-range lookups don't normally occur (and this only affects the
specific case where it's off by one).

[1] It should be "always", but I wouldn't bet my life on it.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list