45 #ifdef CHECK_MEMORY_LEAKS
47 #endif // CHECK_MEMORY_LEAKS
71 : myRed(0), myGreen(0), myBlue(0), myAlpha(0) {}
74 RGBColor::RGBColor(
unsigned char red,
unsigned char green,
unsigned char blue,
unsigned char alpha)
75 : myRed(red), myGreen(green), myBlue(blue), myAlpha(alpha) {}
79 : myRed(col.myRed), myGreen(col.myGreen), myBlue(col.myBlue), myAlpha(col.myAlpha) {}
86 RGBColor::set(
unsigned char r,
unsigned char g,
unsigned char b,
unsigned char a) {
96 if (col == RGBColor::RED) {
99 if (col == RGBColor::GREEN) {
100 return os <<
"green";
102 if (col == RGBColor::BLUE) {
105 if (col == RGBColor::YELLOW) {
106 return os <<
"yellow";
108 if (col == RGBColor::CYAN) {
111 if (col == RGBColor::MAGENTA) {
112 return os <<
"magenta";
114 if (col == RGBColor::WHITE) {
115 return os <<
"white";
117 if (col == RGBColor::BLACK) {
118 return os <<
"black";
120 if (col == RGBColor::GREY) {
123 os << static_cast<int>(col.
myRed) <<
","
124 << static_cast<int>(col.
myGreen) <<
","
125 <<
static_cast<int>(col.
myBlue);
127 os <<
"," <<
static_cast<int>(col.
myAlpha);
147 const unsigned char red = (
unsigned char)(
MIN2(
MAX2(
myRed + change, 0), 255));
152 if (changed == toChange * change) {
154 }
else if (changed == 0) {
157 const int maxedColors = (red !=
myRed + change ? 1 : 0) + (blue != myBlue + change ? 1 : 0) + (green !=
myGreen + change ? 1 : 0);
158 if (maxedColors == 3) {
161 const int toChangeNext = 3 - maxedColors;
162 return result.
changedBrightness((
int)((toChange * change - changed) / toChangeNext), toChangeNext);
169 std::transform(coldef.begin(), coldef.end(), coldef.begin(), tolower);
170 if (coldef ==
"red") {
173 if (coldef ==
"green") {
176 if (coldef ==
"blue") {
179 if (coldef ==
"yellow") {
182 if (coldef ==
"cyan") {
185 if (coldef ==
"magenta") {
188 if (coldef ==
"white") {
191 if (coldef ==
"black") {
194 if (coldef ==
"grey" || coldef ==
"gray") {
200 unsigned char a = 255;
201 if (coldef[0] ==
'#') {
203 if (coldef.length() == 7) {
204 r =
static_cast<unsigned char>((coldesc & 0xFF0000) >> 16);
205 g =
static_cast<unsigned char>((coldesc & 0x00FF00) >> 8);
207 }
else if (coldef.length() == 9) {
208 r =
static_cast<unsigned char>((coldesc & 0xFF000000) >> 24);
209 g =
static_cast<unsigned char>((coldesc & 0x00FF0000) >> 16);
210 b =
static_cast<unsigned char>((coldesc & 0x0000FF00) >> 8);
217 if (st.size() == 3 || st.size() == 4) {
222 if (st.size() == 4) {
225 if (r <= 1 && g <= 1 && b <= 1 && (st.size() == 3 || a <= 1)) {
232 if (st.size() == 4) {
246 const std::string& coldef,
const std::string& objecttype,
247 const char* objectid,
bool report,
bool& ok) {
255 std::ostringstream oss;
256 oss <<
"Attribute 'color' in definition of ";
262 oss <<
" '" << objectid <<
"'";
264 oss <<
" is not a valid color.";
278 const unsigned char r = minColor.
myRed +
static_cast<char>((maxColor.
myRed - minColor.
myRed) * weight);
279 const unsigned char g = minColor.
myGreen +
static_cast<char>((maxColor.
myGreen - minColor.
myGreen) * weight);
280 const unsigned char b = minColor.
myBlue +
static_cast<char>((maxColor.
myBlue - minColor.
myBlue) * weight);
281 const unsigned char a = minColor.
myAlpha +
static_cast<char>((maxColor.
myAlpha - minColor.
myAlpha) * weight);
300 const unsigned char m =
static_cast<unsigned char>(v * (1 - s) * 255. + 0.5);
301 const unsigned char n =
static_cast<unsigned char>(v * (1 - s * f) * 255. + 0.5);
302 const unsigned char vv =
static_cast<unsigned char>(v * 255. + 0.5);
318 return RGBColor(255, 255, 255, 255);
static int _hex2int(const E *const data)
static const RGBColor BLUE
static RGBColor parseColor(std::string coldef)
Parses a color information.
static RGBColor fromHSV(SUMOReal h, SUMOReal s, SUMOReal v)
Converts the given hsv-triplet to rgb.
static SUMOReal _2SUMOReal(const E *const data)
static const RGBColor WHITE
static RGBColor parseColorReporting(const std::string &coldef, const std::string &objecttype, const char *objectid, bool report, bool &ok)
Parses a color information.
bool operator==(const RGBColor &c) const
static RGBColor interpolate(const RGBColor &minColor, const RGBColor &maxColor, SUMOReal weight)
Interpolates between two colors.
static const RGBColor BLACK
#define UNUSED_PARAMETER(x)
unsigned char blue() const
Returns the blue-amount of the color.
bool operator!=(const RGBColor &c) const
static const RGBColor GREEN
static const RGBColor GREY
unsigned char myRed
The color amounts.
void set(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
assigns new values
static const RGBColor DEFAULT_COLOR
The default color (for vehicle types and vehicles)
std::ostream & operator<<(std::ostream &os, const RGBColor &col)
static const RGBColor MAGENTA
RGBColor changedBrightness(int change, int toChange=3) const
Returns a new color with altered brightness.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
std::vector< std::string > getVector()
static const RGBColor YELLOW
static int _2int(const E *const data)
static const RGBColor RED
static const RGBColor CYAN
unsigned char green() const
Returns the green-amount of the color.
unsigned char red() const
Returns the red-amount of the color.
static const std::string DEFAULT_COLOR_STRING
The string description of the default color.