[GRASS-dev] lib fn to convert int color number to RGB values?

Glynn Clements glynn at gclements.plus.com
Thu Jan 31 05:12:28 EST 2008


Hamish wrote:

> > > Is a new D_number_to_RGB(int color, unsigned char &r,&g,&b) fn
> > > needed in lib/display/tran_colr.c?
> Glynn:
> > Yes. E.g.:
> > 
> > int D_color_number_to_RGB(int color, int *r, int *g, int *b)
> > {
> >     const struct color_rgb *c;
> > 
> >     if (color <= 0)
> >         return 0;
> > 
> >     if (color >= ncolors)
> >         return 0;
> > 
> >     c = &colors[color];
> >     r = c->r;
> >     g = c->g;
> >     b = c->b;
> > 
> >     return 1;
> > }
> 
> there is a problem: for some reason ncolors's value is 0 so the fn
> always returns 0.

It also needs:

	if (color < G_num_standard_colors())
	{
		struct color_rgb col = G_standard_color_rgb(color);
		*r = col.r;
		*g = col.g;
		*b = col.b;
	}

These colours are stored in the table, but only when the first "r:g:b"
colour is added.

Alternatively, you could modify translate_or_add_color() to always
create the table, by removing the lines:

    preallocated = D_translate_color(lowerstr);
    if (preallocated)
	return preallocated;

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


More information about the grass-dev mailing list