[GRASS5] color table

Glynn Clements glynn.clements at virgin.net
Mon Aug 25 20:52:00 EDT 2003


Radim Blazek wrote:

> Bug?:

Yep. In libgis.

> r.mapcalc pok1=-6.0
> echo -e "-10.1 green\n-5 green\n-5 blue\n10 blue" | r.colors map=pok1 color=rules
> r.mapcalc pok2="int(pok1)"
> r.colors map=pok2 rast=pok1
> d.rast map=pok2 ---> blue!!!

It's due to an inconsistency in the convertion of negative FP values
to integers. organize_lookup() in color_org.c simply truncates:

  121:    x = (CELL ) cp->min;


while G__lookup_colors() in color_look.c uses floor():

  156:    dmin = cp->min;
  157:    dmax = cp->max;
  158:    min = floor(dmin);

Truncating rounds towards zero, while floor() rounds downwards
(towards minus infinity), so if cp->min is -10.1, truncating gives -10
while floor gives -11. This causes lookups in cp->lookup.{red,grn,blu}
to be off by one.

Try the attached patch.

-- 
Glynn Clements <glynn.clements at virgin.net>

-------------- next part --------------
--- color_look.c~	Tue Jan 22 04:51:10 2002
+++ color_look.c	Tue Aug 26 01:49:50 2003
@@ -155,8 +155,8 @@
     /* we want min, max for cp, not min, max overall */
     dmin = cp->min;
     dmax = cp->max;
-    min = floor(dmin);
-    max = ceil(dmax);
+    min = (CELL) dmin;
+    max = (CELL) dmax + 1;
 
     cell_type = (data_type == CELL_TYPE);
 


More information about the grass-dev mailing list