[GRASSLIST:5492] Re: hexadecimal color codes

Hamish hamish_nospam at yahoo.com
Sun Jan 23 20:08:57 EST 2005


> Can anyone tell me if GRASS can deal with hexadecimal color codes 
> (something like 0100FFAA)? I have a ascii vector file that contains 
> hexadecimal color codes for the lines and polygons. I am writing a 
> small program that converts that ascii vector file (which was output 
> from another gis package) into the v.in.ascii format, and I wonder if
> I can retain that information.


You probably want to transform it into a GRASS RBG column that
'd.vect -a' can use?

see
  http://grass.ibiblio.org/grass60/manuals/html60_user/d.vect.html


GRASS generally uses 0-255 instead of 00-FF for red:green:blue

0  00
1  01
2  02
3  03
4  04
5  05
6  06
7  07
8  08
9  09
10 0a
11 0b
12 0c
13 0d
14 0e
15 0f
16 10
17 11
...
254 fe
255 ff

so:

RRGGBB -> RRR:GGG:BBB

000000 is 0:0:0 is black

FFFFFF is 255:255:255 is white

FF0000 is 255:0:0 is red

etc. sometimes the hex version is shown with a "0x" in front of it, e.g.
0xFFFFFF.


maybe an awk expert can give a shell script version of this C code to do
the translation:

int r,g,b;
sscanf(color, "0x%02x%02x%02x", &r, &g, &b);
printf("%03d:%03d":%03d\n", r, g, b);



> (something like 0100FFAA)? 

if that is correct, the last pair ("AA") might be the alpha channel
(transparency) level? GRASS doesn't support that, but hopefully it
doesn't change in your data.

so that example would be 1:0:255   (after throwing away "AA")


n.b. It isn't advertised or recommended, but d.text.freetype will take
hex colors for its color options in addition to the usual 255:255:255
convention.



Hamish




More information about the grass-user mailing list