31 std::map<Uint32, Uint32> map_rgb;
33 Uint16 new_red = (new_range.
mid() & 0x00FF0000)>>16;
34 Uint16 new_green= (new_range.
mid() & 0x0000FF00)>>8;
35 Uint16 new_blue = (new_range.
mid() & 0x000000FF);
36 Uint16 max_red = (new_range.
max() & 0x00FF0000)>>16;
37 Uint16 max_green= (new_range.
max() & 0x0000FF00)>>8 ;
38 Uint16 max_blue = (new_range.
max() & 0x000000FF) ;
39 Uint16 min_red = (new_range.
min() & 0x00FF0000)>>16;
40 Uint16 min_green= (new_range.
min() & 0x0000FF00)>>8 ;
41 Uint16 min_blue = (new_range.
min() & 0x000000FF) ;
44 Uint32 temp_rgb= old_rgb.empty() ? 0 : old_rgb[0];
45 Uint16 old_r=(temp_rgb & 0X00FF0000)>>16;
46 Uint16 old_g=(temp_rgb & 0X0000FF00)>>8;
47 Uint16 old_b=(temp_rgb & 0X000000FF);
48 Uint16 reference_avg = (( old_r + old_g + old_b) / 3);
50 for(std::vector< Uint32 >::const_iterator temp_rgb2 = old_rgb.begin();
51 temp_rgb2 != old_rgb.end(); ++temp_rgb2)
53 Uint16 old_r=((*temp_rgb2) & 0X00FF0000)>>16;
54 Uint16 old_g=((*temp_rgb2) & 0X0000FF00)>>8;
55 Uint16 old_b=((*temp_rgb2) & 0X000000FF);
57 const Uint16 old_avg = (( old_r + old_g + old_b) / 3);
59 Uint32 new_r, new_g, new_b;
61 if(reference_avg && old_avg <= reference_avg){
62 float old_rat =
static_cast<float>(old_avg)/reference_avg;
63 new_r=Uint32( old_rat * new_red + (1 - old_rat) * min_red);
64 new_g=Uint32( old_rat * new_green + (1 - old_rat) * min_green);
65 new_b=Uint32( old_rat * new_blue + (1 - old_rat) * min_blue);
66 }
else if(255 - reference_avg){
67 float old_rat = (255.0f -
static_cast<float>(old_avg)) /
68 (255.0f - reference_avg);
70 new_r=
static_cast<Uint32
>( old_rat * new_red + (1 - old_rat) * max_red);
71 new_g=
static_cast<Uint32
>( old_rat * new_green + (1 - old_rat) * max_green);
72 new_b=
static_cast<Uint32
>( old_rat * new_blue + (1 - old_rat) * max_blue);
74 new_r=0; new_g=0; new_b=0;
80 if(new_r>255) new_r=255;
81 if(new_g>255) new_g=255;
82 if(new_b>255) new_b=255;
84 Uint32 newrgb = (new_r << 16) + (new_g << 8) + (new_b );
85 map_rgb[*temp_rgb2]=newrgb;
92 result = std::vector<Uint32>();
93 std::vector<Uint32> out;
96 while(c!=rgb_vec.end())
103 rgb_hex = (0x00FF0000 & ((
lexical_cast<
int>(*c++))<<16));
106 rgb_hex += (0x0000FF00 & ((
lexical_cast<
int>(*c++))<<8));
109 rgb_hex += (0x000000FF & ((
lexical_cast<
int>(*c++))<<0));
118 rgb_hex = (0x00FFFFFF & strtol(c->c_str(), &endptr, 16));
119 if (*endptr !=
'\0') {
124 out.push_back(rgb_hex);
132 std::vector<Uint32> temp,
res;
133 std::set<Uint32> clist;
135 for(
int i=255;
i!=0;
i--){
139 rgb = (j << 16) + (j << 8) + 255;
147 for(std::map<Uint32,Uint32>::const_iterator k=cmap.begin(); k!=cmap.end();++k){
148 clist.insert(k->second);
150 res.push_back(cmap[255]);
151 for(std::set<Uint32>::const_iterator
c=clist.begin();
c!=clist.end();++
c){
152 if(*
c != res[0] && *
c!=0 && *
c != 0x00FFFFFF){
160 std::ostringstream
h;
162 h <<
"<" << ((rgb & 0xFF0000) >> 16)
163 <<
"," << ((rgb & 0x00FF00) >> 8)
164 <<
"," << (rgb & 0x0000FF) <<
">";
170 std::ostringstream
h;
172 h <<
"#" << std::hex << std::setfill('0') << std::setw(2) << ((rgb & 0xFF0000) >> 16)
173 << std::hex << std::setfill(
'0') << std::setw(2) <<((rgb & 0x00FF00) >> 8)
174 << std::hex << std::setfill(
'0') << std::setw(2) <<(rgb & 0x0000FF);
190 std::ostringstream o;
192 static const Uint32
mask = 0x00FFFFFF;
194 o << std::hex << std::setfill(
'0')
195 <<
'{' << std::setw(6) << (
mid_ &
mask)
196 <<
',' << std::setw(6) << (
max_ &
mask)
197 <<
',' << std::setw(6) << (
min_ &
mask)
198 <<
',' << std::setw(6) << (
rep_ &
mask)
std::string debug() const
Return a string describing the color range for debug output.
Uint32 mid() const
Average color shade.
bool string2rgb(const std::string &s, std::vector< Uint32 > &result)
To lexical_cast(From value)
Lexical cast converts one type to another.
Templates and utility-routines for strings and numbers.
A color range definition is made of four reference RGB colors, used for calculating conversions from ...
const color_range & color_info(const std::string &name)
Uint32 min() const
Minimum color shade.
std::map< Uint32, Uint32 > recolor_range(const color_range &new_range, const std::vector< Uint32 > &old_rgb)
Converts a source palette using the specified color_range object.
std::string rgb2highlight(Uint32 rgb)
Converts a color value to WML text markup syntax for highlighting.
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
std::string rgb2highlight_pango(Uint32 rgb)
Converts a color value to WML text markup syntax for highlighting.
Thrown when a lexical_cast fails.
std::vector< Uint32 > palette(color_range cr)
Creates a reference color palette from a color range.
GLsizei const GLcharARB ** string
Uint32 max() const
Maximum color shade.