[GRASS5] confused by lib fns

Glynn Clements glynn at gclements.plus.com
Sat Oct 8 05:46:30 EDT 2005


Hamish wrote:

> while trying to fix the broken d.rast.num "-f", I am running into two
> (possible) gis lib bugs in lib/gis/color_get.c.
> 
> 1) G_get_raster_color() should just be G_get_color() updated to handle
>    FP raster maps, ie you can specify map_type. You should be able to
>    feed the fn a value and a color table and it will return R,G,B values.

Can you clarify?

>    But G_get_raster_color() seems confused .. it takes a raster array?!
>    This conflicts with the Doxygen comment? or at least is misleading.

No, it takes a pointer to a single value. The value can be either
CELL, FCELL or DCELL, depending upon the map_type argument, so you
can't pass it directly.

>    Also flows through to color_look.c's G_lookup_raster_colors() and
>    G__lookup_colors(), also conflicting with Doxygen comments?

G_get_c_raster_color()'s comment is inaccurate. The function has the
same effect as the stated G_get_color() call, but doesn't actually
call it.

>    lib/display/raster_rgb.c and ps/ps.map/ps_raster.c use it, so I won't
>    say that it is completly broken, but it is confusing and I can't get 
>    it to return real values for R,G,B. see number.c in CVS (&cell[col]).
>    Do I need to G_alloc() a cell array first or something?

No.

>    To get `d.rast.num -f` to work currently I need to cast to CELL then 
>    run G_get_color(). :/

	G_get_raster_color(cell[col], &R, &G, &B, &colors, inmap_type);

should be:

	G_get_raster_color(&cell[col], &R, &G, &B, &colors, map_type);

The first argument needs to be a pointer to the value, and the last
argument should reflect the actual type of the data (i.e. it should be
map_type rather than inmap_type).

> 2) All fn's in color_get.c have R,G,B as int,

Pointer to int.

> but lib/raster/RGB_color.c
>    wants unsigned char. You can't access & set the display color without
>    the compiler doing a cast.  gis.h likes unsigned char.
>    Should color_get.c be changed to use unsigned char?

RGB_color.c isn't the only user of that function; most of the callers
use ints.

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




More information about the grass-dev mailing list