color range and palette format - hexadecimal

* RGB triplets may now be specified as a 6-digit hexadecimal number
  instead of three comma-separated integers, e.g. white="FFFFFF"

* This method should be cleaner to read and easier to use.with art programs

* Note: each hexadecimal number must be exactly 6 characters long,
  otherwise it will be interpreted as the beginning of an integer
  triplet. (This means the old method is still supported.)

* Some color_palette definitions in team-colors.cfg still need to be updated
This commit is contained in:
Patrick Parker 2006-11-20 09:54:47 +00:00
parent ae009c8b6c
commit 5072c971a1
2 changed files with 36 additions and 27 deletions

View file

@ -1,54 +1,54 @@
[color_range]
id=1
rgb=255,0,0,255,255,255,0,0,0,255,0,0
rgb=FF0000,FFFFFF,000000,FF0000
name= _ "Red"
[/color_range]
[color_range]
id=2
rgb=46,65,155,255,255,255,15,15,15,0,0,255
rgb=2E419B,FFFFFF,0F0F0F,0000FF
name= _ "Blue"
[/color_range]
[color_range]
id=3
rgb=98,182,100,255,255,255,0,0,0,0,255,0
rgb=62B664,FFFFFF,000000,00FF00
name= _ "Green"
[/color_range]
[color_range]
id=4
rgb=147,0,157,255,255,255,0,0,0,255,0,255
rgb=93009D,FFFFFF,000000,FF00FF
name= _ "Purple"
[/color_range]
[color_range]
id=7
rgb=240,114,0,240,240,240,0,0,0,255,170,0
rgb=F07200,F0F0F0,000000,FFAA00
name= _ "Orange"
[/color_range]
[color_range]
id=5
rgb=90,90,90,255,255,255,0,0,0,0,0,0
rgb=5A5A5A,FFFFFF,000000,000000
name= _ "Black"
[/color_range]
[color_range]
id=8
rgb=225,225,225,255,255,255,30,30,30,255,255,255
rgb=E1E1E1,FFFFFF,1E1E1E,FFFFFF
name= _ "White"
[/color_range]
[color_range]
id=6
rgb=148,80,39,255,255,255,0,0,0,170,70,0
rgb=945027,FFFFFF,000000,AA4600
name= _ "Brown"
[/color_range]
[color_range]
id=9
rgb=48,203,192,255,255,255,0,0,0,0,240,200
rgb=30CBC0,FFFFFF,000000,00F0C8
name= _ "Teal"
[/color_range]

View file

@ -82,26 +82,35 @@ std::map<Uint32, Uint32> recolor_range(const color_range& new_range, const std::
}
std::vector<Uint32> string2rgb(std::string s){
std::vector<Uint32> out;
std::vector<std::string> rgb_vec = utils::split(s);
std::vector<Uint32> out;
std::vector<std::string> rgb_vec = utils::split(s);
while(rgb_vec.size()%3) {
rgb_vec.push_back("0");
}
std::vector<std::string>::iterator c=rgb_vec.begin();
int r,g,b;
while(c!=rgb_vec.end()){
r = (lexical_cast<int>(*c));
c++;
g = (lexical_cast<int>(*c));
c++;
b=(lexical_cast<int>(*c));
c++;
out.push_back((Uint32) ((r<<16 & 0x00FF0000) + (g<<8 & 0x0000FF00) + (b & 0x000000FF)));
}
return(out);
std::vector<std::string>::iterator c=rgb_vec.begin();
while(c!=rgb_vec.end()){
Uint32 rgb_hex;
if(c->length() != 6)
{
//integer triplets, e.g. white="255,255,255"
while(c + 3 > rgb_vec.end())
{
rgb_vec.push_back("0");
}
rgb_hex = (0x00FF0000 & ((lexical_cast<int>(*c++))<<16)); //red
rgb_hex += (0x0000FF00 & ((lexical_cast<int>(*c++))<<8)); //green
rgb_hex += (0x000000FF & ((lexical_cast<int>(*c++))<<0)); //blue
} else {
//hexadecimal format, e.g. white="FFFFFF"
char* endptr;
rgb_hex = (0x00FFFFFF & strtol(c->c_str(), &endptr, 16));
if (*endptr != '\0') {
throw bad_lexical_cast();
}
c++;
}
out.push_back(rgb_hex);
}
return(out);
}
std::vector<Uint32> palette(color_range cr){